-module(fireball). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). -export([get_doc/5, get_file/4, post_file/5, post_file_erl/2, post_file_external/7]). -file("/export/gleam/fireball/src/fireball.gleam", 21). -spec get_doc(binary(), binary(), binary(), binary(), binary()) -> {ok, objects@document:fireball_document()} | {error, error:fireball_error()}. get_doc(Apikey, Apiver, Database, Doc, Proj_id) -> case gleam@http@request:to( <<<<<<<<<<<<<<<<<<"https://firestore.googleapis.com/"/utf8, Apiver/binary>>/binary, "/projects/"/utf8>>/binary, Proj_id/binary>>/binary, "/databases/"/utf8>>/binary, Database/binary>>/binary, "/documents/"/utf8>>/binary, Doc/binary>>/binary, "?key="/utf8>>/binary, Apikey/binary>> ) of {ok, Base_req} -> Req = begin _pipe = gleam@http@request:prepend_header( Base_req, <<"Content-type"/utf8>>, <<"application/json"/utf8>> ), gleam@http@request:set_method(_pipe, get) end, case gleam@httpc:send(Req) of {ok, Resp} -> {ok, {fireball_document, erlang:element(4, Resp), <<""/utf8>>}}; {error, _} -> {error, {fireball_error, <<"error while sending request"/utf8>>}} end; {error, _} -> {error, {fireball_error, <<"error while forming request"/utf8>>}} end. -file("/export/gleam/fireball/src/fireball.gleam", 76). -spec get_file(binary(), binary(), binary(), binary()) -> {ok, objects@storage:fireball_storage()} | {error, error:fireball_error()}. get_file(Apiver, Obj_path, Proj_id, Token) -> case gleam@http@request:to( <<<<<<<<<<<<<<"https://firebasestorage.googleapis.com/"/utf8, Apiver/binary>>/binary, "/b/"/utf8>>/binary, Proj_id/binary>>/binary, ".appspot.com/o/"/utf8>>/binary, (gleam@string:replace( Obj_path, <<"/"/utf8>>, <<"%2F"/utf8>> ))/binary>>/binary, "?alt=media&token="/utf8>>/binary, Token/binary>> ) of {ok, Base_req} -> Req = begin _pipe = gleam@http@request:prepend_header( Base_req, <<"Content-type"/utf8>>, <<"application/json"/utf8>> ), gleam@http@request:set_method(_pipe, get) end, case gleam@httpc:send(Req) of {ok, Resp} -> {ok, {fireball_storage, erlang:element(4, Resp)}}; {error, _} -> {error, {fireball_error, <<"error while sending request"/utf8>>}} end; {error, _} -> {error, {fireball_error, <<"failed to create request"/utf8>>}} end. -file("/export/gleam/fireball/src/fireball.gleam", 126). -spec post_file(binary(), binary(), binary(), binary(), binary()) -> {ok, binary()} | {error, error:fireball_error()}. post_file(Apiver, Apikey, Infile, Outfile, Proj_id) -> case gleam@http@request:to( <<<<<<<<<<"https://firestore.googleapis.com/"/utf8, Apiver/binary>>/binary, "/b/"/utf8>>/binary, Proj_id/binary>>/binary, ".appspot.com/o/"/utf8>>/binary, (gleam@string:replace(Outfile, <<"/"/utf8>>, <<"%2F"/utf8>>))/binary>> ) of {ok, Base_req} -> case simplifile_erl:read_bits(Infile) of {ok, Raw_file_data} -> File_data = gleam_stdlib:bit_array_base64_encode( Raw_file_data, true ), Req = begin _pipe = gleam@http@request:prepend_header( Base_req, <<"Content-type"/utf8>>, <<"text/plain"/utf8>> ), _pipe@1 = gleam@http@request:set_header( _pipe, <<"Authorization"/utf8>>, Apikey ), _pipe@2 = gleam@http@request:set_body( _pipe@1, File_data ), gleam@http@request:set_method(_pipe@2, post) end, case gleam@httpc:send(Req) of {ok, _} -> {ok, <<"OK"/utf8>>}; {error, _} -> {error, {fireball_error, <<"error while sending request"/utf8>>}} end; {error, _} -> {error, {fireball_error, <<"Failed to read in file: "/utf8, Infile/binary>>}} end; {error, _} -> {error, {fireball_error, <<"error while forming request"/utf8>>}} end. -file("/export/gleam/fireball/src/fireball.gleam", 191). -spec post_file_erl(binary(), binary()) -> nil. post_file_erl(Url, Infile) -> fireball_ffi:post_file_erl(Url, Infile). -file("/export/gleam/fireball/src/fireball.gleam", 194). -spec post_file_external( binary(), binary(), binary(), binary(), binary(), binary(), binary() ) -> {ok, binary()} | {error, error:fireball_error()}. post_file_external(Apiver, _, Infile, Outfile, Proj_id, External_script, Wd) -> Url = <<<<<<<<<<"https://firebasestorage.googleapis.com/"/utf8, Apiver/binary>>/binary, "/b/"/utf8>>/binary, Proj_id/binary>>/binary, ".appspot.com/o/"/utf8>>/binary, (gleam@string:replace(Outfile, <<"/"/utf8>>, <<"%2F"/utf8>>))/binary>>, case gleamyshell_ffi:execute(External_script, Wd, [Url, Infile]) of {ok, {command_output, 0, Output}} -> {ok, gleam@string:trim(Output)}; {ok, {command_output, Exit_code, Output@1}} -> {error, {fireball_error, <<<<<<"ERROR:"/utf8, (gleam@int:to_string(Exit_code))/binary>>/binary, ";"/utf8>>/binary, Output@1/binary>>}}; {error, Reason} -> {error, {fireball_error, <<"FATAL_ERROR:"/utf8, Reason/binary>>}} end.