Skip to content

Commit

Permalink
Merge branch 'master' into v1.55
Browse files Browse the repository at this point in the history
  • Loading branch information
k-anderson committed Jun 14, 2012
2 parents d3c79b4 + ea2d52e commit 29e0fbc
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 28 deletions.
30 changes: 25 additions & 5 deletions lib/whistle-1.0.0/src/props.erl
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,25 @@
%%%-------------------------------------------------------------------
-module(props).

-export([get_value/2, get_value/3, delete/2, is_defined/2]).
-export([get_integer_value/2, get_integer_value/3]).
-export([get_is_true/2, get_is_true/3
-export([get_value/2, get_value/3
,delete/2, is_defined/2
,get_integer_value/2, get_integer_value/3
,get_is_true/2, get_is_true/3
,get_is_false/2, get_is_false/3
,get_keys/1
,unique/1
,filter/2, filter_empty/1
]).
-export([get_keys/1]).
-export([unique/1]).

-include_lib("whistle/include/wh_types.hrl").

-spec filter/2 :: (fun(({wh_proplist_key(), wh_proplist_value()}) -> boolean()), wh_proplist()) -> wh_proplist().
filter(Fun, Prop) when is_function(Fun, 1), is_list(Prop) ->
lists:filter(Fun, Prop).

filter_empty(Prop) ->
lists:filter(fun({_, V}) -> not wh_util:is_empty(V) end, Prop).

-spec get_value/2 :: (wh_proplist_key(), wh_proplist()) -> term().
-spec get_value/3 :: (wh_proplist_key(), wh_proplist(), Default) -> Default | term().
get_value(Key, Prop) ->
Expand Down Expand Up @@ -97,6 +106,17 @@ unique([{Key, _}=H|T], Uniques) ->
-include_lib("eunit/include/eunit.hrl").
-ifdef(TEST).

filter_test() ->
Fun = fun({_, V}) -> V < 5 end,
?assertEqual([], filter(Fun, [])),
?assertEqual([], filter(Fun, [{a, 10}, {b, 8}, {c, 6}])),
?assertEqual([{z, 1}], filter(Fun, [{a, 10}, {b, 8}, {c, 6}, {z, 1}])).

filter_empty_test() ->
?assertEqual([], filter_empty([])),
?assertEqual([{a, 10}, {b, 8}, {c, 6}], filter_empty([{a, 10}, {b, 8}, {c, 6}])),
?assertEqual([], filter_empty([{a, 0}, {b, []}, {c, <<>>}, {z, undefined}])).

unique_test() ->
L = [{a, b}, {a, b}, {a, c}, {b,c}, {b,d}],
?assertEqual([{a, b}, {b, c}], unique(L)).
Expand Down
13 changes: 12 additions & 1 deletion lib/whistle-1.0.0/src/wh_api.erl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
-module(wh_api).

%% API
-export([default_headers/2
-export([default_headers_v/1
,default_headers/2
,default_headers/3
,default_headers/4
,default_headers/5
Expand Down Expand Up @@ -54,6 +55,8 @@
%% All fields are required general headers.
%% @end
%%--------------------------------------------------------------------
-spec default_headers_v/1 :: (api_terms()) -> boolean().

-spec default_headers/2 :: (ne_binary(), ne_binary()) -> proplist().
-spec default_headers/3 :: (binary(), ne_binary(), ne_binary()) -> proplist().
-spec default_headers/4 :: (ne_binary(), ne_binary(), ne_binary(), ne_binary()) -> proplist().
Expand Down Expand Up @@ -81,6 +84,14 @@ default_headers(ServerID, EvtCat, EvtName, AppName, AppVsn) ->
,{<<"Node">>, wh_util:to_binary(node())}
].

default_headers_v(Prop) ->
props:get_value(<<"Server-ID">>, Prop) =/= undefined
andalso (not wh_util:is_empty(props:get_value(<<"Event-Category">>, Prop)))
andalso (not wh_util:is_empty(props:get_value(<<"Event-Name">>, Prop)))
andalso (not wh_util:is_empty(props:get_value(<<"App-Name">>, Prop)))
andalso (not wh_util:is_empty(props:get_value(<<"App-Version">>, Prop)))
andalso (not wh_util:is_empty(props:get_value(<<"Node">>, Prop))).

disambiguate_and_publish(ReqJObj, RespJObj, Binding) ->
Wapi = list_to_binary([<<"wapi_">>, wh_util:to_binary(Binding)]),
lager:debug("Wapi mod: ~s", [Wapi]),
Expand Down
2 changes: 1 addition & 1 deletion lib/whistle-1.0.0/src/wh_json.erl
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ map(F, ?JSON_WRAPPER(Prop)) ->
from_list([ F(K, V) || {K,V} <- Prop]).

-spec foldl/3 :: (fun((json_string() | json_strings(), json_term(), any()) -> any()), any(), json_object()) -> any().
foldl(F, Acc0, ?JSON_WRAPPER(Prop)) ->
foldl(F, Acc0, ?JSON_WRAPPER(Prop)) when is_function(F, 3) ->
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().
Expand Down
9 changes: 9 additions & 0 deletions lib/whistle-1.0.0/src/wh_util.erl
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
%%%-------------------------------------------------------------------
%%% @copyright (C) 2010-2012, VoIP INC
%%% @doc
%%% Various utilities - a veritable cornicopia
%%% @end
%%% @contributors
%%% James Aimonetti
%%% Karl Anderson
%%%-------------------------------------------------------------------
-module(wh_util).

-export([format_account_id/1, format_account_id/2]).
Expand Down
5 changes: 1 addition & 4 deletions lib/whistle_translator-1.0.0/src/wht_twiml.erl
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ collect_digits(Call, MaxDigits, FinishOnKey, Timeout, Props) ->
case whapps_call_command:collect_digits(MaxDigitsBin, Timeout, 2000
,undefined, [FinishOnKey], Call
) of
{ok, DTMFs} when byte_size(DTMFs) =:= MaxDigits ->
{ok, DTMFs} ->
lager:debug("recv DTMFs: ~s", [DTMFs]),

NewUri = wht_util:resolve_uri(whapps_call:kvs_fetch(<<"voice_uri">>, Call)
Expand All @@ -485,9 +485,6 @@ collect_digits(Call, MaxDigits, FinishOnKey, Timeout, Props) ->
BaseParams = wh_json:from_list([{<<"Digits">>, DTMFs} | req_params(Call)]),

{request, Call, NewUri, Method, BaseParams};
{ok, _DTMFs} ->
lager:debug("failed to collect ~b digits, got ~s", [MaxDigits, _DTMFs]),
{ok, Call};
{error, _E} ->
lager:debug("failed to collect ~b digits, error: ~p", [MaxDigits, _E]),
{stop, Call}
Expand Down
8 changes: 5 additions & 3 deletions whistle_apps/apps/crossbar/doc/create_ssl_certs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,11 @@ Getting Private key

Now modify the "crossbar" doc in the "system_config" database with the following values:

"ssl_port":"8443"
,"ssl_cert":"priv/ssl/crossbar.crt"
,"ssl_key":"priv/ssl/crossbar.key"
"default":{
"ssl_port":"8443"
,"ssl_cert":"priv/ssl/crossbar.crt"
,"ssl_key":"priv/ssl/crossbar.key"
}

Start Crossbar. You can now test your new SSL-enabled APIs via:

Expand Down
45 changes: 31 additions & 14 deletions whistle_apps/src/whapps_call_command.erl
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@
{'prompt', binary()} | {'prompt', binary(), binary()} |
{'say', binary()} | {'say', binary(), binary()} |
{'say', binary(), binary(), binary()} | {'say', binary(), binary(), binary(), binary()} |
{'tones', wh_json:json_objects()}.
{'tones', wh_json:json_objects()} |
{'tts', ne_binary()} | {'tts', ne_binary(), ne_binary()} | {'tts', ne_binary(), ne_binary(), ne_binary()}.
-export_type([audio_macro_prompt/0]).

-spec audio_macro/2 :: ([audio_macro_prompt(),...], whapps_call:call()) -> ne_binary().
Expand Down Expand Up @@ -138,7 +139,13 @@ audio_macro([{say, Say, Type, Method}|T], Call, Queue) ->
audio_macro([{say, Say, Type, Method, Language}|T], Call, Queue) ->
audio_macro(T, Call, [say_command(Say, Type, Method, Language, Call) | Queue]);
audio_macro([{tones, Tones}|T], Call, Queue) ->
audio_macro(T, Call, [tones_command(Tones, Call) | Queue]).
audio_macro(T, Call, [tones_command(Tones, Call) | Queue]);
audio_macro([{tts, Text}|T], Call, Queue) ->
audio_macro(T, Call, [tts_command(Text, Call) | Queue]);
audio_macro([{tts, Text, Voice}|T], Call, Queue) ->
audio_macro(T, Call, [tts_command(Text, Voice, Call) | Queue]);
audio_macro([{tts, Text, Voice, Lang}|T], Call, Queue) ->
audio_macro(T, Call, [tts_command(Text, Voice, Lang, Call) | Queue]).

%%--------------------------------------------------------------------
%% @public
Expand Down Expand Up @@ -672,28 +679,38 @@ tts(SayMe, Voice, Lang, Call) ->

tts(SayMe, Voice, Lang, Terminators, Call) ->
NoopId = couch_mgr:get_uuid(),
CallId = whapps_call:call_id(Call),
Q = whapps_call:controller_queue(Call),

Commands = [wh_json:from_list([{<<"Application-Name">>, <<"noop">>}
,{<<"Call-ID">>, CallId}
,{<<"Call-ID">>, whapps_call:call_id(Call)}
,{<<"Msg-ID">>, NoopId}
| wh_api:default_headers(Q, <<"call">>, <<"command">>, ?APP_NAME, ?APP_VERSION)
])
,wh_json:from_list([{<<"Application-Name">>, <<"play">>}
,{<<"Media-Name">>, list_to_binary([<<"tts://">>, SayMe])}
,{<<"Terminators">>, Terminators}
,{<<"Voice">>, Voice}
,{<<"Language">>, Lang}
,{<<"Call-ID">>, CallId}
| wh_api:default_headers(Q, <<"call">>, <<"command">>, ?APP_NAME, ?APP_VERSION)
])
,tts_command(SayMe, Voice, Lang, Terminators, Call)
],
Command = [{<<"Application-Name">>, <<"queue">>}
,{<<"Commands">>, Commands}
],
send_command(Command, Call),
NoopId.

-spec tts_command/2 :: (ne_binary(), whapps_call:call()) -> wh_json:json_object().
-spec tts_command/3 :: (ne_binary(), ne_binary(), whapps_call:call()) -> wh_json:json_object().
-spec tts_command/4 :: (ne_binary(), ne_binary(), ne_binary(), whapps_call:call()) -> wh_json:json_object().
-spec tts_command/5 :: (ne_binary(), ne_binary(), ne_binary(), list(), whapps_call:call()) -> wh_json:json_object().
tts_command(SayMe, Call) ->
tts_command(SayMe, <<"female">>, Call).
tts_command(SayMe, Voice, Call) ->
tts_command(SayMe, Voice, <<"en-US">>, Call).
tts_command(SayMe, Voice, Lang, Call) ->
tts_command(SayMe, Voice, Lang, ?ANY_DIGIT, Call).
tts_command(SayMe, Voice, Lang, Terminators, Call) ->
wh_json:from_list([{<<"Application-Name">>, <<"play">>}
,{<<"Media-Name">>, list_to_binary([<<"tts://">>, SayMe])}
,{<<"Terminators">>, Terminators}
,{<<"Voice">>, Voice}
,{<<"Language">>, Lang}
,{<<"Call-ID">>, whapps_call:call_id(Call)}
]).

-spec b_tts/2 :: (ne_binary(), whapps_call:call()) -> whapps_api_std_return().
-spec b_tts/3 :: (ne_binary(), ne_binary(), whapps_call:call()) -> whapps_api_std_return().
-spec b_tts/4 :: (ne_binary(), ne_binary(), ne_binary(), whapps_call:call()) -> whapps_api_std_return().
Expand Down

0 comments on commit 29e0fbc

Please sign in to comment.