Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

resolve KAZOO-807: update atoms and use the request to populate the subj... #24

Merged
merged 1 commit into from over 1 year ago

2 participants

bitbashing Peter
bitbashing
Owner

...ect line when possible

Peter macpie merged commit 471770c into from
Peter macpie closed this
bitbashing k-anderson deleted the branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Apr 08, 2013
bitbashing k-anderson resolve KAZOO-807: update atoms and use the request to populate the s…
…ubject line when possible
8ce99e4
This page is out of date. Refresh to see the latest.
8 whistle_apps/apps/hangups/src/hangups.erl
@@ -30,7 +30,7 @@ start_link() ->
30 30 %%--------------------------------------------------------------------
31 31 -spec stop() -> 'ok'.
32 32 stop() ->
33   - ok = application:stop(hangups).
  33 + 'ok' = application:stop('hangups').
34 34
35 35 %%--------------------------------------------------------------------
36 36 %% @private
@@ -41,6 +41,6 @@ stop() ->
41 41 -spec start_deps() -> 'ok'.
42 42 start_deps() ->
43 43 whistle_apps_deps:ensure(?MODULE), % if started by the whistle_controller, this will exist
44   - wh_util:ensure_started(sasl), % logging
45   - wh_util:ensure_started(crypto), % random
46   - wh_util:ensure_started(whistle_amqp). % amqp wrapper
  44 + wh_util:ensure_started('sasl'), % logging
  45 + wh_util:ensure_started('crypto'), % random
  46 + wh_util:ensure_started('whistle_amqp'). % amqp wrapper
10 whistle_apps/apps/hangups/src/hangups_app.erl
@@ -19,12 +19,12 @@
19 19 %% Implement the application start behaviour
20 20 %% @end
21 21 %%--------------------------------------------------------------------
22   --spec start(term(), term()) -> tuple(ok, pid()) | tuple(error, startlink_err()).
  22 +-spec start(term(), term()) -> {'ok', pid()} | {'error', startlink_err()}.
23 23 start(_, _) ->
24 24 case hangups:start_link() of
25   - {ok, P} -> {ok, P};
26   - {error, {already_started, P} } -> {ok, P};
27   - {error, _}=E -> E
  25 + {'ok', P} -> {'ok', P};
  26 + {'error', {'already_started', P}} -> {'ok', P};
  27 + {'error', _}=E -> E
28 28 end.
29 29
30 30 %%--------------------------------------------------------------------
@@ -35,4 +35,4 @@ start(_, _) ->
35 35 %%--------------------------------------------------------------------
36 36 -spec stop(term()) -> ok.
37 37 stop(_) ->
38   - ok.
  38 + 'ok'.
125 whistle_apps/apps/hangups/src/hangups_listener.erl
... ... @@ -1,7 +1,7 @@
1 1 %%%-------------------------------------------------------------------
2 2 %%% @copyright (C) 2010-2012, VoIP INC
3 3 %%% @doc
4   -%%%
  4 +%%%
5 5 %%% @end
6 6 %%%
7 7 %%% @contributors
@@ -29,11 +29,11 @@
29 29
30 30 -define(SERVER, ?MODULE).
31 31
32   --define(RESPONDERS, [{{?MODULE, handle_cdr}, [{<<"call_detail">>, <<"cdr">>}]}]).
33   --define(BINDINGS, [{call, [{restrict_to, [cdr]}, {callid, <<"*">>}]}]).
  32 +-define(RESPONDERS, [{{?MODULE, 'handle_cdr'}, [{<<"call_detail">>, <<"cdr">>}]}]).
  33 +-define(BINDINGS, [{'call', [{'restrict_to', ['cdr']}, {'callid', <<"*">>}]}]).
34 34 -define(QUEUE_NAME, <<"hangups_listener">>).
35   --define(QUEUE_OPTIONS, [{exclusive, false}]).
36   --define(CONSUME_OPTIONS, [{exclusive, false}]).
  35 +-define(QUEUE_OPTIONS, [{'exclusive', 'false'}]).
  36 +-define(CONSUME_OPTIONS, [{'exclusive', 'false'}]).
