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