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