Skip to content

Commit

Permalink
Remove include file
Browse files Browse the repository at this point in the history
  • Loading branch information
vkatsuba committed Feb 20, 2021
1 parent 22232a2 commit 6fe408f
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 46 deletions.
20 changes: 0 additions & 20 deletions include/bellboy.hrl

This file was deleted.

7 changes: 0 additions & 7 deletions src/bellboy.erl
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,6 @@
nexmo/1
]).

%%% ==================================================================
%%% Includes
%%% ==================================================================

-include("bellboy.hrl").


%%% ==================================================================
%%% API functions
%%% ==================================================================
Expand Down
8 changes: 6 additions & 2 deletions src/bellboy_nexmo.erl
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,14 @@
-export([message/1]).

%%% ==================================================================
%%% Includes
%%% Macros
%%% ==================================================================

-include("bellboy.hrl").
-define(BAD_ARG, {error, bad_arg}).
-define(NEXMO_URL_MSG, "https://rest.nexmo.com/sms/json").
-define(NEXMO_URL_VERIFY, "https://api.nexmo.com/verify/json").
-define(NEXMO_URL_CONTROL, "https://api.nexmo.com/verify/control/json").
-define(NEXMO_URL_CHECK, "https://api.nexmo.com/verify/check/json").

%%% ==================================================================
%%% API functions
Expand Down
11 changes: 6 additions & 5 deletions src/bellboy_plivo.erl
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@
-export([message/1]).

%%% ==================================================================
%%% Includes
%%% Macros
%%% ==================================================================

-include("bellboy.hrl").
-define(BAD_ARG, {error, bad_arg}).
-define(PLIVO_URL_MSG(AuthID), "https://api.plivo.com/v1/Account/" ++ AuthID ++ "/Message/").

%%% ==================================================================
%%% API functions
Expand Down Expand Up @@ -71,7 +72,7 @@ message(_) ->

