Skip to content

Commit

Permalink
Rebrand application as 'grisp_io' (#17)
Browse files Browse the repository at this point in the history
* Rebrand application as 'grisp_io'

* Remove old seawater host
  • Loading branch information
ziopio authored Jan 29, 2024
1 parent 8c98fbd commit 43789cc
Show file tree
Hide file tree
Showing 15 changed files with 59 additions and 61 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/ct.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Grisp Seawater CT
name: grisp_io CT

on:
push:
Expand Down Expand Up @@ -33,4 +33,3 @@ jobs:
eval `ssh-agent -s`
ssh-add - <<< '${{ secrets.STRITZINGER_BOT_SSH_KEY }}'
rebar3 ct
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# grisp_seawater
# grisp_io

Grisp2 Seawater Client Library
GRiSP.io Client Library for GRiSP

## Application env options

Expand All @@ -21,6 +21,6 @@ Allows to tweak the timeout of each API request going through the websocket.

## Basic Low Level API Usage

grisp_seawater_ws:connect().
true = grisp_seawater_ws:is_connected().
{ok, <<pong>>} = grisp_seawater_ws:ping().
grisp_io_ws:connect().
true = grisp_io_ws:is_connected().
{ok, <<pong>>} = grisp_io_ws:ping().
2 changes: 1 addition & 1 deletion config/sys.config
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[
{grisp_seawater, [
{grisp_io, [
{device_linking_token, <<"...">>}
]}
].
1 change: 0 additions & 1 deletion grisp/default/common/deploy/files/erl_inetrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

% Add hosts
{host, {149,248,205,211}, ["grisp.io"]}.
{host, {46,101,169,235}, ["seawater.stritzinger.com"]}. % old
{host, {212,25,1,1}, ["0.europe.pool.ntp.org"]}.

% Do not monitor the hosts file
Expand Down
8 changes: 4 additions & 4 deletions rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

{shell, [
{config, "config/sys.config"},
{apps, [grisp_seawater]}
{apps, [grisp_io]}
]}.

{plugins, [rebar3_grisp, rebar3_ex_doc]}.
Expand All @@ -27,7 +27,7 @@

{relx, [
{sys_config, "config/sys.config"},
{release, {grisp_seawater, "0.1.0"}, [grisp_seawater]}
{release, {grisp_io, "0.1.0"}, [grisp_io]}
]}.

{hex, [{doc, #{provider => ex_doc}}]}.
Expand All @@ -39,7 +39,7 @@
{"LICENSE", #{title => "License"}}
]},
{main, "README.md"},
{homepage_url, "https://github.com/grisp/grisp_seawater"},
{source_url, "https://github.com/grisp/grisp_seawater"},
{homepage_url, "https://github.com/grisp/grisp_io"},
{source_url, "https://github.com/grisp/grisp_io"},
{api_reference, true}
]}.
10 changes: 5 additions & 5 deletions src/grisp_seawater.app.src → src/grisp_io.app.src
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{application, grisp_seawater, [
{description, "Grisp2 Seawater Client Library"},
{application, grisp_io, [
{description, "GRiSP.io Client Library for GRiSP"},
{vsn, "0.1.0"},
{registered, []},
{mod, {grisp_seawater_app, []}},
{mod, {grisp_io_app, []}},
{applications, [
kernel,
inets,
Expand All @@ -14,8 +14,8 @@
jsx
]},
{env, [
{seawater_domain, "grisp.io"},
{seawater_port, 7777},
{domain, "grisp.io"},
{port, 7777},
{connect, true}, % keeps a constant connection with grisp.io
{ntp, false}, % if set to true, starts the NTP client
{ws_requests_timeout, 5_000}
Expand Down
2 changes: 1 addition & 1 deletion src/grisp_seawater.erl → src/grisp_io.erl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
%% @end
%%%-------------------------------------------------------------------

-module(grisp_seawater).
-module(grisp_io).


%--- Exports -------------------------------------------------------------------
Expand Down
6 changes: 3 additions & 3 deletions src/grisp_seawater_app.erl → src/grisp_io_app.erl
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
%%%-------------------------------------------------------------------
%% @doc grisp_seawater public API
%% @doc grisp_io public API
%% @end
%%%-------------------------------------------------------------------

-module(grisp_seawater_app).
-module(grisp_io_app).

-behaviour(application).

Expand All @@ -17,7 +17,7 @@
%--- Behaviour application Callback Functions ----------------------------------

start(_StartType, _StartArgs) ->
grisp_seawater_sup:start_link().
grisp_io_sup:start_link().

stop(_State) ->
ok.
10 changes: 5 additions & 5 deletions src/grisp_io_connection.erl
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ disconnected() ->
% gen_statem CALLBACKS ---------------------------------------------------------

init([]) ->
{ok, Connect} = application:get_env(grisp_seawater, connect),
{ok, Connect} = application:get_env(grisp_io, connect),
NextState = case Connect of
true -> waiting_ip;
false -> idle
Expand Down Expand Up @@ -65,13 +65,13 @@ handle_event(state_timeout, retry, waiting_ip, Data) ->

% CONNECTING
handle_event(enter, _OldState, connecting, _Data) ->
{ok, Domain} = application:get_env(grisp_seawater, seawater_domain),
{ok, Port} = application:get_env(grisp_seawater, seawater_port),
{ok, Domain} = application:get_env(grisp_io, domain),
{ok, Port} = application:get_env(grisp_io, port),
?LOG_NOTICE(#{event => connecting, domain => Domain, port => Port}),
grisp_seawater_ws:connect(Domain, Port),
grisp_io_ws:connect(Domain, Port),
{keep_state_and_data, [{state_timeout, 0, retry}]};
handle_event(state_timeout, retry, connecting, Data) ->
case grisp_seawater_ws:is_connected() of
case grisp_io_ws:is_connected() of
true ->
?LOG_NOTICE(#{event => connected}),
{next_state, connected, Data};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-module(grisp_seawater_jsonrpc).
-module(grisp_io_jsonrpc).

% API
-export([decode/1]).
Expand Down
2 changes: 1 addition & 1 deletion src/grisp_seawater_ntp.erl → src/grisp_io_ntp.erl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-module(grisp_seawater_ntp).
-module(grisp_io_ntp).

% API
-export([start_link/0]).
Expand Down
10 changes: 5 additions & 5 deletions src/grisp_seawater_sup.erl → src/grisp_io_sup.erl
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
%%%-------------------------------------------------------------------
%% @doc grisp_seawater top level supervisor.
%% @doc grisp_io top level supervisor.
%% @end
%%%-------------------------------------------------------------------

-module(grisp_seawater_sup).
-module(grisp_io_sup).

-behaviour(supervisor).

Expand Down Expand Up @@ -34,12 +34,12 @@ init([]) ->
SupFlags = #{
strategy => one_for_all
},
NTP = case application:get_env(grisp_seawater, ntp) of
{ok, true} -> [worker(grisp_seawater_ntp, [])];
NTP = case application:get_env(grisp_io, ntp) of
{ok, true} -> [worker(grisp_io_ntp, [])];
{ok, false} -> []
end,
ChildSpecs = NTP ++ [
worker(grisp_seawater_ws, []),
worker(grisp_io_ws, []),
worker(grisp_io_connection, [])
],
{ok, {SupFlags, ChildSpecs}}.
Expand Down
4 changes: 2 additions & 2 deletions src/grisp_seawater_tls.erl → src/grisp_io_tls.erl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
%% @end
%%%-------------------------------------------------------------------

-module(grisp_seawater_tls).
-module(grisp_io_tls).


%--- Exports -------------------------------------------------------------------
Expand Down Expand Up @@ -73,7 +73,7 @@ load_cert_chain(RelPath) ->
end.

cert_path(RelPath) ->
PrivDir = code:priv_dir(grisp_seawater),
PrivDir = code:priv_dir(grisp_io),
filename:join([PrivDir | RelPath]) ++ ".pem".

decode_cert_chain(PemData) ->
Expand Down
22 changes: 11 additions & 11 deletions src/grisp_seawater_ws.erl → src/grisp_io_ws.erl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
%% @doc Websocket client to connect to grisp.io
-module(grisp_seawater_ws).
-module(grisp_io_ws).

-export([start_link/0]).
-export([connect/0]).
Expand Down Expand Up @@ -36,8 +36,8 @@ start_link() ->
gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).

connect() ->
{ok, Domain} = application:get_env(grisp_seawater, seawater_domain),
{ok, Port} = application:get_env(grisp_seawater, seawater_port),
{ok, Domain} = application:get_env(grisp_io, domain),
{ok, Port} = application:get_env(grisp_io, port),
connect(Domain, Port).

connect(Server, Port) ->
Expand All @@ -47,7 +47,7 @@ is_connected() ->
gen_server:call(?MODULE, ?FUNCTION_NAME).

link_device() ->
case application:get_env(grisp_seawater, device_linking_token) of
case application:get_env(grisp_io, device_linking_token) of
undefined -> {error, token_undefined};
{ok, Token} -> link_device(Token)
end.
Expand Down Expand Up @@ -75,7 +75,7 @@ handle_call({link_device, Token}, From, S) ->
{noreply, NewS}.

handle_cast({connect, Server, Port}, #state{gun_pid = undefined} = S) ->
case grisp_seawater_tls:connect(Server, Port) of
case grisp_io_tls:connect(Server, Port) of
{ok, GunPid} ->
{noreply, #state{gun_pid = GunPid}};
Error ->
Expand All @@ -101,11 +101,11 @@ handle_info({gun_response, Pid, Stream, _, Status, _Headers},
{noreply, shutdown_gun(S)};
handle_info({gun_ws, Conn, Stream, {text, JSON}},
#state{gun_pid = Conn, ws_stream = Stream}= S) ->
JSON_RPC = grisp_seawater_jsonrpc:decode(JSON),
JSON_RPC = grisp_io_jsonrpc:decode(JSON),
case handle_jsonrpc(JSON_RPC, S) of
{[], NewS} -> {noreply, NewS};
{Msgs, NewS} ->
Text = grisp_seawater_jsonrpc:encode(Msgs),
Text = grisp_io_jsonrpc:encode(Msgs),
gun:ws_send(S#state.gun_pid, S#state.ws_stream, {text, Text}),
{noreply, NewS}
end;
Expand Down Expand Up @@ -150,19 +150,19 @@ handle_rpc_messages([{error, _Code, _Msg, _Data, _ID} = E | Batch],
handle_rpc_messages([{internal_error, _, _} = E | Batch], Replies, S) ->
?LOG_ERROR(#{event => internal_jsonrpc_error, message => E}),
handle_rpc_messages(Batch,
[grisp_seawater_jsonrpc:format_error(E)| Replies], S).
[grisp_io_jsonrpc:format_error(E)| Replies], S).

handle_request(<<"post">>, #{type := <<"flash">>} = Params, ID) ->
Led = maps:get(led, Params, 1),
Color = maps:get(color, Params, red),
{result, flash(Led, Color), ID};
handle_request(_, _, ID) ->
grisp_seawater_jsonrpc:format_error({internal_error, method_not_found, ID}).
grisp_io_jsonrpc:format_error({internal_error, method_not_found, ID}).

make_request(Caller, Method, Type, Params, #state{requests = Reqs} = State) ->
ID = id(),
Rpc = {request, Method, maps:put(type, Type, Params), ID},
Msg = grisp_seawater_jsonrpc:encode(Rpc),
Msg = grisp_io_jsonrpc:encode(Rpc),
gun:ws_send(State#state.gun_pid, State#state.ws_stream, {text, Msg}),
TRef = erlang:start_timer(ws_request_timeout(), self(), ID),
Request = {Caller, TRef},
Expand Down Expand Up @@ -206,5 +206,5 @@ shutdown_gun(#state{gun_pid = Pid} = State) ->
State?disconnected_state.

ws_request_timeout() ->
{ok, Timeout} = application:get_env(grisp_seawater, seawater_domain),
{ok, Timeout} = application:get_env(grisp_io, io_domain),
Timeout.
28 changes: 14 additions & 14 deletions test/jsonrpc_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@ all() -> [
positional_parameters(_) ->
Term = {request, <<"subtract">>, [42,23], 1},
Json = <<"{\"id\":1,\"jsonrpc\":\"2.0\",\"method\":\"subtract\",\"params\":[42,23]}">>,
?assertMatch({single, Term}, grisp_seawater_jsonrpc:decode(Json)),
Json = grisp_seawater_jsonrpc:encode(Term),
?assertMatch({single, Term}, grisp_io_jsonrpc:decode(Json)),
Json = grisp_io_jsonrpc:encode(Term),
?assert(jsonrpc_check([<<"\"id\":1">>,
<<"\"method\":\"subtract\"">>,
<<"\"params\":[42,23]">>], Json)).

named_parameters(_) ->
Term = {request, <<"subtract">>, #{<<"subtrahend">> => 23, <<"minuend">> => 42}, 2},
Json = <<"{\"id\":2,\"jsonrpc\":\"2.0\",\"method\":\"subtract\",\"params\":{\"minuend\":42,\"subtrahend\":23}}">>,
?assertMatch({single, Term}, grisp_seawater_jsonrpc:decode(Json)),
Json = grisp_seawater_jsonrpc:encode(Term),
?assertMatch({single, Term}, grisp_io_jsonrpc:decode(Json)),
Json = grisp_io_jsonrpc:encode(Term),
?assert(jsonrpc_check([<<"\"id\":2">>,
<<"\"method\":\"subtract\"">>,
<<"\"minuend\":42">>,
Expand All @@ -44,16 +44,16 @@ named_parameters(_) ->
notification(_) ->
Term = {notification, <<"update">>, [1,2,3,4,5]},
Json = <<"{\"jsonrpc\":\"2.0\",\"method\":\"update\",\"params\":[1,2,3,4,5]}">>,
?assertMatch({single, Term}, grisp_seawater_jsonrpc:decode(Json)),
Json = grisp_seawater_jsonrpc:encode(Term),
?assertMatch({single, Term}, grisp_io_jsonrpc:decode(Json)),
Json = grisp_io_jsonrpc:encode(Term),
?assert(jsonrpc_check([<<"\"method\":\"update\"">>,
<<"\"params\":[1,2,3,4,5]">>], Json)).

invalid_json(_) ->
Term = {internal_error, parse_error, null},
Json = <<"{\"jsonrpc\":\"2.0\",\"method\":\"foobar,\"params\":\"bar\",\"baz]">>,
?assertMatch({single, Term}, grisp_seawater_jsonrpc:decode(Json)),
JsonError = grisp_seawater_jsonrpc:encode(grisp_seawater_jsonrpc:format_error(Term)),
?assertMatch({single, Term}, grisp_io_jsonrpc:decode(Json)),
JsonError = grisp_io_jsonrpc:encode(grisp_io_jsonrpc:format_error(Term)),
?assert(jsonrpc_check([<<"\"error\":{">>,
<<"\"code\":-32700">>,
<<"\"message\":\"Parse error\"">>,
Expand All @@ -62,8 +62,8 @@ invalid_json(_) ->
invalid_request(_) ->
Term = {internal_error, invalid_request, null},
Json = <<"{\"jsonrpc\":\"2.0\",\"method\":1,\"params\":\"bar\"}">>,
?assertMatch({single, Term}, grisp_seawater_jsonrpc:decode(Json)),
JsonError = grisp_seawater_jsonrpc:encode(grisp_seawater_jsonrpc:format_error(Term)),
?assertMatch({single, Term}, grisp_io_jsonrpc:decode(Json)),
JsonError = grisp_io_jsonrpc:encode(grisp_io_jsonrpc:format_error(Term)),
?assert(jsonrpc_check([<<"\"error\":{">>,
<<"\"code\":-32600">>,
<<"\"message\":\"Invalid request\"">>,
Expand All @@ -73,8 +73,8 @@ batch(_) ->
Term1 = {request, <<"sum">>, [1,2,4], <<"1">>},
Term2 = {internal_error, invalid_request, null},
Json = <<"[{\"jsonrpc\":\"2.0\",\"method\":\"sum\",\"params\":[1,2,4],\"id\":\"1\"},{\"foo\":\"boo\"}]">>,
?assertMatch({batch, [Term1,Term2]}, grisp_seawater_jsonrpc:decode(Json)),
JsonError = grisp_seawater_jsonrpc:encode([Term1, grisp_seawater_jsonrpc:format_error(Term2)]),
?assertMatch({batch, [Term1,Term2]}, grisp_io_jsonrpc:decode(Json)),
JsonError = grisp_io_jsonrpc:encode([Term1, grisp_io_jsonrpc:format_error(Term2)]),
?assert(jsonrpc_check([<<"\"id\":\"1\"">>,
<<"\"method\":\"sum\"">>,
<<"params\":[1,2,4]">>,
Expand All @@ -86,8 +86,8 @@ batch(_) ->
result(_) ->
Term = {result, 7, 45},
Json = <<"{\"id\":45,\"jsonrpc\":\"2.0\",\"result\":7}">>,
?assertMatch({single, Term}, grisp_seawater_jsonrpc:decode(Json)),
Json = grisp_seawater_jsonrpc:encode(Term),
?assertMatch({single, Term}, grisp_io_jsonrpc:decode(Json)),
Json = grisp_io_jsonrpc:encode(Term),
?assert(jsonrpc_check([<<"\"id\":45">>,
<<"\"result\":7">>], Json)).

Expand Down

0 comments on commit 43789cc

Please sign in to comment.