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,456 @@
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 InteractionList < ListResource
16
+ ##
17
+ # Initialize the InteractionList
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 [InteractionList] InteractionList
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]}/Interactions"
31
+ end
32
+
33
+ ##
34
+ # Lists InteractionInstance 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 [interaction.ResourceStatus] inbound_participant_status The Inbound
38
+ # Participant Status of this Interaction. One of `accepted`, `answered`, `busy`,
39
+ # `canceled`, `completed`, `deleted`, `delivered`, `delivery-unknown`, `failed`,
40
+ # `in-progress`, `initiated`, `no-answer`, `queued`, `received`, `receiving`,
41
+ # `ringing`, `scheduled`, `sending`, `sent`, `undelivered` or `unknown`.
42
+ # @param [interaction.ResourceStatus] outbound_participant_status The Outbound
43
+ # Participant Status of this Interaction. One of `accepted`, `answered`, `busy`,
44
+ # `canceled`, `completed`, `deleted`, `delivered`, `delivery-unknown`, `failed`,
45
+ # `in-progress`, `initiated`, `no-answer`, `queued`, `received`, `receiving`,
46
+ # `ringing`, `scheduled`, `sending`, `sent`, `undelivered` or `unknown`.
47
+ # @param [Integer] limit Upper limit for the number of records to return. stream()
48
+ # guarantees to never return more than limit. Default is no limit
49
+ # @param [Integer] page_size Number of records to fetch per request, when
50
+ # not set will use the default value of 50 records. If no page_size is defined
51
+ # but a limit is defined, stream() will attempt to read the limit with the most
52
+ # efficient page size, i.e. min(limit, 1000)
53
+ # @return [Array] Array of up to limit results
54
+ def list(inbound_participant_status: :unset, outbound_participant_status: :unset, limit: nil, page_size: nil)
55
+ self.stream(
56
+ inbound_participant_status: inbound_participant_status,
57
+ outbound_participant_status: outbound_participant_status,
58
+ limit: limit,
59
+ page_size: page_size
60
+ ).entries
61
+ end
62
+
63
+ ##
64
+ # Streams InteractionInstance records from the API as an Enumerable.
65
+ # This operation lazily loads records as efficiently as possible until the limit
66
+ # is reached.
67
+ # @param [interaction.ResourceStatus] inbound_participant_status The Inbound
68
+ # Participant Status of this Interaction. One of `accepted`, `answered`, `busy`,
69
+ # `canceled`, `completed`, `deleted`, `delivered`, `delivery-unknown`, `failed`,
70
+ # `in-progress`, `initiated`, `no-answer`, `queued`, `received`, `receiving`,
71
+ # `ringing`, `scheduled`, `sending`, `sent`, `undelivered` or `unknown`.
72
+ # @param [interaction.ResourceStatus] outbound_participant_status The Outbound
73
+ # Participant Status of this Interaction. One of `accepted`, `answered`, `busy`,
74
+ # `canceled`, `completed`, `deleted`, `delivered`, `delivery-unknown`, `failed`,
75
+ # `in-progress`, `initiated`, `no-answer`, `queued`, `received`, `receiving`,
76
+ # `ringing`, `scheduled`, `sending`, `sent`, `undelivered` or `unknown`.
77
+ # @param [Integer] limit Upper limit for the number of records to return. stream()
78
+ # guarantees to never return more than limit. Default is no limit.
79
+ # @param [Integer] page_size Number of records to fetch per request, when
80
+ # not set will use the default value of 50 records. If no page_size is defined
81
+ # but a limit is defined, stream() will attempt to read the limit with the most
82
+ # efficient page size, i.e. min(limit, 1000)
83
+ # @return [Enumerable] Enumerable that will yield up to limit results
84
+ def stream(inbound_participant_status: :unset, outbound_participant_status: :unset, limit: nil, page_size: nil)
85
+ limits = @version.read_limits(limit, page_size)
86
+
87
+ page = self.page(
88
+ inbound_participant_status: inbound_participant_status,
89
+ outbound_participant_status: outbound_participant_status,
90
+ page_size: limits[:page_size],
91
+ )
92
+
93
+ @version.stream(page, limit: limits[:limit], page_limit: limits[:page_limit])
94
+ end
95
+
96
+ ##
97
+ # When passed a block, yields InteractionInstance records from the API.
98
+ # This operation lazily loads records as efficiently as possible until the limit
99
+ # is reached.
100
+ def each
101
+ limits = @version.read_limits
102
+
103
+ page = self.page(
104
+ page_size: limits[:page_size],
105
+ )
106
+
107
+ @version.stream(page,
108
+ limit: limits[:limit],
109
+ page_limit: limits[:page_limit]).each {|x| yield x}
110
+ end
111
+
112
+ ##
113
+ # Retrieve a single page of InteractionInstance records from the API.
114
+ # Request is executed immediately.
115
+ # @param [interaction.ResourceStatus] inbound_participant_status The Inbound
116
+ # Participant Status of this Interaction. One of `accepted`, `answered`, `busy`,
117
+ # `canceled`, `completed`, `deleted`, `delivered`, `delivery-unknown`, `failed`,
118
+ # `in-progress`, `initiated`, `no-answer`, `queued`, `received`, `receiving`,
119
+ # `ringing`, `scheduled`, `sending`, `sent`, `undelivered` or `unknown`.
120
+ # @param [interaction.ResourceStatus] outbound_participant_status The Outbound
121
+ # Participant Status of this Interaction. One of `accepted`, `answered`, `busy`,
122
+ # `canceled`, `completed`, `deleted`, `delivered`, `delivery-unknown`, `failed`,
123
+ # `in-progress`, `initiated`, `no-answer`, `queued`, `received`, `receiving`,
124
+ # `ringing`, `scheduled`, `sending`, `sent`, `undelivered` or `unknown`.
125
+ # @param [String] page_token PageToken provided by the API
126
+ # @param [Integer] page_number Page Number, this value is simply for client state
127
+ # @param [Integer] page_size Number of records to return, defaults to 50
128
+ # @return [Page] Page of InteractionInstance
129
+ def page(inbound_participant_status: :unset, outbound_participant_status: :unset, page_token: :unset, page_number: :unset, page_size: :unset)
130
+ params = Twilio::Values.of({
131
+ 'InboundParticipantStatus' => inbound_participant_status,
132
+ 'OutboundParticipantStatus' => outbound_participant_status,
133
+ 'PageToken' => page_token,
134
+ 'Page' => page_number,
135
+ 'PageSize' => page_size,
136
+ })
137
+ response = @version.page(
138
+ 'GET',
139
+ @uri,
140
+ params
141
+ )
142
+ InteractionPage.new(@version, response, @solution)
143
+ end
144
+
145
+ ##
146
+ # Retrieve a single page of InteractionInstance records from the API.
147
+ # Request is executed immediately.
148
+ # @param [String] target_url API-generated URL for the requested results page
149
+ # @return [Page] Page of InteractionInstance
150
+ def get_page(target_url)
151
+ response = @version.domain.request(
152
+ 'GET',
153
+ target_url
154
+ )
155
+ InteractionPage.new(@version, response, @solution)
156
+ end
157
+
158
+ ##
159
+ # Provide a user friendly representation
160
+ def to_s
161
+ '#<Twilio.Proxy.V1.InteractionList>'
162
+ end
163
+ end
164
+
165
+ ##
166
+ # PLEASE NOTE that this class contains beta products that are subject to change. Use them with caution.
167
+ class InteractionPage < Page
168
+ ##
169
+ # Initialize the InteractionPage
170
+ # @param [Version] version Version that contains the resource
171
+ # @param [Response] response Response from the API
172
+ # @param [Hash] solution Path solution for the resource
173
+ # @return [InteractionPage] InteractionPage
174
+ def initialize(version, response, solution)
175
+ super(version, response)
176
+
177
+ # Path Solution
178
+ @solution = solution
179
+ end
180
+
181
+ ##
182
+ # Build an instance of InteractionInstance
183
+ # @param [Hash] payload Payload response from the API
184
+ # @return [InteractionInstance] InteractionInstance
185
+ def get_instance(payload)
186
+ InteractionInstance.new(
187
+ @version,
188
+ payload,
189
+ service_sid: @solution[:service_sid],
190
+ session_sid: @solution[:session_sid],
191
+ )
192
+ end
193
+
194
+ ##
195
+ # Provide a user friendly representation
196
+ def to_s
197
+ '<Twilio.Proxy.V1.InteractionPage>'
198
+ end
199
+ end
200
+
201
+ ##
202
+ # PLEASE NOTE that this class contains beta products that are subject to change. Use them with caution.
203
+ class InteractionContext < InstanceContext
204
+ ##
205
+ # Initialize the InteractionContext
206
+ # @param [Version] version Version that contains the resource
207
+ # @param [String] service_sid The unique SID identifier of the Service.
208
+ # @param [String] session_sid The unique SID identifier of the Session.
209
+ # @param [String] sid A 34 character string that uniquely identifies this
210
+ # Interaction.
211
+ # @return [InteractionContext] InteractionContext
212
+ def initialize(version, service_sid, session_sid, sid)
213
+ super(version)
214
+
215
+ # Path Solution
216
+ @solution = {
217
+ service_sid: service_sid,
218
+ session_sid: session_sid,
219
+ sid: sid,
220
+ }
221
+ @uri = "/Services/#{@solution[:service_sid]}/Sessions/#{@solution[:session_sid]}/Interactions/#{@solution[:sid]}"
222
+ end
223
+
224
+ ##
225
+ # Fetch a InteractionInstance
226
+ # @return [InteractionInstance] Fetched InteractionInstance
227
+ def fetch
228
+ params = Twilio::Values.of({})
229
+
230
+ payload = @version.fetch(
231
+ 'GET',
232
+ @uri,
233
+ params,
234
+ )
235
+
236
+ InteractionInstance.new(
237
+ @version,
238
+ payload,
239
+ service_sid: @solution[:service_sid],
240
+ session_sid: @solution[:session_sid],
241
+ sid: @solution[:sid],
242
+ )
243
+ end
244
+
245
+ ##
246
+ # Provide a user friendly representation
247
+ def to_s
248
+ context = @solution.map {|k, v| "#{k}: #{v}"}.join(',')
249
+ "#<Twilio.Proxy.V1.InteractionContext #{context}>"
250
+ end
251
+ end
252
+
253
+ ##
254
+ # PLEASE NOTE that this class contains beta products that are subject to change. Use them with caution.
255
+ class InteractionInstance < InstanceResource
256
+ ##
257
+ # Initialize the InteractionInstance
258
+ # @param [Version] version Version that contains the resource
259
+ # @param [Hash] payload payload that contains response from Twilio
260
+ # @param [String] service_sid The unique SID identifier of the Service.
261
+ # @param [String] session_sid The unique SID identifier of the Session.
262
+ # @param [String] sid A 34 character string that uniquely identifies this
263
+ # Interaction.
264
+ # @return [InteractionInstance] InteractionInstance
265
+ def initialize(version, payload, service_sid: nil, session_sid: nil, sid: nil)
266
+ super(version)
267
+
268
+ # Marshaled Properties
269
+ @properties = {
270
+ 'sid' => payload['sid'],
271
+ 'session_sid' => payload['session_sid'],
272
+ 'service_sid' => payload['service_sid'],
273
+ 'account_sid' => payload['account_sid'],
274
+ 'data' => payload['data'],
275
+ 'type' => payload['type'],
276
+ 'inbound_participant_sid' => payload['inbound_participant_sid'],
277
+ 'inbound_resource_sid' => payload['inbound_resource_sid'],
278
+ 'inbound_resource_status' => payload['inbound_resource_status'],
279
+ 'inbound_resource_type' => payload['inbound_resource_type'],
280
+ 'inbound_resource_url' => payload['inbound_resource_url'],
281
+ 'outbound_participant_sid' => payload['outbound_participant_sid'],
282
+ 'outbound_resource_sid' => payload['outbound_resource_sid'],
283
+ 'outbound_resource_status' => payload['outbound_resource_status'],
284
+ 'outbound_resource_type' => payload['outbound_resource_type'],
285
+ 'outbound_resource_url' => payload['outbound_resource_url'],
286
+ 'date_created' => Twilio.deserialize_iso8601_datetime(payload['date_created']),
287
+ 'date_updated' => Twilio.deserialize_iso8601_datetime(payload['date_updated']),
288
+ 'url' => payload['url'],
289
+ }
290
+
291
+ # Context
292
+ @instance_context = nil
293
+ @params = {
294
+ 'service_sid' => service_sid,
295
+ 'session_sid' => session_sid,
296
+ 'sid' => sid || @properties['sid'],
297
+ }
298
+ end
299
+
300
+ ##
301
+ # Generate an instance context for the instance, the context is capable of
302
+ # performing various actions. All instance actions are proxied to the context
303
+ # @return [InteractionContext] InteractionContext for this InteractionInstance
304
+ def context
305
+ unless @instance_context
306
+ @instance_context = InteractionContext.new(
307
+ @version,
308
+ @params['service_sid'],
309
+ @params['session_sid'],
310
+ @params['sid'],
311
+ )
312
+ end
313
+ @instance_context
314
+ end
315
+
316
+ ##
317
+ # @return [String] A string that uniquely identifies this Interaction.
318
+ def sid
319
+ @properties['sid']
320
+ end
321
+
322
+ ##
323
+ # @return [String] Session Sid.
324
+ def session_sid
325
+ @properties['session_sid']
326
+ end
327
+
328
+ ##
329
+ # @return [String] Service Sid.
330
+ def service_sid
331
+ @properties['service_sid']
332
+ end
333
+
334
+ ##
335
+ # @return [String] Account Sid.
336
+ def account_sid
337
+ @properties['account_sid']
338
+ end
339
+
340
+ ##
341
+ # @return [String] Further details about an interaction.
342
+ def data
343
+ @properties['data']
344
+ end
345
+
346
+ ##
347
+ # @return [interaction.Type] The Type of this Interaction
348
+ def type
349
+ @properties['type']
350
+ end
351
+
352
+ ##
353
+ # @return [String] Inbound Participant Sid.
354
+ def inbound_participant_sid
355
+ @properties['inbound_participant_sid']
356
+ end
357
+
358
+ ##
359
+ # @return [String] Inbound Resource Sid.
360
+ def inbound_resource_sid
361
+ @properties['inbound_resource_sid']
362
+ end
363
+
364
+ ##
365
+ # @return [interaction.ResourceStatus] The Inbound Resource Status of this Interaction
366
+ def inbound_resource_status
367
+ @properties['inbound_resource_status']
368
+ end
369
+
370
+ ##
371
+ # @return [String] The type of the Inbound Resource, Call or Message.
372
+ def inbound_resource_type
373
+ @properties['inbound_resource_type']
374
+ end
375
+
376
+ ##
377
+ # @return [String] The URL of the Twilio resource.
378
+ def inbound_resource_url
379
+ @properties['inbound_resource_url']
380
+ end
381
+
382
+ ##
383
+ # @return [String] Outbound Participant Sid.
384
+ def outbound_participant_sid
385
+ @properties['outbound_participant_sid']
386
+ end
387
+
388
+ ##
389
+ # @return [String] Outbound Resource Sid.
390
+ def outbound_resource_sid
391
+ @properties['outbound_resource_sid']
392
+ end
393
+
394
+ ##
395
+ # @return [interaction.ResourceStatus] The Outbound Resource Status of this Interaction
396
+ def outbound_resource_status
397
+ @properties['outbound_resource_status']
398
+ end
399
+
400
+ ##
401
+ # @return [String] The type of the Outbound Resource, Call or Message.
402
+ def outbound_resource_type
403
+ @properties['outbound_resource_type']
404
+ end
405
+
406
+ ##
407
+ # @return [String] The URL of the Twilio resource.
408
+ def outbound_resource_url
409
+ @properties['outbound_resource_url']
410
+ end
411
+
412
+ ##
413
+ # @return [Time] The date this Interaction was created
414
+ def date_created
415
+ @properties['date_created']
416
+ end
417
+
418
+ ##
419
+ # @return [Time] The date this Interaction was updated
420
+ def date_updated
421
+ @properties['date_updated']
422
+ end
423
+
424
+ ##
425
+ # @return [String] The URL of this resource.
426
+ def url
427
+ @properties['url']
428
+ end
429
+
430
+ ##
431
+ # Fetch a InteractionInstance
432
+ # @return [InteractionInstance] Fetched InteractionInstance
433
+ def fetch
434
+ context.fetch
435
+ end
436
+
437
+ ##
438
+ # Provide a user friendly representation
439
+ def to_s
440
+ values = @params.map{|k, v| "#{k}: #{v}"}.join(" ")
441
+ "<Twilio.Proxy.V1.InteractionInstance #{values}>"
442
+ end
443
+
444
+ ##
445
+ # Provide a detailed, user friendly representation
446
+ def inspect
447
+ values = @properties.map{|k, v| "#{k}: #{v}"}.join(" ")
448
+ "<Twilio.Proxy.V1.InteractionInstance #{values}>"
449
+ end
450
+ end
451
+ end
452
+ end
453
+ end
454
+ end
455
+ end
456
+ end