Browse files

WHISTLE-1006: Let's try this again. Added the ability to remove plus …

…from caller id.
  • Loading branch information...
1 parent 7265d1e commit c0cf60af69119a56874941ce808b641027391df4 Jon Blanton committed May 23, 2012
View
6 lib/whistle-1.0.0/src/wh_json.erl
@@ -22,7 +22,7 @@
-export([get_json_value/2, get_json_value/3]).
-export([is_true/2, is_true/3, is_false/2, is_false/3, is_empty/1]).
--export([filter/2, filter/3, map/2, find/2, find/3]).
+-export([filter/2, filter/3, map/2, foldl/3, find/2, find/3]).
-export([get_ne_value/2, get_ne_value/3]).
-export([get_value/2, get_value/3, get_values/1]).
-export([get_keys/1, get_keys/2]).
@@ -237,6 +237,10 @@ filter(Pred, JObj, Key) ->
map(F, ?JSON_WRAPPER(Prop)) ->
from_list([ F(K, V) || {K,V} <- Prop]).
+-spec foldl/3 :: (fun((json_string(), json_term(), Any) -> Any), Any, json_object()) -> Any.
+foldl(F, Acc0, ?JSON_WRAPPER(Prop)) ->
+ lists:foldl(fun({Key, Value}, Acc1) -> F(Key, Value, Acc1) end, Acc0, Prop).
+
-spec get_string_value/2 :: (json_string() | json_strings(), json_object() | json_objects()) -> 'undefined' | list().
-spec get_string_value/3 :: (json_string() | json_strings(), json_object(), Default) -> list() | Default.
get_string_value(Key, JObj) ->
View
2 whistle_apps/apps/callflow/src/cf_attributes.erl
@@ -217,7 +217,7 @@ caller_id_attributes(EndpointId, Attribute, Call) ->
caller_id_attributes(EndpointId, OwnerId, Attribute, Call) ->
Ids = [EndpointId, OwnerId, whapps_call:account_id(Call)],
lager:debug("find caller id attr ~s on ~s", [Attribute, wh_util:join_binary(Ids)]),
- Attributes = fetch_attributes(caller_id_options, Call),
+ Attributes = fetch_attributes(caller_id, Call),
case search_attributes(Attribute, Ids, Attributes) of
undefined ->
lager:debug("unable to find caller id attribute ~s", [Attribute]),
View
28 whistle_apps/apps/callflow/src/cf_endpoint.erl
@@ -174,7 +174,7 @@ create_sip_endpoint(Endpoint, Properties, Call) ->
,{<<"To-Realm">>, cf_util:get_sip_realm(Endpoint, whapps_call:account_id(Call))}
,{<<"To-DID">>, wh_json:get_value([<<"sip">>, <<"number">>], Endpoint, whapps_call:request_user(Call))}
,{<<"Route">>, wh_json:get_value([<<"sip">>, <<"route">>], Endpoint)}
- ,{<<"Outgoing-Caller-ID-Number">>, IntCIDNumber}
+ ,{<<"Outgoing-Caller-ID-Number">>, maybe_format_caller_id_number(Endpoint, IntCIDNumber, Call)}
,{<<"Outgoing-Caller-ID-Name">>, IntCIDName}
,{<<"Callee-ID-Number">>, CalleeNum}
,{<<"Callee-ID-Name">>, CalleeName}
@@ -334,3 +334,29 @@ generate_ccvs(Endpoint, Call, CallFwd) ->
end
],
lists:foldr(fun(F, J) -> F(J) end, wh_json:new(), CCVFuns).
+
+%%--------------------------------------------------------------------
+%% @private
+%% @doc
+%% Conditionally formats the caller id number
+%% @end
+%%--------------------------------------------------------------------
+-spec maybe_format_caller_id_number/3 :: (wh_json:json_object(), ne_binary(), whapps_call:call()) -> ne_binary().
+maybe_format_caller_id_number(Endpoint, CIDNum, Call) ->
+ case cf_attributes:caller_id_attributes(Endpoint, <<"format">>, Call) of
+ undefined ->
+ CIDNum;
+ FormatObj ->
+ case wh_json:is_json_object(FormatObj) of
+ true ->
+ wh_json:foldl(fun(Key, Value, CIDNum1) -> format_caller_id_number_flag(Key, Value, CIDNum1) end, CIDNum, FormatObj);
+ _ ->
+ CIDNum
+ end
+ end.
+
+-spec format_caller_id_number_flag/3 :: (ne_binary(), term(), ne_binary()) -> ne_binary().
+format_caller_id_number_flag(<<"remove_plus">>, true, <<$+, CIDNum/binary>>) ->
+ CIDNum;
+format_caller_id_number_flag(_Key, _Value, CIDNum) ->
+ CIDNum.

0 comments on commit c0cf60a

Please sign in to comment.