twilio-ruby 7.12.0 → 7.13.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 (33) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGES.md +201 -0
  3. data/Gemfile.lock +2 -2
  4. data/README.md +2 -2
  5. data/examples/WebhookSignatureValidation.md +61 -0
  6. data/lib/rack/twilio_webhook_authentication.rb +30 -5
  7. data/lib/twilio-ruby/rest/api/v2010/account/call.rb +7 -0
  8. data/lib/twilio-ruby/rest/client.rb +5 -0
  9. data/lib/twilio-ruby/rest/content/v1/content/approval_create.rb +108 -1
  10. data/lib/twilio-ruby/rest/content/v1/content.rb +8 -2
  11. data/lib/twilio-ruby/rest/conversations/v2/configuration.rb +7 -0
  12. data/lib/twilio-ruby/rest/conversations/v2/conversation.rb +194 -7
  13. data/lib/twilio-ruby/rest/memory/v1/bulk.rb +22 -1
  14. data/lib/twilio-ruby/rest/memory/v1/import.rb +21 -7
  15. data/lib/twilio-ruby/rest/memory/v1/store.rb +7 -0
  16. data/lib/twilio-ruby/rest/trusthub/v1/a2p_brand_registration.rb +5 -5
  17. data/lib/twilio-ruby/rest/trusthub/v1/a2p_campaign_registration.rb +4 -4
  18. data/lib/twilio-ruby/rest/trusthub/v1.rb +2 -2
  19. data/lib/twilio-ruby/rest/webhooks/v1/auth_profile.rb +825 -0
  20. data/lib/twilio-ruby/rest/webhooks/v1/edge_zone.rb +320 -0
  21. data/lib/twilio-ruby/rest/webhooks/v1/operation.rb +513 -0
  22. data/lib/twilio-ruby/rest/webhooks/v1/rule.rb +818 -0
  23. data/lib/twilio-ruby/rest/webhooks/v1/setting.rb +1028 -0
  24. data/lib/twilio-ruby/rest/webhooks/v1/shared_key.rb +722 -0
  25. data/lib/twilio-ruby/rest/webhooks/v1/test.rb +228 -0
  26. data/lib/twilio-ruby/rest/webhooks/v1.rb +126 -0
  27. data/lib/twilio-ruby/rest/webhooks.rb +6 -0
  28. data/lib/twilio-ruby/rest/webhooks_base.rb +38 -0
  29. data/lib/twilio-ruby/security/request_validator.rb +54 -8
  30. data/lib/twilio-ruby/twiml/voice_response.rb +20 -5
  31. data/lib/twilio-ruby/version.rb +1 -1
  32. metadata +13 -3
  33. data/lib/twilio-ruby/rest/oauth/v2/oauth_authorization_server.rb +0 -200
