twilio-ruby 5.3.1 → 5.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGES.md +17 -0
  3. data/README.md +2 -2
  4. data/lib/rack/twilio_webhook_authentication.rb +46 -0
  5. data/lib/twilio-ruby/rest/api/v2010/account/incoming_phone_number/local.rb +10 -1
  6. data/lib/twilio-ruby/rest/api/v2010/account/incoming_phone_number/mobile.rb +10 -1
  7. data/lib/twilio-ruby/rest/api/v2010/account/incoming_phone_number/toll_free.rb +10 -1
  8. data/lib/twilio-ruby/rest/api/v2010/account/incoming_phone_number.rb +22 -3
  9. data/lib/twilio-ruby/rest/api/v2010/account/message.rb +3 -1
  10. data/lib/twilio-ruby/rest/client.rb +7 -0
  11. data/lib/twilio-ruby/rest/preview/hosted_numbers/authorization_document.rb +417 -0
  12. data/lib/twilio-ruby/rest/preview/hosted_numbers/hosted_number_order.rb +8 -7
  13. data/lib/twilio-ruby/rest/preview/hosted_numbers.rb +16 -0
  14. data/lib/twilio-ruby/rest/preview.rb +9 -0
  15. data/lib/twilio-ruby/rest/proxy/v1/service/phone_number.rb +384 -0
  16. data/lib/twilio-ruby/rest/proxy/v1/service/session/interaction.rb +456 -0
  17. data/lib/twilio-ruby/rest/proxy/v1/service/session/participant/message_interaction.rb +465 -0
  18. data/lib/twilio-ruby/rest/proxy/v1/service/session/participant.rb +541 -0
  19. data/lib/twilio-ruby/rest/proxy/v1/service/session.rb +578 -0
  20. data/lib/twilio-ruby/rest/proxy/v1/service/short_code.rb +377 -0
  21. data/lib/twilio-ruby/rest/proxy/v1/service.rb +509 -0
  22. data/lib/twilio-ruby/rest/proxy/v1.rb +41 -0
  23. data/lib/twilio-ruby/rest/proxy.rb +44 -0
  24. data/lib/twilio-ruby/rest/wireless/v1/sim.rb +7 -0
  25. data/lib/twilio-ruby/security/request_validator.rb +1 -1
  26. data/lib/twilio-ruby/twiml/messaging_response.rb +5 -5
  27. data/lib/twilio-ruby/twiml/voice_response.rb +9 -7
  28. data/lib/twilio-ruby/util/configuration.rb +0 -3
  29. data/lib/twilio-ruby/version.rb +1 -1
  30. data/lib/twilio-ruby.rb +1 -0
  31. data/spec/integration/api/v2010/account/incoming_phone_number/local_spec.rb +2 -0
  32. data/spec/integration/api/v2010/account/incoming_phone_number/mobile_spec.rb +2 -0
  33. data/spec/integration/api/v2010/account/incoming_phone_number/toll_free_spec.rb +2 -0
  34. data/spec/integration/api/v2010/account/incoming_phone_number_spec.rb +4 -0
  35. data/spec/integration/preview/hosted_numbers/authorization_document_spec.rb +211 -0
  36. data/spec/integration/preview/hosted_numbers/hosted_number_order_spec.rb +35 -4
  37. data/spec/integration/proxy/v1/service/phone_number_spec.rb +176 -0
  38. data/spec/integration/proxy/v1/service/session/interaction_spec.rb +104 -0
  39. data/spec/integration/proxy/v1/service/session/participant/message_interaction_spec.rb +164 -0
  40. data/spec/integration/proxy/v1/service/session/participant_spec.rb +232 -0
  41. data/spec/integration/proxy/v1/service/session_spec.rb +225 -0
  42. data/spec/integration/proxy/v1/service/short_code_spec.rb +173 -0
  43. data/spec/integration/proxy/v1/service_spec.rb +200 -0
  44. data/spec/integration/wireless/v1/sim_spec.rb +6 -3
  45. data/spec/rack/twilio_webhook_authentication_spec.rb +106 -0
  46. data/spec/security/request_validator_spec.rb +28 -0
  47. data/spec/twiml/messaging_response_spec.rb +6 -6
  48. metadata +31 -2
@@ -166,15 +166,11 @@ module Twilio
166
166
  ##
167
167
  # Retrieve a single page of HostedNumberOrderInstance records from the API.
168
168
  # Request is executed immediately.
169
- # @param [String] address_sid A 34 character string that uniquely identifies the
170
- # Address resource that represents the address of the owner of this phone number.
171
169
  # @param [String] phone_number An E164 formatted phone number hosted by this
