tropo-webapi-ruby 0.1.6 → 0.1.7

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/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.6
1
+ 0.1.7
@@ -73,7 +73,9 @@ module Tropo
73
73
  # @return [String] the Ruby string camelized
74
74
  def camelize(ruby_string)
75
75
  split_string = ruby_string.split('_')
76
- split_string[0] + split_string[1].capitalize
76
+ return_string = split_string[0] + split_string[1].capitalize
77
+ return_string = return_string + split_string[2].capitalize if split_string[2]
78
+ return_string
77
79
  end
78
80
 
79
81
  ##
@@ -127,7 +129,7 @@ module Tropo
127
129
  params.each_pair do |k,v|
128
130
  if k.to_s.include? "_"
129
131
  k = camelize k.to_s
130
- k = k.to_sym
132
+ k = k.to_sym if k
131
133
  end
132
134
  hash.merge!({ k => v })
133
135
  end
@@ -76,6 +76,44 @@ module Tropo
76
76
  end
77
77
  alias :prompt :ask
78
78
 
79
+ ##
80
+ # Prompts initiates a new call. May only be used when no call is active.
81
+ #
82
+ # @overload call(params)
83
+ # @param [Hash] params the options to create a call action request with.
84
+ # @option params [String] :to the destination of the call, may be a phone number, SMS number or IM address
85
+ # @option params [optional, String] :from the phone number or IM address the call will come from
86
+ # @option params [optional, String] :network which network the call will be initiated with, such as SMS
87
+ # @option params [optional, String] :channel the channel the call will be initiated over, may be TEXT or VOICE
88
+ # @option params [optional, Integer] :timeout (30) the amount of time, in seconds, to wait for a response before moving on
89
+ # @option params [optional, Boolean] :answer_on_media (true)
90
+ # @options params [optional, Hash] :headers A set of key/values to apply as customer SIP headers to the outgoing call
91
+ # @options params [optional, Hash] :recording Refer to the recording method for paramaters in the hash
92
+ # @overload ask(params, &block)
93
+ # @param [Hash] params the options to create an message action request with.
94
+ # @param [Block] takes a block so that you may trigger actions, such as a say, on a specific event
95
+ # @option params [String] :to the destination of the call, may be a phone number, SMS number or IM address
96
+ # @option params [optional, String] :from the phone number or IM address the call will come from
97
+ # @option params [optional, String] :network which network the call will be initiated with, such as SMS
98
+ # @option params [optional, String] :channel the channel the call will be initiated over, may be TEXT or VOICE
99
+ # @option params [optional, Integer] :timeout (30) the amount of time, in seconds, to wait for a response before moving on
100
+ # @option params [optional, Boolean] :answer_on_media (true)
101
+ # @options params [optional, Hash] :headers A set of key/values to apply as customer SIP headers to the outgoing call
102
+ # @options params [optional, Hash] :recording Refer to the recording method for paramaters in the hash
103
+ # @return [String, nil] the JSON string to be passed back to Tropo or nil
104
+ # if the method has been called from inside a block
105
+ def call(params={}, &block)
106
+ if block_given?
107
+ create_nested_hash('call', params)
108
+ instance_exec(&block)
109
+ @response[:tropo] << @nested_hash
110
+ else
111
+ hash = build_action('call', params)
112
+ @response[:tropo] << hash
113
+ end
114
+ render_response if @building.nil?
115
+ end
116
+
79
117
  ##
80
118
  # Choices to give the user on input
81
119
  #
@@ -146,6 +184,45 @@ module Tropo
146
184
  end
147
185
  alias :disconnect :hangup
148
186
 
187
+ ##
188
+ # Message initiates a new message to a destination and then hangs up on that destination. Also takes a say method
189
+ # in order to deliver a message to that desintation and then hangup.
190
+ #
191
+ # @overload message(params)
192
+ # @param [Hash] params the options to create a message action request with.
193
+ # @option params [String] :to the destination of the call, may be a phone number, SMS number or IM address
194
+ # @option params [optional, String] :from the phone number or IM address the call will come from
195
+ # @option params [optional, String] :network which network the call will be initiated with, such as SMS
196
+ # @option params [optional, String] :channel the channel the call will be initiated over, may be TEXT or VOICE
197
+ # @option params [optional, Integer] :timeout (30) the amount of time, in seconds, to wait for a response before moving on
198
+ # @option params [optional, Boolean] :answer_on_media (true)
199
+ # @options params [optional, Hash] :headers A set of key/values to apply as customer SIP headers to the outgoing call
200
+ # @options params [optional, Hash] :recording Refer to the recording method for paramaters in the hash
201
+ # @overload ask(params, &block)
202
+ # @param [Hash] params the options to create an message action request with.
203
+ # @param [Block] takes a block so that you may trigger actions, such as a say, on a specific event
204
+ # @option params [String] :to the destination of the call, may be a phone number, SMS number or IM address
205
+ # @option params [optional, String] :from the phone number or IM address the call will come from
206
+ # @option params [optional, String] :network which network the call will be initiated with, such as SMS
207
+ # @option params [optional, String] :channel the channel the call will be initiated over, may be TEXT or VOICE
208
+ # @option params [optional, Integer] :timeout (30) the amount of time, in seconds, to wait for a response before moving on
209
+ # @option params [optional, Boolean] :answer_on_media (true)
210
+ # @options params [optional, Hash] :headers A set of key/values to apply as customer SIP headers to the outgoing call
211
+ # @options params [optional, Hash] :recording Refer to the recording method for paramaters in the hash
212
+ # @return [String, nil] the JSON string to be passed back to Tropo or nil
213
+ # if the method has been called from inside a block
214
+ def message(params={}, &block)
215
+ if block_given?
216
+ create_nested_hash('message', params)
217
+ instance_exec(&block)
218
+ @response[:tropo] << @nested_hash
219
+ else
220
+ hash = build_action('message', params)
221
+ @response[:tropo] << hash
222
+ end
223
+ render_response if @building.nil?
224
+ end
225
+
149
226
  ##
