Skip to content

Commit

Permalink
Use module to present high level API
Browse files Browse the repository at this point in the history
  • Loading branch information
ziopio committed Jan 29, 2024
1 parent cc754ec commit 4ac8824
Showing 1 changed file with 27 additions and 8 deletions.
35 changes: 27 additions & 8 deletions src/grisp_io.erl
Original file line number Diff line number Diff line change
@@ -1,18 +1,37 @@
%%%-------------------------------------------------------------------
%% @doc Grisp Seawater High Level API.
%%%-----------------------------------------------------------------------------
%% @doc GRiSP.io High Level API.
%% @end
%%%-------------------------------------------------------------------
%%%-----------------------------------------------------------------------------

-module(grisp_io).


%--- Exports -------------------------------------------------------------------

% API functions
-export([register/0]).

-export([ping/0]).
-export([link_device/0]).
-export([link_device/1]).

%--- API Functions -------------------------------------------------------------

register() ->
error(not_implmente).
% @doc Ping GRiSP.io.
% Returns 'pong' if the board is linked to an account, 'pang' otherwise.
-spec ping() -> {ok, binary()} | {error, atom()}.
ping() ->
grisp_io_ws:request(post, ping, #{}).


% @doc Links the board to a GRiSP.io account.
% The token is took from the device_linking_token app env.
-spec link_device() -> {ok, binary()} | {error, token_undefined | invalid_token}.
link_device() ->
case application:get_env(grisp_io, device_linking_token) of
undefined -> {error, token_undefined};
{ok, Token} -> link_device(Token)
end.

% @doc Links the board to a GRiSP.io account owning of the specified token.
-spec link_device(Token :: binary()) ->
{ok, binary()} | {error, invalid_token}.
link_device(Token) ->
grisp_io_ws:request(post, device_linking_token, #{token => Token}).

0 comments on commit 4ac8824

Please sign in to comment.