-module(glats). -compile([no_auto_import, nowarn_unused_vars]). -export([connect/1, publish/3, publish_message/2, request/3, handle_subscription/3, new_settings/2, default_settings/0, with_host/2, with_port/2, with_ca/2, with_client_cert/3, with_no_tls/1]). -spec connect(glats@connection:settings()) -> {ok, gleam@erlang@process:subject(glats@connection:command())} | {error, gleam@otp@actor:start_error()}. connect(Settings) -> glats@connection:start(Settings). -spec publish( gleam@erlang@process:subject(glats@connection:command()), binary(), binary() ) -> {ok, nil} | {error, binary()}. publish(Conn, Subject, Message) -> glats@connection:publish(Conn, Subject, Message). -spec publish_message( gleam@erlang@process:subject(glats@connection:command()), glats@message:message() ) -> {ok, nil} | {error, binary()}. publish_message(Conn, Message) -> glats@connection:publish_message(Conn, Message). -spec request( gleam@erlang@process:subject(glats@connection:command()), binary(), binary() ) -> {ok, glats@message:message()} | {error, glats@connection:server_error()}. request(Conn, Subject, Message) -> glats@connection:request(Conn, Subject, Message). -spec handle_subscription( gleam@erlang@process:subject(glats@connection:command()), binary(), fun((glats@message:message(), gleam@erlang@process:subject(glats@connection:command())) -> {ok, nil} | {error, binary()}) ) -> {ok, gleam@erlang@process:subject(glats@message:message())} | {error, gleam@otp@actor:start_error()}. handle_subscription(Conn, Subject, Handler) -> glats@handler:handle_subscription(Conn, Subject, Handler). -spec new_settings(binary(), integer()) -> glats@connection:settings(). new_settings(Host, Port) -> {settings, {some, Host}, {some, Port}, none, none}. -spec default_settings() -> glats@connection:settings(). default_settings() -> new_settings(<<"localhost"/utf8>>, 4222). -spec with_host(glats@connection:settings(), binary()) -> glats@connection:settings(). with_host(Old, Host) -> erlang:setelement(2, Old, {some, Host}). -spec with_port(glats@connection:settings(), integer()) -> glats@connection:settings(). with_port(Old, Port) -> erlang:setelement(3, Old, {some, Port}). -spec with_ca(glats@connection:settings(), binary()) -> glats@connection:settings(). with_ca(Old, Cafile) -> erlang:setelement( 5, erlang:setelement(4, Old, {some, true}), {some, begin _pipe = erlang:element(5, Old), _pipe@1 = gleam@option:unwrap(_pipe, gleam@map:new()), gleam@map:insert(_pipe@1, <<"cacertfile"/utf8>>, Cafile) end} ). -spec with_client_cert(glats@connection:settings(), binary(), binary()) -> glats@connection:settings(). with_client_cert(Old, Certfile, Keyfile) -> erlang:setelement( 5, erlang:setelement(4, Old, {some, true}), {some, begin _pipe = erlang:element(5, Old), _pipe@1 = gleam@option:unwrap(_pipe, gleam@map:new()), _pipe@2 = gleam@map:insert( _pipe@1, <<"certfile"/utf8>>, Certfile ), gleam@map:insert(_pipe@2, <<"keyfile"/utf8>>, Keyfile) end} ). -spec with_no_tls(glats@connection:settings()) -> glats@connection:settings(). with_no_tls(Old) -> erlang:setelement(5, erlang:setelement(4, Old, {some, false}), none).