@@ -0,0 +1,513 @@
1
+ ##
2
+ # This code was generated by
3
+ # ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __
4
+ # | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/
5
+ # | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \
6
+ #
7
+ # Twilio - Webhooks Configuration
8
+ # Centralized webhook configuration with OAuth2 support, immutable resources, and zero-downtime credential rotation.
9
+ #
10
+ # NOTE: This class is auto generated by OpenAPI Generator.
11
+ # https://openapi-generator.tech
12
+ # Do not edit the class manually.
13
+ #
14
+
15
+
16
+ module Twilio
17
+ module REST
18
+ class Webhooks < WebhooksBase
19
+ class V1 < Version
20
+ class OperationList < ListResource
21
+
22
+ ##
23
+ # Initialize the OperationList
24
+ # @param [Version] version Version that contains the resource
25
+ # @return [OperationList] OperationList
26
+ def initialize(version)
27
+
28
+ apiV1Version = ApiV1Version.new version.domain, version
29
+ super(apiV1Version)
30
+ # Path Solution
31
+ @solution = { }
32
+ @uri = "/Webhooks/Operations"
33
+
34
+ end
35
+
36
+ ##
37
+ # Lists OperationInstance records from the API as a list.
38
+ # Unlike stream(), this operation is eager and will load `limit` records into
39
+ # memory before returning.
40
+ # @param [String] page_token Token for pagination
41
+ # @param [String] status Filter by operation state
42
+ # @param [String] resource_id Filter operations affecting a specific resource ID
43
+ # @param [Integer] limit Upper limit for the number of records to return. stream()
44
+ # guarantees to never return more than limit. Default is no limit
45
+ # @param [Integer] page_size Number of records to fetch per request, when
46
+ # not set will use the default value of 50 records. If no page_size is defined
47
+ # but a limit is defined, stream() will attempt to read the limit with the most
48
+ # efficient page size, i.e. min(limit, 1000)
49
+ # @return [Array] Array of up to limit results
50
+ def list(page_token: :unset, status: :unset, resource_id: :unset, limit: nil, page_size: nil)
51
+ self.stream(
52
+ page_token: page_token,
53
+ status: status,
54
+ resource_id: resource_id,
55
+ limit: limit,
56
+ page_size: page_size
57
+ ).entries
58
+ end
59
+
60
+ ##
61
+ # Streams Instance records from the API as an Enumerable.
62
+ # This operation lazily loads records as efficiently as possible until the limit
63
+ # is reached.
64
+ # @param [String] page_token Token for pagination
65
+ # @param [String] status Filter by operation state
66
+ # @param [String] resource_id Filter operations affecting a specific resource ID
67
+ # @param [Integer] limit Upper limit for the number of records to return. stream()
68
+ # guarantees to never return more than limit. Default is no limit
69
+ # @param [Integer] page_size Number of records to fetch per request, when
70
+ # not set will use the default value of 50 records. If no page_size is defined
71
+ # but a limit is defined, stream() will attempt to read the limit with the most
72
+ # efficient page size, i.e. min(limit, 1000)
73
+ # @return [Enumerable] Enumerable that will yield up to limit results
74
+ def stream(page_token: :unset, status: :unset, resource_id: :unset, limit: nil, page_size: nil)
75
+ limits = @version.read_limits(limit, page_size)
76
+
77
+ page = self.page(
78
+ page_token: page_token,
79
+ status: status,
80
+ resource_id: resource_id,
81
+ page_size: limits[:page_size], )
82
+
83
+ return [].each if page.nil?
84
+
85
+ result = @version.stream(page, limit: limits[:limit], page_limit: limits[:page_limit])
86
+ return [].each if result.nil?
87
+ result
88
+ end
89
+
90
+ ##
91
+ # Lists OperationPageMetadata records from the API as a list.
92
+ # @param [String] page_token Token for pagination
93
+ # @param [String] status Filter by operation state
94
+ # @param [String] resource_id Filter operations affecting a specific resource ID
95
+ # @param [Integer] limit Upper limit for the number of records to return. stream()
96
+ # guarantees to never return more than limit. Default is no limit
97
+ # @param [Integer] page_size Number of records to fetch per request, when
98
+ # not set will use the default value of 50 records. If no page_size is defined
99
+ # but a limit is defined, stream() will attempt to read the limit with the most
100
+ # efficient page size, i.e. min(limit, 1000)
101
+ # @return [Array] Array of up to limit results
102
+ def list_with_metadata(page_token: :unset, status: :unset, resource_id: :unset, limit: nil, page_size: nil)
103
+ limits = @version.read_limits(limit, page_size)
104
+ params = Twilio::Values.of({
105
+ 'pageToken' => page_token,
106
+ 'status' => status,
107
+ 'resourceId' => resource_id,
108
+
109
+ 'PageSize' => limits[:page_size],
110
+ });
111
+ headers = Twilio::Values.of({})
112
+
113
+ response = @version.page('GET', @uri, params: params, headers: headers)
114
+
115
+ OperationPageMetadata.new(@version, response, @solution, limits[:limit])
116
+ end
117
+
118
+ ##
119
+ # When passed a block, yields OperationInstance records from the API.
120
+ # This operation lazily loads records as efficiently as possible until the limit
121
+ # is reached.
122
+ def each
123
+ limits = @version.read_limits
124
+
125
+ page = self.page(page_size: limits[:page_size], )
126
+
127
+ return [].each if page.nil?
128
+
129
+ result = @version.stream(page,
130
+ limit: limits[:limit],
131
+ page_limit: limits[:page_limit])
132
+ return [].each if result.nil?
133
+ result.each {|x| yield x}
134
+ end
135
+
136
+ ##
137
+ # Retrieve a single page of OperationInstance records from the API.
138
+ # Request is executed immediately.
139
+ # @param [String] page_token Token for pagination
140
+ # @param [String] status Filter by operation state
141
+ # @param [String] resource_id Filter operations affecting a specific resource ID
142
+
143
+ # @return [Page] Page of OperationInstance
144
+ def page(page_token: :unset, status: :unset, resource_id: :unset, page_size: :unset)
145
+ params = Twilio::Values.of({
146
+ 'pageToken' => page_token,
147
+ 'status' => status,
148
+ 'resourceId' => resource_id,
149
+ 'PageSize' => page_size,
150
+ })
151
+ headers = Twilio::Values.of({})
152
+
153
+
154
+
155
+ response = @version.page('GET', @uri, params: params, headers: headers)
156
+
157
+ OperationPage.new(@version, response, @solution)
158
+ end
159
+
160
+ ##
161
+ # Retrieve a single page of OperationInstance records from the API.
162
+ # Request is executed immediately.
163
+ # @param [String] target_url API-generated URL for the requested results page
164
+ # @return [Page] Page of OperationInstance
165
+ def get_page(target_url)
166
+ response = @version.domain.request(
167
+ 'GET',
168
+ target_url
169
+ )
170
+ OperationPage.new(@version, response, @solution)
171
+ end
172
+
173
+
174
+
175
+ # Provide a user friendly representation
176
+ def to_s
177
+ '#<Twilio.Webhooks.V1.OperationList>'
178
+ end
179
+ end
180
+
181
+
182
+ class OperationContext < InstanceContext
183
+ ##
184
+ # Initialize the OperationContext
185
+ # @param [Version] version Version that contains the resource
186
+ # @param [String] operation_id
187
+ # @return [OperationContext] OperationContext
188
+ def initialize(version, operation_id)
189
+
190
+ apiV1Version = ApiV1Version.new version.domain, version
191
+ super(apiV1Version)
192
+
193
+ # Path Solution
194
+ @solution = { operation_id: operation_id, }
195
+ @uri = "/Webhooks/Operations/#{@solution[:operation_id]}"
196
+
197
+
198
+ end
199
+ ##
200
+ # Fetch the OperationInstance
201
+ # @return [OperationInstance] Fetched OperationInstance
202
+ def fetch
203
+
204
+ headers = Twilio::Values.of({'Content-Type' => 'application/x-www-form-urlencoded', })
205
+
206
+
207
+
208
+
209
+ headers['Accept'] = '*/*'
210
+ payload = @version.fetch('GET', @uri, headers: headers)
211
+ OperationInstance.new(
212
+ @version,
213
+ payload,
214
+ operation_id: @solution[:operation_id],
215
+ )
216
+ end
217
+
218
+ ##
219
+ # Fetch the OperationInstanceMetadata
220
+ # @return [OperationInstance] Fetched OperationInstance
221
+ def fetch_with_metadata
222
+
223
+ headers = Twilio::Values.of({'Content-Type' => 'application/x-www-form-urlencoded', })
224
+
225
+
226
+
227
+
228
+ headers['Accept'] = '*/*'
229
+ response = @version.fetch_with_metadata('GET', @uri, headers: headers)
230
+ operation_instance = OperationInstance.new(
231
+ @version,
232
+ response.body,
233
+ operation_id: @solution[:operation_id],
234
+ )
235
+ OperationInstanceMetadata.new(
236
+ @version,
237
+ operation_instance,
238
+ response.headers,
239
+ response.status_code
240
+ )
241
+ end
242
+
243
+
244
+ ##
245
+ # Provide a user friendly representation
246
+ def to_s
247
+ context = @solution.map{|k, v| "#{k}: #{v}"}.join(',')
248
+ "#<Twilio.Webhooks.V1.OperationContext #{context}>"
249
+ end
250
+
251
+ ##
252
+ # Provide a detailed, user friendly representation
253
+ def inspect
254
+ context = @solution.map{|k, v| "#{k}: #{v}"}.join(',')
255
+ "#<Twilio.Webhooks.V1.OperationContext #{context}>"
256
+ end
257
+ end
258
+
259
+ class OperationInstanceMetadata < InstanceResourceMetadata
260
+ ##
261
+ # Initializes a new OperationInstanceMetadata.
262
+ # @param [Version] version Version that contains the resource
263
+ # @param [}OperationInstance] operation_instance The instance associated with the metadata.
264
+ # @param [Hash] headers Header object with response headers.
265
+ # @param [Integer] status_code The HTTP status code of the response.
266
+ # @return [OperationInstanceMetadata] The initialized instance with metadata.
267
+ def initialize(version, operation_instance, headers, status_code)
268
+ super(version, headers, status_code)
269
+ @operation_instance = operation_instance
270
+ end
271
+
272
+ def operation
273
+ @operation_instance
274
+ end
275
+
276
+ def headers
277
+ @headers
278
+ end
279
+
280
+ def status_code
281
+ @status_code
282
+ end
283
+
284
+ def to_s
285
+ "<Twilio.Api.V2010.OperationInstanceMetadata status=#{@status_code}>"
286
+ end
287
+ end
288
+
289
+ class OperationListResponse < InstanceListResource
290
+ # @param [Array<OperationInstance>] instance
291
+ # @param [Hash{String => Object}] headers
292
+ # @param [Integer] status_code
293
+ def initialize(version, payload, key)
294
+ @operation_instance = payload.body[key].map do |data|
295
+ OperationInstance.new(version, data)
296
+ end
297
+ @headers = payload.headers
298
+ @status_code = payload.status_code
299
+ end
300
+
301
+ def operation_instance
302
+ @instance
303
+ end
304
+ end
305
+
306
+ class OperationPage < TokenPage
307
+ ##
308
+ # Initialize the OperationPage
309
+ # @param [Version] version Version that contains the resource
310
+ # @param [Response] response Response from the API
311
+ # @param [Hash] solution Path solution for the resource
312
+ # @return [OperationPage] OperationPage
313
+ def initialize(version, response, solution)
314
+
315
+ apiV1Version = ApiV1Version.new version.domain, version
316
+ super(apiV1Version, response)
317
+
318
+ # Path Solution
319
+ @solution = solution
320
+ end
321
+
322
+ ##
323
+ # Build an instance of OperationInstance
324
+ # @param [Hash] payload Payload response from the API
325
+ # @return [OperationInstance] OperationInstance
326
+ def get_instance(payload)
327
+ OperationInstance.new(@version, payload)
328
+ end
329
+
330
+ ##
331
+ # Provide a user friendly representation
332
+ def to_s
333
+ '<Twilio.Webhooks.V1.OperationPage>'
334
+ end
335
+ end
336
+
337
+ class OperationPageMetadata < PageMetadata
338
+ attr_reader :operation_page
339
+
340
+ def initialize(version, response, solution, limit)
341
+ super(version, response)
342
+ @operation_page = []
343
+ @limit = limit
344
+ key = get_key(response.body)
345
+ records = 0
346
+ while( limit != :unset && records < limit )
347
+ @operation_page << OperationListResponse.new(version, @payload, key, limit - records)
348
+ @payload = self.next_page
349
+ break unless @payload
350
+ records += (@payload.body[key] || []).size
351
+ end
352
+ # Path Solution
353
+ @solution = solution
354
+ end
355
+
356
+ def each
357
+ @operation_page.each do |record|
358
+ yield record
359
+ end
360
+ end
361
+
362
+ def to_s
363
+ '<Twilio::REST::Webhooks::V1PageMetadata>';
364
+ end
365
+ end
366
+ class OperationListResponse < InstanceListResource
367
+
368
+ # @param [Array<OperationInstance>] instance
369
+ # @param [Hash{String => Object}] headers
370
+ # @param [Integer] status_code
371
+ def initialize(version, payload, key, limit = :unset)
372
+ data_list = payload.body[key] || []
373
+ if limit != :unset
374
+ data_list = data_list[0, limit]
375
+ end
376
+ @operation = data_list.map do |data|
377
+ OperationInstance.new(version, data)
378
+ end
379
+ @headers = payload.headers
380
+ @status_code = payload.status_code
381
+ end
382
+
383
+ def operation
384
+ @operation
385
+ end
386
+
387
+ def headers
388
+ @headers
389
+ end
390
+
391
+ def status_code
392
+ @status_code
393
+ end
394
+ end
395
+
396
+ class OperationInstance < InstanceResource
397
+ ##
398
+ # Initialize the OperationInstance
399
+ # @param [Version] version Version that contains the resource
400
+ # @param [Hash] payload payload that contains response from Twilio
401
+ # @param [String] account_sid The SID of the
402
+ # {Account}[https://www.twilio.com/docs/iam/api/account] that created this Operation
403
+ # resource.
404
+ # @param [String] sid The SID of the Call resource to fetch.
405
+ # @return [OperationInstance] OperationInstance
406
+ def initialize(version, payload , operation_id: nil)
407
+
408
+ apiV1Version = ApiV1Version.new version.domain, version
409
+ super(apiV1Version)
410
+
411
+ # Marshaled Properties
412
+ @properties = {
413
+ 'id' => payload['id'],
414
+ 'status_url' => payload['status_url'],
415
+ 'status' => payload['status'],
416
+ 'error' => payload['error'],
417
+ 'resource_id' => payload['resource_id'],
418
+ 'created_at' => Twilio.deserialize_iso8601_datetime(payload['created_at']),
419
+ 'completed_at' => Twilio.deserialize_iso8601_datetime(payload['completed_at']),
420
+ 'retention_period' => payload['retention_period'],
421
+ }
422
+
423
+ # Context
424
+ @instance_context = nil
425
+ @params = { 'operation_id' => operation_id || @properties['operation_id'] , }
426
+ end
427
+
428
+ ##
429
+ # Generate an instance context for the instance, the context is capable of
430
+ # performing various actions. All instance actions are proxied to the context
431
+ # @return [OperationContext] CallContext for this CallInstance
432
+ def context
433
+ unless @instance_context
434
+ @instance_context = OperationContext.new(@version , @params['operation_id'])
435
+ end
436
+ @instance_context
437
+ end
438
+
439
+ ##
440
+ # @return [String] Unique operation identifier (TypeID/TTID format)
441
+ def id
442
+ @properties['id']
443
+ end
444
+
445
+ ##
446
+ # @return [String] URL to poll for operation status (same as Location header in 202 response)
447
+ def status_url
448
+ @properties['status_url']
449
+ end
450
+
451
+ ##
452
+ # @return [String] Current state of the operation: - PENDING: Accepted, not yet started - RUNNING: Propagating to all regions (typically 30-60 seconds) - COMPLETED: Rule active globally - CANCELLED: Operation was cancelled before completion - FAILED: Operation could not complete; see error field for details
453
+ def status
454
+ @properties['status']
455
+ end
456
+
457
+ ##
458
+ # @return [OperationError] Present only when status is FAILED
459
+ def error
460
+ @properties['error']
461
+ end
462
+
463
+ ##
464
+ # @return [String] ID of the affected resource
465
+ def resource_id
466
+ @properties['resource_id']
467
+ end
468
+
469
+ ##
470
+ # @return [Time]
471
+ def created_at
472
+ @properties['created_at']
473
+ end
474
+
475
+ ##
476
+ # @return [Time]
477
+ def completed_at
478
+ @properties['completed_at']
479
+ end
480
+
481
+ ##
482
+ # @return [String] ISO-8601 duration for how long this Operation record is retained after creation (fixed at 7 days)
483
+ def retention_period
484
+ @properties['retention_period']
485
+ end
486
+
487
+ ##
488
+ # Fetch the OperationInstance
489
+ # @return [OperationInstance] Fetched OperationInstance
490
+ def fetch
491
+
492
+ context.fetch
493
+ end
494
+
495
+ ##
496
+ # Provide a user friendly representation
497
+ def to_s
498
+ values = @params.map{|k, v| "#{k}: #{v}"}.join(" ")
499
+ "<Twilio.Webhooks.V1.OperationInstance #{values}>"
500
+ end
501
+
502
+ ##
503
+ # Provide a detailed, user friendly representation
504
+ def inspect
505
+ values = @properties.map{|k, v| "#{k}: #{v}"}.join(" ")
506
+ "<Twilio.Webhooks.V1.OperationInstance #{values}>"
507
+ end
508
+ end
509
+
510
+ end
511
+ end
512
+ end
513
+ end