twilio-ruby 5.3.1 → 5.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.
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
@@ -0,0 +1,541 @@
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
+ class SessionContext < InstanceContext
13
+ ##
14
+ # PLEASE NOTE that this class contains beta products that are subject to change. Use them with caution.
15
+ class ParticipantList < ListResource
16
+ ##
17
+ # Initialize the ParticipantList
18
+ # @param [Version] version Version that contains the resource
19
+ # @param [String] service_sid The unique SID identifier of the Service.
20
+ # @param [String] session_sid The unique SID identifier of the Session.
21
+ # @return [ParticipantList] ParticipantList
22
+ def initialize(version, service_sid: nil, session_sid: nil)
23
+ super(version)
24
+
25
+ # Path Solution
26
+ @solution = {
27
+ service_sid: service_sid,
28
+ session_sid: session_sid
29
+ }
30
+ @uri = "/Services/#{@solution[:service_sid]}/Sessions/#{@solution[:session_sid]}/Participants"
31
+ end
32
+
33
+ ##
34
+ # Lists ParticipantInstance records from the API as a list.
35
+ # Unlike stream(), this operation is eager and will load `limit` records into
36
+ # memory before returning.
37
+ # @param [participant.ParticipantType] participant_type The participant_type
38
+ # @param [String] identifier The identifier
39
+ # @param [Integer] limit Upper limit for the number of records to return. stream()
40
+ # guarantees to never return more than limit. Default is no limit
41
+ # @param [Integer] page_size Number of records to fetch per request, when
42
+ # not set will use the default value of 50 records. If no page_size is defined
43
+ # but a limit is defined, stream() will attempt to read the limit with the most
44
+ # efficient page size, i.e. min(limit, 1000)
45
+ # @return [Array] Array of up to limit results
46
+ def list(participant_type: :unset, identifier: :unset, limit: nil, page_size: nil)
47
+ self.stream(
48
+ participant_type: participant_type,
49
+ identifier: identifier,
50
+ limit: limit,
51
+ page_size: page_size
52
+ ).entries
53
+ end
54
+
55
+ ##
56
+ # Streams ParticipantInstance records from the API as an Enumerable.
57
+ # This operation lazily loads records as efficiently as possible until the limit
58
+ # is reached.
59
+ # @param [participant.ParticipantType] participant_type The participant_type
60
+ # @param [String] identifier The identifier
61
+ # @param [Integer] limit Upper limit for the number of records to return. stream()
62
+ # guarantees to never return more than limit. Default is no limit.
63
+ # @param [Integer] page_size Number of records to fetch per request, when
64
+ # not set will use the default value of 50 records. If no page_size is defined
65
+ # but a limit is defined, stream() will attempt to read the limit with the most
66
+ # efficient page size, i.e. min(limit, 1000)
67
+ # @return [Enumerable] Enumerable that will yield up to limit results
68
+ def stream(participant_type: :unset, identifier: :unset, limit: nil, page_size: nil)
69
+ limits = @version.read_limits(limit, page_size)
70
+
71
+ page = self.page(
72
+ participant_type: participant_type,
73
+ identifier: identifier,
74
+ page_size: limits[:page_size],
75
+ )
76
+
77
+ @version.stream(page, limit: limits[:limit], page_limit: limits[:page_limit])
78
+ end
79
+
80
+ ##
81
+ # When passed a block, yields ParticipantInstance records from the API.
82
+ # This operation lazily loads records as efficiently as possible until the limit
83
+ # is reached.
84
+ def each
85
+ limits = @version.read_limits
86
+
87
+ page = self.page(
88
+ page_size: limits[:page_size],
89
+ )
90
+
91
+ @version.stream(page,
92
+ limit: limits[:limit],
93
+ page_limit: limits[:page_limit]).each {|x| yield x}
94
+ end
95
+
96
+ ##
97
+ # Retrieve a single page of ParticipantInstance records from the API.
98
+ # Request is executed immediately.
99
+ # @param [participant.ParticipantType] participant_type The participant_type
100
+ # @param [String] identifier The identifier
101
+ # @param [String] page_token PageToken provided by the API
102
+ # @param [Integer] page_number Page Number, this value is simply for client state
103
+ # @param [Integer] page_size Number of records to return, defaults to 50
104
+ # @return [Page] Page of ParticipantInstance
105
+ def page(participant_type: :unset, identifier: :unset, page_token: :unset, page_number: :unset, page_size: :unset)
106
+ params = Twilio::Values.of({
107
+ 'ParticipantType' => participant_type,
108
+ 'Identifier' => identifier,
109
+ 'PageToken' => page_token,
110
+ 'Page' => page_number,
111
+ 'PageSize' => page_size,
112
+ })
113
+ response = @version.page(
114
+ 'GET',
115
+ @uri,
116
+ params
117
+ )
118
+ ParticipantPage.new(@version, response, @solution)
119
+ end
120
+
121
+ ##
122
+ # Retrieve a single page of ParticipantInstance records from the API.
123
+ # Request is executed immediately.
124
+ # @param [String] target_url API-generated URL for the requested results page
125
+ # @return [Page] Page of ParticipantInstance
126
+ def get_page(target_url)
127
+ response = @version.domain.request(
128
+ 'GET',
129
+ target_url
130
+ )
131
+ ParticipantPage.new(@version, response, @solution)
132
+ end
133
+
134
+ ##
135
+ # Retrieve a single page of ParticipantInstance records from the API.
136
+ # Request is executed immediately.
137
+ # @param [String] identifier The phone number of this Participant.
138
+ # @param [String] friendly_name A human readable description of this resource, up
139
+ # to 64 characters.
140
+ # @param [participant.ParticipantType] participant_type The Participant Type of
141
+ # this Participant. One of `message-only`, `voice-only` or `voice-and-message`.
142
+ # @param [String] proxy_identifier The proxy phone number for this Participant.
143
+ # @param [String] proxy_identifier_sid The unique SID identifier of the Proxy
144
+ # Identifier.
145
+ # @return [ParticipantInstance] Newly created ParticipantInstance
146
+ def create(identifier: nil, friendly_name: :unset, participant_type: :unset, proxy_identifier: :unset, proxy_identifier_sid: :unset)
147
+ data = Twilio::Values.of({
148
+ 'Identifier' => identifier,
149
+ 'FriendlyName' => friendly_name,
150
+ 'ParticipantType' => participant_type,
151
+ 'ProxyIdentifier' => proxy_identifier,
152
+ 'ProxyIdentifierSid' => proxy_identifier_sid,
153
+ })
154
+
155
+ payload = @version.create(
156
+ 'POST',
157
+ @uri,
158
+ data: data
159
+ )
160
+
161
+ ParticipantInstance.new(
162
+ @version,
163
+ payload,
164
+ service_sid: @solution[:service_sid],
165
+ session_sid: @solution[:session_sid],
166
+ )
167
+ end
168
+
169
+ ##
170
+ # Provide a user friendly representation
171
+ def to_s
172
+ '#<Twilio.Proxy.V1.ParticipantList>'
173
+ end
174
+ end
175
+
176
+ ##
177
+ # PLEASE NOTE that this class contains beta products that are subject to change. Use them with caution.
178
+ class ParticipantPage < Page
179
+ ##
180
+ # Initialize the ParticipantPage
181
+ # @param [Version] version Version that contains the resource
182
+ # @param [Response] response Response from the API
183
+ # @param [Hash] solution Path solution for the resource
184
+ # @return [ParticipantPage] ParticipantPage
185
+ def initialize(version, response, solution)
186
+ super(version, response)
187
+
188
+ # Path Solution
189
+ @solution = solution
190
+ end
191
+
192
+ ##
193
+ # Build an instance of ParticipantInstance
194
+ # @param [Hash] payload Payload response from the API
195
+ # @return [ParticipantInstance] ParticipantInstance
196
+ def get_instance(payload)
197
+ ParticipantInstance.new(
198
+ @version,
199
+ payload,
200
+ service_sid: @solution[:service_sid],
201
+ session_sid: @solution[:session_sid],
202
+ )
203
+ end
204
+
205
+ ##
206
+ # Provide a user friendly representation
207
+ def to_s
208
+ '<Twilio.Proxy.V1.ParticipantPage>'
209
+ end
210
+ end
211
+
212
+ ##
213
+ # PLEASE NOTE that this class contains beta products that are subject to change. Use them with caution.
214
+ class ParticipantContext < InstanceContext
215
+ ##
216
+ # Initialize the ParticipantContext
217
+ # @param [Version] version Version that contains the resource
218
+ # @param [String] service_sid The unique SID identifier of the Service.
219
+ # @param [String] session_sid The unique SID identifier of the Session.
220
+ # @param [String] sid A 34 character string that uniquely identifies this
221
+ # Participant.
222
+ # @return [ParticipantContext] ParticipantContext
223
+ def initialize(version, service_sid, session_sid, sid)
224
+ super(version)
225
+
226
+ # Path Solution
227
+ @solution = {
228
+ service_sid: service_sid,
229
+ session_sid: session_sid,
230
+ sid: sid,
231
+ }
232
+ @uri = "/Services/#{@solution[:service_sid]}/Sessions/#{@solution[:session_sid]}/Participants/#{@solution[:sid]}"
233
+
234
+ # Dependents
235
+ @message_interactions = nil
236
+ end
237
+
238
+ ##
239
+ # Fetch a ParticipantInstance
240
+ # @return [ParticipantInstance] Fetched ParticipantInstance
241
+ def fetch
242
+ params = Twilio::Values.of({})
243
+
244
+ payload = @version.fetch(
245
+ 'GET',
246
+ @uri,
247
+ params,
248
+ )
249
+
250
+ ParticipantInstance.new(
251
+ @version,
252
+ payload,
253
+ service_sid: @solution[:service_sid],
254
+ session_sid: @solution[:session_sid],
255
+ sid: @solution[:sid],
256
+ )
257
+ end
258
+
259
+ ##
260
+ # Deletes the ParticipantInstance
261
+ # @return [Boolean] true if delete succeeds, true otherwise
262
+ def delete
263
+ @version.delete('delete', @uri)
264
+ end
265
+
266
+ ##
267
+ # Update the ParticipantInstance
268
+ # @param [participant.ParticipantType] participant_type The Participant Type of
269
+ # this Participant. One of `message-only`, `voice-only` or `voice-and-message`.
270
+ # @param [String] identifier The phone number of this Participant.
271
+ # @param [String] friendly_name A human readable description of this resource, up
272
+ # to 64 characters.
273
+ # @param [String] proxy_identifier The proxy phone number for this Participant.
274
+ # @param [String] proxy_identifier_sid The unique SID identifier of the Proxy
275
+ # Identifier.
276
+ # @return [ParticipantInstance] Updated ParticipantInstance
277
+ def update(participant_type: :unset, identifier: :unset, friendly_name: :unset, proxy_identifier: :unset, proxy_identifier_sid: :unset)
278
+ data = Twilio::Values.of({
279
+ 'ParticipantType' => participant_type,
280
+ 'Identifier' => identifier,
281
+ 'FriendlyName' => friendly_name,
282
+ 'ProxyIdentifier' => proxy_identifier,
283
+ 'ProxyIdentifierSid' => proxy_identifier_sid,
284
+ })
285
+
286
+ payload = @version.update(
287
+ 'POST',
288
+ @uri,
289
+ data: data,
290
+ )
291
+
292
+ ParticipantInstance.new(
293
+ @version,
294
+ payload,
295
+ service_sid: @solution[:service_sid],
296
+ session_sid: @solution[:session_sid],
297
+ sid: @solution[:sid],
298
+ )
299
+ end
300
+
301
+ ##
302
+ # Access the message_interactions
303
+ # @return [MessageInteractionList]
304
+ # @return [MessageInteractionContext] if sid was passed.
305
+ def message_interactions(sid=:unset)
306
+ raise ArgumentError, 'sid cannot be nil' if sid.nil?
307
+
308
+ if sid != :unset
309
+ return MessageInteractionContext.new(
310
+ @version,
311
+ @solution[:service_sid],
312
+ @solution[:session_sid],
313
+ @solution[:sid],
314
+ sid,
315
+ )
316
+ end
317
+
318
+ unless @message_interactions
319
+ @message_interactions = MessageInteractionList.new(
320
+ @version,
321
+ service_sid: @solution[:service_sid],
322
+ session_sid: @solution[:session_sid],
323
+ participant_sid: @solution[:sid],
324
+ )
325
+ end
326
+
327
+ @message_interactions
328
+ end
329
+
330
+ ##
331
+ # Provide a user friendly representation
332
+ def to_s
333
+ context = @solution.map {|k, v| "#{k}: #{v}"}.join(',')
334
+ "#<Twilio.Proxy.V1.ParticipantContext #{context}>"
335
+ end
336
+ end
337
+
338
+ ##
339
+ # PLEASE NOTE that this class contains beta products that are subject to change. Use them with caution.
340
+ class ParticipantInstance < InstanceResource
341
+ ##
342
+ # Initialize the ParticipantInstance
343
+ # @param [Version] version Version that contains the resource
344
+ # @param [Hash] payload payload that contains response from Twilio
345
+ # @param [String] service_sid The unique SID identifier of the Service.
346
+ # @param [String] session_sid The unique SID identifier of the Session.
347
+ # @param [String] sid A 34 character string that uniquely identifies this
348
+ # Participant.
349
+ # @return [ParticipantInstance] ParticipantInstance
350
+ def initialize(version, payload, service_sid: nil, session_sid: nil, sid: nil)
351
+ super(version)
352
+
353
+ # Marshaled Properties
354
+ @properties = {
355
+ 'sid' => payload['sid'],
356
+ 'session_sid' => payload['session_sid'],
357
+ 'service_sid' => payload['service_sid'],
358
+ 'account_sid' => payload['account_sid'],
359
+ 'friendly_name' => payload['friendly_name'],
360
+ 'participant_type' => payload['participant_type'],
361
+ 'identifier' => payload['identifier'],
362
+ 'proxy_identifier' => payload['proxy_identifier'],
363
+ 'proxy_identifier_sid' => payload['proxy_identifier_sid'],
364
+ 'date_deleted' => Twilio.deserialize_iso8601_datetime(payload['date_deleted']),
365
+ 'date_created' => Twilio.deserialize_iso8601_datetime(payload['date_created']),
366
+ 'date_updated' => Twilio.deserialize_iso8601_datetime(payload['date_updated']),
367
+ 'url' => payload['url'],
368
+ 'links' => payload['links'],
369
+ }
370
+
371
+ # Context
372
+ @instance_context = nil
373
+ @params = {
374
+ 'service_sid' => service_sid,
375
+ 'session_sid' => session_sid,
376
+ 'sid' => sid || @properties['sid'],
377
+ }
378
+ end
379
+
380
+ ##
381
+ # Generate an instance context for the instance, the context is capable of
382
+ # performing various actions. All instance actions are proxied to the context
383
+ # @return [ParticipantContext] ParticipantContext for this ParticipantInstance
384
+ def context
385
+ unless @instance_context
386
+ @instance_context = ParticipantContext.new(
387
+ @version,
388
+ @params['service_sid'],
389
+ @params['session_sid'],
390
+ @params['sid'],
391
+ )
392
+ end
393
+ @instance_context
394
+ end
395
+
396
+ ##
397
+ # @return [String] A string that uniquely identifies this Participant.
398
+ def sid
399
+ @properties['sid']
400
+ end
401
+
402
+ ##
403
+ # @return [String] Session Sid.
404
+ def session_sid
405
+ @properties['session_sid']
406
+ end
407
+
408
+ ##
409
+ # @return [String] Service Sid.
410
+ def service_sid
411
+ @properties['service_sid']
412
+ end
413
+
414
+ ##
415
+ # @return [String] Account Sid.
416
+ def account_sid
417
+ @properties['account_sid']
418
+ end
419
+
420
+ ##
421
+ # @return [String] A human readable description of this resource.
422
+ def friendly_name
423
+ @properties['friendly_name']
424
+ end
425
+
426
+ ##
427
+ # @return [participant.ParticipantType] The Participant Type of this Participant
428
+ def participant_type
429
+ @properties['participant_type']
430
+ end
431
+
432
+ ##
433
+ # @return [String] The phone number of this Participant.
434
+ def identifier
435
+ @properties['identifier']
436
+ end
437
+
438
+ ##
439
+ # @return [String] The proxy phone number for this Participant.
440
+ def proxy_identifier
441
+ @properties['proxy_identifier']
442
+ end
443
+
444
+ ##
445
+ # @return [String] Proxy Identifier Sid.
446
+ def proxy_identifier_sid
447
+ @properties['proxy_identifier_sid']
448
+ end
449
+
450
+ ##
451
+ # @return [Time] The date this Participant was deleted
452
+ def date_deleted
453
+ @properties['date_deleted']
454
+ end
455
+
456
+ ##
457
+ # @return [Time] The date this Participant was created
458
+ def date_created
459
+ @properties['date_created']
460
+ end
461
+
462
+ ##
463
+ # @return [Time] The date this Participant was updated
464
+ def date_updated
465
+ @properties['date_updated']
466
+ end
467
+
468
+ ##
469
+ # @return [String] The URL of this resource.
470
+ def url
471
+ @properties['url']
472
+ end
473
+
474
+ ##
475
+ # @return [String] Nested resource URLs.
476
+ def links
477
+ @properties['links']
478
+ end
479
+
480
+ ##
481
+ # Fetch a ParticipantInstance
482
+ # @return [ParticipantInstance] Fetched ParticipantInstance
483
+ def fetch
484
+ context.fetch
485
+ end
486
+
487
+ ##
488
+ # Deletes the ParticipantInstance
489
+ # @return [Boolean] true if delete succeeds, true otherwise
490
+ def delete
491
+ context.delete
492
+ end
493
+
494
+ ##
495
+ # Update the ParticipantInstance
496
+ # @param [participant.ParticipantType] participant_type The Participant Type of
497
+ # this Participant. One of `message-only`, `voice-only` or `voice-and-message`.
498
+ # @param [String] identifier The phone number of this Participant.
499
+ # @param [String] friendly_name A human readable description of this resource, up
500
+ # to 64 characters.
501
+ # @param [String] proxy_identifier The proxy phone number for this Participant.
502
+ # @param [String] proxy_identifier_sid The unique SID identifier of the Proxy
503
+ # Identifier.
504
+ # @return [ParticipantInstance] Updated ParticipantInstance
505
+ def update(participant_type: :unset, identifier: :unset, friendly_name: :unset, proxy_identifier: :unset, proxy_identifier_sid: :unset)
506
+ context.update(
507
+ participant_type: participant_type,
508
+ identifier: identifier,
509
+ friendly_name: friendly_name,
510
+ proxy_identifier: proxy_identifier,
511
+ proxy_identifier_sid: proxy_identifier_sid,
512
+ )
513
+ end
514
+
515
+ ##
516
+ # Access the message_interactions
517
+ # @return [message_interactions] message_interactions
518
+ def message_interactions
519
+ context.message_interactions
520
+ end
521
+
522
+ ##
523
+ # Provide a user friendly representation
524
+ def to_s
525
+ values = @params.map{|k, v| "#{k}: #{v}"}.join(" ")
526
+ "<Twilio.Proxy.V1.ParticipantInstance #{values}>"
527
+ end
528
+
529
+ ##
530
+ # Provide a detailed, user friendly representation
531
+ def inspect
532
+ values = @properties.map{|k, v| "#{k}: #{v}"}.join(" ")
533
+ "<Twilio.Proxy.V1.ParticipantInstance #{values}>"
534
+ end
535
+ end
536
+ end
537
+ end
538
+ end
539
+ end
540
+ end
541
+ end