From 6fe408f1136454f7fd7c021a53ac909c1f20ec34 Mon Sep 17 00:00:00 2001 From: vkatsuba Date: Sat, 20 Feb 2021 12:06:00 +0200 Subject: [PATCH] Remove include file --- include/bellboy.hrl | 20 -------------------- src/bellboy.erl | 7 ------- src/bellboy_nexmo.erl | 8 ++++++-- src/bellboy_plivo.erl | 11 ++++++----- src/bellboy_twilio.erl | 12 +++++++----- src/bellboy_utils.erl | 12 +++++------- 6 files changed, 24 insertions(+), 46 deletions(-) delete mode 100644 include/bellboy.hrl diff --git a/include/bellboy.hrl b/include/bellboy.hrl deleted file mode 100644 index 6abb16c..0000000 --- a/include/bellboy.hrl +++ /dev/null @@ -1,20 +0,0 @@ --ifndef(BELLBOY_HRL). --define(BELLBOY_HRL, 1). - -%%% ================================================================== -%%% Bellboy -%%% ================================================================== - --define(NO_REDIRECT, {autoredirect, false}). --define(CIPHERS, [[{ciphers, [{rsa, aes_128_cbc, sha}]}]]). --define(SSLC, {ssl, ?CIPHERS}). --define(BAD_ARG, {error, bad_arg}). --define(PLIVO_URL_MSG(AuthID), "https://api.plivo.com/v1/Account/" ++ AuthID ++ "/Message/"). --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"). --define(BASIC_AUTH(AuthID, AuthToken), "Basic " ++ binary_to_list(base64:encode(AuthID ++ ":" ++ AuthToken))). --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"). --endif. diff --git a/src/bellboy.erl b/src/bellboy.erl index 749be74..b5709e9 100644 --- a/src/bellboy.erl +++ b/src/bellboy.erl @@ -33,13 +33,6 @@ nexmo/1 ]). -%%% ================================================================== -%%% Includes -%%% ================================================================== - --include("bellboy.hrl"). - - %%% ================================================================== %%% API functions %%% ================================================================== diff --git a/src/bellboy_nexmo.erl b/src/bellboy_nexmo.erl index 7117b8e..718eb46 100644 --- a/src/bellboy_nexmo.erl +++ b/src/bellboy_nexmo.erl @@ -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 diff --git a/src/bellboy_plivo.erl b/src/bellboy_plivo.erl index 6663352..7697ff2 100644 --- a/src/bellboy_plivo.erl +++ b/src/bellboy_plivo.erl @@ -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 @@ -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}}; @@ -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}}; @@ -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}}; diff --git a/src/bellboy_twilio.erl b/src/bellboy_twilio.erl index 3169469..eacaa05 100644 --- a/src/bellboy_twilio.erl +++ b/src/bellboy_twilio.erl @@ -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 @@ -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}}; @@ -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}}; @@ -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}}; diff --git a/src/bellboy_utils.erl b/src/bellboy_utils.erl index ad73e34..31bb342 100644 --- a/src/bellboy_utils.erl +++ b/src/bellboy_utils.erl @@ -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 %%% ================================================================== @@ -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)).