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.
- checksums.yaml +4 -4
- data/CHANGES.md +201 -0
- data/Gemfile.lock +2 -2
- data/README.md +2 -2
- data/examples/WebhookSignatureValidation.md +61 -0
- data/lib/rack/twilio_webhook_authentication.rb +30 -5
- data/lib/twilio-ruby/rest/api/v2010/account/call.rb +7 -0
- data/lib/twilio-ruby/rest/client.rb +5 -0
- data/lib/twilio-ruby/rest/content/v1/content/approval_create.rb +108 -1
- data/lib/twilio-ruby/rest/content/v1/content.rb +8 -2
- data/lib/twilio-ruby/rest/conversations/v2/configuration.rb +7 -0
- data/lib/twilio-ruby/rest/conversations/v2/conversation.rb +194 -7
- data/lib/twilio-ruby/rest/memory/v1/bulk.rb +22 -1
- data/lib/twilio-ruby/rest/memory/v1/import.rb +21 -7
- data/lib/twilio-ruby/rest/memory/v1/store.rb +7 -0
- data/lib/twilio-ruby/rest/trusthub/v1/a2p_brand_registration.rb +5 -5
- data/lib/twilio-ruby/rest/trusthub/v1/a2p_campaign_registration.rb +4 -4
- data/lib/twilio-ruby/rest/trusthub/v1.rb +2 -2
- data/lib/twilio-ruby/rest/webhooks/v1/auth_profile.rb +825 -0
- data/lib/twilio-ruby/rest/webhooks/v1/edge_zone.rb +320 -0
- data/lib/twilio-ruby/rest/webhooks/v1/operation.rb +513 -0
- data/lib/twilio-ruby/rest/webhooks/v1/rule.rb +818 -0
- data/lib/twilio-ruby/rest/webhooks/v1/setting.rb +1028 -0
- data/lib/twilio-ruby/rest/webhooks/v1/shared_key.rb +722 -0
- data/lib/twilio-ruby/rest/webhooks/v1/test.rb +228 -0
- data/lib/twilio-ruby/rest/webhooks/v1.rb +126 -0
- data/lib/twilio-ruby/rest/webhooks.rb +6 -0
- data/lib/twilio-ruby/rest/webhooks_base.rb +38 -0
- data/lib/twilio-ruby/security/request_validator.rb +54 -8
- data/lib/twilio-ruby/twiml/voice_response.rb +20 -5
- data/lib/twilio-ruby/version.rb +1 -1
- metadata +13 -3
- data/lib/twilio-ruby/rest/oauth/v2/oauth_authorization_server.rb +0 -200
|
@@ -0,0 +1,818 @@
|
|
|
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 RuleList < ListResource
|
|
21
|
+
|
|
22
|
+
class PatchRule
|
|
23
|
+
# @param [friendly_name]: [String] Human-readable name for the Rule
|
|
24
|
+
# @param [description]: [String] Optional description of the Rule's purpose and usage
|
|
25
|
+
# @param [match_type]: [String]
|
|
26
|
+
# @param [prefix]: [String] New URL prefix to match, MUST be unique across all prefix match rules and MUST end with `/`.
|
|
27
|
+
# @param [settings]: [Array<RuleList.SettingReference>] Settings to apply with traffic distribution (percentages must sum to 100)
|
|
28
|
+
# @param [value]: [String] New exact URL to match, MUST be unique across all exact match rules and MUST NOT end with `/`.
|
|
29
|
+
attr_accessor :friendly_name, :description, :match_type, :prefix, :settings, :value
|
|
30
|
+
def initialize(payload)
|
|
31
|
+
@friendly_name = payload["friendly_name"]
|
|
32
|
+
@description = payload["description"]
|
|
33
|
+
@match_type = payload["match_type"]
|
|
34
|
+
@prefix = payload["prefix"]
|
|
35
|
+
@settings = payload["settings"]
|
|
36
|
+
@value = payload["value"]
|
|
37
|
+
end
|
|
38
|
+
def to_json(options = {})
|
|
39
|
+
{
|
|
40
|
+
"friendlyName": @friendly_name,
|
|
41
|
+
"description": @description,
|
|
42
|
+
"matchType": @match_type,
|
|
43
|
+
"prefix": @prefix,
|
|
44
|
+
"settings": @settings,
|
|
45
|
+
"value": @value,
|
|
46
|
+
}.to_json(options)
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
class PostRule
|
|
51
|
+
# @param [friendly_name]: [String] Human-readable name for the Rule (optional, defaults to blank)
|
|
52
|
+
# @param [description]: [String] Optional description of the Rule's purpose and usage
|
|
53
|
+
# @param [match_type]: [String]
|
|
54
|
+
# @param [settings]: [Array<RuleList.SettingReference>] Settings to apply with traffic distribution (percentages must sum to 100)
|
|
55
|
+
# @param [prefix]: [String] URL prefix to match, MUST be unique across all prefix match rules and MUST end with `/`.
|
|
56
|
+
# @param [value]: [String] Exact URL to match, MUST be unique across all exact match rules and MUST NOT end with `/`.
|
|
57
|
+
attr_accessor :friendly_name, :description, :match_type, :settings, :prefix, :value
|
|
58
|
+
def initialize(payload)
|
|
59
|
+
@friendly_name = payload["friendly_name"]
|
|
60
|
+
@description = payload["description"]
|
|
61
|
+
@match_type = payload["match_type"]
|
|
62
|
+
@settings = payload["settings"]
|
|
63
|
+
@prefix = payload["prefix"]
|
|
64
|
+
@value = payload["value"]
|
|
65
|
+
end
|
|
66
|
+
def to_json(options = {})
|
|
67
|
+
{
|
|
68
|
+
"friendlyName": @friendly_name,
|
|
69
|
+
"description": @description,
|
|
70
|
+
"matchType": @match_type,
|
|
71
|
+
"settings": @settings,
|
|
72
|
+
"prefix": @prefix,
|
|
73
|
+
"value": @value,
|
|
74
|
+
}.to_json(options)
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
class PatchRule
|
|
80
|
+
# @param [friendly_name]: [String] Human-readable name for the Rule
|
|
81
|
+
# @param [description]: [String] Optional description of the Rule's purpose and usage
|
|
82
|
+
# @param [match_type]: [String]
|
|
83
|
+
# @param [prefix]: [String] New URL prefix to match, MUST be unique across all prefix match rules and MUST end with `/`.
|
|
84
|
+
# @param [settings]: [Array<RuleList.SettingReference>] Settings to apply with traffic distribution (percentages must sum to 100)
|
|
85
|
+
# @param [value]: [String] New exact URL to match, MUST be unique across all exact match rules and MUST NOT end with `/`.
|
|
86
|
+
attr_accessor :friendly_name, :description, :match_type, :prefix, :settings, :value
|
|
87
|
+
def initialize(payload)
|
|
88
|
+
@friendly_name = payload["friendly_name"]
|
|
89
|
+
@description = payload["description"]
|
|
90
|
+
@match_type = payload["match_type"]
|
|
91
|
+
@prefix = payload["prefix"]
|
|
92
|
+
@settings = payload["settings"]
|
|
93
|
+
@value = payload["value"]
|
|
94
|
+
end
|
|
95
|
+
def to_json(options = {})
|
|
96
|
+
{
|
|
97
|
+
"friendlyName": @friendly_name,
|
|
98
|
+
"description": @description,
|
|
99
|
+
"matchType": @match_type,
|
|
100
|
+
"prefix": @prefix,
|
|
101
|
+
"settings": @settings,
|
|
102
|
+
"value": @value,
|
|
103
|
+
}.to_json(options)
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
class PostRule
|
|
108
|
+
# @param [friendly_name]: [String] Human-readable name for the Rule (optional, defaults to blank)
|
|
109
|
+
# @param [description]: [String] Optional description of the Rule's purpose and usage
|
|
110
|
+
# @param [match_type]: [String]
|
|
111
|
+
# @param [settings]: [Array<RuleList.SettingReference>] Settings to apply with traffic distribution (percentages must sum to 100)
|
|
112
|
+
# @param [prefix]: [String] URL prefix to match, MUST be unique across all prefix match rules and MUST end with `/`.
|
|
113
|
+
# @param [value]: [String] Exact URL to match, MUST be unique across all exact match rules and MUST NOT end with `/`.
|
|
114
|
+
attr_accessor :friendly_name, :description, :match_type, :settings, :prefix, :value
|
|
115
|
+
def initialize(payload)
|
|
116
|
+
@friendly_name = payload["friendly_name"]
|
|
117
|
+
@description = payload["description"]
|
|
118
|
+
@match_type = payload["match_type"]
|
|
119
|
+
@settings = payload["settings"]
|
|
120
|
+
@prefix = payload["prefix"]
|
|
121
|
+
@value = payload["value"]
|
|
122
|
+
end
|
|
123
|
+
def to_json(options = {})
|
|
124
|
+
{
|
|
125
|
+
"friendlyName": @friendly_name,
|
|
126
|
+
"description": @description,
|
|
127
|
+
"matchType": @match_type,
|
|
128
|
+
"settings": @settings,
|
|
129
|
+
"prefix": @prefix,
|
|
130
|
+
"value": @value,
|
|
131
|
+
}.to_json(options)
|
|
132
|
+
end
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
##
|
|
137
|
+
# Initialize the RuleList
|
|
138
|
+
# @param [Version] version Version that contains the resource
|
|
139
|
+
# @return [RuleList] RuleList
|
|
140
|
+
def initialize(version)
|
|
141
|
+
|
|
142
|
+
apiV1Version = ApiV1Version.new version.domain, version
|
|
143
|
+
super(apiV1Version)
|
|
144
|
+
# Path Solution
|
|
145
|
+
@solution = { }
|
|
146
|
+
@uri = "/Webhooks/Rules"
|
|
147
|
+
|
|
148
|
+
end
|
|
149
|
+
##
|
|
150
|
+
# Create the RuleInstance
|
|
151
|
+
# @param [String] idempotency_key Idempotency key for mutation operations. Must be a UUIDv7 (other UUID versions are rejected with a 400).
|
|
152
|
+
# @param [PostRule] post_rule
|
|
153
|
+
# @return [RuleInstance] Created RuleInstance
|
|
154
|
+
def create(
|
|
155
|
+
idempotency_key: :unset,
|
|
156
|
+
post_rule: nil
|
|
157
|
+
)
|
|
158
|
+
|
|
159
|
+
headers = Twilio::Values.of({'Content-Type' => 'application/x-www-form-urlencoded', 'Idempotency-Key' => idempotency_key, })
|
|
160
|
+
headers['Content-Type'] = 'application/json'
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
headers['Accept'] = '*/*'
|
|
165
|
+
payload = @version.create('POST', @uri, headers: headers, data: post_rule.to_json)
|
|
166
|
+
RuleInstance.new(
|
|
167
|
+
@version,
|
|
168
|
+
payload,
|
|
169
|
+
)
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
##
|
|
173
|
+
# Create the RuleInstanceMetadata
|
|
174
|
+
# @param [String] idempotency_key Idempotency key for mutation operations. Must be a UUIDv7 (other UUID versions are rejected with a 400).
|
|
175
|
+
# @param [PostRule] post_rule
|
|
176
|
+
# @return [RuleInstance] Created RuleInstance
|
|
177
|
+
def create_with_metadata(
|
|
178
|
+
idempotency_key: :unset,
|
|
179
|
+
post_rule: nil
|
|
180
|
+
)
|
|
181
|
+
|
|
182
|
+
headers = Twilio::Values.of({'Content-Type' => 'application/x-www-form-urlencoded', 'Idempotency-Key' => idempotency_key, })
|
|
183
|
+
headers['Content-Type'] = 'application/json'
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
headers['Accept'] = '*/*'
|
|
188
|
+
response = @version.create_with_metadata('POST', @uri, headers: headers, data: post_rule.to_json)
|
|
189
|
+
rule_instance = RuleInstance.new(
|
|
190
|
+
@version,
|
|
191
|
+
response.body,
|
|
192
|
+
)
|
|
193
|
+
RuleInstanceMetadata.new(
|
|
194
|
+
@version,
|
|
195
|
+
rule_instance,
|
|
196
|
+
response.headers,
|
|
197
|
+
response.status_code
|
|
198
|
+
)
|
|
199
|
+
end
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
##
|
|
203
|
+
# Lists RuleInstance records from the API as a list.
|
|
204
|
+
# Unlike stream(), this operation is eager and will load `limit` records into
|
|
205
|
+
# memory before returning.
|
|
206
|
+
# @param [String] page_token Token for pagination
|
|
207
|
+
# @param [String] setting_id Filter Rules that reference this Setting ID
|
|
208
|
+
# @param [Integer] limit Upper limit for the number of records to return. stream()
|
|
209
|
+
# guarantees to never return more than limit. Default is no limit
|
|
210
|
+
# @param [Integer] page_size Number of records to fetch per request, when
|
|
211
|
+
# not set will use the default value of 50 records. If no page_size is defined
|
|
212
|
+
# but a limit is defined, stream() will attempt to read the limit with the most
|
|
213
|
+
# efficient page size, i.e. min(limit, 1000)
|
|
214
|
+
# @return [Array] Array of up to limit results
|
|
215
|
+
def list(page_token: :unset, setting_id: :unset, limit: nil, page_size: nil)
|
|
216
|
+
self.stream(
|
|
217
|
+
page_token: page_token,
|
|
218
|
+
setting_id: setting_id,
|
|
219
|
+
limit: limit,
|
|
220
|
+
page_size: page_size
|
|
221
|
+
).entries
|
|
222
|
+
end
|
|
223
|
+
|
|
224
|
+
##
|
|
225
|
+
# Streams Instance records from the API as an Enumerable.
|
|
226
|
+
# This operation lazily loads records as efficiently as possible until the limit
|
|
227
|
+
# is reached.
|
|
228
|
+
# @param [String] page_token Token for pagination
|
|
229
|
+
# @param [String] setting_id Filter Rules that reference this Setting ID
|
|
230
|
+
# @param [Integer] limit Upper limit for the number of records to return. stream()
|
|
231
|
+
# guarantees to never return more than limit. Default is no limit
|
|
232
|
+
# @param [Integer] page_size Number of records to fetch per request, when
|
|
233
|
+
# not set will use the default value of 50 records. If no page_size is defined
|
|
234
|
+
# but a limit is defined, stream() will attempt to read the limit with the most
|
|
235
|
+
# efficient page size, i.e. min(limit, 1000)
|
|
236
|
+
# @return [Enumerable] Enumerable that will yield up to limit results
|
|
237
|
+
def stream(page_token: :unset, setting_id: :unset, limit: nil, page_size: nil)
|
|
238
|
+
limits = @version.read_limits(limit, page_size)
|
|
239
|
+
|
|
240
|
+
page = self.page(
|
|
241
|
+
page_token: page_token,
|
|
242
|
+
setting_id: setting_id,
|
|
243
|
+
page_size: limits[:page_size], )
|
|
244
|
+
|
|
245
|
+
return [].each if page.nil?
|
|
246
|
+
|
|
247
|
+
result = @version.stream(page, limit: limits[:limit], page_limit: limits[:page_limit])
|
|
248
|
+
return [].each if result.nil?
|
|
249
|
+
result
|
|
250
|
+
end
|
|
251
|
+
|
|
252
|
+
##
|
|
253
|
+
# Lists RulePageMetadata records from the API as a list.
|
|
254
|
+
# @param [String] page_token Token for pagination
|
|
255
|
+
# @param [String] setting_id Filter Rules that reference this Setting ID
|
|
256
|
+
# @param [Integer] limit Upper limit for the number of records to return. stream()
|
|
257
|
+
# guarantees to never return more than limit. Default is no limit
|
|
258
|
+
# @param [Integer] page_size Number of records to fetch per request, when
|
|
259
|
+
# not set will use the default value of 50 records. If no page_size is defined
|
|
260
|
+
# but a limit is defined, stream() will attempt to read the limit with the most
|
|
261
|
+
# efficient page size, i.e. min(limit, 1000)
|
|
262
|
+
# @return [Array] Array of up to limit results
|
|
263
|
+
def list_with_metadata(page_token: :unset, setting_id: :unset, limit: nil, page_size: nil)
|
|
264
|
+
limits = @version.read_limits(limit, page_size)
|
|
265
|
+
params = Twilio::Values.of({
|
|
266
|
+
'pageToken' => page_token,
|
|
267
|
+
'settingId' => setting_id,
|
|
268
|
+
|
|
269
|
+
'PageSize' => limits[:page_size],
|
|
270
|
+
});
|
|
271
|
+
headers = Twilio::Values.of({})
|
|
272
|
+
|
|
273
|
+
response = @version.page('GET', @uri, params: params, headers: headers)
|
|
274
|
+
|
|
275
|
+
RulePageMetadata.new(@version, response, @solution, limits[:limit])
|
|
276
|
+
end
|
|
277
|
+
|
|
278
|
+
##
|
|
279
|
+
# When passed a block, yields RuleInstance records from the API.
|
|
280
|
+
# This operation lazily loads records as efficiently as possible until the limit
|
|
281
|
+
# is reached.
|
|
282
|
+
def each
|
|
283
|
+
limits = @version.read_limits
|
|
284
|
+
|
|
285
|
+
page = self.page(page_size: limits[:page_size], )
|
|
286
|
+
|
|
287
|
+
return [].each if page.nil?
|
|
288
|
+
|
|
289
|
+
result = @version.stream(page,
|
|
290
|
+
limit: limits[:limit],
|
|
291
|
+
page_limit: limits[:page_limit])
|
|
292
|
+
return [].each if result.nil?
|
|
293
|
+
result.each {|x| yield x}
|
|
294
|
+
end
|
|
295
|
+
|
|
296
|
+
##
|
|
297
|
+
# Retrieve a single page of RuleInstance records from the API.
|
|
298
|
+
# Request is executed immediately.
|
|
299
|
+
# @param [String] page_token Token for pagination
|
|
300
|
+
# @param [String] setting_id Filter Rules that reference this Setting ID
|
|
301
|
+
|
|
302
|
+
# @return [Page] Page of RuleInstance
|
|
303
|
+
def page(page_token: :unset, setting_id: :unset, page_size: :unset)
|
|
304
|
+
params = Twilio::Values.of({
|
|
305
|
+
'pageToken' => page_token,
|
|
306
|
+
'settingId' => setting_id,
|
|
307
|
+
'PageSize' => page_size,
|
|
308
|
+
})
|
|
309
|
+
headers = Twilio::Values.of({})
|
|
310
|
+
|
|
311
|
+
|
|
312
|
+
|
|
313
|
+
response = @version.page('GET', @uri, params: params, headers: headers)
|
|
314
|
+
|
|
315
|
+
RulePage.new(@version, response, @solution)
|
|
316
|
+
end
|
|
317
|
+
|
|
318
|
+
##
|
|
319
|
+
# Retrieve a single page of RuleInstance records from the API.
|
|
320
|
+
# Request is executed immediately.
|
|
321
|
+
# @param [String] target_url API-generated URL for the requested results page
|
|
322
|
+
# @return [Page] Page of RuleInstance
|
|
323
|
+
def get_page(target_url)
|
|
324
|
+
response = @version.domain.request(
|
|
325
|
+
'GET',
|
|
326
|
+
target_url
|
|
327
|
+
)
|
|
328
|
+
RulePage.new(@version, response, @solution)
|
|
329
|
+
end
|
|
330
|
+
|
|
331
|
+
|
|
332
|
+
|
|
333
|
+
# Provide a user friendly representation
|
|
334
|
+
def to_s
|
|
335
|
+
'#<Twilio.Webhooks.V1.RuleList>'
|
|
336
|
+
end
|
|
337
|
+
end
|
|
338
|
+
|
|
339
|
+
|
|
340
|
+
class RuleContext < InstanceContext
|
|
341
|
+
##
|
|
342
|
+
# Initialize the RuleContext
|
|
343
|
+
# @param [Version] version Version that contains the resource
|
|
344
|
+
# @param [String] rule_id
|
|
345
|
+
# @return [RuleContext] RuleContext
|
|
346
|
+
def initialize(version, rule_id)
|
|
347
|
+
|
|
348
|
+
apiV1Version = ApiV1Version.new version.domain, version
|
|
349
|
+
super(apiV1Version)
|
|
350
|
+
|
|
351
|
+
# Path Solution
|
|
352
|
+
@solution = { rule_id: rule_id, }
|
|
353
|
+
@uri = "/Webhooks/Rules/#{@solution[:rule_id]}"
|
|
354
|
+
|
|
355
|
+
|
|
356
|
+
end
|
|
357
|
+
##
|
|
358
|
+
# Delete the RuleInstance
|
|
359
|
+
# @param [String] idempotency_key Idempotency key for mutation operations. Must be a UUIDv7 (other UUID versions are rejected with a 400).
|
|
360
|
+
# @return [Boolean] True if delete succeeds, false otherwise
|
|
361
|
+
def delete(
|
|
362
|
+
idempotency_key: :unset
|
|
363
|
+
)
|
|
364
|
+
|
|
365
|
+
headers = Twilio::Values.of({'Content-Type' => 'application/x-www-form-urlencoded', 'Idempotency-Key' => idempotency_key, })
|
|
366
|
+
|
|
367
|
+
|
|
368
|
+
|
|
369
|
+
response = @version.delete_with_metadata('DELETE', @uri, headers: headers)
|
|
370
|
+
RuleInstance.new(
|
|
371
|
+
@version,
|
|
372
|
+
response.body,
|
|
373
|
+
rule_id: @solution[:rule_id],
|
|
374
|
+
)
|
|
375
|
+
|
|
376
|
+
end
|
|
377
|
+
|
|
378
|
+
##
|
|
379
|
+
# Delete the RuleInstanceMetadata
|
|
380
|
+
# @param [String] idempotency_key Idempotency key for mutation operations. Must be a UUIDv7 (other UUID versions are rejected with a 400).
|
|
381
|
+
# @return [Boolean] True if delete succeeds, false otherwise
|
|
382
|
+
def delete_with_metadata(
|
|
383
|
+
idempotency_key: :unset
|
|
384
|
+
)
|
|
385
|
+
|
|
386
|
+
headers = Twilio::Values.of({'Content-Type' => 'application/x-www-form-urlencoded', 'Idempotency-Key' => idempotency_key, })
|
|
387
|
+
|
|
388
|
+
|
|
389
|
+
|
|
390
|
+
response = @version.delete_with_metadata('DELETE', @uri, headers: headers)
|
|
391
|
+
rule_instance = RuleInstance.new(
|
|
392
|
+
@version,
|
|
393
|
+
response.body,
|
|
394
|
+
account_sid: @solution[:account_sid],
|
|
395
|
+
sid: @solution[:sid],
|
|
396
|
+
)
|
|
397
|
+
RuleInstanceMetadata.new(@version, rule_instance, response.headers, response.status_code)
|
|
398
|
+
end
|
|
399
|
+
|
|
400
|
+
##
|
|
401
|
+
# Fetch the RuleInstance
|
|
402
|
+
# @return [RuleInstance] Fetched RuleInstance
|
|
403
|
+
def fetch
|
|
404
|
+
|
|
405
|
+
headers = Twilio::Values.of({'Content-Type' => 'application/x-www-form-urlencoded', })
|
|
406
|
+
|
|
407
|
+
|
|
408
|
+
|
|
409
|
+
|
|
410
|
+
headers['Accept'] = '*/*'
|
|
411
|
+
payload = @version.fetch('GET', @uri, headers: headers)
|
|
412
|
+
RuleInstance.new(
|
|
413
|
+
@version,
|
|
414
|
+
payload,
|
|
415
|
+
rule_id: @solution[:rule_id],
|
|
416
|
+
)
|
|
417
|
+
end
|
|
418
|
+
|
|
419
|
+
##
|
|
420
|
+
# Fetch the RuleInstanceMetadata
|
|
421
|
+
# @return [RuleInstance] Fetched RuleInstance
|
|
422
|
+
def fetch_with_metadata
|
|
423
|
+
|
|
424
|
+
headers = Twilio::Values.of({'Content-Type' => 'application/x-www-form-urlencoded', })
|
|
425
|
+
|
|
426
|
+
|
|
427
|
+
|
|
428
|
+
|
|
429
|
+
headers['Accept'] = '*/*'
|
|
430
|
+
response = @version.fetch_with_metadata('GET', @uri, headers: headers)
|
|
431
|
+
rule_instance = RuleInstance.new(
|
|
432
|
+
@version,
|
|
433
|
+
response.body,
|
|
434
|
+
rule_id: @solution[:rule_id],
|
|
435
|
+
)
|
|
436
|
+
RuleInstanceMetadata.new(
|
|
437
|
+
@version,
|
|
438
|
+
rule_instance,
|
|
439
|
+
response.headers,
|
|
440
|
+
response.status_code
|
|
441
|
+
)
|
|
442
|
+
end
|
|
443
|
+
|
|
444
|
+
##
|
|
445
|
+
# Patch the RuleInstance
|
|
446
|
+
# @param [String] idempotency_key Idempotency key for mutation operations. Must be a UUIDv7 (other UUID versions are rejected with a 400).
|
|
447
|
+
# @param [PatchRule] patch_rule
|
|
448
|
+
# @return [RuleInstance] Patched RuleInstance
|
|
449
|
+
def patch(
|
|
450
|
+
idempotency_key: :unset,
|
|
451
|
+
patch_rule: nil
|
|
452
|
+
)
|
|
453
|
+
|
|
454
|
+
headers = Twilio::Values.of({'Content-Type' => 'application/x-www-form-urlencoded', 'Idempotency-Key' => idempotency_key, })
|
|
455
|
+
headers['Content-Type'] = 'application/json'
|
|
456
|
+
|
|
457
|
+
|
|
458
|
+
|
|
459
|
+
headers['Accept'] = '*/*'
|
|
460
|
+
payload = @version.patch('PATCH', @uri, headers: headers, data: patch_rule.to_json)
|
|
461
|
+
RuleInstance.new(
|
|
462
|
+
@version,
|
|
463
|
+
payload,
|
|
464
|
+
rule_id: @solution[:rule_id],
|
|
465
|
+
)
|
|
466
|
+
end
|
|
467
|
+
|
|
468
|
+
##
|
|
469
|
+
# Patch the RuleInstanceMetadata
|
|
470
|
+
# @param [String] idempotency_key Idempotency key for mutation operations. Must be a UUIDv7 (other UUID versions are rejected with a 400).
|
|
471
|
+
# @param [PatchRule] patch_rule
|
|
472
|
+
# @return [RuleInstance] Patchd RuleInstance
|
|
473
|
+
def patch_with_metadata(
|
|
474
|
+
idempotency_key: :unset,
|
|
475
|
+
patch_rule: nil
|
|
476
|
+
)
|
|
477
|
+
|
|
478
|
+
headers = Twilio::Values.of({'Content-Type' => 'application/x-www-form-urlencoded', 'Idempotency-Key' => idempotency_key, })
|
|
479
|
+
headers['Content-Type'] = 'application/json'
|
|
480
|
+
|
|
481
|
+
|
|
482
|
+
|
|
483
|
+
headers['Accept'] = '*/*'
|
|
484
|
+
response = @version.patch_with_metadata('PATCH', @uri, headers: headers, data: patch_rule.to_json)
|
|
485
|
+
rule_instance = RuleInstance.new(
|
|
486
|
+
@version,
|
|
487
|
+
response.body,
|
|
488
|
+
rule_id: @solution[:rule_id],
|
|
489
|
+
)
|
|
490
|
+
RuleInstanceMetadata.new(
|
|
491
|
+
@version,
|
|
492
|
+
rule_instance,
|
|
493
|
+
response.headers,
|
|
494
|
+
response.status_code
|
|
495
|
+
)
|
|
496
|
+
end
|
|
497
|
+
|
|
498
|
+
|
|
499
|
+
##
|
|
500
|
+
# Provide a user friendly representation
|
|
501
|
+
def to_s
|
|
502
|
+
context = @solution.map{|k, v| "#{k}: #{v}"}.join(',')
|
|
503
|
+
"#<Twilio.Webhooks.V1.RuleContext #{context}>"
|
|
504
|
+
end
|
|
505
|
+
|
|
506
|
+
##
|
|
507
|
+
# Provide a detailed, user friendly representation
|
|
508
|
+
def inspect
|
|
509
|
+
context = @solution.map{|k, v| "#{k}: #{v}"}.join(',')
|
|
510
|
+
"#<Twilio.Webhooks.V1.RuleContext #{context}>"
|
|
511
|
+
end
|
|
512
|
+
end
|
|
513
|
+
|
|
514
|
+
class RuleInstanceMetadata < InstanceResourceMetadata
|
|
515
|
+
##
|
|
516
|
+
# Initializes a new RuleInstanceMetadata.
|
|
517
|
+
# @param [Version] version Version that contains the resource
|
|
518
|
+
# @param [}RuleInstance] rule_instance The instance associated with the metadata.
|
|
519
|
+
# @param [Hash] headers Header object with response headers.
|
|
520
|
+
# @param [Integer] status_code The HTTP status code of the response.
|
|
521
|
+
# @return [RuleInstanceMetadata] The initialized instance with metadata.
|
|
522
|
+
def initialize(version, rule_instance, headers, status_code)
|
|
523
|
+
super(version, headers, status_code)
|
|
524
|
+
@rule_instance = rule_instance
|
|
525
|
+
end
|
|
526
|
+
|
|
527
|
+
def rule
|
|
528
|
+
@rule_instance
|
|
529
|
+
end
|
|
530
|
+
|
|
531
|
+
def headers
|
|
532
|
+
@headers
|
|
533
|
+
end
|
|
534
|
+
|
|
535
|
+
def status_code
|
|
536
|
+
@status_code
|
|
537
|
+
end
|
|
538
|
+
|
|
539
|
+
def to_s
|
|
540
|
+
"<Twilio.Api.V2010.RuleInstanceMetadata status=#{@status_code}>"
|
|
541
|
+
end
|
|
542
|
+
end
|
|
543
|
+
|
|
544
|
+
class RuleListResponse < InstanceListResource
|
|
545
|
+
# @param [Array<RuleInstance>] instance
|
|
546
|
+
# @param [Hash{String => Object}] headers
|
|
547
|
+
# @param [Integer] status_code
|
|
548
|
+
def initialize(version, payload, key)
|
|
549
|
+
@rule_instance = payload.body[key].map do |data|
|
|
550
|
+
RuleInstance.new(version, data)
|
|
551
|
+
end
|
|
552
|
+
@headers = payload.headers
|
|
553
|
+
@status_code = payload.status_code
|
|
554
|
+
end
|
|
555
|
+
|
|
556
|
+
def rule_instance
|
|
557
|
+
@instance
|
|
558
|
+
end
|
|
559
|
+
end
|
|
560
|
+
|
|
561
|
+
class RulePage < TokenPage
|
|
562
|
+
##
|
|
563
|
+
# Initialize the RulePage
|
|
564
|
+
# @param [Version] version Version that contains the resource
|
|
565
|
+
# @param [Response] response Response from the API
|
|
566
|
+
# @param [Hash] solution Path solution for the resource
|
|
567
|
+
# @return [RulePage] RulePage
|
|
568
|
+
def initialize(version, response, solution)
|
|
569
|
+
|
|
570
|
+
apiV1Version = ApiV1Version.new version.domain, version
|
|
571
|
+
super(apiV1Version, response)
|
|
572
|
+
|
|
573
|
+
# Path Solution
|
|
574
|
+
@solution = solution
|
|
575
|
+
end
|
|
576
|
+
|
|
577
|
+
##
|
|
578
|
+
# Build an instance of RuleInstance
|
|
579
|
+
# @param [Hash] payload Payload response from the API
|
|
580
|
+
# @return [RuleInstance] RuleInstance
|
|
581
|
+
def get_instance(payload)
|
|
582
|
+
RuleInstance.new(@version, payload)
|
|
583
|
+
end
|
|
584
|
+
|
|
585
|
+
##
|
|
586
|
+
# Provide a user friendly representation
|
|
587
|
+
def to_s
|
|
588
|
+
'<Twilio.Webhooks.V1.RulePage>'
|
|
589
|
+
end
|
|
590
|
+
end
|
|
591
|
+
|
|
592
|
+
class RulePageMetadata < PageMetadata
|
|
593
|
+
attr_reader :rule_page
|
|
594
|
+
|
|
595
|
+
def initialize(version, response, solution, limit)
|
|
596
|
+
super(version, response)
|
|
597
|
+
@rule_page = []
|
|
598
|
+
@limit = limit
|
|
599
|
+
key = get_key(response.body)
|
|
600
|
+
records = 0
|
|
601
|
+
while( limit != :unset && records < limit )
|
|
602
|
+
@rule_page << RuleListResponse.new(version, @payload, key, limit - records)
|
|
603
|
+
@payload = self.next_page
|
|
604
|
+
break unless @payload
|
|
605
|
+
records += (@payload.body[key] || []).size
|
|
606
|
+
end
|
|
607
|
+
# Path Solution
|
|
608
|
+
@solution = solution
|
|
609
|
+
end
|
|
610
|
+
|
|
611
|
+
def each
|
|
612
|
+
@rule_page.each do |record|
|
|
613
|
+
yield record
|
|
614
|
+
end
|
|
615
|
+
end
|
|
616
|
+
|
|
617
|
+
def to_s
|
|
618
|
+
'<Twilio::REST::Webhooks::V1PageMetadata>';
|
|
619
|
+
end
|
|
620
|
+
end
|
|
621
|
+
class RuleListResponse < InstanceListResource
|
|
622
|
+
|
|
623
|
+
# @param [Array<RuleInstance>] instance
|
|
624
|
+
# @param [Hash{String => Object}] headers
|
|
625
|
+
# @param [Integer] status_code
|
|
626
|
+
def initialize(version, payload, key, limit = :unset)
|
|
627
|
+
data_list = payload.body[key] || []
|
|
628
|
+
if limit != :unset
|
|
629
|
+
data_list = data_list[0, limit]
|
|
630
|
+
end
|
|
631
|
+
@rule = data_list.map do |data|
|
|
632
|
+
RuleInstance.new(version, data)
|
|
633
|
+
end
|
|
634
|
+
@headers = payload.headers
|
|
635
|
+
@status_code = payload.status_code
|
|
636
|
+
end
|
|
637
|
+
|
|
638
|
+
def rule
|
|
639
|
+
@rule
|
|
640
|
+
end
|
|
641
|
+
|
|
642
|
+
def headers
|
|
643
|
+
@headers
|
|
644
|
+
end
|
|
645
|
+
|
|
646
|
+
def status_code
|
|
647
|
+
@status_code
|
|
648
|
+
end
|
|
649
|
+
end
|
|
650
|
+
|
|
651
|
+
class RuleInstance < InstanceResource
|
|
652
|
+
##
|
|
653
|
+
# Initialize the RuleInstance
|
|
654
|
+
# @param [Version] version Version that contains the resource
|
|
655
|
+
# @param [Hash] payload payload that contains response from Twilio
|
|
656
|
+
# @param [String] account_sid The SID of the
|
|
657
|
+
# {Account}[https://www.twilio.com/docs/iam/api/account] that created this Rule
|
|
658
|
+
# resource.
|
|
659
|
+
# @param [String] sid The SID of the Call resource to fetch.
|
|
660
|
+
# @return [RuleInstance] RuleInstance
|
|
661
|
+
def initialize(version, payload , rule_id: nil)
|
|
662
|
+
|
|
663
|
+
apiV1Version = ApiV1Version.new version.domain, version
|
|
664
|
+
super(apiV1Version)
|
|
665
|
+
|
|
666
|
+
# Marshaled Properties
|
|
667
|
+
@properties = {
|
|
668
|
+
'operation' => payload['operation'],
|
|
669
|
+
'rule' => payload['rule'],
|
|
670
|
+
'id' => payload['id'],
|
|
671
|
+
'friendly_name' => payload['friendly_name'],
|
|
672
|
+
'description' => payload['description'],
|
|
673
|
+
'match_type' => payload['match_type'],
|
|
674
|
+
'settings' => payload['settings'],
|
|
675
|
+
'created_at' => Twilio.deserialize_iso8601_datetime(payload['created_at']),
|
|
676
|
+
'updated_at' => Twilio.deserialize_iso8601_datetime(payload['updated_at']),
|
|
677
|
+
'prefix' => payload['prefix'],
|
|
678
|
+
'value' => payload['value'],
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
# Context
|
|
682
|
+
@instance_context = nil
|
|
683
|
+
@params = { 'rule_id' => rule_id || @properties['rule_id'] , }
|
|
684
|
+
end
|
|
685
|
+
|
|
686
|
+
##
|
|
687
|
+
# Generate an instance context for the instance, the context is capable of
|
|
688
|
+
# performing various actions. All instance actions are proxied to the context
|
|
689
|
+
# @return [RuleContext] CallContext for this CallInstance
|
|
690
|
+
def context
|
|
691
|
+
unless @instance_context
|
|
692
|
+
@instance_context = RuleContext.new(@version , @params['rule_id'])
|
|
693
|
+
end
|
|
694
|
+
@instance_context
|
|
695
|
+
end
|
|
696
|
+
|
|
697
|
+
##
|
|
698
|
+
# @return [Operation] Operation tracking object — poll statusUrl for completion
|
|
699
|
+
def operation
|
|
700
|
+
@properties['operation']
|
|
701
|
+
end
|
|
702
|
+
|
|
703
|
+
##
|
|
704
|
+
# @return [Rule] State of the Rule resource at the time the operation was accepted (omitted for DELETE)
|
|
705
|
+
def rule
|
|
706
|
+
@properties['rule']
|
|
707
|
+
end
|
|
708
|
+
|
|
709
|
+
##
|
|
710
|
+
# @return [String] Unique Rule identifier (TypeID/TTID format)
|
|
711
|
+
def id
|
|
712
|
+
@properties['id']
|
|
713
|
+
end
|
|
714
|
+
|
|
715
|
+
##
|
|
716
|
+
# @return [String] Human-readable name for identification
|
|
717
|
+
def friendly_name
|
|
718
|
+
@properties['friendly_name']
|
|
719
|
+
end
|
|
720
|
+
|
|
721
|
+
##
|
|
722
|
+
# @return [String] Optional description of the Rule's purpose and usage
|
|
723
|
+
def description
|
|
724
|
+
@properties['description']
|
|
725
|
+
end
|
|
726
|
+
|
|
727
|
+
##
|
|
728
|
+
# @return [String]
|
|
729
|
+
def match_type
|
|
730
|
+
@properties['match_type']
|
|
731
|
+
end
|
|
732
|
+
|
|
733
|
+
##
|
|
734
|
+
# @return [Array<SettingReference>] Settings to apply with traffic distribution (percentages must sum to 100)
|
|
735
|
+
def settings
|
|
736
|
+
@properties['settings']
|
|
737
|
+
end
|
|
738
|
+
|
|
739
|
+
##
|
|
740
|
+
# @return [Time]
|
|
741
|
+
def created_at
|
|
742
|
+
@properties['created_at']
|
|
743
|
+
end
|
|
744
|
+
|
|
745
|
+
##
|
|
746
|
+
# @return [Time]
|
|
747
|
+
def updated_at
|
|
748
|
+
@properties['updated_at']
|
|
749
|
+
end
|
|
750
|
+
|
|
751
|
+
##
|
|
752
|
+
# @return [String] URL prefix to match. Must be unique - only one rule per prefix allowed. Example: 'https://api.example.com/webhooks/'
|
|
753
|
+
def prefix
|
|
754
|
+
@properties['prefix']
|
|
755
|
+
end
|
|
756
|
+
|
|
757
|
+
##
|
|
758
|
+
# @return [String] Exact URL to match. Must be unique - only one rule per value allowed. Example: 'https://api.example.com/webhooks/voice/incoming'
|
|
759
|
+
def value
|
|
760
|
+
@properties['value']
|
|
761
|
+
end
|
|
762
|
+
|
|
763
|
+
##
|
|
764
|
+
# Delete the RuleInstance
|
|
765
|
+
# @param [String] idempotency_key Idempotency key for mutation operations. Must be a UUIDv7 (other UUID versions are rejected with a 400).
|
|
766
|
+
# @return [Boolean] True if delete succeeds, false otherwise
|
|
767
|
+
def delete(
|
|
768
|
+
idempotency_key: :unset
|
|
769
|
+
)
|
|
770
|
+
|
|
771
|
+
context.delete(
|
|
772
|
+
idempotency_key: idempotency_key,
|
|
773
|
+
)
|
|
774
|
+
end
|
|
775
|
+
|
|
776
|
+
##
|
|
777
|
+
# Fetch the RuleInstance
|
|
778
|
+
# @return [RuleInstance] Fetched RuleInstance
|
|
779
|
+
def fetch
|
|
780
|
+
|
|
781
|
+
context.fetch
|
|
782
|
+
end
|
|
783
|
+
|
|
784
|
+
##
|
|
785
|
+
# Patch the RuleInstance
|
|
786
|
+
# @param [String] idempotency_key Idempotency key for mutation operations. Must be a UUIDv7 (other UUID versions are rejected with a 400).
|
|
787
|
+
# @param [PatchRule] patch_rule
|
|
788
|
+
# @return [RuleInstance] Patched RuleInstance
|
|
789
|
+
def patch(
|
|
790
|
+
idempotency_key: :unset,
|
|
791
|
+
patch_rule: nil
|
|
792
|
+
)
|
|
793
|
+
|
|
794
|
+
context.patch(
|
|
795
|
+
idempotency_key: idempotency_key,
|
|
796
|
+
patch_rule: patch_rule,
|
|
797
|
+
)
|
|
798
|
+
end
|
|
799
|
+
|
|
800
|
+
##
|
|
801
|
+
# Provide a user friendly representation
|
|
802
|
+
def to_s
|
|
803
|
+
values = @params.map{|k, v| "#{k}: #{v}"}.join(" ")
|
|
804
|
+
"<Twilio.Webhooks.V1.RuleInstance #{values}>"
|
|
805
|
+
end
|
|
806
|
+
|
|
807
|
+
##
|
|
808
|
+
# Provide a detailed, user friendly representation
|
|
809
|
+
def inspect
|
|
810
|
+
values = @properties.map{|k, v| "#{k}: #{v}"}.join(" ")
|
|
811
|
+
"<Twilio.Webhooks.V1.RuleInstance #{values}>"
|
|
812
|
+
end
|
|
813
|
+
end
|
|
814
|
+
|
|
815
|
+
end
|
|
816
|
+
end
|
|
817
|
+
end
|
|
818
|
+
end
|