-module(finch). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). -export([stream/5, start_link/1, build/1, request/3]). -export_type([method/0, request_option/0, request/0, response/0, exception/0, response_body_key/0, response_headers_key/0, response_status_key/0]). -if(?OTP_RELEASE >= 27). -define(MODULEDOC(Str), -moduledoc(Str)). -define(DOC(Str), -doc(Str)). -else. -define(MODULEDOC(Str), -compile([])). -define(DOC(Str), -compile([])). -endif. ?MODULEDOC( " Finch API wrapper module.\n" "\n" " See the [Finch documentation](https://hexdocs.pm/finch) for additional\n" " information about the functions.\n" ). -type method() :: head | get | put | post | patch | delete | options. -type request_option() :: {pool_timeout, finch@timeout:timeout_()} | {receive_timeout, finch@timeout:timeout_()} | {request_timeout, finch@timeout:timeout_()}. -type request() :: any(). -type response() :: any(). -type exception() :: any(). -type response_body_key() :: body. -type response_headers_key() :: headers. -type response_status_key() :: status. -file("src/finch.gleam", 96). ?DOC(" Stream a request using the Finch instance with the given name.\n"). -spec stream( request(), gleam@erlang@atom:atom_(), ONO, fun((finch@stream:stream_block(), ONO) -> ONO), list(request_option()) ) -> {ok, ONO} | {error, exception()}. stream(Req, Name, Acc, Fun, Opts) -> 'Elixir.Finch':stream(Req, Name, Acc, Fun, Opts). -file("src/finch.gleam", 106). ?DOC(" Start a new Finch instance with the given options.\n"). -spec start_link(list(finch@otp:instance_option())) -> finch@otp:on_start(). start_link(Opts) -> 'Elixir.Finch':start_link(Opts). -file("src/finch.gleam", 120). -spec gleam_method_to_finch_method(gleam@http:method()) -> method(). gleam_method_to_finch_method(Method) -> case Method of get -> get; head -> head; post -> post; put -> put; patch -> patch; delete -> delete; options -> options; _ -> get end. -file("src/finch.gleam", 50). ?DOC( " Build a Finch request that can be run with `request/2` or `stream/5`.\n" "\n" " Note, the HTTP methods CONNECT, TRACE, and `Other(String)` are not\n" " supported, and will be converted to GET.\n" ). -spec build(gleam@http@request:request(binary())) -> request(). build(Req) -> Url_str = begin _pipe = Req, _pipe@1 = gleam@http@request:to_uri(_pipe), gleam@uri:to_string(_pipe@1) end, 'Elixir.Finch':build( gleam_method_to_finch_method(erlang:element(2, Req)), Url_str, erlang:element(3, Req), erlang:element(4, Req) ). -file("src/finch.gleam", 108). -spec response_body(response()) -> binary(). response_body(Resp) -> 'Elixir.Map':'fetch!'(Resp, body). -file("src/finch.gleam", 116). -spec response_status(response()) -> integer(). response_status(Resp) -> 'Elixir.Map':'fetch!'(Resp, status). -file("src/finch.gleam", 112). -spec response_headers(response()) -> list({binary(), binary()}). response_headers(Resp) -> 'Elixir.Map':'fetch!'(Resp, headers). -file("src/finch.gleam", 73). ?DOC(" Send a request using the Finch instance with the given name.\n"). -spec request(request(), gleam@erlang@atom:atom_(), list(request_option())) -> {ok, gleam@http@response:response(binary())} | {error, exception()}. request(Req, Name, Opts) -> gleam@result:then( 'Elixir.Finch':request(Req, Name, Opts), fun(Resp) -> {ok, {response, response_status(Resp), response_headers(Resp), response_body(Resp)}} end ).