Skip to main content

src/examples@profile.erl

-module(examples@profile).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/examples/profile.gleam").
-export([main/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(
    " Fetch and print a Rocksky profile.\n"
    "\n"
    " Run with:\n"
    "   gleam run -m examples/profile\n"
).

-file("src/examples/profile.gleam", 12).
-spec main() -> nil.
main() ->
    Client = rocksky:new(),
    Result = begin
        _pipe = rocksky@actor:get_profile(<<"tsiry-sandratraina.com"/utf8>>),
        rocksky:send(_pipe, Client)
    end,
    case Result of
        {ok, Profile} ->
            gleam_stdlib:println(
                <<"did:          "/utf8,
                    (gleam@option:unwrap(
                        erlang:element(3, Profile),
                        <<"?"/utf8>>
                    ))/binary>>
            ),
            gleam_stdlib:println(
                <<"handle:       "/utf8,
                    (gleam@option:unwrap(
                        erlang:element(4, Profile),
                        <<"?"/utf8>>
                    ))/binary>>
            ),
            gleam_stdlib:println(
                <<"display name: "/utf8,
                    (gleam@option:unwrap(
                        erlang:element(5, Profile),
                        <<"?"/utf8>>
                    ))/binary>>
            ),
            gleam_stdlib:println(
                <<"avatar:       "/utf8,
                    (gleam@option:unwrap(
                        erlang:element(6, Profile),
                        <<"?"/utf8>>
                    ))/binary>>
            );

        {error, Err} ->
            gleam_stdlib:println_error(
                <<"Failed: "/utf8, (gleam@string:inspect(Err))/binary>>
            )
    end.