Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

4.3.caller id numbers #6655

Open
wants to merge 6 commits into
base: 4.3
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion applications/tasks/src/modules/kt_rates.erl
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,33 @@ get_ratedeck_db(_ExtraArgs) ->
-spec to_csv_row(kz_json:object()) -> kz_csv:row().
to_csv_row(Row) ->
Doc = kz_json:get_json_value(<<"doc">>, Row),
[kz_json:get_binary_value(Key, Doc) || Key <- ?DOC_FIELDS].
[to_csv(Key, Doc) || Key <- ?DOC_FIELDS].

-spec to_csv(kz_term:ne_binary(), kz_json:object()) -> kz_term:ne_binary().
% Convert list of regex's to a ":" seperated binary string
% e.g. [<<"^\\+?441.+$">>,<<"^\\+?442.+$">>,<<"^\\+?443.+$">>,<<"^\\+?447.+$">>] -> <<"441:442:443:447">>
to_csv(<<"caller_id_numbers">>, Doc) ->
case kzd_rates:caller_id_numbers(Doc) of
'undefined' -> 'undefined';
RegexList ->
try
RE = "^\\^\\\\\\+\\?(.*)\\\.\\+\\$",
<<":", ColonList/binary>> =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would look at using kz_binary:join([convert_regex_to_caller_id()], <<":">>) instead of the fold, personally.

lists:foldr(fun(X, Acc) ->
{match, [Y]} = re:run(X, RE, [{capture, all_but_first, binary}]),
<<$:, Y/binary, Acc/binary>>
end,
<<>>,
RegexList),
ColonList
catch
E:R ->
lager:warning("caller_id_numbers filters not in expected format ~p:~p", [E, R]),
RegexList
end
end;
to_csv(Key, Doc) ->
kz_json:get_binary_value(Key, Doc).

-spec maybe_override_rate(kz_tasks:args()) -> kzd_rates:doc().
maybe_override_rate(Args) ->
Expand Down
2 changes: 1 addition & 1 deletion core/kazoo_documents/src/kzd_rates.erl
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ caller_id_numbers(Doc) ->

-spec caller_id_numbers(doc(), Default) -> binary() | Default.
caller_id_numbers(Doc, Default) ->
kz_json:get_binary_value([<<"caller_id_numbers">>], Doc, Default).
kz_json:get_list_value([<<"caller_id_numbers">>], Doc, Default).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spec needs updating if you're fetching a list here.


-spec set_caller_id_numbers(doc(), binary()) -> doc().
set_caller_id_numbers(Doc, CallerIdNumbers) ->
Expand Down