2023-01-15 19:07:41 +13:00
|
|
|
defmodule AshJsonApiWrapper.Paginator.ContinuationProperty do
|
|
|
|
use AshJsonApiWrapper.Paginator
|
|
|
|
|
2023-07-01 07:21:45 +12:00
|
|
|
def continue(_response, [], _), do: :halt
|
2023-01-15 19:07:41 +13:00
|
|
|
|
2023-07-01 07:21:45 +12:00
|
|
|
def continue(response, _entities, opts) do
|
2023-01-15 19:07:41 +13:00
|
|
|
case ExJSONPath.eval(response, opts[:get]) do
|
|
|
|
{:ok, [value | _]} when not is_nil(value) ->
|
|
|
|
if opts[:header] do
|
|
|
|
{:ok, %{headers: %{opts[:header] => value}}}
|
|
|
|
else
|
|
|
|
if opts[:param] do
|
|
|
|
{:ok,
|
|
|
|
%{params: AshJsonApiWrapper.Helpers.put_at_path(%{}, List.wrap(opts[:param]), value)}}
|
|
|
|
else
|
|
|
|
:halt
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
_ ->
|
|
|
|
:halt
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|