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