webficient-twilio 1.3.0 → 1.4.0

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.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
+ :minor: 4
2
3
  :patch: 0
3
4
  :major: 1
4
- :minor: 3
data/lib/twilio/verb.rb CHANGED
@@ -23,7 +23,7 @@ module Twilio
23
23
  #
24
24
  # Twilio::Verb.say_4_times_with_pause('Your PIN is 1 2 3 4')
25
25
  #
26
- # Optional params (see http://www.twilio.com/docs/api_reference/TwiML/say) are passed in as a hash:
26
+ # Options (see http://www.twilio.com/docs/api_reference/TwiML/say) are passed in as a hash:
27
27
  #
28
28
  # Twilio::Verb.say('The time is 9:35 PM.', :voice => 'woman')
29
29
  # Twilio::Verb.say('The time is 9:35 PM.', {:voice => 'woman', :language => 'es'})
@@ -53,7 +53,7 @@ module Twilio
53
53
  }
54
54
  end
55
55
 
56
- # The Play verb plays an audio URL back to the caller.
56
+ # The Play verb plays an audio URL back to the caller.
57
57
  # Examples:
58
58
  # Twilio::Verb.play('http://foo.com/cowbell.mp3')
59
59
  # Twilio::Verb.play_3_times('http://foo.com/cowbell.mp3')
@@ -62,7 +62,7 @@ module Twilio
62
62
  #
63
63
  # Twilio::Verb.play_3_times_with_pause('http://foo.com/cowbell.mp3')
64
64
  #
65
- # Optional params (see http://www.twilio.com/docs/api_reference/TwiML/play) are passed in as a hash,
65
+ # Options (see http://www.twilio.com/docs/api_reference/TwiML/play) are passed in as a hash,
66
66
  # however, since the Play verb only supports 'loop' as the current option, you can instead use the
67
67
  # above form to keep things concise.
68
68
  def play(*args, &block)
@@ -90,25 +90,75 @@ module Twilio
90
90
  end
91
91
  }
92
92
  end
93
-
93
+
94
+ # The Gather verb collects digits entered by a caller into their telephone keypad.
95
+ # When the caller is done entering data, Twilio submits that data to a provided URL,
96
+ # as either a HTTP GET or POST request, just like a web browser submits data from an HTML form.
97
+ #
98
+ # Options (see http://www.twilio.com/docs/api_reference/TwiML/gather) are passed in as a hash
99
+ #
100
+ # Examples:
101
+ # Twilio::Verb.gather
102
+ # Twilio::Verb.gather(:action => 'http://foobar.com')
103
+ # Twilio::Verb.gather(:finishOnKey => '*')
104
+ # Twilio::Verb.gather(:action => 'http://foobar.com', :finishOnKey => '*')
94
105
  def gather(*args, &block)
95
106
  options = args.shift
96
-
97
107
  xml = Builder::XmlMarkup.new
98
108
  xml.instruct!
99
- xml.Response {
100
- xml.Gather(options)
101
- }
109
+ xml.Response { xml.Gather(options) }
102
110
  end
103
111
 
104
- #Not yet implemented
105
- def record(options = {})
106
- raise NotImplementedError.new 'Not yet implemented - coming soon'
112
+ # The Record verb records the caller's voice and returns a URL that links to a file
113
+ # containing the audio recording.
114
+ #
115
+ # Options (see http://www.twilio.com/docs/api_reference/TwiML/record) are passed in as a hash
116
+ #
117
+ # Examples:
118
+ # Twilio::Verb.record
119
+ # Twilio::Verb.record(:action => 'http://foobar.com')
120
+ # Twilio::Verb.record(:finishOnKey => '*')
121
+ # Twilio::Verb.record(:transcribe => true, :transcribeCallback => '/handle_transcribe')
122
+ def record(*args, &block)
123
+ options = args.shift
124
+ xml = Builder::XmlMarkup.new
125
+ xml.instruct!
126
+ xml.Response { xml.Record(options) }
107
127
  end
108
128
 
