-module(finch). -compile([no_auto_import, nowarn_unused_vars]). -export([build/2, stream/5, start_link/1, request/2]). -export_type([method/0, request_option/0, response_body_key/0, response_headers_key/0, response_status_key/0, request/0, response/0, exception/0]). -type method() :: head | get | put | post | patch | delete | options. -type request_option() :: {pool_timeout, integer()} | {request_timeout, integer()}. -type response_body_key() :: body. -type response_headers_key() :: headers. -type response_status_key() :: status. -type request() :: any(). -type response() :: any(). -type exception() :: any(). -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. -spec build(gleam@http@request:request(binary()), list(request_option())) -> request(). build(Req, Opts) -> 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), Opts ). -spec stream( request(), gleam@erlang@atom:atom_(), IYT, fun((finch@stream:stream_block(), IYT) -> IYT), list(request_option()) ) -> {ok, IYT} | {error, exception()}. stream(Field@0, Field@1, Field@2, Field@3, Field@4) -> 'Elixir.Finch':stream(Field@0, Field@1, Field@2, Field@3, Field@4). -spec start_link(list(finch@otp:instance_option())) -> finch@otp:on_start(). start_link(Field@0) -> 'Elixir.Finch':start_link(Field@0). -spec response_body(response()) -> binary(). response_body(Resp) -> 'Elixir.Map':'fetch!'(Resp, body). -spec response_status(response()) -> integer(). response_status(Resp) -> 'Elixir.Map':'fetch!'(Resp, status). -spec response_headers(response()) -> list({binary(), binary()}). response_headers(Resp) -> 'Elixir.Map':'fetch!'(Resp, headers). -spec request(request(), gleam@erlang@atom:atom_()) -> {ok, gleam@http@response:response(binary())} | {error, exception()}. request(Req, Name) -> gleam@result:then( 'Elixir.Finch':request(Req, Name), fun(Resp) -> {ok, {response, response_status(Resp), response_headers(Resp), response_body(Resp)}} end ).