-module(fireball). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). -export([get_doc/5, put_doc/7, put_doc_from_string/7, put_doc_from_file/7, get_file/5, 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)}}; {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", 75). -spec put_doc( binary(), binary(), binary(), binary(), binary(), objects@document:fireball_document(), binary() ) -> {ok, objects@document:fireball_document()} | {error, error:fireball_error()}. put_doc(Apikey, Apiver, Database, Collection_path, Doc_path, Input_doc, Proj_id) -> Url = <<<<<<<<<<<<<<<<<<<<<<"https://firestore.googleapis.com/"/utf8, Apiver/binary>>/binary, "/projects/"/utf8>>/binary, Proj_id/binary>>/binary, "/databases/"/utf8>>/binary, Database/binary>>/binary, "/documents/"/utf8>>/binary, Collection_path/binary>>/binary, "?documentId="/utf8>>/binary, Doc_path/binary>>/binary, "&key="/utf8>>/binary, Apikey/binary>>, case gleam@http@request:to(Url) of {ok, Base_req} -> Req = begin _pipe = gleam@http@request:prepend_header( Base_req, <<"Content-type"/utf8>>, <<"application/json"/utf8>> ), _pipe@1 = gleam@http@request:set_method(_pipe, post), gleam@http@request:set_body( _pipe@1, objects@document:doc_to_json(Input_doc) ) end, case gleam@httpc:send(Req) of {ok, Resp} -> {ok, {fireball_document, erlang:element(4, Resp)}}; {error, _} -> {error, {fireball_error, <<"error while sending request"/utf8>>}} end; {error, _} -> {error, {fireball_error, <<"error while creating request"/utf8>>}} end. -file("/export/gleam/fireball/src/fireball.gleam", 134). -spec put_doc_from_string( binary(), binary(), binary(), binary(), binary(), binary(), binary() ) -> {ok, objects@document:fireball_document()} | {error, error:fireball_error()}. put_doc_from_string( Apikey, Apiver, Database, Collection_path, Doc_path, Input_data, Proj_id ) -> Url = <<<<<<<<<<<<<<<<<<<<<<"https://firestore.googleapis.com/"/utf8, Apiver/binary>>/binary, "/projects/"/utf8>>/binary, Proj_id/binary>>/binary, "/databases/"/utf8>>/binary, Database/binary>>/binary, "/documents/"/utf8>>/binary, Collection_path/binary>>/binary, "?documentId="/utf8>>/binary, Doc_path/binary>>/binary, "&key="/utf8>>/binary, Apikey/binary>>, case gleam@http@request:to(Url) of {ok, Base_req} -> Req = begin _pipe = gleam@http@request:prepend_header( Base_req, <<"Content-type"/utf8>>, <<"application/json"/utf8>> ), _pipe@1 = gleam@http@request:set_method(_pipe, post), gleam@http@request:set_body(_pipe@1, Input_data) end, case gleam@httpc:send(Req) of {ok, Resp} -> {ok, {fireball_document, erlang:element(4, Resp)}}; {error, _} -> {error, {fireball_error, <<"error while sending request"/utf8>>}} end; {error, _} -> {error, {fireball_error, <<"error while creating request"/utf8>>}} end. -file("/export/gleam/fireball/src/fireball.gleam", 194). -spec put_doc_from_file( binary(), binary(), binary(), binary(), binary(), binary(), binary() ) -> {ok, objects@document:fireball_document()} | {error, error:fireball_error()}. put_doc_from_file( Apikey, Apiver, Database, Collection_path, Doc_path, Input_doc, Proj_id ) -> Url = <<<<<<<<<<<<<<<<<<<<<<"https://firestore.googleapis.com/"/utf8, Apiver/binary>>/binary, "/projects/"/utf8>>/binary, Proj_id/binary>>/binary, "/databases/"/utf8>>/binary, Database/binary>>/binary, "/documents/"/utf8>>/binary, Collection_path/binary>>/binary, "?documentId="/utf8>>/binary, Doc_path/binary>>/binary, "&key="/utf8>>/binary, Apikey/binary>>, case gleam@http@request:to(Url) of {ok, Base_req} -> case simplifile:read(Input_doc) of {ok, Json_data} -> Req = begin _pipe = gleam@http@request:prepend_header( Base_req, <<"Content-type"/utf8>>, <<"application/json"/utf8>> ), _pipe@1 = gleam@http@request:set_method(_pipe, post), gleam@http@request:set_body(_pipe@1, Json_data) end, case gleam@httpc:send(Req) of {ok, Resp} -> {ok, {fireball_document, erlang:element(4, Resp)}}; {error, _} -> {error, {fireball_error, <<"error while sending request"/utf8>>}} end; {error, _} -> {error, {fireball_error, <<"failed to read file"/utf8>>}} end; {error, _} -> {error, {fireball_error, <<"error while creating request"/utf8>>}} end. -file("/export/gleam/fireball/src/fireball.gleam", 263). -spec get_file(binary(), binary(), binary(), binary(), binary()) -> {ok, objects@storage:fireball_storage()} | {error, error:fireball_error()}. get_file(Apiver, Obj_path, Proj_id, Token, Content_type) -> Url = <<<<<<<<<<<<<<"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>>, case gleam@http@request:to(Url) of {ok, Base_req} -> Req = begin _pipe = gleam@http@request:prepend_header( Base_req, <<"Content-type"/utf8>>, Content_type ), 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", 314). -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", 379). -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", 382). -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.