29
29
-export ([message /1 ]).
30
30
31
31
% %% ==================================================================
32
- % %% Includes
32
+ % %% Macros
33
33
% %% ==================================================================
34
34
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" ).
36
38
37
39
% %% ==================================================================
38
40
% %% API functions
@@ -69,7 +71,7 @@ send_message(#{account_sid := AID, auth_token := AT, body := B, from := F, to :=
69
71
case bellboy_utils :is_valid ([is_list (AID ), is_list (AT ), is_list (B ), is_list (F ), is_list (T )]) of
70
72
true ->
71
73
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 },
73
75
case bellboy_utils :httpc_request (RD ) of
74
76
{ok , Resp } ->
75
77
{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(_) ->
92
94
-spec get_message (Params :: maps :map ()) -> {ok , Result :: maps :map ()} | {error , Reason :: tuple () | bad_arg }.
93
95
94
96
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 )}},
96
98
case bellboy_utils :httpc_request (RD ) of
97
99
{ok , Resp } ->
98
100
{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(_) ->
112
114
-spec get_messages (Params :: maps :map ()) -> {ok , Result :: maps :map ()} | {error , Reason :: tuple () | bad_arg }.
113
115
114
116
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 )}},
116
118
case bellboy_utils :httpc_request (RD ) of
117
119
{ok , Resp } ->
118
120
{ok , #{code => bellboy_utils :get_code (Resp ), body => bellboy_utils :gen_body (bellboy_utils :get_body (Resp )), response => Resp }};
0 commit comments