172
170
  # HostedNumberOrder.
173
171
  # @param [String] iso_country The ISO country code of the phone_number.
174
172
  # @param [Boolean] sms_capability Used to specify that the SMS capability will be
175
173
  # hosted on Twilio's platform.
176
- # @param [String] email Email of the owner of this phone number that is being
177
- # hosted.
178
174
  # @param [String] account_sid Optional. The unique SID identifier of the Account
179
175
  # or Sub-Account to create this HostedNumberOrder on.
180
176
  # @param [String] friendly_name Optional. A human readable description of this
@@ -200,14 +196,17 @@ module Twilio
200
196
  # application Twilio should use to handle SMS messages sent to this number. If a
201
197
  # `SmsApplicationSid` is present, Twilio will ignore all of the SMS urls above and
202
198
  # use those set on the application.
199
+ # @param [String] address_sid Optional. A 34 character string that uniquely
200
+ # identifies the Address resource that represents the address of the owner of this
201
+ # phone number.
202
+ # @param [String] email Optional. Email of the owner of this phone number that is
203
+ # being hosted.
203
204
  # @return [HostedNumberOrderInstance] Newly created HostedNumberOrderInstance
204
- def create(address_sid: nil, phone_number: nil, iso_country: nil, sms_capability: nil, email: nil, account_sid: :unset, friendly_name: :unset, unique_name: :unset, cc_emails: :unset, sms_url: :unset, sms_method: :unset, sms_fallback_url: :unset, sms_fallback_method: :unset, status_callback_url: :unset, status_callback_method: :unset, sms_application_sid: :unset)
205
+ def create(phone_number: nil, iso_country: nil, sms_capability: nil, account_sid: :unset, friendly_name: :unset, unique_name: :unset, cc_emails: :unset, sms_url: :unset, sms_method: :unset, sms_fallback_url: :unset, sms_fallback_method: :unset, status_callback_url: :unset, status_callback_method: :unset, sms_application_sid: :unset, address_sid: :unset, email: :unset)
205
206
  data = Twilio::Values.of({
206
- 'AddressSid' => address_sid,
207
207
  'PhoneNumber' => phone_number,
208
208
  'IsoCountry' => iso_country,
209
209
  'SmsCapability' => sms_capability,
210
- 'Email' => email,
211
210
  'AccountSid' => account_sid,
212
211
  'FriendlyName' => friendly_name,
213
212
  'UniqueName' => unique_name,
@@ -219,6 +218,8 @@ module Twilio
219
218
  'StatusCallbackUrl' => status_callback_url,
220
219
  'StatusCallbackMethod' => status_callback_method,
221
220
  'SmsApplicationSid' => sms_application_sid,
221
+ 'AddressSid' => address_sid,
222
+ 'Email' => email,
222
223
  })
223
224
 