150
227
  # Sets event handlers to call a REST resource when a particular event occurs
151
228
  #
@@ -224,6 +301,7 @@ module Tropo
224
301
  # @option params [optional, String] :format (audio/wav) the audio format to record in, either a wav or mp3
225
302
  # @option params [optional, String] :username if posting to FTP, the username for the FTP server
226
303
  # @option params [optional, String] :password if posting to FTP, the password for the FTP server
304
+ # @option params [optional, Hash] :transcription parameters used to transcribe the recording
227
305
  # @overload record(params, &block)
228
306
  # @param [Hash] params the options to create a message with.
229
307
  # @param [Block] takes a block so that you may trigger actions, such as a say, on a specific event
@@ -232,6 +310,7 @@ module Tropo
232
310
  # @option params [optional, String] :format (audio/wav) the audio format to record in, either a wav or mp3
233
311
  # @option params [optional, String] :username if posting to FTP, the username for the FTP server
234
312
  # @option params [optional, String] :password if posting to FTP, the password for the FTP server
313
+ # @option params [optional, Hash] :transcription parameters used to transcribe the recording
235
314
  # @option [String, nil] the JSON string to be passed back to Tropo or nil
236
315
  # if the method has been called from inside a block
237
316
  def record(params={}, &block)
@@ -449,4 +449,74 @@ describe "Tropo" do
449
449
  tropo.text_session.should == true
450
450
  end
451
451
 
452
+ it "should generate a valid JSON string for a call method" do
453
+ 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}}]}"
454
+ tropo = Tropo::Generator.call({ :to => 'foo',
455
+ :from => 'bar',
456
+ :network => 'SMS',
457
+ :channel => 'TEXT',
458
+ :timeout => 10,
459
+ :answer_on_media => false,
460
+ :headers => { :foo => 'foo', :bar => 'bar' },
461
+ :recording => { :url => 'http://foobar',
462
+ :method => 'POST',
463
+ :format => 'audio/mp3',
464
+ :username => 'jose',
465
+ :password => 'passwd' } })
466
+ JSON.parse(tropo).should == JSON.parse(json_result)
467
+ end
468
+
469
+ it "should generate a valid JSON string for a message method" do
470
+ 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"}}}]}
471
+ tropo = Tropo::Generator.message({ :to => 'foo',
472
+ :from => 'bar',
473
+ :network => 'SMS',
474
+ :channel => 'TEXT',
475
+ :timeout => 10,
476
+ :answer_on_media => false,
477
+ :headers => { :foo => 'foo', :bar => 'bar' },
478
+ :recording => { :url => 'http://foobar',
479
+ :method => 'POST',
480
+ :format => 'audio/mp3',
481
+ :username => 'jose',
482
+ :password => 'passwd' } }) do
483
+ say :value => 'Please say your account number'
484
+ end
485
+ JSON.parse(tropo).should == hash_result
486
+ end
487
+
488
+ it "should generate a valid JSON string for a record method with a transcription request" do
489
+ 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]"}}}]}
490
+ tropo = Tropo::Generator.record({ :name => 'foo',
491
+ :url => 'http://sendme.com/tropo',
492
+ :beep => true,
493
+ :send_tones => false,
494
+ :transcription => { :id => 'bling',
495
+ :url => 'mailto:jose@voxeo.com',
496
+ :email_format => 'encoded' },
497
+ :exit_tone => '#' }) do
498
+ say :value => 'Please say your account number'
499
+ choices :value => '[5 DIGITS]'
500
+ end
501
+ JSON.parse(tropo).should == hash_result
502
+ end
503
+
504
+ it "should properly generate a JSON document when calling an ask with says as hash elements rather than as methods" do
505
+ 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)"}}}]}
506
+ help_stop_choices = "0(0,help,i do not know, agent, operator, assistance, representative, real person, human), 9(9,quit,stop,shut up)"
507
+ yes_no_choices = "true(1,yes,sure,affirmative), false(2,no,no thank you,negative), " + help_stop_choices
508
+
509
+ t = Tropo::Generator.new
510
+ t.ask :name => 'donate_to_id',
511
+ :bargein => true,
512
+ :timeout => 10,
513
+ :silence_timeout => 10,
514
+ :attempts => 4,
515
+ :say => [{:event => "timeout", :value => "Sorry, I did not hear anything."},
516
+ {: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'."},
517
+ {: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."},
518
+ {:event => "nomatch:3", :value => "This is your last attempt."}],
519
+ :choices => { :value => yes_no_choices}
520
+ JSON.parse(t.response).should == hash_result
521
+ end
452
522
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{tropo-webapi-ruby}
8
- s.version = "0.1.6"
8
+ s.version = "0.1.7"
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{2010-04-26}
12
+ s.date = %q{2010-04-29}
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 = [
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tropo-webapi-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason Goecke
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-04-26 00:00:00 -07:00
12
+ date: 2010-04-29 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency