tropo-webapi-ruby 0.1.8 → 0.1.9
Sign up to get free protection for your applications and to get access to all the features.
- data/HISTORY.rdoc +10 -1
- data/README.rdoc +4 -4
- data/VERSION +1 -1
- data/lib/tropo-webapi-ruby/object_patch.rb +13 -0
- data/lib/tropo-webapi-ruby/tropo-webapi-ruby-helpers.rb +1 -1
- data/lib/tropo-webapi-ruby/tropo-webapi-ruby.rb +18 -6
- data/spec/tropo-webapi-ruby_spec.rb +34 -4
- data/tropo-webapi-ruby.gemspec +2 -1
- metadata +49 -16
data/HISTORY.rdoc
CHANGED
@@ -7,4 +7,13 @@
|
|
7
7
|
== Version 0.1.6
|
8
8
|
|
9
9
|
- Added the appropriate ActiveSupport dependency for 'instance_exec' for Ruby 1.8.6 support.
|
10
|
-
- Added a dependency and support for Hashie.
|
10
|
+
- Added a dependency and support for Hashie.
|
11
|
+
|
12
|
+
== Version 0.1.9
|
13
|
+
|
14
|
+
- Fixed the start_recording so it does not require a 'name' parameter
|
15
|
+
- Aliased start_call_recording -> start_recording
|
16
|
+
- Aliased stop_call_recording -> stop_recording
|
17
|
+
- Fixes to the README
|
18
|
+
- Fixed the yardoc install
|
19
|
+
- The Tropo::Generator.parse method will now take a JSON string or a Ruby hash.
|
data/README.rdoc
CHANGED
@@ -30,7 +30,7 @@ Optional, if you would like to use with Sinatra:
|
|
30
30
|
|
31
31
|
=== Project Developer
|
32
32
|
|
33
|
-
$ sudo gem install
|
33
|
+
$ sudo gem install yard
|
34
34
|
|
35
35
|
From within the project:
|
36
36
|
|
@@ -125,7 +125,7 @@ Using the great RESTful Web Services framework Sinatra for Ruby.
|
|
125
125
|
on :event => 'hangup', :next => '/hangup.json'
|
126
126
|
on :event => 'continue', :next => '/answer.json'
|
127
127
|
ask({ :name => 'account_number',
|
128
|
-
:bargein =>
|
128
|
+
:bargein => true,
|
129
129
|
:timeout => 30,
|
130
130
|
:require => 'true' }) do
|
131
131
|
say :value => 'Please say your account number'
|
@@ -203,7 +203,7 @@ Using the great RESTful Web Services framework Sinatra for Ruby.
|
|
203
203
|
post '/ask.json' do
|
204
204
|
t = Tropo::Generator.new(:recognizer => 'fr-fr')
|
205
205
|
t.ask({ :name => 'account_number', # Will now use the French speech recognition engine
|
206
|
-
:bargein =>
|
206
|
+
:bargein => true,
|
207
207
|
:timeout => 30,
|
208
208
|
:require => 'true' }) do
|
209
209
|
say :value => "S'il vous plaît dire votre numéro de compte", :voice => 'florence'
|
@@ -215,7 +215,7 @@ Using the great RESTful Web Services framework Sinatra for Ruby.
|
|
215
215
|
t = Tropo::Generator.new
|
216
216
|
t.recognizer = 'fr-fr'
|
217
217
|
t.ask({ :name => 'account_number', # Will now use the French speech recognition engine
|
218
|
-
:bargein =>
|
218
|
+
:bargein => true,
|
219
219
|
:timeout => 30,
|
220
220
|
:require => 'true' }) do
|
221
221
|
say :value => "S'il vous plaît dire votre numéro de compte", :voice => 'florence'
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.9
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# Borrowed from here: http://eigenclass.org/hiki.rb?instance_exec
|
2
|
+
class Object
|
3
|
+
def instance_exec(*args, &block)
|
4
|
+
mname = "__instance_exec_#{Thread.current.object_id.abs}"
|
5
|
+
class << self; self end.class_eval{ define_method(mname, &block) }
|
6
|
+
begin
|
7
|
+
ret = send(mname, *args)
|
8
|
+
ensure
|
9
|
+
class << self; self end.class_eval{ undef_method(mname) } rescue nil
|
10
|
+
end
|
11
|
+
ret
|
12
|
+
end
|
13
|
+
end
|
@@ -27,7 +27,7 @@ module Tropo
|
|
27
27
|
when 'record'
|
28
28
|
has_params?(params, 'record', ['name', 'url'])
|
29
29
|
when 'start_recording'
|
30
|
-
has_params?(params, 'start_recording', ['
|
30
|
+
has_params?(params, 'start_recording', ['url'])
|
31
31
|
|
32
32
|
# Camelcase this one to be Java friendly
|
33
33
|
action = 'startRecording'
|
@@ -266,12 +266,14 @@ module Tropo
|
|
266
266
|
end
|
267
267
|
|
268
268
|
##
|
269
|
-
# Parses the JSON string recieved from Tropo into a Ruby Hash
|
269
|
+
# Parses the JSON string recieved from Tropo into a Ruby Hash, or
|
270
|
+
# if already a Ruby Hash parses it with the nicities provided by
|
271
|
+
# the gem
|
270
272
|
#
|
271
|
-
# @param [String] a JSON string
|
272
|
-
# @return [Hash] a Hash representing the response from Tropo
|
273
|
-
def parse(
|
274
|
-
response = JSON.parse(
|
273
|
+
# @param [String or Hash] a JSON string or a Ruby Hash
|
274
|
+
# @return [Hash] a Hash representing the formatted response from Tropo
|
275
|
+
def parse(response)
|
276
|
+
response = JSON.parse(response) if response.class == String
|
275
277
|
|
276
278
|
# Check to see what type of response we are working with
|
277
279
|
if response['session']
|
@@ -473,7 +475,8 @@ module Tropo
|
|
473
475
|
end
|
474
476
|
render_response if @building.nil?
|
475
477
|
end
|
476
|
-
|
478
|
+
alias :start_call_recording :start_recording
|
479
|
+
|
477
480
|
##
|
478
481
|
# Stops the recording of the current session after startCallRecording has been called
|
479
482
|
#
|
@@ -483,6 +486,7 @@ module Tropo
|
|
483
486
|
@response[:tropo] << { :stopRecording => nil }
|
484
487
|
render_response if @building.nil?
|
485
488
|
end
|
489
|
+
alias :stop_call_recording :stop_recording
|
486
490
|
|
487
491
|
##
|
488
492
|
# Transfers an already answered call to another destination / phone number.
|
@@ -531,6 +535,14 @@ module Tropo
|
|
531
535
|
render_response if @building.nil?
|
532
536
|
end
|
533
537
|
|
538
|
+
##
|
539
|
+
# Returns the current hash object of the response, as opposed to JSON
|
540
|
+
#
|
541
|
+
# @return [Hash] the current hash of the response
|
542
|
+
def to_hash
|
543
|
+
@response
|
544
|
+
end
|
545
|
+
|
534
546
|
##
|
535
547
|
# Sets the default voice for the object
|
536
548
|
#
|
@@ -285,10 +285,20 @@ describe "Tropo" do
|
|
285
285
|
|
286
286
|
# Start & Stop Recording actions tests
|
287
287
|
it "should generate a JSON document with a 'start_recording' action" do
|
288
|
-
response = Tropo::Generator.start_recording(:
|
289
|
-
JSON.parse(response).should == {"tropo"=>[{"startRecording"=>{"
|
288
|
+
response = Tropo::Generator.start_recording(:url => 'http://postrecording.com/tropo')
|
289
|
+
JSON.parse(response).should == {"tropo"=>[{"startRecording"=>{"url"=>"http://postrecording.com/tropo"}}]}
|
290
290
|
end
|
291
291
|
|
292
|
+
it "should generate a JSON document with a 'start_call_recording' action" do
|
293
|
+
response = Tropo::Generator.start_call_recording(:url => 'http://postrecording.com/tropo')
|
294
|
+
JSON.parse(response).should == {"tropo"=>[{"startRecording"=>{"url"=>"http://postrecording.com/tropo"}}]}
|
295
|
+
end
|
296
|
+
|
297
|
+
it "should generate a JSON document with a 'stopRecording' action" do
|
298
|
+
response = Tropo::Generator.stop_call_recording
|
299
|
+
JSON.parse(response).should == {"tropo"=>[{"stopRecording"=>nil}]}
|
300
|
+
end
|
301
|
+
|
292
302
|
it "should generate a JSON document with a 'stoprecording' action" do
|
293
303
|
response = Tropo::Generator.stop_recording
|
294
304
|
JSON.parse(response).should == {"tropo"=>[{"stopRecording"=>nil}]}
|
@@ -426,13 +436,13 @@ describe "Tropo" do
|
|
426
436
|
t.on :event => 'hangup', :next => '/hangup.json' # When a user hangs or call is done. We will want to log some details.
|
427
437
|
t.on :event => 'continue', :next => '/next.json'
|
428
438
|
t.say "Hello"
|
429
|
-
t.start_recording(:
|
439
|
+
t.start_recording(:url => "http://heroku-voip.marksilver.net/post_audio_to_s3?filename=foo.wav&unique_id=bar")
|
430
440
|
# [From this point, until stop_recording(), we will record what the caller *and* the IVR say]
|
431
441
|
t.say "You are now on the record."
|
432
442
|
# Prompt the user to incriminate themselve on-the-record
|
433
443
|
t.say "Go ahead, sing-along."
|
434
444
|
t.say "http://denalidomain.com/music/keepers/HappyHappyBirthdaytoYou-Disney.mp3"
|
435
|
-
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"=>{"
|
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"}]}]}
|
436
446
|
end
|
437
447
|
|
438
448
|
it "should generate a voice_session true if a JSON session is received that is a channel of 'VOICE'" do
|
@@ -610,4 +620,24 @@ describe "Tropo" do
|
|
610
620
|
JSON.parse(t.response)['tropo'][0]['ask']['recognizer'].should == 'fr-fr'
|
611
621
|
JSON.parse(t.response)['tropo'][1]['ask']['recognizer'].should == 'de-de'
|
612
622
|
end
|
623
|
+
|
624
|
+
it "should parse a JSON string or a Ruby Hash the same" do
|
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
|
+
tropo = Tropo::Generator.parse json_session
|
627
|
+
tropo.session.user_type.should == 'HUMAN'
|
628
|
+
|
629
|
+
tropo = Tropo::Generator.parse(JSON.parse(json_session))
|
630
|
+
tropo.session.user_type.should == 'HUMAN'
|
631
|
+
end
|
632
|
+
|
633
|
+
it "should return a hash of the response object" do
|
634
|
+
result = Tropo::Generator.new do
|
635
|
+
say [{ :value => '1234' }, { :value => 'abcd', :event => "nomatch:1" }]
|
636
|
+
say [{ :value => '0987' }, { :value => 'zyxw', :event => "nomatch:2" }]
|
637
|
+
end
|
638
|
+
result.to_hash.should == { :tropo => [{ :say => [{ :value => "1234" },
|
639
|
+
{ :event => "nomatch:1", :value => "abcd" }] },
|
640
|
+
{ :say => [{ :value => "0987" },
|
641
|
+
{ :event => "nomatch:2", :value => "zyxw" }] }] }
|
642
|
+
end
|
613
643
|
end
|
data/tropo-webapi-ruby.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
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.9"
|
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"]
|
@@ -26,6 +26,7 @@ Gem::Specification.new do |s|
|
|
26
26
|
"VERSION",
|
27
27
|
"examples/sinatra_server.rb",
|
28
28
|
"lib/tropo-webapi-ruby.rb",
|
29
|
+
"lib/tropo-webapi-ruby/object_patch.rb",
|
29
30
|
"lib/tropo-webapi-ruby/tropo-webapi-ruby-helpers.rb",
|
30
31
|
"lib/tropo-webapi-ruby/tropo-webapi-ruby.rb",
|
31
32
|
"spec/spec.opts",
|
metadata
CHANGED
@@ -1,7 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tropo-webapi-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
hash: 9
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 9
|
10
|
+
version: 0.1.9
|
5
11
|
platform: ruby
|
6
12
|
authors:
|
7
13
|
- Jason Goecke
|
@@ -14,34 +20,52 @@ default_executable:
|
|
14
20
|
dependencies:
|
15
21
|
- !ruby/object:Gem::Dependency
|
16
22
|
name: rspec
|
17
|
-
|
18
|
-
|
19
|
-
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
20
26
|
requirements:
|
21
27
|
- - ">="
|
22
28
|
- !ruby/object:Gem::Version
|
29
|
+
hash: 13
|
30
|
+
segments:
|
31
|
+
- 1
|
32
|
+
- 2
|
33
|
+
- 9
|
23
34
|
version: 1.2.9
|
24
|
-
|
35
|
+
type: :development
|
36
|
+
version_requirements: *id001
|
25
37
|
- !ruby/object:Gem::Dependency
|
26
38
|
name: json_pure
|
27
|
-
|
28
|
-
|
29
|
-
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
30
42
|
requirements:
|
31
43
|
- - ">="
|
32
44
|
- !ruby/object:Gem::Version
|
45
|
+
hash: 31
|
46
|
+
segments:
|
47
|
+
- 1
|
48
|
+
- 2
|
49
|
+
- 0
|
33
50
|
version: 1.2.0
|
34
|
-
|
51
|
+
type: :runtime
|
52
|
+
version_requirements: *id002
|
35
53
|
- !ruby/object:Gem::Dependency
|
36
54
|
name: hashie
|
37
|
-
|
38
|
-
|
39
|
-
|
55
|
+
prerelease: false
|
56
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
40
58
|
requirements:
|
41
59
|
- - ">="
|
42
60
|
- !ruby/object:Gem::Version
|
61
|
+
hash: 23
|
62
|
+
segments:
|
63
|
+
- 0
|
64
|
+
- 2
|
65
|
+
- 0
|
43
66
|
version: 0.2.0
|
44
|
-
|
67
|
+
type: :runtime
|
68
|
+
version_requirements: *id003
|
45
69
|
description: Ruby library for interacting with the Tropo Web API via REST & JSON
|
46
70
|
email: jsgoecke@voxeo.com
|
47
71
|
executables: []
|
@@ -61,6 +85,7 @@ files:
|
|
61
85
|
- VERSION
|
62
86
|
- examples/sinatra_server.rb
|
63
87
|
- lib/tropo-webapi-ruby.rb
|
88
|
+
- lib/tropo-webapi-ruby/object_patch.rb
|
64
89
|
- lib/tropo-webapi-ruby/tropo-webapi-ruby-helpers.rb
|
65
90
|
- lib/tropo-webapi-ruby/tropo-webapi-ruby.rb
|
66
91
|
- spec/spec.opts
|
@@ -77,21 +102,29 @@ rdoc_options:
|
|
77
102
|
require_paths:
|
78
103
|
- lib
|
79
104
|
required_ruby_version: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
80
106
|
requirements:
|
81
107
|
- - ">="
|
82
108
|
- !ruby/object:Gem::Version
|
109
|
+
hash: 59
|
110
|
+
segments:
|
111
|
+
- 1
|
112
|
+
- 8
|
113
|
+
- 6
|
83
114
|
version: 1.8.6
|
84
|
-
version:
|
85
115
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
116
|
+
none: false
|
86
117
|
requirements:
|
87
118
|
- - ">="
|
88
119
|
- !ruby/object:Gem::Version
|
120
|
+
hash: 3
|
121
|
+
segments:
|
122
|
+
- 0
|
89
123
|
version: "0"
|
90
|
-
version:
|
91
124
|
requirements: []
|
92
125
|
|
93
126
|
rubyforge_project:
|
94
|
-
rubygems_version: 1.3.
|
127
|
+
rubygems_version: 1.3.7
|
95
128
|
signing_key:
|
96
129
|
specification_version: 3
|
97
130
|
summary: Tropo Web API Ruby Gem
|