37 37
38 38 %%%===================================================================
39 39 %%% API
@@ -47,16 +47,16 @@
47 47 %% @end
48 48 %%--------------------------------------------------------------------
49 49 start_link() ->
50   - gen_listener:start_link(?MODULE, [{responders, ?RESPONDERS}
51   - ,{bindings, ?BINDINGS}
52   - ,{queue_name, ?QUEUE_NAME}
53   - ,{queue_options, ?QUEUE_OPTIONS}
54   - ,{consume_options, ?CONSUME_OPTIONS}
  50 + gen_listener:start_link(?MODULE, [{'responders', ?RESPONDERS}
  51 + ,{'bindings', ?BINDINGS}
  52 + ,{'queue_name', ?QUEUE_NAME}
  53 + ,{'queue_options', ?QUEUE_OPTIONS}
  54 + ,{'consume_options', ?CONSUME_OPTIONS}
55 55 ], []).
56 56
57 57 -spec handle_cdr(wh_json:json_object(), proplist()) -> no_return().
58 58 handle_cdr(JObj, _Props) ->
59   - true = wapi_call:cdr_v(JObj),
  59 + 'true' = wapi_call:cdr_v(JObj),
60 60 IgnoreCauses = whapps_config:get(<<"hangups">>, <<"ignore_hangup_causes">>, [<<"NO_ANSWER">>
61 61 ,<<"USER_BUSY">>
62 62 ,<<"NO_USER_RESPONSE">>
@@ -68,24 +68,18 @@ handle_cdr(JObj, _Props) ->
68 68 ]),
69 69 HangupCause = wh_json:get_value(<<"Hangup-Cause">>, JObj, <<"unknown">>),
70 70 case lists:member(HangupCause, IgnoreCauses) of
71   - true -> ok;
72   - false ->
  71 + 'true' -> 'ok';
  72 + 'false' ->
73 73 AccountId = wh_json:get_value([<<"Custom-Channel-Vars">>, <<"Account-ID">>], JObj),
74   -
75 74 lager:debug("abnormal call termination: ~s", [HangupCause]),
76   - FromNumber = case catch binary:split(wh_json:get_value(<<"From-Uri">>, JObj), <<"@">>) of
77   - [FNum|_] -> FNum;
78   - _ -> wh_json:get_value(<<"Caller-ID-Number">>, JObj)
79   - end,
80   - ToNumber = case catch binary:split(wh_json:get_value(<<"To-Uri">>, JObj), <<"@">>) of
81   - [TNum|_] -> TNum;
82   - _ -> wh_json:get_value(<<"Callee-ID-Number">>, JObj)
83   - end,
84   - Direction = wh_json:get_value(<<"Call-Direction">>, JObj),
85   - Realm = get_account_realm(AccountId),
86 75 wh_notify:system_alert("~s ~s to ~s (~s) on ~s(~s)"
87   - ,[wh_util:to_lower_binary(HangupCause), FromNumber, ToNumber, Direction, Realm, AccountId]
88   - ,wh_json:to_proplist(JObj))
  76 + ,[wh_util:to_lower_binary(HangupCause)
  77 + ,find_source(JObj)
  78 + ,find_destination(JObj)
  79 + ,find_direction(JObj)
  80 + ,find_realm(JObj, AccountId)
  81 + ,AccountId
  82 + ], wh_json:to_proplist(JObj))
89 83 end.
90 84
91 85 %%%===================================================================
@@ -105,7 +99,7 @@ handle_cdr(JObj, _Props) ->
105 99 %%--------------------------------------------------------------------
106 100 init([]) ->
107 101 lager:debug("started hangups listener"),
108   - {ok, ok}.
  102 + {'ok', 'ok'}.
109 103
110 104 %%--------------------------------------------------------------------
111 105 %% @private
@@ -122,8 +116,7 @@ init([]) ->
122 116 %% @end
123 117 %%--------------------------------------------------------------------
124 118 handle_call(_Request, _From, State) ->
125   - Reply = ok,
126   - {reply, Reply, State}.
  119 + {'reply', {'error', 'not_implemented'}, State}.
127 120
128 121 %%--------------------------------------------------------------------
129 122 %% @private
@@ -136,7 +129,7 @@ handle_call(_Request, _From, State) ->
136 129 %% @end
137 130 %%--------------------------------------------------------------------
138 131 handle_cast(_Msg, State) ->
139   - {noreply, State}.
  132 + {'noreply', State}.
140 133
141 134 %%--------------------------------------------------------------------
142 135 %% @private
@@ -149,7 +142,7 @@ handle_cast(_Msg, State) ->
149 142 %% @end
150 143 %%--------------------------------------------------------------------
151 144 handle_info(_Info, State) ->
152   - {noreply, State}.
  145 + {'noreply', State}.
153 146
154 147 %%--------------------------------------------------------------------
155 148 %% @private
@@ -160,7 +153,7 @@ handle_info(_Info, State) ->
160 153 %% @end
161 154 %%--------------------------------------------------------------------
162 155 handle_event(_JObj, _State) ->
163   - {reply, []}.
  156 + {'reply', []}.
164 157
165 158 %%--------------------------------------------------------------------
166 159 %% @private
@@ -175,7 +168,7 @@ handle_event(_JObj, _State) ->
175 168 %%--------------------------------------------------------------------
176 169 terminate(_Reason, _State) ->
177 170 lager:debug("hangups listener ~p termination", [_Reason]),
178   - ok.
  171 + 'ok'.
179 172
180 173 %%--------------------------------------------------------------------
181 174 %% @private
@@ -186,15 +179,71 @@ terminate(_Reason, _State) ->
186 179 %% @end
187 180 %%--------------------------------------------------------------------
188 181 code_change(_OldVsn, State, _Extra) ->
189   - {ok, State}.
  182 + {'ok', State}.
190 183
191 184 %%%===================================================================
192 185 %%% Internal functions
193 186 %%%===================================================================
194   --spec get_account_realm(ne_binary()) -> api_binary().
195   -get_account_realm(undefined) -> undefined;
  187 +%%--------------------------------------------------------------------
  188 +%% @private
  189 +%% @doc
  190 +%%
  191 +%% @end
  192 +%%--------------------------------------------------------------------
  193 +-spec find_realm(wh_json:object(), ne_binary()) -> ne_binary().
  194 +find_realm(JObj, AccountId) ->
  195 + case wh_json:get_value([<<"Custom-Channel-Vars">>, <<"Account-ID">>], JObj) of
  196 + 'undefined' -> get_account_realm(AccountId);
  197 + Realm -> Realm
  198 + end.
  199 +
  200 +-spec get_account_realm(api_binary()) -> ne_binary().
  201 +get_account_realm('undefined') -> <<"unknown">>;
196 202 get_account_realm(AccountId) ->
197 203 case couch_mgr:open_cache_doc(?WH_ACCOUNTS_DB, AccountId) of
198   - {ok, JObj} -> wh_json:get_value(<<"realm">>, JObj);
199   - {error, _} -> undefined
  204 + {'ok', JObj} -> wh_json:get_value(<<"realm">>, JObj, <<"unknown">>);
  205 + {'error', _} -> <<"unknown">>
  206 + end.
  207 +
  208 +%%--------------------------------------------------------------------
  209 +%% @private
  210 +%% @doc
  211 +%%
  212 +%% @end
  213 +%%--------------------------------------------------------------------
  214 +-spec find_destination(wh_json:object()) -> ne_binary().
  215 +find_destination(JObj) ->
  216 + case catch binary:split(wh_json:get_value(<<"Request">>, JObj), <<"@">>) of
  217 + [Num|_] -> Num;
  218 + _ -> use_to_as_destination(JObj)
200 219 end.
  220 +
  221 +-spec use_to_as_destination(wh_json:object()) -> ne_binary().
  222 +use_to_as_destination(JObj) ->
  223 + case catch binary:split(wh_json:get_value(<<"To-Uri">>, JObj), <<"@">>) of
  224 + [Num|_] -> Num;
  225 + _ -> wh_json:get_value(<<"Callee-ID-Number">>, JObj, <<"unknown">>)
  226 + end.
  227 +
  228 +%%--------------------------------------------------------------------
  229 +%% @private
  230 +%% @doc
  231 +%%
  232 +%% @end
  233 +%%--------------------------------------------------------------------
  234 +-spec find_source(wh_json:object()) -> ne_binary().
  235 +find_source(JObj) ->
  236 + case catch binary:split(wh_json:get_value(<<"From-Uri">>, JObj), <<"@">>) of
  237 + [Num|_] -> Num;
  238 + _ -> wh_json:get_value(<<"Caller-ID-Number">>, JObj, <<"unknown">>)
  239 + end.
  240 +
  241 +%%--------------------------------------------------------------------
  242 +%% @private
  243 +%% @doc
  244 +%%
  245 +%% @end
  246 +%%--------------------------------------------------------------------
  247 +-spec find_direction(wh_json:object()) -> ne_binary().
  248 +find_direction(JObj) ->
  249 + wh_json:get_value(<<"Call-Direction">>, JObj, <<"unknown">>).
10 whistle_apps/apps/hangups/src/hangups_sup.erl
@@ -18,8 +18,8 @@
18 18 -export([init/1]).
19 19
20 20 %% Helper macro for declaring children of supervisor
21   --define(CHILD(Name, Type), {Name, {Name, start_link, []}, permanent, 5000, Type, [Name]}).
22   --define(CHILDREN, [{hangups_listener, worker}]).
  21 +-define(CHILD(Name, Type), {Name, {Name, 'start_link', []}, 'permanent', 5000, Type, [Name]}).
  22 +-define(CHILDREN, [{'hangups_listener', 'worker'}]).
23 23
24 24 %% ===================================================================
25 25 %% API functions
@@ -33,7 +33,7 @@
33 33 %%--------------------------------------------------------------------
34 34 -spec start_link() -> startlink_ret().
35 35 start_link() ->
36   - supervisor:start_link({local, ?MODULE}, ?MODULE, []).
  36 + supervisor:start_link({'local', ?MODULE}, ?MODULE, []).
37 37
38 38 %% ===================================================================
39 39 %% Supervisor callbacks
@@ -50,11 +50,11 @@ start_link() ->
50 50 %%--------------------------------------------------------------------
51 51 -spec init([]) -> sup_init_ret().
52 52 init([]) ->
53   - RestartStrategy = one_for_one,
  53 + RestartStrategy = 'one_for_one',
54 54 MaxRestarts = 5,
55 55 MaxSecondsBetweenRestarts = 10,
56 56
57 57 SupFlags = {RestartStrategy, MaxRestarts, MaxSecondsBetweenRestarts},
58 58 Children = [?CHILD(Name, Type) || {Name, Type} <- ?CHILDREN],
59 59
60   - {ok, {SupFlags, Children}}.
  60 + {'ok', {SupFlags, Children}}.

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.