Skip to content

Commit 6fe408f

Browse files
author
vkatsuba
committed
Remove include file
1 parent 22232a2 commit 6fe408f

6 files changed

+24
-46
lines changed

include/bellboy.hrl

-20
This file was deleted.

src/bellboy.erl

-7
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,6 @@
3333
nexmo/1
3434
]).
3535

36-
%%% ==================================================================
37-
%%% Includes
38-
%%% ==================================================================
39-
40-
-include("bellboy.hrl").
41-
42-
4336
%%% ==================================================================
4437
%%% API functions
4538
%%% ==================================================================

src/bellboy_nexmo.erl

+6-2
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,14 @@
2929
-export([message/1]).
3030

3131
%%% ==================================================================
32-
%%% Includes
32+
%%% Macros
3333
%%% ==================================================================
3434

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

3741
%%% ==================================================================
3842
%%% API functions

src/bellboy_plivo.erl

+6-5
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,11 @@
2929
-export([message/1]).
3030

3131
%%% ==================================================================
32-
%%% Includes
32+
%%% Macros
3333
%%% ==================================================================
3434

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

3738
%%% ==================================================================
3839
%%% API functions
@@ -71,7 +72,7 @@ message(_) ->
7172

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

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

113114
get_messages(#{auth_id := AID, auth_token := AT}) when is_list(AID), is_list(AT) ->
114-
RD = #{m => get, u => ?PLIVO_URL_MSG(AID), h => #{"Authorization" => ?BASIC_AUTH(AID, AT)}},
115+
RD = #{m => get, u => ?PLIVO_URL_MSG(AID), h => #{"Authorization" => bellboy_utils:basic_auth(AID, AT)}},
115116
case bellboy_utils:httpc_request(RD) of
116117
{ok, Resp} ->
117118
{ok, #{code => bellboy_utils:get_code(Resp), body => bellboy_utils:gen_body(bellboy_utils:get_body(Resp)), response => Resp}};

src/bellboy_twilio.erl

+7-5
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,12 @@
2929
-export([message/1]).
3030

3131
%%% ==================================================================
32-
%%% Includes
32+
%%% Macros
3333
%%% ==================================================================
3434

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

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

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

114116
get_messages(#{account_sid := AID, auth_token := AT}) when is_list(AID), is_list(AT) ->
115-
RD = #{m => get, u => ?TWILIO_URL_MSG(AID), h => #{"Authorization" => ?BASIC_AUTH(AID, AT)}},
117+
RD = #{m => get, u => ?TWILIO_URL_MSG(AID), h => #{"Authorization" => bellboy_utils:basic_auth(AID, AT)}},
116118
case bellboy_utils:httpc_request(RD) of
117119
{ok, Resp} ->
118120
{ok, #{code => bellboy_utils:get_code(Resp), body => bellboy_utils:gen_body(bellboy_utils:get_body(Resp)), response => Resp}};

src/bellboy_utils.erl

+5-7
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,10 @@
3131
get_body/1,
3232
gen_body/1,
3333
httpc_request/1,
34-
is_valid/1
34+
is_valid/1,
35+
basic_auth/2
3536
]).
3637

37-
%%% ==================================================================
38-
%%% Includes
39-
%%% ==================================================================
40-
41-
-include("bellboy.hrl").
42-
4338
%%% ==================================================================
4439
%%% Public functions
4540
%%% ==================================================================
@@ -103,3 +98,6 @@ httpc_request(#{m := M, u := URL}) ->
10398
is_valid([]) -> true;
10499
is_valid([true | T]) -> is_valid(T);
105100
is_valid(_) -> false.
101+
102+
basic_auth(AuthID, AuthToken) ->
103+
"Basic " ++ binary_to_list(base64:encode(AuthID ++ ":" ++ AuthToken)).

0 commit comments

Comments
 (0)