-module(tallgrass@client). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). -export([new/0, cache/1, pagination/1, with_cache/2, with_pagination/2, next/2, previous/2, fetch_resource/3, fetch_by_id/4, fetch_by_name/4, fetch_resources/2]). -export_type([client/0, pagination_options/0]). -opaque client() :: {client, pagination_options(), gleam@option:option(tallgrass@client@cache:cache())}. -type pagination_options() :: default | {limit, integer()} | {offset, integer()} | {paginate, integer(), integer()}. -file("/Users/stevetoro/Code/tallgrass/src/tallgrass/client.gleam", 18). -spec new() -> client(). new() -> {client, default, none}. -file("/Users/stevetoro/Code/tallgrass/src/tallgrass/client.gleam", 23). -spec cache(client()) -> gleam@option:option(tallgrass@client@cache:cache()). cache(Client) -> erlang:element(3, Client). -file("/Users/stevetoro/Code/tallgrass/src/tallgrass/client.gleam", 28). -spec pagination(client()) -> pagination_options(). pagination(Client) -> erlang:element(2, Client). -file("/Users/stevetoro/Code/tallgrass/src/tallgrass/client.gleam", 33). -spec with_cache(client(), tallgrass@client@cache:cache()) -> client(). with_cache(Client, Cache) -> erlang:setelement(3, Client, {some, Cache}). -file("/Users/stevetoro/Code/tallgrass/src/tallgrass/client.gleam", 38). -spec with_pagination(client(), pagination_options()) -> client(). with_pagination(Client, Pagination) -> erlang:setelement(2, Client, Pagination). -file("/Users/stevetoro/Code/tallgrass/src/tallgrass/client.gleam", 74). -spec next(client(), tallgrass@common@resource:paginated_resource()) -> {ok, tallgrass@common@resource:paginated_resource()} | {error, tallgrass@client@request:error()}. next(Client, Page) -> tallgrass@client@request:next( erlang:element(3, Page), tallgrass@common@resource:paginated_resource(), begin _pipe = Client, cache(_pipe) end ). -file("/Users/stevetoro/Code/tallgrass/src/tallgrass/client.gleam", 87). -spec previous(client(), tallgrass@common@resource:paginated_resource()) -> {ok, tallgrass@common@resource:paginated_resource()} | {error, tallgrass@client@request:error()}. previous(Client, Page) -> tallgrass@client@request:previous( erlang:element(4, Page), tallgrass@common@resource:paginated_resource(), begin _pipe = Client, cache(_pipe) end ). -file("/Users/stevetoro/Code/tallgrass/src/tallgrass/client.gleam", 119). -spec fetch_resource( client(), tallgrass@common@resource:resource(), decode:decoder(KFW) ) -> {ok, KFW} | {error, tallgrass@client@request:error()}. fetch_resource(Client, Resource, Decoder) -> tallgrass@client@request:get_url( erlang:element(2, Resource), Decoder, begin _pipe = Client, cache(_pipe) end ). -file("/Users/stevetoro/Code/tallgrass/src/tallgrass/client.gleam", 123). -spec path_from(gleam@option:option(binary()), binary()) -> binary(). path_from(Resource, Path) -> Split_path = begin _pipe = Path, gleam@string:split(_pipe, <<","/utf8>>) end, case {Resource, Split_path} of {{some, R}, [P | Rest]} -> _pipe@1 = [P, R | Rest], gleam@string:join(_pipe@1, <<"/"/utf8>>); {{some, R@1}, _} -> <<<>/binary, R@1/binary>>; {none, _} -> _pipe@2 = Split_path, gleam@string:join(_pipe@2, <<"/"/utf8>>) end. -file("/Users/stevetoro/Code/tallgrass/src/tallgrass/client.gleam", 92). -spec fetch_by_id(client(), binary(), integer(), decode:decoder(KFP)) -> {ok, KFP} | {error, tallgrass@client@request:error()}. fetch_by_id(Client, Path, Id, Decoder) -> Path@1 = path_from( {some, begin _pipe = Id, gleam@int:to_string(_pipe) end}, Path ), tallgrass@client@request:get( Path@1, [], Decoder, begin _pipe@1 = Client, cache(_pipe@1) end ). -file("/Users/stevetoro/Code/tallgrass/src/tallgrass/client.gleam", 98). -spec fetch_by_name(client(), binary(), binary(), decode:decoder(KFS)) -> {ok, KFS} | {error, tallgrass@client@request:error()}. fetch_by_name(Client, Path, Name, Decoder) -> Path@1 = path_from({some, Name}, Path), tallgrass@client@request:get( Path@1, [], Decoder, begin _pipe = Client, cache(_pipe) end ). -file("/Users/stevetoro/Code/tallgrass/src/tallgrass/client.gleam", 132). -spec 'query'(pagination_options()) -> list({binary(), binary()}). 'query'(Options) -> case Options of default -> []; {limit, Limit} -> [{<<"limit"/utf8>>, begin _pipe = Limit, gleam@int:to_string(_pipe) end}]; {offset, Offset} -> [{<<"offset"/utf8>>, begin _pipe@1 = Offset, gleam@int:to_string(_pipe@1) end}]; {paginate, Limit@1, Offset@1} -> [{<<"limit"/utf8>>, begin _pipe@2 = Limit@1, gleam@int:to_string(_pipe@2) end}, {<<"offset"/utf8>>, begin _pipe@3 = Offset@1, gleam@int:to_string(_pipe@3) end}] end. -file("/Users/stevetoro/Code/tallgrass/src/tallgrass/client.gleam", 109). -spec fetch_resources(client(), binary()) -> {ok, tallgrass@common@resource:paginated_resource()} | {error, tallgrass@client@request:error()}. fetch_resources(Client, Path) -> tallgrass@client@request:get( Path, 'query'( begin _pipe = Client, pagination(_pipe) end ), tallgrass@common@resource:paginated_resource(), begin _pipe@1 = Client, cache(_pipe@1) end ).