224
225
  payload = @version.create(
@@ -13,9 +13,25 @@ module Twilio
13
13
  def initialize(domain)
14
14
  super
15
15
  @version = 'HostedNumbers'
16
+ @authorization_documents = nil
16
17
  @hosted_number_orders = nil
17
18
  end
18
19
 
20
+ ##
21
+ # @param [String] sid A 34 character string that uniquely identifies this
22
+ # AuthorizationDocument.
23
+ # @return [Twilio::REST::Preview::HostedNumbers::AuthorizationDocumentInstance] if sid was passed.
24
+ # @return [Twilio::REST::Preview::HostedNumbers::AuthorizationDocumentList]
25
+ def authorization_documents(sid=:unset)
26
+ if sid.nil?
27
+ raise ArgumentError, 'sid cannot be nil'
28
+ elsif sid == :unset
29
+ @authorization_documents ||= AuthorizationDocumentList.new self
30
+ else
31
+ AuthorizationDocumentContext.new(self, sid)
32
+ end
33
+ end
34
+
19
35
  ##
20
36
  # @param [String] sid A 34 character string that uniquely identifies this
21
37
  # HostedNumberOrder.
@@ -100,6 +100,15 @@ module Twilio
100
100
  self.deployed_devices.fleets(sid)
101
101
  end
102
102
 
103
+ ##
104
+ # @param [String] sid A 34 character string that uniquely identifies this
105
+ # AuthorizationDocument.
106
+ # @return [Twilio::REST::Preview::HostedNumbers::AuthorizationDocumentInstance] if sid was passed.
107
+ # @return [Twilio::REST::Preview::HostedNumbers::AuthorizationDocumentList]
108
+ def authorization_documents(sid=:unset)
109
+ self.hosted_numbers.authorization_documents(sid)
110
+ end
111
+
103
112
  ##
104
113
  # @param [String] sid A 34 character string that uniquely identifies this
105
114
  # HostedNumberOrder.
@@ -0,0 +1,384 @@
1
+ ##
2
+ # This code was generated by
3
+ # \ / _ _ _| _ _
4
+ # | (_)\/(_)(_|\/| |(/_ v1.0.0
5
+ # / /
6
+
7
+ module Twilio
8
+ module REST
9
+ class Proxy < Domain
10
+ class V1 < Version
11
+ class ServiceContext < InstanceContext
12
+ ##
13
+ # PLEASE NOTE that this class contains beta products that are subject to change. Use them with caution.
14
+ class PhoneNumberList < ListResource
15
+ ##
16
+ # Initialize the PhoneNumberList
17
+ # @param [Version] version Version that contains the resource
18
+ # @param [String] service_sid The unique SID identifier of the Service.
19
+ # @return [PhoneNumberList] PhoneNumberList
20
+ def initialize(version, service_sid: nil)
21
+ super(version)
22
+
23
+ # Path Solution
24
+ @solution = {
25
+ service_sid: service_sid
26
+ }
27
+ @uri = "/Services/#{@solution[:service_sid]}/PhoneNumbers"
28
+ end
29
+
30
+ ##
31
+ # Retrieve a single page of PhoneNumberInstance records from the API.
32
+ # Request is executed immediately.
33
+ # @param [String] sid A 34 character string that uniquely identifies this Phone
34
+ # Number.
35
+ # @return [PhoneNumberInstance] Newly created PhoneNumberInstance
36
+ def create(sid: nil)
37
+ data = Twilio::Values.of({
38
+ 'Sid' => sid,
39
+ })
40
+
41
+ payload = @version.create(
42
+ 'POST',
43
+ @uri,
44
+ data: data
45
+ )
46
+
47
+ PhoneNumberInstance.new(
48
+ @version,
49
+ payload,
50
+ service_sid: @solution[:service_sid],
51
+ )
52
+ end
53
+
54
+ ##
55
+ # Lists PhoneNumberInstance records from the API as a list.
56
+ # Unlike stream(), this operation is eager and will load `limit` records into
57
+ # memory before returning.
58
+ # @param [Integer] limit Upper limit for the number of records to return. stream()
59
+ # guarantees to never return more than limit. Default is no limit
60
+ # @param [Integer] page_size Number of records to fetch per request, when
61
+ # not set will use the default value of 50 records. If no page_size is defined
62
+ # but a limit is defined, stream() will attempt to read the limit with the most
63
+ # efficient page size, i.e. min(limit, 1000)
64
+ # @return [Array] Array of up to limit results
65
+ def list(limit: nil, page_size: nil)
66
+ self.stream(
67
+ limit: limit,
68
+ page_size: page_size
69
+ ).entries
70
+ end
71
+
72
+ ##
73
+ # Streams PhoneNumberInstance records from the API as an Enumerable.
74
+ # This operation lazily loads records as efficiently as possible until the limit
75
+ # is reached.
76
+ # @param [Integer] limit Upper limit for the number of records to return. stream()
77
+ # guarantees to never return more than limit. Default is no limit.
78
+ # @param [Integer] page_size Number of records to fetch per request, when
79
+ # not set will use the default value of 50 records. If no page_size is defined
80
+ # but a limit is defined, stream() will attempt to read the limit with the most
81
+ # efficient page size, i.e. min(limit, 1000)
82
+ # @return [Enumerable] Enumerable that will yield up to limit results
83
+ def stream(limit: nil, page_size: nil)
84
+ limits = @version.read_limits(limit, page_size)
85
+
86
+ page = self.page(
87
+ page_size: limits[:page_size],
88
+ )
89
+
90
+ @version.stream(page, limit: limits[:limit], page_limit: limits[:page_limit])
91
+ end
92
+
93
+ ##
94
+ # When passed a block, yields PhoneNumberInstance records from the API.
95
+ # This operation lazily loads records as efficiently as possible until the limit
96
+ # is reached.
97
+ def each
98
+ limits = @version.read_limits
99
+
100
+ page = self.page(
101
+ page_size: limits[:page_size],
102
+ )
103
+
104
+ @version.stream(page,
105
+ limit: limits[:limit],
106
+ page_limit: limits[:page_limit]).each {|x| yield x}
107
+ end
108
+
109
+ ##
110
+ # Retrieve a single page of PhoneNumberInstance records from the API.
111
+ # Request is executed immediately.
112
+ # @param [String] page_token PageToken provided by the API
113
+ # @param [Integer] page_number Page Number, this value is simply for client state
114
+ # @param [Integer] page_size Number of records to return, defaults to 50
115
+ # @return [Page] Page of PhoneNumberInstance
116
+ def page(page_token: :unset, page_number: :unset, page_size: :unset)
117
+ params = Twilio::Values.of({
118
+ 'PageToken' => page_token,
119
+ 'Page' => page_number,
120
+ 'PageSize' => page_size,
121
+ })
122
+ response = @version.page(
123
+ 'GET',
124
+ @uri,
125
+ params
126
+ )
127
+ PhoneNumberPage.new(@version, response, @solution)
128
+ end
129
+
130
+ ##
131
+ # Retrieve a single page of PhoneNumberInstance records from the API.
132
+ # Request is executed immediately.
133
+ # @param [String] target_url API-generated URL for the requested results page
134
+ # @return [Page] Page of PhoneNumberInstance
135
+ def get_page(target_url)
136
+ response = @version.domain.request(
137
+ 'GET',
138
+ target_url
139
+ )
140
+ PhoneNumberPage.new(@version, response, @solution)
141
+ end
142
+
143
+ ##
144
+ # Provide a user friendly representation
145
+ def to_s
146
+ '#<Twilio.Proxy.V1.PhoneNumberList>'
147
+ end
148
+ end
149
+
150
+ ##
151
+ # PLEASE NOTE that this class contains beta products that are subject to change. Use them with caution.
152
+ class PhoneNumberPage < Page
153
+ ##
154
+ # Initialize the PhoneNumberPage
155
+ # @param [Version] version Version that contains the resource
156
+ # @param [Response] response Response from the API
157
+ # @param [Hash] solution Path solution for the resource
158
+ # @return [PhoneNumberPage] PhoneNumberPage
159
+ def initialize(version, response, solution)
160
+ super(version, response)
161
+
162
+ # Path Solution
163
+ @solution = solution
164
+ end
165
+
166
+ ##
167
+ # Build an instance of PhoneNumberInstance
168
+ # @param [Hash] payload Payload response from the API
169
+ # @return [PhoneNumberInstance] PhoneNumberInstance
170
+ def get_instance(payload)
171
+ PhoneNumberInstance.new(
172
+ @version,
173
+ payload,
174
+ service_sid: @solution[:service_sid],
175
+ )
176
+ end
177
+
178
+ ##
179
+ # Provide a user friendly representation
180
+ def to_s
181
+ '<Twilio.Proxy.V1.PhoneNumberPage>'
182
+ end
183
+ end
184
+
185
+ ##
186
+ # PLEASE NOTE that this class contains beta products that are subject to change. Use them with caution.
187
+ class PhoneNumberContext < InstanceContext
188
+ ##
189
+ # Initialize the PhoneNumberContext
190
+ # @param [Version] version Version that contains the resource
191
+ # @param [String] service_sid The unique SID identifier of the Service.
192
+ # @param [String] sid A 34 character string that uniquely identifies this Phone
193
+ # Number.
194
+ # @return [PhoneNumberContext] PhoneNumberContext
195
+ def initialize(version, service_sid, sid)
196
+ super(version)
197
+
198
+ # Path Solution
199
+ @solution = {
200
+ service_sid: service_sid,
201
+ sid: sid,
202
+ }
203
+ @uri = "/Services/#{@solution[:service_sid]}/PhoneNumbers/#{@solution[:sid]}"
204
+ end
205
+
206
+ ##
207
+ # Deletes the PhoneNumberInstance
208
+ # @return [Boolean] true if delete succeeds, true otherwise
209
+ def delete
210
+ @version.delete('delete', @uri)
211
+ end
212
+
213
+ ##
214
+ # Fetch a PhoneNumberInstance
215
+ # @return [PhoneNumberInstance] Fetched PhoneNumberInstance
216
+ def fetch
217
+ params = Twilio::Values.of({})
218
+
219
+ payload = @version.fetch(
220
+ 'GET',
221
+ @uri,
222
+ params,
223
+ )
224
+
225
+ PhoneNumberInstance.new(
226
+ @version,
227
+ payload,
228
+ service_sid: @solution[:service_sid],
229
+ sid: @solution[:sid],
230
+ )
231
+ end
232
+
233
+ ##
234
+ # Provide a user friendly representation
235
+ def to_s
236
+ context = @solution.map {|k, v| "#{k}: #{v}"}.join(',')
237
+ "#<Twilio.Proxy.V1.PhoneNumberContext #{context}>"
238
+ end
239
+ end
240
+
241
+ ##
242
+ # PLEASE NOTE that this class contains beta products that are subject to change. Use them with caution.
243
+ class PhoneNumberInstance < InstanceResource
244
+ ##
245
+ # Initialize the PhoneNumberInstance
246
+ # @param [Version] version Version that contains the resource
247
+ # @param [Hash] payload payload that contains response from Twilio
248
+ # @param [String] service_sid The unique SID identifier of the Service.
249
+ # @param [String] sid A 34 character string that uniquely identifies this Phone
250
+ # Number.
251
+ # @return [PhoneNumberInstance] PhoneNumberInstance
252
+ def initialize(version, payload, service_sid: nil, sid: nil)
253
+ super(version)
254
+
255
+ # Marshaled Properties
256
+ @properties = {
257
+ 'sid' => payload['sid'],
258
+ 'account_sid' => payload['account_sid'],
259
+ 'service_sid' => payload['service_sid'],
260
+ 'date_created' => Twilio.deserialize_iso8601_datetime(payload['date_created']),
261
+ 'date_updated' => Twilio.deserialize_iso8601_datetime(payload['date_updated']),
262
+ 'phone_number' => payload['phone_number'],
263
+ 'friendly_name' => payload['friendly_name'],
264
+ 'iso_country' => payload['iso_country'],
265
+ 'capabilities' => payload['capabilities'],
266
+ 'url' => payload['url'],
267
+ }
268
+
269
+ # Context
270
+ @instance_context = nil
271
+ @params = {
272
+ 'service_sid' => service_sid,
273
+ 'sid' => sid || @properties['sid'],
274
+ }
275
+ end
276
+
277
+ ##
278
+ # Generate an instance context for the instance, the context is capable of
279
+ # performing various actions. All instance actions are proxied to the context
280
+ # @return [PhoneNumberContext] PhoneNumberContext for this PhoneNumberInstance
281
+ def context
282
+ unless @instance_context
283
+ @instance_context = PhoneNumberContext.new(
284
+ @version,
285
+ @params['service_sid'],
286
+ @params['sid'],
287
+ )
288
+ end
289
+ @instance_context
290
+ end
291
+
292
+ ##
293
+ # @return [String] A string that uniquely identifies this Phone Number.
294
+ def sid
295
+ @properties['sid']
296
+ end
297
+
298
+ ##
299
+ # @return [String] Account Sid.
300
+ def account_sid
301
+ @properties['account_sid']
302
+ end
303
+
304
+ ##
305
+ # @return [String] Service Sid.
306
+ def service_sid
307
+ @properties['service_sid']
308
+ end
309
+
310
+ ##
311
+ # @return [Time] The date this Phone Number was created
312
+ def date_created
313
+ @properties['date_created']
314
+ end
315
+
316
+ ##
317
+ # @return [Time] The date this Phone Number was updated
318
+ def date_updated
319
+ @properties['date_updated']
320
+ end
321
+
322
+ ##
323
+ # @return [String] The phone number.
324
+ def phone_number
325
+ @properties['phone_number']
326
+ end
327
+
328
+ ##
329
+ # @return [String] A human readable description of this resource.
330
+ def friendly_name
331
+ @properties['friendly_name']
332
+ end
333
+
334
+ ##
335
+ # @return [String] ISO Country Code,
336
+ def iso_country
337
+ @properties['iso_country']
338
+ end
339
+
340
+ ##
341
+ # @return [String] A list of capabilities.
342
+ def capabilities
343
+ @properties['capabilities']
344
+ end
345
+
346
+ ##
347
+ # @return [String] The URL of this resource.
348
+ def url
349
+ @properties['url']
350
+ end
351
+
352
+ ##
353
+ # Deletes the PhoneNumberInstance
354
+ # @return [Boolean] true if delete succeeds, true otherwise
355
+ def delete
356
+ context.delete
357
+ end
358
+
359
+ ##
360
+ # Fetch a PhoneNumberInstance
361
+ # @return [PhoneNumberInstance] Fetched PhoneNumberInstance
362
+ def fetch
363
+ context.fetch
364
+ end
365
+
366
+ ##
367
+ # Provide a user friendly representation
368
+ def to_s
369
+ values = @params.map{|k, v| "#{k}: #{v}"}.join(" ")
370
+ "<Twilio.Proxy.V1.PhoneNumberInstance #{values}>"
371
+ end
372
+
373
+ ##
374
+ # Provide a detailed, user friendly representation
375
+ def inspect
376
+ values = @properties.map{|k, v| "#{k}: #{v}"}.join(" ")
377
+ "<Twilio.Proxy.V1.PhoneNumberInstance #{values}>"
378
+ end
379
+ end
380
+ end
381
+ end
382
+ end
383
+ end
384
+ end