send_message(#{auth_id := AID, auth_token := AT} = Data) when is_list(AID), is_list(AT) ->
P = maps:without([type, auth_id, payload], Data),
RD = #{m => post, u => ?PLIVO_URL_MSG(AID), h => #{"Authorization" => ?BASIC_AUTH(AID, AT)}, b => jsx:encode(P), ct => "application/json"},
RD = #{m => post, u => ?PLIVO_URL_MSG(AID), h => #{"Authorization" => bellboy_utils:basic_auth(AID, AT)}, b => jsx:encode(P), ct => "application/json"},
case bellboy_utils:httpc_request(RD) of
{ok, Resp} ->
{ok, #{code => bellboy_utils:get_code(Resp), body => bellboy_utils:gen_body(bellboy_utils:get_body(Resp)), response => Resp}};
Expand All @@ -91,7 +92,7 @@ send_message(_) ->
-spec get_message(Params :: maps:map()) -> {ok, Result :: maps:map()} | {error, Reason :: tuple() | bad_arg}.

get_message(#{auth_id := AID, auth_token := AT, message_uuid := MUUID}) when is_list(AID), is_list(AT), is_list(MUUID) ->
RD = #{m => get, u => ?PLIVO_URL_MSG(AID) ++ MUUID, h => #{"Authorization" => ?BASIC_AUTH(AID, AT)}},
RD = #{m => get, u => ?PLIVO_URL_MSG(AID) ++ MUUID, h => #{"Authorization" => bellboy_utils:basic_auth(AID, AT)}},
case bellboy_utils:httpc_request(RD) of
{ok, Resp} ->
{ok, #{code => bellboy_utils:get_code(Resp), body => bellboy_utils:gen_body(bellboy_utils:get_body(Resp)), response => Resp}};
Expand All @@ -111,7 +112,7 @@ get_message(_) ->
-spec get_messages(Params :: maps:map()) -> {ok, Result :: maps:map()} | {error, Reason :: tuple() | bad_arg}.

get_messages(#{auth_id := AID, auth_token := AT}) when is_list(AID), is_list(AT) ->
RD = #{m => get, u => ?PLIVO_URL_MSG(AID), h => #{"Authorization" => ?BASIC_AUTH(AID, AT)}},
RD = #{m => get, u => ?PLIVO_URL_MSG(AID), h => #{"Authorization" => bellboy_utils:basic_auth(AID, AT)}},
case bellboy_utils:httpc_request(RD) of
{ok, Resp} ->
{ok, #{code => bellboy_utils:get_code(Resp), body => bellboy_utils:gen_body(bellboy_utils:get_body(Resp)), response => Resp}};
Expand Down
12 changes: 7 additions & 5 deletions src/bellboy_twilio.erl
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@
-export([message/1]).

%%% ==================================================================
%%% Includes
%%% Macros
%%% ==================================================================

-include("bellboy.hrl").
-define(BAD_ARG, {error, bad_arg}).
-define(TWILIO_URL_MSG(AuthID), "https://api.twilio.com/2010-04-01/Accounts/" ++ AuthID ++ "/Messages.json").
-define(TWILIO_URL_SPEC_MSG(AuthID, Sid), "https://api.twilio.com/2010-04-01/Accounts/" ++ AuthID ++ "/Messages/" ++ Sid ++ ".json").

%%% ==================================================================
%%% API functions
Expand Down Expand Up @@ -69,7 +71,7 @@ send_message(#{account_sid := AID, auth_token := AT, body := B, from := F, to :=
case bellboy_utils:is_valid([is_list(AID), is_list(AT), is_list(B), is_list(F), is_list(T)]) of
true ->
BURI = "Body=" ++ http_uri:encode(B) ++ "&From=" ++ http_uri:encode(F) ++ "&To=" ++ http_uri:encode(T),
RD = #{m => post, u => ?TWILIO_URL_MSG(AID), h => #{"Authorization" => ?BASIC_AUTH(AID, AT)}, ct => "application/x-www-form-urlencoded", b => BURI},
RD = #{m => post, u => ?TWILIO_URL_MSG(AID), h => #{"Authorization" => bellboy_utils:basic_auth(AID, AT)}, ct => "application/x-www-form-urlencoded", b => BURI},
case bellboy_utils:httpc_request(RD) of
{ok, Resp} ->
{ok, #{code => bellboy_utils:get_code(Resp), body => bellboy_utils:gen_body(bellboy_utils:get_body(Resp)), response => Resp}};
Expand All @@ -92,7 +94,7 @@ send_message(_) ->
-spec get_message(Params :: maps:map()) -> {ok, Result :: maps:map()} | {error, Reason :: tuple() | bad_arg}.

get_message(#{account_sid := AID, auth_token := AT, sid := SID}) when is_list(AID), is_list(AT), is_list(SID) ->
RD = #{m => get, u => ?TWILIO_URL_SPEC_MSG(AID, SID), h => #{"Authorization" => ?BASIC_AUTH(AID, AT)}},
RD = #{m => get, u => ?TWILIO_URL_SPEC_MSG(AID, SID), h => #{"Authorization" => bellboy_utils:basic_auth(AID, AT)}},
case bellboy_utils:httpc_request(RD) of
{ok, Resp} ->
{ok, #{code => bellboy_utils:get_code(Resp), body => bellboy_utils:gen_body(bellboy_utils:get_body(Resp)), response => Resp}};
Expand All @@ -112,7 +114,7 @@ get_message(_) ->
-spec get_messages(Params :: maps:map()) -> {ok, Result :: maps:map()} | {error, Reason :: tuple() | bad_arg}.

get_messages(#{account_sid := AID, auth_token := AT}) when is_list(AID), is_list(AT) ->
RD = #{m => get, u => ?TWILIO_URL_MSG(AID), h => #{"Authorization" => ?BASIC_AUTH(AID, AT)}},
RD = #{m => get, u => ?TWILIO_URL_MSG(AID), h => #{"Authorization" => bellboy_utils:basic_auth(AID, AT)}},
case bellboy_utils:httpc_request(RD) of
{ok, Resp} ->
{ok, #{code => bellboy_utils:get_code(Resp), body => bellboy_utils:gen_body(bellboy_utils:get_body(Resp)), response => Resp}};
Expand Down
12 changes: 5 additions & 7 deletions src/bellboy_utils.erl
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,10 @@
get_body/1,
gen_body/1,
httpc_request/1,
is_valid/1
is_valid/1,
basic_auth/2
]).

%%% ==================================================================
%%% Includes
%%% ==================================================================

-include("bellboy.hrl").

%%% ==================================================================
%%% Public functions
%%% ==================================================================
Expand Down Expand Up @@ -103,3 +98,6 @@ httpc_request(#{m := M, u := URL}) ->
is_valid([]) -> true;
is_valid([true | T]) -> is_valid(T);
is_valid(_) -> false.

basic_auth(AuthID, AuthToken) ->
"Basic " ++ binary_to_list(base64:encode(AuthID ++ ":" ++ AuthToken)).

0 comments on commit 6fe408f

Please sign in to comment.