Current section

Files

Jump to
go_over src go_over@hex@puller.erl
Raw

src/go_over@hex@puller.erl

-module(go_over@hex@puller).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/go_over/hex/puller.gleam").
-export([run/2]).
-export_type([puller/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(false).
-type puller() :: native | c_u_r_l | w_g_e_t | h_t_t_p_i_e | {mock, binary()}.
-file("src/go_over/hex/puller.gleam", 32).
?DOC(false).
-spec native_get(binary()) -> {ok, binary()} | {error, {integer(), binary()}}.
native_get(Url) ->
_pipe = Url,
_pipe@1 = gleam@http@request:to(_pipe),
_pipe@2 = gleam@result:replace_error(_pipe@1, response_timeout),
_pipe@3 = gleam@result:'try'(_pipe@2, fun gleam@httpc:send/1),
_pipe@4 = gleam@result:map(
_pipe@3,
fun(Resp) -> erlang:element(4, Resp) end
),
gleam@result:map_error(
_pipe@4,
fun(Err) -> {1, gleam@string:inspect(Err)} end
).
-file("src/go_over/hex/puller.gleam", 46).
?DOC(false).
-spec run(puller(), binary()) -> {ok, binary()} | {error, {integer(), binary()}}.
run(Puller, Url) ->
case Puller of
native ->
native_get(Url);
c_u_r_l ->
go_over@util@util:retry_cmd(<<"curl"/utf8>>, [<<"-sf"/utf8>>, Url]);
w_g_e_t ->
go_over@util@util:retry_cmd(<<"wget"/utf8>>, [<<"-qO-"/utf8>>, Url]);
h_t_t_p_i_e ->
go_over@util@util:retry_cmd(
<<"https"/utf8>>,
[<<"--body"/utf8>>, Url]
);
{mock, Result_filepath} ->
_pipe = simplifile:read(Result_filepath),
gleam@result:replace_error(_pipe, {1, <<"Mock Failure"/utf8>>})
end.