-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use module to present high level API
- Loading branch information
Showing
1 changed file
with
27 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}). |