109
- #Not yet implemented
110
- def dial(phone_number, options = {})
111
- raise NotImplementedError.new 'Not yet implemented - coming soon'
129
+ # The Dial verb connects the current caller to an another phone. If the called party picks up,
130
+ # the two parties are connected and can communicate until one hangs up. If the called party does
131
+ # not pick up, if a busy signal is received, or the number doesn't exist, the dial verb will finish.
132
+ #
133
+ # If an action verb is provided, Twilio will submit the outcome of the call attempt to the action URL.
134
+ # If no action is provided, Dial will fall through to the next verb in the document.
135
+ #
136
+ # Note: this is different than the behavior of Record and Gather. Dial does not submit back to the
137
+ # current document URL if no action is provided.
138
+ #
139
+ # Options (see http://www.twilio.com/docs/api_reference/TwiML/dial) are passed in as a hash
140
+ #
141
+ # Examples:
142
+ # Twilio::Verb.dial('415-123-4567')
143
+ # Twilio::Verb.dial('415-123-4567', :action => 'http://foobar.com')
144
+ # Twilio::Verb.dial('415-123-4567', {:timeout => 10, :callerId => '858-987-6543'})
145
+ def dial(*args, &block)
146
+ number_to_dial = ''
147
+ options = {}
148
+ args.each do |arg|
149
+ case arg
150
+ when String
151
+ number_to_dial = arg
152
+ when Hash
153
+ options.merge!(arg)
154
+ else
155
+ raise ArgumentError, 'dial expects String or Hash argument'
156
+ end
157
+ end
158
+
159
+ xml = Builder::XmlMarkup.new
160
+ xml.instruct!
161
+ xml.Response { xml.Dial(number_to_dial, options) }
112
162
  end
113
163
 
114
164
  def method_missing(method_id, *args) #:nodoc:
@@ -38,4 +38,52 @@ gather_with_finish_key:
38
38
  response: <?xml version="1.0" encoding="UTF-8"?><Response><Gather finishOnKey="*"/></Response>
39
39
 
40
40
  gather_with_num_digits:
41
- response: <?xml version="1.0" encoding="UTF-8"?><Response><Gather numDigits="5"/></Response>
41
+ response: <?xml version="1.0" encoding="UTF-8"?><Response><Gather numDigits="5"/></Response>
42
+
43
+ gather_with_all_options_set:
44
+ response: <?xml version="1.0" encoding="UTF-8"?><Response><Gather finishOnKey="*" method="GET" action="http://foobar.com" numDigits="5" timeout="10"/></Response>
45
+
46
+ record:
47
+ response: <?xml version="1.0" encoding="UTF-8"?><Response><Record></Record></Response>
48
+
49
+ record_with_action:
50
+ response: <?xml version="1.0" encoding="UTF-8"?><Response><Record action="http://foobar.com"/></Response>
51
+
52
+ record_with_get_method:
53
+ response: <?xml version="1.0" encoding="UTF-8"?><Response><Record method="GET"/></Response>
54
+
55
+ record_with_timeout:
56
+ response: <?xml version="1.0" encoding="UTF-8"?><Response><Record timeout="10"/></Response>
57
+
58
+ record_with_finish_key:
59
+ response: <?xml version="1.0" encoding="UTF-8"?><Response><Record finishOnKey="*"/></Response>
60
+
61
+ record_with_max_length:
62
+ response: <?xml version="1.0" encoding="UTF-8"?><Response><Record maxLength="1800"/></Response>
63
+
64
+ record_with_transcribe:
65
+ response: <?xml version="1.0" encoding="UTF-8"?><Response><Record transcribe="true" transcribeCallback="/handle_transcribe"/></Response>
66
+
67
+ dial:
68
+ response: <?xml version="1.0" encoding="UTF-8"?><Response><Dial>415-123-4567</Dial></Response>
69
+
70
+ dial_with_action:
71
+ response: <?xml version="1.0" encoding="UTF-8"?><Response><Dial action="http://foobar.com">415-123-4567</Dial></Response>
72
+
73
+ dial_with_get_method:
74
+ response: <?xml version="1.0" encoding="UTF-8"?><Response><Dial method="GET">415-123-4567</Dial></Response>
75
+
76
+ dial_with_timeout:
77
+ response: <?xml version="1.0" encoding="UTF-8"?><Response><Dial timeout="10">415-123-4567</Dial></Response>
78
+
79
+ dial_with_hangup_on_star:
80
+ response: <?xml version="1.0" encoding="UTF-8"?><Response><Dial hangupOnStar="true">415-123-4567</Dial></Response>
81
+
82
+ dial_with_time_limit:
83
+ response: <?xml version="1.0" encoding="UTF-8"?><Response><Dial timeLimit="3600">415-123-4567</Dial></Response>
84
+
85
+ dial_with_caller_id:
86
+ response: <?xml version="1.0" encoding="UTF-8"?><Response><Dial callerId="858-987-6543">415-123-4567</Dial></Response>
87
+
88
+ dial_with_timeout_and_caller_id:
89
+ response: <?xml version="1.0" encoding="UTF-8"?><Response><Dial callerId="858-987-6543" timeout="10">415-123-4567</Dial></Response>
@@ -58,12 +58,68 @@ class VerbTest < Test::Unit::TestCase #:nodoc: all
58
58
  assert_equal verb_response(:gather_with_num_digits), Twilio::Verb.gather(:numDigits => 5)
