tropo-webapi-ruby 0.1.10 → 0.1.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Rakefile +4 -6
- data/VERSION +1 -1
- data/lib/tropo-webapi-ruby/tropo-webapi-ruby-helpers.rb +23 -21
- data/spec/spec_helper.rb +1 -1
- data/spec/tropo-webapi-ruby_spec.rb +121 -129
- data/tropo-webapi-ruby.gemspec +20 -28
- metadata +20 -12
- data/.gitignore +0 -24
data/Rakefile
CHANGED
@@ -24,14 +24,12 @@ rescue LoadError
|
|
24
24
|
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
25
25
|
end
|
26
26
|
|
27
|
-
require '
|
28
|
-
|
29
|
-
spec.
|
30
|
-
spec.spec_files = FileList['spec/**/*_spec.rb']
|
27
|
+
require 'rspec/core/rake_task'
|
28
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
29
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
31
30
|
end
|
32
31
|
|
33
|
-
|
34
|
-
spec.libs << 'lib' << 'spec'
|
32
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
35
33
|
spec.pattern = 'spec/**/*_spec.rb'
|
36
34
|
spec.rcov = true
|
37
35
|
end
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.11
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module Tropo
|
2
2
|
module Helpers
|
3
3
|
private
|
4
|
-
|
4
|
+
|
5
5
|
##
|
6
6
|
# Method checks for presence of required elements and then builds the action
|
7
7
|
#
|
@@ -10,10 +10,12 @@ module Tropo
|
|
10
10
|
# @return [Hash] provides the properply built hash for the action
|
11
11
|
def build_action(action, params)
|
12
12
|
raise ArgumentError, 'Action requires parameters' if params.nil?
|
13
|
-
|
13
|
+
|
14
14
|
case action
|
15
|
+
when 'ask'
|
16
|
+
has_params?(params, 'ask', 'name')
|
15
17
|
when 'choices'
|
16
|
-
if params[:mode]
|
18
|
+
if params[:mode]
|
17
19
|
if params[:mode] != 'dtmf' && params[:mode] != 'speech'
|
18
20
|
raise ArgumentError, "If mode is provided, only 'dtmf', 'speech' or 'any' is supported"
|
19
21
|
end
|
@@ -26,7 +28,7 @@ module Tropo
|
|
26
28
|
has_params?(params, 'record', ['name', 'url'])
|
27
29
|
when 'start_recording'
|
28
30
|
has_params?(params, 'start_recording', ['url'])
|
29
|
-
|
31
|
+
|
30
32
|
# Camelcase this one to be Java friendly
|
31
33
|
action = 'startRecording'
|
32
34
|
when 'redirect'
|
@@ -38,14 +40,14 @@ module Tropo
|
|
38
40
|
when 'transfer'
|
39
41
|
has_params?(params, 'transfer', 'to')
|
40
42
|
end
|
41
|
-
|
43
|
+
|
42
44
|
if action == 'on'
|
43
45
|
build_elements(params)
|
44
46
|
else
|
45
47
|
{ action.to_sym => build_elements(params) }
|
46
48
|
end
|
47
49
|
end
|
48
|
-
|
50
|
+
|
49
51
|
##
|
50
52
|
# Checks to see if certain parameters are present, and if not raises an error
|
51
53
|
#
|
@@ -64,7 +66,7 @@ module Tropo
|
|
64
66
|
raise ArgumentError, "A '#{names}' must be provided to a '#{action}' action" if params[names.to_sym].nil?
|
65
67
|
end
|
66
68
|
end
|
67
|
-
|
69
|
+
|
68
70
|
# Takes a Ruby underscore string and converts to a Java friendly camelized string
|
69
71
|
#
|
70
72
|
# @param [String] the string to be camelized
|
@@ -75,7 +77,7 @@ module Tropo
|
|
75
77
|
return_string = return_string + split_string[2].capitalize if split_string[2]
|
76
78
|
return_string
|
77
79
|
end
|
78
|
-
|
80
|
+
|
79
81
|
##
|
80
82
|
# Creates a nested hash when we have block within a block
|
81
83
|
#
|
@@ -97,7 +99,7 @@ module Tropo
|
|
97
99
|
@nested_on_hash_cnt ||= 0
|
98
100
|
@nested_on_hash[:on] << params
|
99
101
|
end
|
100
|
-
|
102
|
+
|
101
103
|
##
|
102
104
|
# Creates an on_hash for the on action
|
103
105
|
#
|
@@ -105,7 +107,7 @@ module Tropo
|
|
105
107
|
def create_on_hash
|
106
108
|
@on_hash ||= { :on => Array.new }
|
107
109
|
end
|
108
|
-
|
110
|
+
|
109
111
|
##
|
110
112
|
# Method builds the elements for each of the actions
|
111
113
|
#
|
@@ -122,9 +124,9 @@ module Tropo
|
|
122
124
|
end
|
123
125
|
end
|
124
126
|
end
|
125
|
-
|
127
|
+
|
126
128
|
hash = Hash.new
|
127
|
-
params.each_pair do |k,v|
|
129
|
+
params.each_pair do |k,v|
|
128
130
|
if k.to_s.include? "_"
|
129
131
|
k = camelize k.to_s
|
130
132
|
k = k.to_sym if k
|
@@ -133,7 +135,7 @@ module Tropo
|
|
133
135
|
end
|
134
136
|
hash
|
135
137
|
end
|
136
|
-
|
138
|
+
|
137
139
|
##
|
138
140
|
# Takes a Java Camelized string and converts to an underscore string
|
139
141
|
#
|
@@ -142,7 +144,7 @@ module Tropo
|
|
142
144
|
def decamelize(camel_string)
|
143
145
|
camel_string.gsub(/[A-Z]/) { |char| '_' + char.downcase }
|
144
146
|
end
|
145
|
-
|
147
|
+
|
146
148
|
##
|
147
149
|
# Formats the @response instance variable to JSON before making it available to the accessor
|
148
150
|
#
|
@@ -150,7 +152,7 @@ module Tropo
|
|
150
152
|
def render_response
|
151
153
|
@response.to_json
|
152
154
|
end
|
153
|
-
|
155
|
+
|
154
156
|
##
|
155
157
|
# Determines if there is a voice or recognizer specified, if not set it to the default specified and if not default leave it alone
|
156
158
|
# this is for the speech synthesis and speech recognition language to use on a say/ask methods
|
@@ -162,7 +164,7 @@ module Tropo
|
|
162
164
|
params.merge!({ :voice => @voice }) if params[:voice].nil? && @voice
|
163
165
|
params
|
164
166
|
end
|
165
|
-
|
167
|
+
|
166
168
|
##
|
167
169
|
# Returns an hash from a collapsed array, using the values of 'key' or 'name' as the collpassed hash key
|
168
170
|
#
|
@@ -175,10 +177,10 @@ module Tropo
|
|
175
177
|
# Set the key to the value of the respresentative key
|
176
178
|
key = ele['key'] if ele['key']
|
177
179
|
key = ele['name'] if ele['name']
|
178
|
-
|
180
|
+
|
179
181
|
# Merge this new key into the hash
|
180
182
|
transformed_to_hash.merge!({ key => Hash.new })
|
181
|
-
|
183
|
+
|
182
184
|
# Then add the corresponding key/values to this new hash
|
183
185
|
ele.each_pair do |k, v|
|
184
186
|
if k != 'key' && k != 'name'
|
@@ -209,7 +211,7 @@ module Tropo
|
|
209
211
|
# @param[Hash] the newly created hash that contins the properly formatted key
|
210
212
|
def transform_pair(key, value)
|
211
213
|
hash = { decamelize(key) => value }
|
212
|
-
hash['timestamp'] = Time.parse(value) if hash['timestamp']
|
214
|
+
hash['timestamp'] = Time.parse(value) if hash['timestamp'] && (! hash['timestamp'].is_a?(Time))
|
213
215
|
if hash['actions']
|
214
216
|
if hash['actions']['name']
|
215
217
|
key_name = hash['actions']['name']
|
@@ -220,11 +222,11 @@ module Tropo
|
|
220
222
|
set_session_type(hash) if hash['channel']
|
221
223
|
hash
|
222
224
|
end
|
223
|
-
|
225
|
+
|
224
226
|
##
|
225
227
|
# Sets the session type instance variables of voice_session and text_session
|
226
228
|
#
|
227
|
-
# @param[Hash] the key, value pair of the channel
|
229
|
+
# @param[Hash] the key, value pair of the channel
|
228
230
|
# @return nil
|
229
231
|
def set_session_type(hash)
|
230
232
|
case hash['channel']
|
data/spec/spec_helper.rb
CHANGED
@@ -1,19 +1,19 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
2
|
|
3
3
|
describe "Tropo" do
|
4
|
-
|
4
|
+
|
5
5
|
# Ask action tests (and alias Prompt)
|
6
6
|
it "should generate a complete 'ask' JSON document" do
|
7
|
-
response = Tropo::Generator.ask({ :name => 'foo',
|
8
|
-
:bargein => 'true',
|
7
|
+
response = Tropo::Generator.ask({ :name => 'foo',
|
8
|
+
:bargein => 'true',
|
9
9
|
:timeout => 30,
|
10
10
|
:require => 'true' })
|
11
11
|
JSON.parse(response).should == { "tropo" => [{ "ask" => { "name" => "foo", "bargein" => "true", "timeout" => 30, "require" => "true" } }] }
|
12
12
|
end
|
13
|
-
|
13
|
+
|
14
14
|
it "should generate an 'ask' JSON document when a block is passed" do
|
15
|
-
response = Tropo::Generator.ask({ :name => 'foo',
|
16
|
-
:bargein => 'true',
|
15
|
+
response = Tropo::Generator.ask({ :name => 'foo',
|
16
|
+
:bargein => 'true',
|
17
17
|
:timeout => 30,
|
18
18
|
:require => 'true' }) do
|
19
19
|
say :value => 'Please say your account number'
|
@@ -25,8 +25,8 @@ describe "Tropo" do
|
|
25
25
|
# There is currently a feature request to support an on within an ask
|
26
26
|
#
|
27
27
|
# it "should generate an 'ask' JSON document when a block is passed with an 'on' action" do
|
28
|
-
# response = Tropo::Generator.ask({ :name => 'foo',
|
29
|
-
# :bargein => 'true',
|
28
|
+
# response = Tropo::Generator.ask({ :name => 'foo',
|
29
|
+
# :bargein => 'true',
|
30
30
|
# :timeout => 30,
|
31
31
|
# :require => 'true' }) do
|
32
32
|
# say :value => 'Please say your account number'
|
@@ -35,7 +35,7 @@ describe "Tropo" do
|
|
35
35
|
# end
|
36
36
|
# JSON.parse(response).should == {"tropo"=>[{"ask"=>{"name"=>"foo", "say"=>[{"value"=>"Please say your account number"}], "bargein"=>"true", "timeout"=>30, "require"=>"true", "on"=>[{"event"=>"success", "next"=>"/result.json"}], "choices"=>{"value"=>"[5 DIGITS]"}}}]}
|
37
37
|
# end
|
38
|
-
|
38
|
+
|
39
39
|
it "should generate an error if an 'ask' is passed without a 'name' parameter" do
|
40
40
|
begin
|
41
41
|
response = Tropo::Generator.ask({ :foo => 'bar' })
|
@@ -43,19 +43,19 @@ describe "Tropo" do
|
|
43
43
|
err.to_s.should == "A 'name' must be provided to a 'ask' action"
|
44
44
|
end
|
45
45
|
end
|
46
|
-
|
46
|
+
|
47
47
|
# Prompt
|
48
48
|
it "should generate a complete 'prompt' JSON document" do
|
49
|
-
response = Tropo::Generator.prompt({ :name => 'foo',
|
50
|
-
:bargein => 'true',
|
49
|
+
response = Tropo::Generator.prompt({ :name => 'foo',
|
50
|
+
:bargein => 'true',
|
51
51
|
:timeout => 30,
|
52
52
|
:require => 'true' })
|
53
53
|
JSON.parse(response).should == { "tropo" => [{ "ask" => { "name" => "foo", "bargein" => "true", "timeout" => 30, "require" => "true" } }] }
|
54
54
|
end
|
55
|
-
|
55
|
+
|
56
56
|
it "should generate an 'prompt' JSON document when a block is passed" do
|
57
|
-
response = Tropo::Generator.prompt({ :name => 'foo',
|
58
|
-
:bargein => 'true',
|
57
|
+
response = Tropo::Generator.prompt({ :name => 'foo',
|
58
|
+
:bargein => 'true',
|
59
59
|
:timeout => 30,
|
60
60
|
:require => 'true' }) do
|
61
61
|
say :value => 'Please say your account number'
|
@@ -63,7 +63,7 @@ describe "Tropo" do
|
|
63
63
|
end
|
64
64
|
JSON.parse(response).should == {"tropo"=>[{"ask"=>{"name"=>"foo", "say"=>[{"value"=>"Please say your account number"}], "bargein"=>"true", "timeout"=>30, "require"=>"true", "choices"=>{"value"=>"[5 DIGITS]"}}}]}
|
65
65
|
end
|
66
|
-
|
66
|
+
|
67
67
|
it "should generate an error if an 'prompt' is passed without a 'name' parameter" do
|
68
68
|
begin
|
69
69
|
response = Tropo::Generator.prompt({ :foo => 'bar' })
|
@@ -71,13 +71,13 @@ describe "Tropo" do
|
|
71
71
|
err.to_s.should == "A 'name' must be provided to a 'ask' action"
|
72
72
|
end
|
73
73
|
end
|
74
|
-
|
74
|
+
|
75
75
|
# Choices tests
|
76
76
|
it "should generate a standard 'choices' JSON document" do
|
77
77
|
response = Tropo::Generator.choices({ :value => '[5 DIGITS]' })
|
78
78
|
JSON.parse(response).should == { 'tropo' => [{ 'choices' => { 'value' => '[5 DIGITS]' } }] }
|
79
79
|
end
|
80
|
-
|
80
|
+
|
81
81
|
it "should raise an error if a 'choices' passes an unspported mode" do
|
82
82
|
begin
|
83
83
|
response = Tropo::Generator.choices({ :value => '[5 DIGITS]', :mode => 'frootloops' })
|
@@ -85,25 +85,25 @@ describe "Tropo" do
|
|
85
85
|
err.to_s.should == "If mode is provided, only 'dtmf', 'speech' or 'any' is supported"
|
86
86
|
end
|
87
87
|
end
|
88
|
-
|
88
|
+
|
89
89
|
it "should generate a standard 'choices' JSON document with a mode" do
|
90
90
|
response = Tropo::Generator.choices({ :value => '[5 DIGITS]', :mode => 'dtmf' })
|
91
91
|
JSON.parse(response).should == { 'tropo' => [{ 'choices' => { 'value' => '[5 DIGITS]', 'mode' => 'dtmf' } }] }
|
92
92
|
end
|
93
|
-
|
93
|
+
|
94
94
|
# Conference action tests
|
95
95
|
it "should generate a complete 'conference' JSON document" do
|
96
|
-
response = Tropo::Generator.conference({ :name => 'foo',
|
97
|
-
:id => '1234',
|
96
|
+
response = Tropo::Generator.conference({ :name => 'foo',
|
97
|
+
:id => '1234',
|
98
98
|
:mute => false,
|
99
99
|
:send_tones => false,
|
100
100
|
:exit_tone => '#' })
|
101
101
|
JSON.parse(response).should == {"tropo"=>[{"conference"=>{"name"=>"foo", "mute"=>false, "sendTones"=>false, "id"=>"1234", "exitTone"=>"#"}}]}
|
102
102
|
end
|
103
|
-
|
103
|
+
|
104
104
|
it "should generate a complete 'conference' JSON document when a block is passed" do
|
105
|
-
response = Tropo::Generator.conference({ :name => 'foo',
|
106
|
-
:id => '1234',
|
105
|
+
response = Tropo::Generator.conference({ :name => 'foo',
|
106
|
+
:id => '1234',
|
107
107
|
:mute => false,
|
108
108
|
:send_tones => false,
|
109
109
|
:exit_tone => '#' }) do
|
@@ -112,7 +112,7 @@ describe "Tropo" do
|
|
112
112
|
end
|
113
113
|
JSON.parse(response).should == {"tropo"=>[{"conference"=>{"name"=>"foo", "mute"=>false, "id"=>"1234", "exitTone"=>"#", "sendTones"=>false, "on"=>[{"say"=>[{"value"=>"Welcome to the conference"}], "event"=>"join"}, {"say"=>[{"value"=>"Someone has left the conference"}], "event"=>"leave"}]}}]}
|
114
114
|
end
|
115
|
-
|
115
|
+
|
116
116
|
it "should generate an error if an 'conference' is passed without a 'name' parameter" do
|
117
117
|
begin
|
118
118
|
response = Tropo::Generator.conference({ :foo => 'bar' })
|
@@ -120,7 +120,7 @@ describe "Tropo" do
|
|
120
120
|
err.to_s.should == "A 'name' must be provided to a 'conference' action"
|
121
121
|
end
|
122
122
|
end
|
123
|
-
|
123
|
+
|
124
124
|
it "should generate an error if an 'conference' is passed without an 'id' parameter" do
|
125
125
|
begin
|
126
126
|
response = Tropo::Generator.conference({ :name => 'bar' })
|
@@ -128,23 +128,23 @@ describe "Tropo" do
|
|
128
128
|
err.to_s.should == "A 'id' must be provided to a 'conference' action"
|
129
129
|
end
|
130
130
|
end
|
131
|
-
|
131
|
+
|
132
132
|
# Hangup action tests and Disconnect alias
|
133
133
|
it "should generate a JSON document with a 'hangup' action" do
|
134
134
|
response = Tropo::Generator.hangup
|
135
135
|
JSON.parse(response).should == {"tropo"=>[{"hangup"=>nil}]}
|
136
136
|
end
|
137
|
-
|
137
|
+
|
138
138
|
it "should generate a JSON document with a 'disconnect' action" do
|
139
139
|
response = Tropo::Generator.disconnect
|
140
140
|
JSON.parse(response).should == {"tropo"=>[{"hangup"=>nil}]}
|
141
141
|
end
|
142
|
-
|
142
|
+
|
143
143
|
it "should generate a standard 'on' JSON document" do
|
144
144
|
response = Tropo::Generator.on({ :event => 'hangup', :next => 'myresource' })
|
145
145
|
JSON.parse(response).should == { "tropo" => [{ "on" =>{ "event" => "hangup", "next" => "myresource" } }] }
|
146
146
|
end
|
147
|
-
|
147
|
+
|
148
148
|
# On tests
|
149
149
|
it "should generate a an error of an 'on' document does not pass an event param" do
|
150
150
|
begin
|
@@ -153,7 +153,7 @@ describe "Tropo" do
|
|
153
153
|
err.to_s.should == "A 'event' must be provided to a 'on' action"
|
154
154
|
end
|
155
155
|
end
|
156
|
-
|
156
|
+
|
157
157
|
it "should generate a an error of an 'on' document does not pass an event param" do
|
158
158
|
begin
|
159
159
|
response = Tropo::Generator.on({ :event => 'bar' })
|
@@ -161,20 +161,20 @@ describe "Tropo" do
|
|
161
161
|
err.to_s.should == "A 'next' resource must be provided"
|
162
162
|
end
|
163
163
|
end
|
164
|
-
|
164
|
+
|
165
165
|
# Record action tests
|
166
166
|
it "should generate a complete 'record' JSON document" do
|
167
|
-
response = Tropo::Generator.record({ :name => 'foo',
|
168
|
-
:url => 'http://sendme.com/tropo',
|
167
|
+
response = Tropo::Generator.record({ :name => 'foo',
|
168
|
+
:url => 'http://sendme.com/tropo',
|
169
169
|
:beep => true,
|
170
170
|
:send_tones => false,
|
171
171
|
:exit_tone => '#' })
|
172
172
|
JSON.parse(response).should == {"tropo"=>[{"record"=>{"name"=>"foo", "beep"=>true, "url"=>"http://sendme.com/tropo", "exitTone"=>"#", "sendTones"=>false}}]}
|
173
173
|
end
|
174
|
-
|
174
|
+
|
175
175
|
it "should generate a complete 'record' JSON document when a block is passed" do
|
176
|
-
response = Tropo::Generator.record({ :name => 'foo',
|
177
|
-
:url => 'http://sendme.com/tropo',
|
176
|
+
response = Tropo::Generator.record({ :name => 'foo',
|
177
|
+
:url => 'http://sendme.com/tropo',
|
178
178
|
:beep => true,
|
179
179
|
:send_tones => false,
|
180
180
|
:exit_tone => '#' }) do
|
@@ -183,7 +183,7 @@ describe "Tropo" do
|
|
183
183
|
end
|
184
184
|
JSON.parse(response).should == {"tropo"=>[{"record"=>{"name"=>"foo", "say"=>[{"value"=>"Please say your account number"}], "beep"=>true, "url"=>"http://sendme.com/tropo", "sendTones"=>false, "exitTone"=>"#", "choices"=>{"value"=>"[5 DIGITS]"}}}]}
|
185
185
|
end
|
186
|
-
|
186
|
+
|
187
187
|
it "should generate an error if an 'record' is passed without a 'name' parameter" do
|
188
188
|
begin
|
189
189
|
response = Tropo::Generator.record({ :foo => 'bar' })
|
@@ -191,7 +191,7 @@ describe "Tropo" do
|
|
191
191
|
err.to_s.should == "A 'name' must be provided to a 'record' action"
|
192
192
|
end
|
193
193
|
end
|
194
|
-
|
194
|
+
|
195
195
|
it "should generate an error if an 'record' is passed without an 'url' parameter" do
|
196
196
|
begin
|
197
197
|
response = Tropo::Generator.record({ :name => 'bar' })
|
@@ -199,7 +199,7 @@ describe "Tropo" do
|
|
199
199
|
err.to_s.should == "A 'url' must be provided to a 'record' action"
|
200
200
|
end
|
201
201
|
end
|
202
|
-
|
202
|
+
|
203
203
|
it "should generate an error if an 'record' is passed without an invalid 'url' parameter" do
|
204
204
|
begin
|
205
205
|
response = Tropo::Generator.record({ :name => 'bar',
|
@@ -208,19 +208,19 @@ describe "Tropo" do
|
|
208
208
|
err.to_s.should == "The 'url' paramater must be a valid URL"
|
209
209
|
end
|
210
210
|
end
|
211
|
-
|
211
|
+
|
212
212
|
it "should accept a valid email address when a 'record' action is called" do
|
213
213
|
response = Tropo::Generator.record({ :name => 'bar',
|
214
214
|
:url => 'foo@bar.com' })
|
215
215
|
JSON.parse(response).should == JSON.parse("{\"tropo\":[{\"record\":{\"url\":\"foo@bar.com\",\"name\":\"bar\"}}]}")
|
216
216
|
end
|
217
|
-
|
217
|
+
|
218
218
|
# Redirect action tests
|
219
219
|
it "should generate a JSON document with a 'redirect' action" do
|
220
220
|
response = Tropo::Generator.redirect({ :to => 'sip:1234', :from => '4155551212' })
|
221
221
|
JSON.parse(response).should == {"tropo"=>[{"redirect"=>{"from"=>"4155551212", "to"=>"sip:1234"}}]}
|
222
222
|
end
|
223
|
-
|
223
|
+
|
224
224
|
it "should generate an error if a 'redirect' action is included in a block" do
|
225
225
|
begin
|
226
226
|
response = Tropo::Generator.conference(:name => 'foobar', :id => 1234) do
|
@@ -230,7 +230,7 @@ describe "Tropo" do
|
|
230
230
|
err.to_s.should == 'Redirect should only be used alone and before the session is answered, use transfer instead'
|
231
231
|
end
|
232
232
|
end
|
233
|
-
|
233
|
+
|
234
234
|
it "should generate an error when no 'to' is passed to a 'redirect' action" do
|
235
235
|
begin
|
236
236
|
response = Tropo::Generator.redirect
|
@@ -238,18 +238,18 @@ describe "Tropo" do
|
|
238
238
|
err.to_s.should == "A 'to' must be provided to a 'redirect' action"
|
239
239
|
end
|
240
240
|
end
|
241
|
-
|
241
|
+
|
242
242
|
# Reject action tests
|
243
243
|
it "should generate a JSON document with a 'reject' action" do
|
244
244
|
response = Tropo::Generator.reject
|
245
245
|
JSON.parse(response).should == {"tropo"=>[{"reject"=>nil}]}
|
246
246
|
end
|
247
|
-
|
247
|
+
|
248
248
|
# Say action tests
|
249
249
|
it "should generate a standard 'say' JSON document when a stiring is passed" do
|
250
250
|
JSON.parse(Tropo::Generator.say('1234')).should == { "tropo" => [{ "say" => [{ "value" => "1234" }] }] }
|
251
251
|
end
|
252
|
-
|
252
|
+
|
253
253
|
it "should generate an error if I try to pass an integer to a 'say' action" do
|
254
254
|
begin
|
255
255
|
Tropo::Generator.say(1234)
|
@@ -257,16 +257,16 @@ describe "Tropo" do
|
|
257
257
|
err.to_s.should == "An invalid paramater type Fixnum has been passed"
|
258
258
|
end
|
259
259
|
end
|
260
|
-
|
260
|
+
|
261
261
|
it "should generate a standard 'say' JSON document" do
|
262
262
|
JSON.parse(Tropo::Generator.say({ :value => '1234' })).should == { "tropo" => [{ "say" => [{ "value" => "1234" }] }] }
|
263
263
|
end
|
264
|
-
|
264
|
+
|
265
265
|
it "should generate a 'say' JSON document when an array of values is passed" do
|
266
266
|
response = Tropo::Generator.say([{ :value => '1234' }, { :value => 'abcd', :event => 'nomatch:1' }])
|
267
267
|
JSON.parse(response).should == { "tropo" => [{ "say" => [{ "value" => "1234" }, { "value" => "abcd", "event"=>"nomatch:1" }] }] }
|
268
268
|
end
|
269
|
-
|
269
|
+
|
270
270
|
it "should generate an error if no 'value' key is passed to a 'say' request" do
|
271
271
|
begin
|
272
272
|
response = Tropo::Generator.say({ :name => 'foo' })
|
@@ -274,7 +274,7 @@ describe "Tropo" do
|
|
274
274
|
err.to_s.should == "A 'value' must be provided to a 'say' action"
|
275
275
|
end
|
276
276
|
end
|
277
|
-
|
277
|
+
|
278
278
|
it "should generate a JSON document with a 'say' and an 'on'" do
|
279
279
|
result = Tropo::Generator.new do
|
280
280
|
say :value => 'blah'
|
@@ -282,13 +282,13 @@ describe "Tropo" do
|
|
282
282
|
end
|
283
283
|
JSON.parse(result.response).should == {"tropo"=>[{"say"=>[{"value"=>"blah"}]}, {"on"=>{"event"=>"error", "next"=>"error.json"}}]}
|
284
284
|
end
|
285
|
-
|
285
|
+
|
286
286
|
# Start & Stop Recording actions tests
|
287
287
|
it "should generate a JSON document with a 'start_recording' action" do
|
288
288
|
response = Tropo::Generator.start_recording(:url => 'http://postrecording.com/tropo')
|
289
289
|
JSON.parse(response).should == {"tropo"=>[{"startRecording"=>{"url"=>"http://postrecording.com/tropo"}}]}
|
290
290
|
end
|
291
|
-
|
291
|
+
|
292
292
|
it "should generate a JSON document with a 'start_call_recording' action" do
|
293
293
|
response = Tropo::Generator.start_call_recording(:url => 'http://postrecording.com/tropo')
|
294
294
|
JSON.parse(response).should == {"tropo"=>[{"startRecording"=>{"url"=>"http://postrecording.com/tropo"}}]}
|
@@ -298,18 +298,18 @@ describe "Tropo" do
|
|
298
298
|
response = Tropo::Generator.stop_call_recording
|
299
299
|
JSON.parse(response).should == {"tropo"=>[{"stopRecording"=>nil}]}
|
300
300
|
end
|
301
|
-
|
301
|
+
|
302
302
|
it "should generate a JSON document with a 'stoprecording' action" do
|
303
303
|
response = Tropo::Generator.stop_recording
|
304
304
|
JSON.parse(response).should == {"tropo"=>[{"stopRecording"=>nil}]}
|
305
305
|
end
|
306
|
-
|
306
|
+
|
307
307
|
# Transfer action tests
|
308
308
|
it "should generate a JSON document with a 'transfer' action" do
|
309
309
|
response = Tropo::Generator.transfer(:to => 'tel:+14157044517')
|
310
310
|
JSON.parse(response).should == {"tropo"=>[{"transfer"=>{"to"=>"tel:+14157044517"}}]}
|
311
311
|
end
|
312
|
-
|
312
|
+
|
313
313
|
# Transfer action tests
|
314
314
|
it "should generate a JSON document with a 'transfer' action with an 'on' and 'choices' actions" do
|
315
315
|
response = Tropo::Generator.transfer(:to => 'tel:+14157044517') do
|
@@ -318,7 +318,7 @@ describe "Tropo" do
|
|
318
318
|
end
|
319
319
|
JSON.parse(response).should == {"tropo"=>[{"transfer"=>{"to"=>"tel:+14157044517", "choices"=>{"value"=>"[5 DIGITS]"}, "on"=>[{"event"=>"unbounded", "next"=>"/error.json"}]}}]}
|
320
320
|
end
|
321
|
-
|
321
|
+
|
322
322
|
it "should generate an error if no 'to' key is passed to a 'transfer' request" do
|
323
323
|
begin
|
324
324
|
response = Tropo::Generator.transfer
|
@@ -326,7 +326,7 @@ describe "Tropo" do
|
|
326
326
|
err.to_s.should == "A 'to' must be provided to a 'transfer' action"
|
327
327
|
end
|
328
328
|
end
|
329
|
-
|
329
|
+
|
330
330
|
# General tests
|
331
331
|
it "should generate a JSON document when a block is passed" do
|
332
332
|
result = Tropo::Generator.new do
|
@@ -335,23 +335,23 @@ describe "Tropo" do
|
|
335
335
|
end
|
336
336
|
JSON.parse(result.response).should == {"tropo"=>[{"say"=>[{"value"=>"1234"}, {"value"=>"abcd", "event"=>"nomatch:1"}]}, {"say"=>[{"value"=>"0987"}, {"value"=>"zyxw", "event"=>"nomatch:2"}]}]}
|
337
337
|
end
|
338
|
-
|
338
|
+
|
339
339
|
it "should build a Ruby hash object when a session arrives in JSON" do
|
340
340
|
json_session = "{\"session\":{\"id\":\"dih06n\",\"accountId\":\"33932\",\"timestamp\":\"2010-01-19T23:18:48.562Z\",\"userType\":\"HUMAN\",\"to\":{\"id\":\"tropomessaging@bot.im\",\"name\":\"unknown\",\"channel\":\"TEXT\",\"network\":\"JABBER\"},\"from\":{\"id\":\"john_doe@gmail.com\",\"name\":\"unknown\",\"channel\":\"TEXT\",\"network\":\"JABBER\"}}}"
|
341
341
|
hash = Tropo::Generator.parse(json_session)
|
342
342
|
hash[:session][:timestamp] == Time.parse('2010-01-19T18:27:46.852-05:00')
|
343
343
|
end
|
344
|
-
|
344
|
+
|
345
345
|
it "should build a Ruby hash object when a result arrives in JSON" do
|
346
346
|
json_result = "{\"result\":{\"sessionId\":\"sessionId\",\"callState\":\"ANSWERED\",\"sessionDuration\":10,\"sequence\":1,\"complete\":true,\"error\":\"error\",\"properties\":[{\"key\":\"foo\",\"value\":\"bar\"},{\"key\":\"charlie\",\"value\":\"foxtrot\"}],\"actions\":{\"name\":\"pin\",\"attempts\":1,\"disposition\":\"SUCCESS\",\"confidence\":100,\"interpretation\":\"12345\",\"utterance\":\"1 2 3 4 5\"}}}"
|
347
347
|
Tropo::Generator.parse(json_result).should == Hashie::Mash.new({:result=>{:session_id=>"sessionId", :properties=>{:foo=>{:value=>"bar"}, :charlie=>{:value=>"foxtrot"}}, :complete=>true, :call_state=>"ANSWERED", :actions=>{:pin=>{:disposition=>"SUCCESS", :utterance=>"1 2 3 4 5", :attempts=>1, :interpretation=>"12345", :confidence=>100}}, :session_duration=>10, :error=>"error", :sequence=>1}})
|
348
348
|
end
|
349
|
-
|
349
|
+
|
350
350
|
it "should build a ruby hash object when a realworld JSON string arrives" do
|
351
351
|
json_result = "{\"result\":{\"sessionId\":\"CCFD9C86-1DD1-11B2-B76D-B9B253E4B7FB@161.253.55.20\",\"callState\":\"ANSWERED\",\"sessionDuration\":2,\"sequence\":1,\"complete\":true,\"error\":null,\"actions\":[{\"name\":\"zip\",\"attempts\":1,\"disposition\":\"SUCCESS\",\"confidence\":100,\"interpretation\":\"12345\",\"utterance\":\"1 2 3 4 5\"},{\"name\":\"days\",\"attempts\":1,\"disposition\":\"SUCCESS\",\"confidence\":100,\"interpretation\":\"1\",\"utterance\":\"1\"}]}}"
|
352
352
|
Tropo::Generator.parse(json_result).should == Hashie::Mash.new({:result=>{:call_state=>"ANSWERED", :complete=>true, :actions=>{:zip=>{:disposition=>"SUCCESS", :utterance=>"1 2 3 4 5", :attempts=>1, :interpretation=>"12345", :confidence=>100}, :days=>{:disposition=>"SUCCESS", :utterance=>"1", :attempts=>1, :interpretation=>"1", :confidence=>100}}, :session_duration=>2, :sequence=>1, :session_id=>"CCFD9C86-1DD1-11B2-B76D-B9B253E4B7FB@161.253.55.20", :error=>nil}})
|
353
353
|
end
|
354
|
-
|
354
|
+
|
355
355
|
it "should see an object delcared outside of a block" do
|
356
356
|
@@session = 'foobar'
|
357
357
|
result = Tropo::Generator.new do
|
@@ -361,7 +361,7 @@ describe "Tropo" do
|
|
361
361
|
end
|
362
362
|
@@new_session.should == 'foobar'
|
363
363
|
end
|
364
|
-
|
364
|
+
|
365
365
|
it "should see an object passed into the block" do
|
366
366
|
session = 'foobar'
|
367
367
|
result = Tropo::Generator.new(session) do
|
@@ -370,20 +370,20 @@ describe "Tropo" do
|
|
370
370
|
on :event => 'error', :next => 'error.json'
|
371
371
|
end
|
372
372
|
end
|
373
|
-
|
373
|
+
|
374
374
|
it "should allow you to create a Tropo::Generator object and build up a JSON request with two says" do
|
375
375
|
tropo = Tropo::Generator.new
|
376
376
|
tropo.say('foo')
|
377
377
|
tropo.say('bar')
|
378
378
|
tropo.response.should == "{\"tropo\":[{\"say\":[{\"value\":\"foo\"}]},{\"say\":[{\"value\":\"bar\"}]}]}"
|
379
379
|
end
|
380
|
-
|
380
|
+
|
381
381
|
it "should allow you to create a Tropo::Generator object and build up a JSON request with: a say, an on and a record" do
|
382
382
|
tropo = Tropo::Generator.new
|
383
383
|
tropo.say 'Welcome to the app'
|
384
384
|
tropo.on :event => 'hangup', :next => '/hangup.json'
|
385
|
-
tropo.record({ :name => 'foo',
|
386
|
-
:url => 'http://sendme.com/tropo',
|
385
|
+
tropo.record({ :name => 'foo',
|
386
|
+
:url => 'http://sendme.com/tropo',
|
387
387
|
:beep => true,
|
388
388
|
:send_tones => false,
|
389
389
|
:exit_tone => '#' }) do
|
@@ -392,13 +392,13 @@ describe "Tropo" do
|
|
392
392
|
end
|
393
393
|
JSON.parse(tropo.response).should == {"tropo"=>[{"say"=>[{"value"=>"Welcome to the app"}]}, {"on"=>{"event"=>"hangup", "next"=>"/hangup.json"}}, {"record"=>{"name"=>"foo", "say"=>[{"value"=>"Please say your account number"}], "beep"=>true, "url"=>"http://sendme.com/tropo", "sendTones"=>false, "exitTone"=>"#", "choices"=>{"value"=>"[5 DIGITS]"}}}]}
|
394
394
|
end
|
395
|
-
|
395
|
+
|
396
396
|
it "should allow you to reset the object to a fresh response after building a response first" do
|
397
397
|
tropo = Tropo::Generator.new
|
398
398
|
tropo.say 'Welcome to the app'
|
399
399
|
tropo.on :event => 'hangup', :next => '/hangup.json'
|
400
|
-
tropo.record({ :name => 'foo',
|
401
|
-
:url => 'http://sendme.com/tropo',
|
400
|
+
tropo.record({ :name => 'foo',
|
401
|
+
:url => 'http://sendme.com/tropo',
|
402
402
|
:beep => true,
|
403
403
|
:send_tones => false,
|
404
404
|
:exit_tone => '#' }) do
|
@@ -409,19 +409,19 @@ describe "Tropo" do
|
|
409
409
|
tropo.reset
|
410
410
|
tropo.response.should == "{\"tropo\":[]}"
|
411
411
|
end
|
412
|
-
|
412
|
+
|
413
413
|
it "should build a Ruby hash object when a session arrives in JSON with a proper Ruby Time object" do
|
414
414
|
json_session = "{\"session\":{\"id\":\"dih06n\",\"accountId\":\"33932\",\"timestamp\":\"2010-01-19T23:18:48.562Z\",\"userType\":\"HUMAN\",\"to\":{\"id\":\"tropomessaging@bot.im\",\"name\":\"unknown\",\"channel\":\"TEXT\",\"network\":\"JABBER\"},\"from\":{\"id\":\"john_doe@gmail.com\",\"name\":\"unknown\",\"channel\":\"TEXT\",\"network\":\"JABBER\"}}}"
|
415
415
|
hash = Tropo::Generator.parse(json_session)
|
416
416
|
hash[:session][:timestamp].should == Time.parse("2010-01-19T23:18:48.562Z")
|
417
417
|
end
|
418
|
-
|
418
|
+
|
419
419
|
it "should build a Ruby hash object when a result arrives in JSON with one action returned in an array" do
|
420
420
|
json_result = "{\"result\":{\"sessionId\":\"CCFD9C86-1DD1-11B2-B76D-B9B253E4B7FB@161.253.55.20\",\"callState\":\"ANSWERED\",\"sessionDuration\":2,\"sequence\":1,\"complete\":true,\"error\":null,\"actions\":{\"name\":\"zip\",\"attempts\":1,\"disposition\":\"SUCCESS\",\"confidence\":100,\"interpretation\":\"12345\",\"utterance\":\"1 2 3 4 5\"}}}"
|
421
421
|
hash = Tropo::Generator.parse(json_result)
|
422
422
|
hash.should == Hashie::Mash.new({:result=>{:call_state=>"ANSWERED", :complete=>true, :actions=>{:zip=>{:utterance=>"1 2 3 4 5", :attempts=>1, :interpretation=>"12345", :confidence=>100, :disposition=>"SUCCESS"}}, :session_id=>"CCFD9C86-1DD1-11B2-B76D-B9B253E4B7FB@161.253.55.20", :session_duration=>2, :error=>nil, :sequence=>1}})
|
423
423
|
end
|
424
|
-
|
424
|
+
|
425
425
|
it "should build a Hashie object when a result arrives in JSON" do
|
426
426
|
json_result = "{\"result\":{\"sessionId\":\"CCFD9C86-1DD1-11B2-B76D-B9B253E4B7FB@161.253.55.20\",\"callState\":\"ANSWERED\",\"sessionDuration\":2,\"sequence\":1,\"complete\":true,\"error\":null,\"actions\":{\"name\":\"zip\",\"attempts\":1,\"disposition\":\"SUCCESS\",\"confidence\":100,\"interpretation\":\"12345\",\"utterance\":\"1 2 3 4 5\"}}}"
|
427
427
|
hash = Tropo::Generator.parse(json_result)
|
@@ -429,7 +429,7 @@ describe "Tropo" do
|
|
429
429
|
hash[:result][:call_state].should == 'ANSWERED'
|
430
430
|
hash['result']['call_state'].should == 'ANSWERED'
|
431
431
|
end
|
432
|
-
|
432
|
+
|
433
433
|
it "should generate valid JSON when a startRecording is used" do
|
434
434
|
t = Tropo::Generator.new
|
435
435
|
t.on :event => 'error', :next => '/error.json' # For fatal programming errors. Log some details so we can fix it
|
@@ -444,14 +444,14 @@ describe "Tropo" do
|
|
444
444
|
t.say "http://denalidomain.com/music/keepers/HappyHappyBirthdaytoYou-Disney.mp3"
|
445
445
|
JSON.parse(t.response).should == {"tropo"=>[{"on"=>{"event"=>"error", "next"=>"/error.json"}}, {"on"=>{"event"=>"hangup", "next"=>"/hangup.json"}}, {"on"=>{"event"=>"continue", "next"=>"/next.json"}}, {"say"=>[{"value"=>"Hello"}]}, {"startRecording"=>{"url"=>"http://heroku-voip.marksilver.net/post_audio_to_s3?filename=foo.wav&unique_id=bar"}}, {"say"=>[{"value"=>"You are now on the record."}]}, {"say"=>[{"value"=>"Go ahead, sing-along."}]}, {"say"=>[{"value"=>"http://denalidomain.com/music/keepers/HappyHappyBirthdaytoYou-Disney.mp3"}]}]}
|
446
446
|
end
|
447
|
-
|
447
|
+
|
448
448
|
it "should generate a voice_session true if a JSON session is received that is a channel of 'VOICE'" do
|
449
449
|
tropo = Tropo::Generator.new
|
450
450
|
tropo.parse "{\"session\":{\"id\":\"0-13c4-4b563da3-7aecefda-46af-1d10bdd0\",\"accountId\":\"33932\",\"timestamp\":\"2010-01-19T23:18:00.854Z\",\"userType\":\"HUMAN\",\"to\":{\"id\":\"9991427589\",\"name\":\"unknown\",\"channel\":\"VOICE\",\"network\":\"PSTN\"},\"from\":{\"id\":\"jsgoecke\",\"name\":\"unknown\",\"channel\":\"VOICE\",\"network\":\"PSTN\"}}}"
|
451
451
|
tropo.voice_session.should == true
|
452
452
|
tropo.text_session.should == false
|
453
453
|
end
|
454
|
-
|
454
|
+
|
455
455
|
it "should generate a text_session true if a JSON session is received that is a channel of 'TEXT'" do
|
456
456
|
tropo = Tropo::Generator.new
|
457
457
|
tropo.parse "{\"session\":{\"id\":\"dih06n\",\"accountId\":\"33932\",\"timestamp\":\"2010-01-19T23:18:48.562Z\",\"userType\":\"HUMAN\",\"to\":{\"id\":\"tropomessaging@bot.im\",\"name\":\"unknown\",\"channel\":\"TEXT\",\"network\":\"JABBER\"},\"from\":{\"id\":\"john_doe@gmail.com\",\"name\":\"unknown\",\"channel\":\"TEXT\",\"network\":\"JABBER\"}}}"
|
@@ -461,7 +461,7 @@ describe "Tropo" do
|
|
461
461
|
|
462
462
|
it "should generate a valid JSON string for a call method" do
|
463
463
|
json_result = "{\"tropo\":[{\"call\":{\"recording\":{\"password\":\"passwd\",\"username\":\"jose\",\"method\":\"POST\",\"url\":\"http://foobar\",\"format\":\"audio/mp3\"},\"timeout\":10,\"network\":\"SMS\",\"channel\":\"TEXT\",\"to\":\"foo\",\"from\":\"bar\",\"headers\":{\"foo\":\"foo\",\"bar\":\"bar\"},\"answerOnMedia\":false}}]}"
|
464
|
-
tropo = Tropo::Generator.call({ :to => 'foo',
|
464
|
+
tropo = Tropo::Generator.call({ :to => 'foo',
|
465
465
|
:from => 'bar',
|
466
466
|
:network => 'SMS',
|
467
467
|
:channel => 'TEXT',
|
@@ -475,10 +475,10 @@ describe "Tropo" do
|
|
475
475
|
:password => 'passwd' } })
|
476
476
|
JSON.parse(tropo).should == JSON.parse(json_result)
|
477
477
|
end
|
478
|
-
|
478
|
+
|
479
479
|
it "should generate a valid JSON string for a message method" do
|
480
480
|
hash_result = {"tropo"=>[{"message"=>{"say"=>[{"value"=>"Please say your account number"}], "from"=>"bar", "timeout"=>10, "to"=>"foo", "network"=>"SMS", "answerOnMedia"=>false, "channel"=>"TEXT", "recording"=>{"format"=>"audio/mp3", "method"=>"POST", "url"=>"http://foobar", "username"=>"jose", "password"=>"passwd"}, "headers"=>{"foo"=>"foo", "bar"=>"bar"}}}]}
|
481
|
-
tropo = Tropo::Generator.message({ :to => 'foo',
|
481
|
+
tropo = Tropo::Generator.message({ :to => 'foo',
|
482
482
|
:from => 'bar',
|
483
483
|
:network => 'SMS',
|
484
484
|
:channel => 'TEXT',
|
@@ -491,14 +491,14 @@ describe "Tropo" do
|
|
491
491
|
:username => 'jose',
|
492
492
|
:password => 'passwd' } }) do
|
493
493
|
say :value => 'Please say your account number'
|
494
|
-
end
|
494
|
+
end
|
495
495
|
JSON.parse(tropo).should == hash_result
|
496
496
|
end
|
497
|
-
|
497
|
+
|
498
498
|
it "should generate a valid JSON string for a record method with a transcription request" do
|
499
499
|
hash_result = {"tropo"=>[{"record"=>{"name"=>"foo", "transcription"=>{"email_format"=>"encoded", "url"=>"mailto:jose@voxeo.com", "id"=>"bling"}, "say"=>[{"value"=>"Please say your account number"}], "beep"=>true, "url"=>"http://sendme.com/tropo", "exitTone"=>"#", "sendTones"=>false, "choices"=>{"value"=>"[5 DIGITS]"}}}]}
|
500
|
-
tropo = Tropo::Generator.record({ :name => 'foo',
|
501
|
-
:url => 'http://sendme.com/tropo',
|
500
|
+
tropo = Tropo::Generator.record({ :name => 'foo',
|
501
|
+
:url => 'http://sendme.com/tropo',
|
502
502
|
:beep => true,
|
503
503
|
:send_tones => false,
|
504
504
|
:transcription => { :id => 'bling',
|
@@ -507,20 +507,20 @@ describe "Tropo" do
|
|
507
507
|
:exit_tone => '#' }) do
|
508
508
|
say :value => 'Please say your account number'
|
509
509
|
choices :value => '[5 DIGITS]'
|
510
|
-
end
|
510
|
+
end
|
511
511
|
JSON.parse(tropo).should == hash_result
|
512
512
|
end
|
513
|
-
|
513
|
+
|
514
514
|
it "should properly generate a JSON document when calling an ask with says as hash elements rather than as methods" do
|
515
515
|
hash_result = {"tropo"=>[{"ask"=>{"name"=>"donate_to_id", "say"=>[{"event"=>"timeout", "value"=>"Sorry, I did not hear anything."}, {"event"=>"nomatch:1 nomatch:2 nomatch:3", "value"=>"Sorry, that wasn't a valid answer. You can press or say 1 for 'yes', or 2 for 'no'."}, {"value"=>"You chose organization foobar. Are you ready to donate to them? If you say no, I will tell you a little more about the organization."}, {"event"=>"nomatch:3", "value"=>"This is your last attempt."}], "bargein"=>true, "silenceTimeout"=>10, "timeout"=>10, "attempts"=>4, "choices"=>{"value"=>"true(1,yes,sure,affirmative), false(2,no,no thank you,negative), 0(0,help,i do not know, agent, operator, assistance, representative, real person, human), 9(9,quit,stop,shut up)"}}}]}
|
516
516
|
help_stop_choices = "0(0,help,i do not know, agent, operator, assistance, representative, real person, human), 9(9,quit,stop,shut up)"
|
517
517
|
yes_no_choices = "true(1,yes,sure,affirmative), false(2,no,no thank you,negative), " + help_stop_choices
|
518
|
-
|
518
|
+
|
519
519
|
t = Tropo::Generator.new
|
520
|
-
t.ask :name => 'donate_to_id',
|
521
|
-
:bargein => true,
|
522
|
-
:timeout => 10,
|
523
|
-
:silence_timeout => 10,
|
520
|
+
t.ask :name => 'donate_to_id',
|
521
|
+
:bargein => true,
|
522
|
+
:timeout => 10,
|
523
|
+
:silence_timeout => 10,
|
524
524
|
:attempts => 4,
|
525
525
|
:say => [{:event => "timeout", :value => "Sorry, I did not hear anything."},
|
526
526
|
{:event => "nomatch:1 nomatch:2 nomatch:3", :value => "Sorry, that wasn't a valid answer. You can press or say 1 for 'yes', or 2 for 'no'."},
|
@@ -529,28 +529,28 @@ describe "Tropo" do
|
|
529
529
|
:choices => { :value => yes_no_choices}
|
530
530
|
JSON.parse(t.response).should == hash_result
|
531
531
|
end
|
532
|
-
|
532
|
+
|
533
533
|
it "should set the voice variable when called" do
|
534
534
|
t = Tropo::Generator.new
|
535
535
|
t.voice.should == nil
|
536
|
-
|
536
|
+
|
537
537
|
t = Tropo::Generator.new(:voice => 'barnie')
|
538
538
|
t.voice.should == 'barnie'
|
539
|
-
|
539
|
+
|
540
540
|
t = Tropo::Generator.new
|
541
541
|
t.voice = 'barnie'
|
542
542
|
t.voice.should == 'barnie'
|
543
543
|
end
|
544
|
-
|
544
|
+
|
545
545
|
it "should handle the setting of the voice parameter based on defaults" do
|
546
546
|
t = Tropo::Generator.new
|
547
547
|
t.say 'Hi there!'
|
548
548
|
JSON.parse(t.response)['tropo'][0]['say'][0]['voice'].should == nil
|
549
|
-
|
549
|
+
|
550
550
|
t = Tropo::Generator.new
|
551
551
|
t.say 'Hi there!', :voice => 'barnie'
|
552
552
|
JSON.parse(t.response)['tropo'][0]['say'][0]['voice'].should == 'barnie'
|
553
|
-
|
553
|
+
|
554
554
|
t = Tropo::Generator.new(:voice => 'barnie')
|
555
555
|
t.say 'Hi there!'
|
556
556
|
t.say 'Wow!'
|
@@ -562,7 +562,7 @@ describe "Tropo" do
|
|
562
562
|
t.say 'Wow!', :voice => 'jack'
|
563
563
|
JSON.parse(t.response)['tropo'][0]['say'][0]['voice'].should == 'barnie'
|
564
564
|
JSON.parse(t.response)['tropo'][1]['say'][0]['voice'].should == 'jack'
|
565
|
-
|
565
|
+
|
566
566
|
t = Tropo::Generator.new
|
567
567
|
t.voice = 'barnie'
|
568
568
|
t.say 'Hi there!'
|
@@ -570,82 +570,74 @@ describe "Tropo" do
|
|
570
570
|
JSON.parse(t.response)['tropo'][0]['say'][0]['voice'].should == 'barnie'
|
571
571
|
JSON.parse(t.response)['tropo'][1]['say'][0]['voice'].should == 'jack'
|
572
572
|
end
|
573
|
-
|
573
|
+
|
574
574
|
it "should set the recognizer variable when called" do
|
575
575
|
t = Tropo::Generator.new
|
576
576
|
t.recognizer.should == nil
|
577
|
-
|
577
|
+
|
578
578
|
t = Tropo::Generator.new(:recognizer => 'fr-fr')
|
579
579
|
t.recognizer.should == 'fr-fr'
|
580
|
-
|
580
|
+
|
581
581
|
t = Tropo::Generator.new
|
582
582
|
t.recognizer = 'fr-fr'
|
583
583
|
t.recognizer.should == 'fr-fr'
|
584
584
|
end
|
585
|
-
|
585
|
+
|
586
586
|
it "should handle the setting of the recognizer parameter based on defaults" do
|
587
587
|
t = Tropo::Generator.new
|
588
|
-
t.ask({ :name => 'foo',
|
589
|
-
:bargein => 'true',
|
588
|
+
t.ask({ :name => 'foo',
|
589
|
+
:bargein => 'true',
|
590
590
|
:timeout => 30,
|
591
591
|
:require => 'true' })
|
592
592
|
JSON.parse(t.response)['tropo'][0]['ask']['recognizer'].should == nil
|
593
|
-
|
593
|
+
|
594
594
|
t = Tropo::Generator.new(:recognizer => 'fr-fr')
|
595
|
-
t.ask({ :name => 'foo',
|
596
|
-
:bargein => 'true',
|
595
|
+
t.ask({ :name => 'foo',
|
596
|
+
:bargein => 'true',
|
597
597
|
:timeout => 30,
|
598
598
|
:require => 'true' })
|
599
599
|
JSON.parse(t.response)['tropo'][0]['ask']['recognizer'].should == 'fr-fr'
|
600
|
-
|
600
|
+
|
601
601
|
t = Tropo::Generator.new
|
602
602
|
t.recognizer = 'fr-fr'
|
603
|
-
t.ask({ :name => 'foo',
|
604
|
-
:bargein => 'true',
|
603
|
+
t.ask({ :name => 'foo',
|
604
|
+
:bargein => 'true',
|
605
605
|
:timeout => 30,
|
606
606
|
:require => 'true' })
|
607
607
|
JSON.parse(t.response)['tropo'][0]['ask']['recognizer'].should == 'fr-fr'
|
608
|
-
|
608
|
+
|
609
609
|
t = Tropo::Generator.new
|
610
610
|
t.recognizer = 'fr-fr'
|
611
|
-
t.ask({ :name => 'foo',
|
612
|
-
:bargein => 'true',
|
611
|
+
t.ask({ :name => 'foo',
|
612
|
+
:bargein => 'true',
|
613
613
|
:timeout => 30,
|
614
614
|
:require => 'true' })
|
615
|
-
t.ask({ :name => 'foo',
|
616
|
-
:bargein => 'true',
|
615
|
+
t.ask({ :name => 'foo',
|
616
|
+
:bargein => 'true',
|
617
617
|
:timeout => 30,
|
618
618
|
:require => 'true',
|
619
619
|
:recognizer => 'de-de' })
|
620
620
|
JSON.parse(t.response)['tropo'][0]['ask']['recognizer'].should == 'fr-fr'
|
621
621
|
JSON.parse(t.response)['tropo'][1]['ask']['recognizer'].should == 'de-de'
|
622
622
|
end
|
623
|
-
|
623
|
+
|
624
624
|
it "should parse a JSON string or a Ruby Hash the same" do
|
625
625
|
json_session = "{\"session\":{\"id\":\"dih06n\",\"accountId\":\"33932\",\"timestamp\":\"2010-01-19T23:18:48.562Z\",\"userType\":\"HUMAN\",\"to\":{\"id\":\"tropomessaging@bot.im\",\"name\":\"unknown\",\"channel\":\"TEXT\",\"network\":\"JABBER\"},\"from\":{\"id\":\"john_doe@gmail.com\",\"name\":\"unknown\",\"channel\":\"TEXT\",\"network\":\"JABBER\"}}}"
|
626
626
|
tropo = Tropo::Generator.parse json_session
|
627
627
|
tropo.session.user_type.should == 'HUMAN'
|
628
|
-
|
628
|
+
|
629
629
|
tropo = Tropo::Generator.parse(JSON.parse(json_session))
|
630
630
|
tropo.session.user_type.should == 'HUMAN'
|
631
631
|
end
|
632
|
-
|
632
|
+
|
633
633
|
it "should return a hash of the response object" do
|
634
634
|
result = Tropo::Generator.new do
|
635
635
|
say [{ :value => '1234' }, { :value => 'abcd', :event => "nomatch:1" }]
|
636
636
|
say [{ :value => '0987' }, { :value => 'zyxw', :event => "nomatch:2" }]
|
637
637
|
end
|
638
|
-
result.to_hash.should == { :tropo => [{ :say => [{ :value => "1234" },
|
639
|
-
{ :event => "nomatch:1", :value => "abcd" }] },
|
640
|
-
{ :say => [{ :value => "0987" },
|
638
|
+
result.to_hash.should == { :tropo => [{ :say => [{ :value => "1234" },
|
639
|
+
{ :event => "nomatch:1", :value => "abcd" }] },
|
640
|
+
{ :say => [{ :value => "0987" },
|
641
641
|
{ :event => "nomatch:2", :value => "zyxw" }] }] }
|
642
642
|
end
|
643
|
-
|
644
|
-
it "should not require a name in an ask" do
|
645
|
-
t = Tropo::Generator.new
|
646
|
-
t.ask({ :bargein => 'true',
|
647
|
-
:timeout => 30,
|
648
|
-
:require => 'true' })
|
649
|
-
JSON.parse(t.response)['tropo'][0]['ask']['timeout'].should == 30
|
650
|
-
end
|
651
643
|
end
|
data/tropo-webapi-ruby.gemspec
CHANGED
@@ -1,56 +1,48 @@
|
|
1
1
|
# Generated by jeweler
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{tropo-webapi-ruby}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.11"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Jason Goecke"]
|
12
|
-
s.date = %q{
|
12
|
+
s.date = %q{2011-06-24}
|
13
13
|
s.description = %q{Ruby library for interacting with the Tropo Web API via REST & JSON}
|
14
14
|
s.email = %q{jsgoecke@voxeo.com}
|
15
15
|
s.extra_rdoc_files = [
|
16
16
|
"LICENSE",
|
17
|
-
|
17
|
+
"README.rdoc"
|
18
18
|
]
|
19
19
|
s.files = [
|
20
20
|
".document",
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
"tropo-webapi-ruby.gemspec"
|
21
|
+
"HISTORY.rdoc",
|
22
|
+
"LICENSE",
|
23
|
+
"README.rdoc",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION",
|
26
|
+
"examples/sinatra_server.rb",
|
27
|
+
"lib/tropo-webapi-ruby.rb",
|
28
|
+
"lib/tropo-webapi-ruby/object_patch.rb",
|
29
|
+
"lib/tropo-webapi-ruby/tropo-webapi-ruby-helpers.rb",
|
30
|
+
"lib/tropo-webapi-ruby/tropo-webapi-ruby.rb",
|
31
|
+
"spec/spec.opts",
|
32
|
+
"spec/spec_helper.rb",
|
33
|
+
"spec/tropo-webapi-ruby_spec.rb",
|
34
|
+
"tropo-webapi-ruby.gemspec"
|
36
35
|
]
|
37
36
|
s.homepage = %q{http://tropo.com}
|
38
|
-
s.rdoc_options = ["--charset=UTF-8"]
|
39
37
|
s.require_paths = ["lib"]
|
40
38
|
s.required_ruby_version = Gem::Requirement.new(">= 1.8.6")
|
41
|
-
s.rubygems_version = %q{1.
|
39
|
+
s.rubygems_version = %q{1.5.0}
|
42
40
|
s.summary = %q{Tropo Web API Ruby Gem}
|
43
|
-
s.test_files = [
|
44
|
-
"spec/spec_helper.rb",
|
45
|
-
"spec/tropo-webapi-ruby_spec.rb",
|
46
|
-
"examples/sinatra_server.rb"
|
47
|
-
]
|
48
41
|
|
49
42
|
if s.respond_to? :specification_version then
|
50
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
51
43
|
s.specification_version = 3
|
52
44
|
|
53
|
-
if Gem::Version.new(Gem::
|
45
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
54
46
|
s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
|
55
47
|
s.add_runtime_dependency(%q<json_pure>, [">= 1.2.0"])
|
56
48
|
s.add_runtime_dependency(%q<hashie>, [">= 0.2.0"])
|
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tropo-webapi-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
hash: 13
|
5
|
+
prerelease:
|
5
6
|
segments:
|
6
7
|
- 0
|
7
8
|
- 1
|
8
|
-
-
|
9
|
-
version: 0.1.
|
9
|
+
- 11
|
10
|
+
version: 0.1.11
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- Jason Goecke
|
@@ -14,16 +15,18 @@ autorequire:
|
|
14
15
|
bindir: bin
|
15
16
|
cert_chain: []
|
16
17
|
|
17
|
-
date:
|
18
|
+
date: 2011-06-24 00:00:00 -07:00
|
18
19
|
default_executable:
|
19
20
|
dependencies:
|
20
21
|
- !ruby/object:Gem::Dependency
|
21
22
|
name: rspec
|
22
23
|
prerelease: false
|
23
24
|
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
24
26
|
requirements:
|
25
27
|
- - ">="
|
26
28
|
- !ruby/object:Gem::Version
|
29
|
+
hash: 13
|
27
30
|
segments:
|
28
31
|
- 1
|
29
32
|
- 2
|
@@ -35,9 +38,11 @@ dependencies:
|
|
35
38
|
name: json_pure
|
36
39
|
prerelease: false
|
37
40
|
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
38
42
|
requirements:
|
39
43
|
- - ">="
|
40
44
|
- !ruby/object:Gem::Version
|
45
|
+
hash: 31
|
41
46
|
segments:
|
42
47
|
- 1
|
43
48
|
- 2
|
@@ -49,9 +54,11 @@ dependencies:
|
|
49
54
|
name: hashie
|
50
55
|
prerelease: false
|
51
56
|
requirement: &id003 !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
52
58
|
requirements:
|
53
59
|
- - ">="
|
54
60
|
- !ruby/object:Gem::Version
|
61
|
+
hash: 23
|
55
62
|
segments:
|
56
63
|
- 0
|
57
64
|
- 2
|
@@ -70,7 +77,6 @@ extra_rdoc_files:
|
|
70
77
|
- README.rdoc
|
71
78
|
files:
|
72
79
|
- .document
|
73
|
-
- .gitignore
|
74
80
|
- HISTORY.rdoc
|
75
81
|
- LICENSE
|
76
82
|
- README.rdoc
|
@@ -90,34 +96,36 @@ homepage: http://tropo.com
|
|
90
96
|
licenses: []
|
91
97
|
|
92
98
|
post_install_message:
|
93
|
-
rdoc_options:
|
94
|
-
|
99
|
+
rdoc_options: []
|
100
|
+
|
95
101
|
require_paths:
|
96
102
|
- lib
|
97
103
|
required_ruby_version: !ruby/object:Gem::Requirement
|
104
|
+
none: false
|
98
105
|
requirements:
|
99
106
|
- - ">="
|
100
107
|
- !ruby/object:Gem::Version
|
108
|
+
hash: 59
|
101
109
|
segments:
|
102
110
|
- 1
|
103
111
|
- 8
|
104
112
|
- 6
|
105
113
|
version: 1.8.6
|
106
114
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
115
|
+
none: false
|
107
116
|
requirements:
|
108
117
|
- - ">="
|
109
118
|
- !ruby/object:Gem::Version
|
119
|
+
hash: 3
|
110
120
|
segments:
|
111
121
|
- 0
|
112
122
|
version: "0"
|
113
123
|
requirements: []
|
114
124
|
|
115
125
|
rubyforge_project:
|
116
|
-
rubygems_version: 1.
|
126
|
+
rubygems_version: 1.5.0
|
117
127
|
signing_key:
|
118
128
|
specification_version: 3
|
119
129
|
summary: Tropo Web API Ruby Gem
|
120
|
-
test_files:
|
121
|
-
|
122
|
-
- spec/tropo-webapi-ruby_spec.rb
|
123
|
-
- examples/sinatra_server.rb
|
130
|
+
test_files: []
|
131
|
+
|
data/.gitignore
DELETED