-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implements recently viewed records api #67
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -376,6 +376,23 @@ defmodule ExForce do | |
) | ||
end | ||
|
||
@doc """ | ||
Get recently viewed items | ||
""" | ||
@spec get_recently_viewed_items(client, limit :: integer) :: | ||
{:ok, Enumerable.t()} | {:error, any()} | ||
def get_recently_viewed_items(client, limit) do | ||
case Client.request(client, %Request{ | ||
method: :get, | ||
url: "recent/?limit=#{limit}" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
}) do | ||
{:ok, %Response{status: 200, body: []}} -> {:ok, []} | ||
{:ok, %Response{status: 200, body: body}} -> {:ok, SObject.build(body)} | ||
Comment on lines
+389
to
+390
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This introduces We can just use {:ok, %Response{status: 200, body: body}} -> {:ok, Enum.map(body, &SObject.build/1) } |
||
{:ok, %Response{body: body}} -> {:error, body} | ||
{:error, _} = other -> other | ||
end | ||
end | ||
|
||
defp stream_next({client, :halt}), do: {:halt, client} | ||
|
||
defp stream_next({client, {:error, _} = error_tuple}), do: {[error_tuple], {client, :halt}} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,12 @@ defmodule ExForce.SObject do | |
@spec build(map) :: t | ||
def build(%{"attributes" => %{}} = raw), do: do_build(raw) | ||
|
||
def build([%{"attributes" => %{"url" => _, "type" => _}, "Id" => _, "Name" => _} | _] = raw) do | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Beside it's necessary addition...
|
||
Enum.map(raw, fn val -> | ||
do_build(val) | ||
end) | ||
end | ||
|
||
defp do_build(%{"attributes" => %{"type" => type, "url" => url}} = val) do | ||
id = url |> String.split("/") |> List.last() | ||
%__MODULE__{type: type, id: id, data: do_build_data(val)} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use the same convention with other functions