59
59
  end
60
60
 
61
- should "raise not implemented error with record" do
62
- assert_raise(NotImplementedError) { Twilio::Verb.record('something') }
61
+ should "gather with all options set" do
62
+ assert_equal verb_response(:gather_with_all_options_set), Twilio::Verb.gather(:action => 'http://foobar.com', :method => 'GET', :timeout => 10, :finishOnKey => '*', :numDigits => 5)
63
63
  end
64
64
 
65
- should "raise not implemented error with dial" do
66
- assert_raise(NotImplementedError) { Twilio::Verb.record('dial') }
65
+ should "record" do
66
+ assert_equal verb_response(:record), Twilio::Verb.record
67
+ end
68
+
69
+ should "record with action" do
70
+ assert_equal verb_response(:record_with_action), Twilio::Verb.record(:action => 'http://foobar.com')
71
+ end
72
+
73
+ should "record with GET method" do
74
+ assert_equal verb_response(:record_with_get_method), Twilio::Verb.record(:method => 'GET')
75
+ end
76
+
77
+ should "record with timeout" do
78
+ assert_equal verb_response(:record_with_timeout), Twilio::Verb.record(:timeout => 10)
79
+ end
80
+
81
+ should "record with finish key" do
82
+ assert_equal verb_response(:record_with_finish_key), Twilio::Verb.record(:finishOnKey => '*')
83
+ end
84
+
85
+ should "record with max length" do
86
+ assert_equal verb_response(:record_with_max_length), Twilio::Verb.record(:maxLength => 1800)
87
+ end
88
+
89
+ should "record with transcribe" do
90
+ assert_equal verb_response(:record_with_transcribe), Twilio::Verb.record(:transcribe => true, :transcribeCallback => '/handle_transcribe')
91
+ end
92
+
93
+ should "dial" do
94
+ assert_equal verb_response(:dial), Twilio::Verb.dial('415-123-4567')
95
+ end
96
+
97
+ should "dial with action" do
98
+ assert_equal verb_response(:dial_with_action), Twilio::Verb.dial('415-123-4567', :action => 'http://foobar.com')
99
+ end
100
+
101
+ should "dial with GET method" do
102
+ assert_equal verb_response(:dial_with_get_method), Twilio::Verb.dial('415-123-4567', :method => 'GET')
103
+ end
104
+
105
+ should "dial with timeout" do
106
+ assert_equal verb_response(:dial_with_timeout), Twilio::Verb.dial('415-123-4567', :timeout => 10)
107
+ end
108
+
109
+ should "dial with hangup on star" do
110
+ assert_equal verb_response(:dial_with_hangup_on_star), Twilio::Verb.dial('415-123-4567', :hangupOnStar => true)
111
+ end
112
+
113
+ should "dial with time limit" do
114
+ assert_equal verb_response(:dial_with_time_limit), Twilio::Verb.dial('415-123-4567', :timeLimit => 3600)
115
+ end
116
+
117
+ should "dial with caller id" do
118
+ assert_equal verb_response(:dial_with_caller_id), Twilio::Verb.dial('415-123-4567', :callerId => '858-987-6543')
119
+ end
120
+
121
+ should "dial with timeout and caller id" do
122
+ assert_equal verb_response(:dial_with_timeout_and_caller_id), Twilio::Verb.dial('415-123-4567', {:timeout => 10, :callerId => '858-987-6543'})
67
123
  end
68
124
  end
69
125
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: webficient-twilio
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Phil Misiowiec