twilio-ruby 5.19.0 → 5.20.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (76) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGES.md +13 -0
  3. data/README.md +2 -2
  4. data/lib/twilio-ruby/rest/api.rb +16 -13
  5. data/lib/twilio-ruby/rest/api/v2010/account/address.rb +85 -88
  6. data/lib/twilio-ruby/rest/api/v2010/account/address/dependent_phone_number.rb +4 -4
  7. data/lib/twilio-ruby/rest/api/v2010/account/application.rb +135 -146
  8. data/lib/twilio-ruby/rest/api/v2010/account/authorized_connect_app.rb +21 -17
  9. data/lib/twilio-ruby/rest/api/v2010/account/available_phone_number.rb +14 -8
  10. data/lib/twilio-ruby/rest/api/v2010/account/available_phone_number/local.rb +150 -166
  11. data/lib/twilio-ruby/rest/api/v2010/account/available_phone_number/machine_to_machine.rb +174 -79
  12. data/lib/twilio-ruby/rest/api/v2010/account/available_phone_number/mobile.rb +147 -160
  13. data/lib/twilio-ruby/rest/api/v2010/account/available_phone_number/national.rb +174 -79
  14. data/lib/twilio-ruby/rest/api/v2010/account/available_phone_number/shared_cost.rb +174 -79
  15. data/lib/twilio-ruby/rest/api/v2010/account/available_phone_number/toll_free.rb +147 -160
  16. data/lib/twilio-ruby/rest/api/v2010/account/available_phone_number/voip.rb +174 -79
  17. data/lib/twilio-ruby/rest/api/v2010/account/connect_app.rb +51 -51
  18. data/lib/twilio-ruby/rest/api/v2010/account/incoming_phone_number.rb +246 -251
  19. data/lib/twilio-ruby/rest/api/v2010/account/incoming_phone_number/assigned_add_on.rb +31 -26
  20. data/lib/twilio-ruby/rest/api/v2010/account/incoming_phone_number/assigned_add_on/assigned_add_on_extension.rb +34 -26
  21. data/lib/twilio-ruby/rest/api/v2010/account/incoming_phone_number/local.rb +109 -112
  22. data/lib/twilio-ruby/rest/api/v2010/account/incoming_phone_number/mobile.rb +108 -112
  23. data/lib/twilio-ruby/rest/api/v2010/account/incoming_phone_number/toll_free.rb +108 -112
  24. data/lib/twilio-ruby/rest/api/v2010/account/message/feedback.rb +21 -11
  25. data/lib/twilio-ruby/rest/api/v2010/account/new_key.rb +7 -6
  26. data/lib/twilio-ruby/rest/api/v2010/account/new_signing_key.rb +7 -6
  27. data/lib/twilio-ruby/rest/api/v2010/account/notification.rb +32 -25
  28. data/lib/twilio-ruby/rest/api/v2010/account/outgoing_caller_id.rb +36 -36
  29. data/lib/twilio-ruby/rest/api/v2010/account/sip.rb +2 -1
  30. data/lib/twilio-ruby/rest/api/v2010/account/sip/domain.rb +70 -66
  31. data/lib/twilio-ruby/rest/api/v2010/account/sip/domain/auth_types.rb +10 -10
  32. data/lib/twilio-ruby/rest/api/v2010/account/sip/domain/auth_types/auth_calls_mapping.rb +14 -14
  33. data/lib/twilio-ruby/rest/api/v2010/account/sip/domain/auth_types/auth_calls_mapping/auth_calls_credential_list_mapping.rb +26 -23
  34. data/lib/twilio-ruby/rest/api/v2010/account/sip/domain/auth_types/auth_calls_mapping/auth_calls_ip_access_control_list_mapping.rb +26 -23
  35. data/lib/twilio-ruby/rest/api/v2010/account/sip/domain/auth_types/auth_registrations_mapping.rb +12 -12
  36. data/lib/twilio-ruby/rest/api/v2010/account/sip/domain/auth_types/auth_registrations_mapping/auth_registrations_credential_list_mapping.rb +26 -23
  37. data/lib/twilio-ruby/rest/api/v2010/account/sip/domain/credential_list_mapping.rb +4 -4
  38. data/lib/twilio-ruby/rest/api/v2010/account/sip/domain/ip_access_control_list_mapping.rb +4 -4
  39. data/lib/twilio-ruby/rest/api/v2010/account/token.rb +11 -9
  40. data/lib/twilio-ruby/rest/api/v2010/account/usage.rb +2 -1
  41. data/lib/twilio-ruby/rest/api/v2010/account/usage/record.rb +56 -47
  42. data/lib/twilio-ruby/rest/api/v2010/account/usage/record/all_time.rb +59 -44
  43. data/lib/twilio-ruby/rest/api/v2010/account/usage/record/daily.rb +59 -44
  44. data/lib/twilio-ruby/rest/api/v2010/account/usage/record/last_month.rb +59 -47
  45. data/lib/twilio-ruby/rest/api/v2010/account/usage/record/monthly.rb +59 -44
  46. data/lib/twilio-ruby/rest/api/v2010/account/usage/record/this_month.rb +59 -44
  47. data/lib/twilio-ruby/rest/api/v2010/account/usage/record/today.rb +59 -44
  48. data/lib/twilio-ruby/rest/api/v2010/account/usage/record/yearly.rb +59 -44
  49. data/lib/twilio-ruby/rest/api/v2010/account/usage/record/yesterday.rb +59 -44
  50. data/lib/twilio-ruby/rest/api/v2010/account/usage/trigger.rb +76 -74
  51. data/lib/twilio-ruby/rest/authy.rb +8 -8
  52. data/lib/twilio-ruby/rest/authy/v1.rb +15 -15
  53. data/lib/twilio-ruby/rest/client.rb +16 -13
  54. data/lib/twilio-ruby/rest/messaging.rb +15 -0
  55. data/lib/twilio-ruby/rest/messaging/v1.rb +23 -0
  56. data/lib/twilio-ruby/rest/messaging/v1/session.rb +482 -0
  57. data/lib/twilio-ruby/rest/messaging/v1/session/message.rb +434 -0
  58. data/lib/twilio-ruby/rest/messaging/v1/session/participant.rb +458 -0
  59. data/lib/twilio-ruby/rest/messaging/v1/webhook.rb +285 -0
  60. data/lib/twilio-ruby/rest/preview.rb +8 -8
  61. data/lib/twilio-ruby/rest/preview/marketplace.rb +13 -13
  62. data/lib/twilio-ruby/rest/proxy/v1/service/session.rb +3 -2
  63. data/lib/twilio-ruby/rest/video.rb +9 -9
  64. data/lib/twilio-ruby/rest/video/v1.rb +16 -16
  65. data/lib/twilio-ruby/rest/video/v1/composition.rb +7 -6
  66. data/lib/twilio-ruby/rest/video/v1/composition_hook.rb +37 -21
  67. data/lib/twilio-ruby/rest/video/v1/recording.rb +12 -3
  68. data/lib/twilio-ruby/security/request_validator.rb +2 -2
  69. data/lib/twilio-ruby/version.rb +1 -1
  70. data/spec/integration/messaging/v1/session/message_spec.rb +238 -0
  71. data/spec/integration/messaging/v1/session/participant_spec.rb +256 -0
  72. data/spec/integration/messaging/v1/session_spec.rb +223 -0
  73. data/spec/integration/messaging/v1/webhook_spec.rb +92 -0
  74. data/spec/integration/video/v1/composition_hook_spec.rb +1 -1
  75. data/spec/security/request_validator_spec.rb +5 -7
  76. metadata +14 -2
@@ -0,0 +1,434 @@
1
+ ##
2
+ # This code was generated by
3
+ # \ / _ _ _| _ _
4
+ # | (_)\/(_)(_|\/| |(/_ v1.0.0
5
+ # / /
6
+ #
7
+ # frozen_string_literal: true
8
+
9
+ module Twilio
10
+ module REST
11
+ class Messaging < Domain
12
+ class V1 < Version
13
+ class SessionContext < InstanceContext
14
+ ##
15
+ # PLEASE NOTE that this class contains preview products that are subject to change. Use them with caution. If you currently do not have developer preview access, please contact help@twilio.com.
16
+ class MessageList < ListResource
17
+ ##
18
+ # Initialize the MessageList
19
+ # @param [Version] version Version that contains the resource
20
+ # @param [String] session_sid The unique id of the
21
+ # [Session](https://www.twilio.com/docs/sessions/api/session) for this message.
22
+ # @return [MessageList] MessageList
23
+ def initialize(version, session_sid: nil)
24
+ super(version)
25
+
26
+ # Path Solution
27
+ @solution = {session_sid: session_sid}
28
+ @uri = "/Sessions/#{@solution[:session_sid]}/Messages"
29
+ end
30
+
31
+ ##
32
+ # Retrieve a single page of MessageInstance records from the API.
33
+ # Request is executed immediately.
34
+ # @param [String] author The
35
+ # [identity](https://www.twilio.com/docs/api/chat/guides/identity) of the
36
+ # message's author. Defaults to `system`.
37
+ # @param [String] attributes A string metadata field you can use to store any data
38
+ # you wish. The string value must contain structurally valid JSON if specified.
39
+ # @param [Time] date_created The date that this resource was created.
40
+ # @param [Time] date_updated The date that this resource was last updated. `null`
41
+ # if the message has not been edited.
42
+ # @param [String] body The contents of the message.
43
+ # @return [MessageInstance] Newly created MessageInstance
44
+ def create(author: :unset, attributes: :unset, date_created: :unset, date_updated: :unset, body: :unset)
45
+ data = Twilio::Values.of({
46
+ 'Author' => author,
47
+ 'Attributes' => attributes,
48
+ 'DateCreated' => Twilio.serialize_iso8601_datetime(date_created),
49
+ 'DateUpdated' => Twilio.serialize_iso8601_datetime(date_updated),
50
+ 'Body' => body,
51
+ })
52
+
53
+ payload = @version.create(
54
+ 'POST',
55
+ @uri,
56
+ data: data
57
+ )
58
+
59
+ MessageInstance.new(@version, payload, session_sid: @solution[:session_sid], )
60
+ end
61
+
62
+ ##
63
+ # Lists MessageInstance records from the API as a list.
64
+ # Unlike stream(), this operation is eager and will load `limit` records into
65
+ # memory before returning.
66
+ # @param [Integer] limit Upper limit for the number of records to return. stream()
67
+ # guarantees to never return more than limit. Default is no limit
68
+ # @param [Integer] page_size Number of records to fetch per request, when
69
+ # not set will use the default value of 50 records. If no page_size is defined
70
+ # but a limit is defined, stream() will attempt to read the limit with the most
71
+ # efficient page size, i.e. min(limit, 1000)
72
+ # @return [Array] Array of up to limit results
73
+ def list(limit: nil, page_size: nil)
74
+ self.stream(limit: limit, page_size: page_size).entries
75
+ end
76
+
77
+ ##
78
+ # Streams MessageInstance records from the API as an Enumerable.
79
+ # This operation lazily loads records as efficiently as possible until the limit
80
+ # is reached.
81
+ # @param [Integer] limit Upper limit for the number of records to return. stream()
82
+ # guarantees to never return more than limit. Default is no limit.
83
+ # @param [Integer] page_size Number of records to fetch per request, when
84
+ # not set will use the default value of 50 records. If no page_size is defined
85
+ # but a limit is defined, stream() will attempt to read the limit with the most
86
+ # efficient page size, i.e. min(limit, 1000)
87
+ # @return [Enumerable] Enumerable that will yield up to limit results
88
+ def stream(limit: nil, page_size: nil)
89
+ limits = @version.read_limits(limit, page_size)
90
+
91
+ page = self.page(page_size: limits[:page_size], )
92
+
93
+ @version.stream(page, limit: limits[:limit], page_limit: limits[:page_limit])
94
+ end
95
+
96
+ ##
97
+ # When passed a block, yields MessageInstance records from the API.
98
+ # This operation lazily loads records as efficiently as possible until the limit
99
+ # is reached.
100
+ def each
101
+ limits = @version.read_limits
102
+
103
+ page = self.page(page_size: limits[:page_size], )
104
+
105
+ @version.stream(page,
106
+ limit: limits[:limit],
107
+ page_limit: limits[:page_limit]).each {|x| yield x}
108
+ end
109
+
110
+ ##
111
+ # Retrieve a single page of MessageInstance records from the API.
112
+ # Request is executed immediately.
113
+ # @param [String] page_token PageToken provided by the API
114
+ # @param [Integer] page_number Page Number, this value is simply for client state
115
+ # @param [Integer] page_size Number of records to return, defaults to 50
116
+ # @return [Page] Page of MessageInstance
117
+ def page(page_token: :unset, page_number: :unset, page_size: :unset)
118
+ params = Twilio::Values.of({
119
+ 'PageToken' => page_token,
120
+ 'Page' => page_number,
121
+ 'PageSize' => page_size,
122
+ })
123
+ response = @version.page(
124
+ 'GET',
125
+ @uri,
126
+ params
127
+ )
128
+ MessagePage.new(@version, response, @solution)
129
+ end
130
+
131
+ ##
132
+ # Retrieve a single page of MessageInstance records from the API.
133
+ # Request is executed immediately.
134
+ # @param [String] target_url API-generated URL for the requested results page
135
+ # @return [Page] Page of MessageInstance
136
+ def get_page(target_url)
137
+ response = @version.domain.request(
138
+ 'GET',
139
+ target_url
140
+ )
141
+ MessagePage.new(@version, response, @solution)
142
+ end
143
+
144
+ ##
145
+ # Provide a user friendly representation
146
+ def to_s
147
+ '#<Twilio.Messaging.V1.MessageList>'
148
+ end
149
+ end
150
+
151
+ ##
152
+ # PLEASE NOTE that this class contains preview products that are subject to change. Use them with caution. If you currently do not have developer preview access, please contact help@twilio.com.
153
+ class MessagePage < Page
154
+ ##
155
+ # Initialize the MessagePage
156
+ # @param [Version] version Version that contains the resource
157
+ # @param [Response] response Response from the API
158
+ # @param [Hash] solution Path solution for the resource
159
+ # @return [MessagePage] MessagePage
160
+ def initialize(version, response, solution)
161
+ super(version, response)
162
+
163
+ # Path Solution
164
+ @solution = solution
165
+ end
166
+
167
+ ##
168
+ # Build an instance of MessageInstance
169
+ # @param [Hash] payload Payload response from the API
170
+ # @return [MessageInstance] MessageInstance
171
+ def get_instance(payload)
172
+ MessageInstance.new(@version, payload, session_sid: @solution[:session_sid], )
173
+ end
174
+
175
+ ##
176
+ # Provide a user friendly representation
177
+ def to_s
178
+ '<Twilio.Messaging.V1.MessagePage>'
179
+ end
180
+ end
181
+
182
+ ##
183
+ # PLEASE NOTE that this class contains preview products that are subject to change. Use them with caution. If you currently do not have developer preview access, please contact help@twilio.com.
184
+ class MessageContext < InstanceContext
185
+ ##
186
+ # Initialize the MessageContext
187
+ # @param [Version] version Version that contains the resource
188
+ # @param [String] session_sid The unique id of the
189
+ # [Session](https://www.twilio.com/docs/sessions/api/session) for this message.
190
+ # @param [String] sid A 34 character string that uniquely identifies this
191
+ # resource.
192
+ # @return [MessageContext] MessageContext
193
+ def initialize(version, session_sid, sid)
194
+ super(version)
195
+
196
+ # Path Solution
197
+ @solution = {session_sid: session_sid, sid: sid, }
198
+ @uri = "/Sessions/#{@solution[:session_sid]}/Messages/#{@solution[:sid]}"
199
+ end
200
+
201
+ ##
202
+ # Fetch a MessageInstance
203
+ # @return [MessageInstance] Fetched MessageInstance
204
+ def fetch
205
+ params = Twilio::Values.of({})
206
+
207
+ payload = @version.fetch(
208
+ 'GET',
209
+ @uri,
210
+ params,
211
+ )
212
+
213
+ MessageInstance.new(@version, payload, session_sid: @solution[:session_sid], sid: @solution[:sid], )
214
+ end
215
+
216
+ ##
217
+ # Update the MessageInstance
218
+ # @param [String] author The
219
+ # [identity](https://www.twilio.com/docs/api/chat/guides/identity) of the
220
+ # message's author. Defaults to `system`.
221
+ # @param [String] attributes A string metadata field you can use to store any data
222
+ # you wish. The string value must contain structurally valid JSON if specified.
223
+ # @param [Time] date_created The date that this resource was created.
224
+ # @param [Time] date_updated The date that this resource was last updated. `null`
225
+ # if the message has not been edited.
226
+ # @param [String] body The contents of the message.
227
+ # @return [MessageInstance] Updated MessageInstance
228
+ def update(author: :unset, attributes: :unset, date_created: :unset, date_updated: :unset, body: :unset)
229
+ data = Twilio::Values.of({
230
+ 'Author' => author,
231
+ 'Attributes' => attributes,
232
+ 'DateCreated' => Twilio.serialize_iso8601_datetime(date_created),
233
+ 'DateUpdated' => Twilio.serialize_iso8601_datetime(date_updated),
234
+ 'Body' => body,
235
+ })
236
+
237
+ payload = @version.update(
238
+ 'POST',
239
+ @uri,
240
+ data: data,
241
+ )
242
+
243
+ MessageInstance.new(@version, payload, session_sid: @solution[:session_sid], sid: @solution[:sid], )
244
+ end
245
+
246
+ ##
247
+ # Deletes the MessageInstance
248
+ # @return [Boolean] true if delete succeeds, true otherwise
249
+ def delete
250
+ @version.delete('delete', @uri)
251
+ end
252
+
253
+ ##
254
+ # Provide a user friendly representation
255
+ def to_s
256
+ context = @solution.map {|k, v| "#{k}: #{v}"}.join(',')
257
+ "#<Twilio.Messaging.V1.MessageContext #{context}>"
258
+ end
259
+ end
260
+
261
+ ##
262
+ # PLEASE NOTE that this class contains preview products that are subject to change. Use them with caution. If you currently do not have developer preview access, please contact help@twilio.com.
263
+ class MessageInstance < InstanceResource
264
+ ##
265
+ # Initialize the MessageInstance
266
+ # @param [Version] version Version that contains the resource
267
+ # @param [Hash] payload payload that contains response from Twilio
268
+ # @param [String] session_sid The unique id of the
269
+ # [Session](https://www.twilio.com/docs/sessions/api/session) for this message.
270
+ # @param [String] sid A 34 character string that uniquely identifies this
271
+ # resource.
272
+ # @return [MessageInstance] MessageInstance
273
+ def initialize(version, payload, session_sid: nil, sid: nil)
274
+ super(version)
275
+
276
+ # Marshaled Properties
277
+ @properties = {
278
+ 'account_sid' => payload['account_sid'],
279
+ 'service_sid' => payload['service_sid'],
280
+ 'messaging_service_sid' => payload['messaging_service_sid'],
281
+ 'session_sid' => payload['session_sid'],
282
+ 'sid' => payload['sid'],
283
+ 'index' => payload['index'].to_i,
284
+ 'author' => payload['author'],
285
+ 'body' => payload['body'],
286
+ 'attributes' => payload['attributes'],
287
+ 'date_created' => Twilio.deserialize_iso8601_datetime(payload['date_created']),
288
+ 'date_updated' => Twilio.deserialize_iso8601_datetime(payload['date_updated']),
289
+ 'url' => payload['url'],
290
+ }
291
+
292
+ # Context
293
+ @instance_context = nil
294
+ @params = {'session_sid' => session_sid, 'sid' => sid || @properties['sid'], }
295
+ end
296
+
297
+ ##
298
+ # Generate an instance context for the instance, the context is capable of
299
+ # performing various actions. All instance actions are proxied to the context
300
+ # @return [MessageContext] MessageContext for this MessageInstance
301
+ def context
302
+ unless @instance_context
303
+ @instance_context = MessageContext.new(@version, @params['session_sid'], @params['sid'], )
304
+ end
305
+ @instance_context
306
+ end
307
+
308
+ ##
309
+ # @return [String] The unique id of the Account responsible for this message.
310
+ def account_sid
311
+ @properties['account_sid']
312
+ end
313
+
314
+ ##
315
+ # @return [String] The unique id of the Chat Service this message belongs to.
316
+ def service_sid
317
+ @properties['service_sid']
318
+ end
319
+
320
+ ##
321
+ # @return [String] The unique id of the SMS Service this message belongs to.
322
+ def messaging_service_sid
323
+ @properties['messaging_service_sid']
324
+ end
325
+
326
+ ##
327
+ # @return [String] The unique id of the Session for this message.
328
+ def session_sid
329
+ @properties['session_sid']
330
+ end
331
+
332
+ ##
333
+ # @return [String] A 34 character string that uniquely identifies this resource.
334
+ def sid
335
+ @properties['sid']
336
+ end
337
+
338
+ ##
339
+ # @return [String] The index of the message within the Session
340
+ def index
341
+ @properties['index']
342
+ end
343
+
344
+ ##
345
+ # @return [String] The identity or the address of the device of the message's author.
346
+ def author
347
+ @properties['author']
348
+ end
349
+
350
+ ##
351
+ # @return [String] The contents of the message.
352
+ def body
353
+ @properties['body']
354
+ end
355
+
356
+ ##
357
+ # @return [String] A string metadata field you can use to store any data you wish.
358
+ def attributes
359
+ @properties['attributes']
360
+ end
361
+
362
+ ##
363
+ # @return [Time] The date that this resource was created.
364
+ def date_created
365
+ @properties['date_created']
366
+ end
367
+
368
+ ##
369
+ # @return [Time] The date that this resource was last updated.
370
+ def date_updated
371
+ @properties['date_updated']
372
+ end
373
+
374
+ ##
375
+ # @return [String] An absolute URL for this message.
376
+ def url
377
+ @properties['url']
378
+ end
379
+
380
+ ##
381
+ # Fetch a MessageInstance
382
+ # @return [MessageInstance] Fetched MessageInstance
383
+ def fetch
384
+ context.fetch
385
+ end
386
+
387
+ ##
388
+ # Update the MessageInstance
389
+ # @param [String] author The
390
+ # [identity](https://www.twilio.com/docs/api/chat/guides/identity) of the
391
+ # message's author. Defaults to `system`.
392
+ # @param [String] attributes A string metadata field you can use to store any data
393
+ # you wish. The string value must contain structurally valid JSON if specified.
394
+ # @param [Time] date_created The date that this resource was created.
395
+ # @param [Time] date_updated The date that this resource was last updated. `null`
396
+ # if the message has not been edited.
397
+ # @param [String] body The contents of the message.
398
+ # @return [MessageInstance] Updated MessageInstance
399
+ def update(author: :unset, attributes: :unset, date_created: :unset, date_updated: :unset, body: :unset)
400
+ context.update(
401
+ author: author,
402
+ attributes: attributes,
403
+ date_created: date_created,
404
+ date_updated: date_updated,
405
+ body: body,
406
+ )
407
+ end
408
+
409
+ ##
410
+ # Deletes the MessageInstance
411
+ # @return [Boolean] true if delete succeeds, true otherwise
412
+ def delete
413
+ context.delete
414
+ end
415
+
416
+ ##
417
+ # Provide a user friendly representation
418
+ def to_s
419
+ values = @params.map{|k, v| "#{k}: #{v}"}.join(" ")
420
+ "<Twilio.Messaging.V1.MessageInstance #{values}>"
421
+ end
422
+
423
+ ##
424
+ # Provide a detailed, user friendly representation
425
+ def inspect
426
+ values = @properties.map{|k, v| "#{k}: #{v}"}.join(" ")
427
+ "<Twilio.Messaging.V1.MessageInstance #{values}>"
428
+ end
429
+ end
430
+ end
431
+ end
432
+ end
433
+ end
434
+ end
@@ -0,0 +1,458 @@
1
+ ##
2
+ # This code was generated by
3
+ # \ / _ _ _| _ _
4
+ # | (_)\/(_)(_|\/| |(/_ v1.0.0
5
+ # / /
6
+ #
7
+ # frozen_string_literal: true
8
+
9
+ module Twilio
10
+ module REST
11
+ class Messaging < Domain
12
+ class V1 < Version
13
+ class SessionContext < InstanceContext
14
+ ##
15
+ # PLEASE NOTE that this class contains preview products that are subject to change. Use them with caution. If you currently do not have developer preview access, please contact help@twilio.com.
16
+ class ParticipantList < ListResource
17
+ ##
18
+ # Initialize the ParticipantList
19
+ # @param [Version] version Version that contains the resource
20
+ # @param [String] session_sid The unique id of the
21
+ # [Session](https://www.twilio.com/docs/sessions/api/session) for this
22
+ # participant.
23
+ # @return [ParticipantList] ParticipantList
24
+ def initialize(version, session_sid: nil)
25
+ super(version)
26
+
27
+ # Path Solution
28
+ @solution = {session_sid: session_sid}
29
+ @uri = "/Sessions/#{@solution[:session_sid]}/Participants"
30
+ end
31
+
32
+ ##
33
+ # Retrieve a single page of ParticipantInstance records from the API.
34
+ # Request is executed immediately.
35
+ # @param [String] attributes An optional string metadata field you can use to
36
+ # store any data you wish. The string value must contain structurally valid JSON
37
+ # if specified. **Note** that if the attributes are not set "{}" will be
38
+ # returned.
39
+ # @param [String] twilio_address The address of the Twilio phone number (or
40
+ # WhatsApp number, or Messenger Page ID) that the participant is in contact with.
41
+ # This field, together with user_address, is only null when the participant is
42
+ # interacting from a Chat endpoint (see the 'identity' field).
43
+ # @param [Time] date_created The date that this resource was created. This is most
44
+ # often useful when bulk-importing messages from another system, as the provided
45
+ # value will be trusted and displayed on SDK clients.
46
+ # @param [Time] date_updated The date that this resource was last updated. This is
47
+ # most often provided when bulk-importing messages from another system, as the
48
+ # provided value will be trusted and displayed on SDK clients.
49
+ # @param [String] identity A unique string identifier for the session participant
50
+ # as [Chat User](https://www.twilio.com/docs/api/chat/rest/users). This parameter
51
+ # is non-null if (and only if) the participant is using the Programmable Chat SDK
52
+ # to communicate.
53
+ # @param [String] user_address The address of the participant's device, e.g. a
54
+ # phone number or Messenger ID. Together with the Twilio Address, this determines
55
+ # a participant uniquely. This field (with twilio_address) is only null when the
56
+ # participant is interacting from a Chat endpoint (see the 'identity' field).
57
+ # @return [ParticipantInstance] Newly created ParticipantInstance
58
+ def create(attributes: :unset, twilio_address: :unset, date_created: :unset, date_updated: :unset, identity: :unset, user_address: :unset)
59
+ data = Twilio::Values.of({
60
+ 'Identity' => identity,
61
+ 'UserAddress' => user_address,
62
+ 'Attributes' => attributes,
63
+ 'TwilioAddress' => twilio_address,
64
+ 'DateCreated' => Twilio.serialize_iso8601_datetime(date_created),
65
+ 'DateUpdated' => Twilio.serialize_iso8601_datetime(date_updated),
66
+ })
67
+
68
+ payload = @version.create(
69
+ 'POST',
70
+ @uri,
71
+ data: data
72
+ )
73
+
74
+ ParticipantInstance.new(@version, payload, session_sid: @solution[:session_sid], )
75
+ end
76
+
77
+ ##
78
+ # Lists ParticipantInstance records from the API as a list.
79
+ # Unlike stream(), this operation is eager and will load `limit` records into
80
+ # memory before returning.
81
+ # @param [Integer] limit Upper limit for the number of records to return. stream()
82
+ # guarantees to never return more than limit. Default is no limit
83
+ # @param [Integer] page_size Number of records to fetch per request, when
84
+ # not set will use the default value of 50 records. If no page_size is defined
85
+ # but a limit is defined, stream() will attempt to read the limit with the most
86
+ # efficient page size, i.e. min(limit, 1000)
87
+ # @return [Array] Array of up to limit results
88
+ def list(limit: nil, page_size: nil)
89
+ self.stream(limit: limit, page_size: page_size).entries
90
+ end
91
+
92
+ ##
93
+ # Streams ParticipantInstance records from the API as an Enumerable.
94
+ # This operation lazily loads records as efficiently as possible until the limit
95
+ # is reached.
96
+ # @param [Integer] limit Upper limit for the number of records to return. stream()
97
+ # guarantees to never return more than limit. Default is no limit.
98
+ # @param [Integer] page_size Number of records to fetch per request, when
99
+ # not set will use the default value of 50 records. If no page_size is defined
100
+ # but a limit is defined, stream() will attempt to read the limit with the most
101
+ # efficient page size, i.e. min(limit, 1000)
102
+ # @return [Enumerable] Enumerable that will yield up to limit results
103
+ def stream(limit: nil, page_size: nil)
104
+ limits = @version.read_limits(limit, page_size)
105
+
106
+ page = self.page(page_size: limits[:page_size], )
107
+
108
+ @version.stream(page, limit: limits[:limit], page_limit: limits[:page_limit])
109
+ end
110
+
111
+ ##
112
+ # When passed a block, yields ParticipantInstance records from the API.
113
+ # This operation lazily loads records as efficiently as possible until the limit
114
+ # is reached.
115
+ def each
116
+ limits = @version.read_limits
117
+
118
+ page = self.page(page_size: limits[:page_size], )
119
+
120
+ @version.stream(page,
121
+ limit: limits[:limit],
122
+ page_limit: limits[:page_limit]).each {|x| yield x}
123
+ end
124
+
125
+ ##
126
+ # Retrieve a single page of ParticipantInstance records from the API.
127
+ # Request is executed immediately.
128
+ # @param [String] page_token PageToken provided by the API
129
+ # @param [Integer] page_number Page Number, this value is simply for client state
130
+ # @param [Integer] page_size Number of records to return, defaults to 50
131
+ # @return [Page] Page of ParticipantInstance
132
+ def page(page_token: :unset, page_number: :unset, page_size: :unset)
133
+ params = Twilio::Values.of({
134
+ 'PageToken' => page_token,
135
+ 'Page' => page_number,
136
+ 'PageSize' => page_size,
137
+ })
138
+ response = @version.page(
139
+ 'GET',
140
+ @uri,
141
+ params
142
+ )
143
+ ParticipantPage.new(@version, response, @solution)
144
+ end
145
+
146
+ ##
147
+ # Retrieve a single page of ParticipantInstance records from the API.
148
+ # Request is executed immediately.
149
+ # @param [String] target_url API-generated URL for the requested results page
150
+ # @return [Page] Page of ParticipantInstance
151
+ def get_page(target_url)
152
+ response = @version.domain.request(
153
+ 'GET',
154
+ target_url
155
+ )
156
+ ParticipantPage.new(@version, response, @solution)
157
+ end
158
+
159
+ ##
160
+ # Provide a user friendly representation
161
+ def to_s
162
+ '#<Twilio.Messaging.V1.ParticipantList>'
163
+ end
164
+ end
165
+
166
+ ##
167
+ # PLEASE NOTE that this class contains preview products that are subject to change. Use them with caution. If you currently do not have developer preview access, please contact help@twilio.com.
168
+ class ParticipantPage < Page
169
+ ##
170
+ # Initialize the ParticipantPage
171
+ # @param [Version] version Version that contains the resource
172
+ # @param [Response] response Response from the API
173
+ # @param [Hash] solution Path solution for the resource
174
+ # @return [ParticipantPage] ParticipantPage
175
+ def initialize(version, response, solution)
176
+ super(version, response)
177
+
178
+ # Path Solution
179
+ @solution = solution
180
+ end
181
+
182
+ ##
183
+ # Build an instance of ParticipantInstance
184
+ # @param [Hash] payload Payload response from the API
185
+ # @return [ParticipantInstance] ParticipantInstance
186
+ def get_instance(payload)
187
+ ParticipantInstance.new(@version, payload, session_sid: @solution[:session_sid], )
188
+ end
189
+
190
+ ##
191
+ # Provide a user friendly representation
192
+ def to_s
193
+ '<Twilio.Messaging.V1.ParticipantPage>'
194
+ end
195
+ end
196
+
197
+ ##
198
+ # PLEASE NOTE that this class contains preview products that are subject to change. Use them with caution. If you currently do not have developer preview access, please contact help@twilio.com.
199
+ class ParticipantContext < InstanceContext
200
+ ##
201
+ # Initialize the ParticipantContext
202
+ # @param [Version] version Version that contains the resource
203
+ # @param [String] session_sid The unique id of the
204
+ # [Session](https://www.twilio.com/docs/sessions/api/session) for this
205
+ # participant.
206
+ # @param [String] sid A 34 character string that uniquely identifies this
207
+ # resource.
208
+ # @return [ParticipantContext] ParticipantContext
209
+ def initialize(version, session_sid, sid)
210
+ super(version)
211
+
212
+ # Path Solution
213
+ @solution = {session_sid: session_sid, sid: sid, }
214
+ @uri = "/Sessions/#{@solution[:session_sid]}/Participants/#{@solution[:sid]}"
215
+ end
216
+
217
+ ##
218
+ # Update the ParticipantInstance
219
+ # @param [String] attributes An optional string metadata field you can use to
220
+ # store any data you wish. The string value must contain structurally valid JSON
221
+ # if specified. **Note** that if the attributes are not set "{}" will be
222
+ # returned.
223
+ # @param [Time] date_created The date that this resource was created. This is
224
+ # useful when bulk-importing messages from another system, as the provided value
225
+ # will be trusted and displayed on SDK clients.
226
+ # @param [Time] date_updated The date that this resource was last updated.
227
+ # @return [ParticipantInstance] Updated ParticipantInstance
228
+ def update(attributes: :unset, date_created: :unset, date_updated: :unset)
229
+ data = Twilio::Values.of({
230
+ 'Attributes' => attributes,
231
+ 'DateCreated' => Twilio.serialize_iso8601_datetime(date_created),
232
+ 'DateUpdated' => Twilio.serialize_iso8601_datetime(date_updated),
233
+ })
234
+
235
+ payload = @version.update(
236
+ 'POST',
237
+ @uri,
238
+ data: data,
239
+ )
240
+
241
+ ParticipantInstance.new(
242
+ @version,
243
+ payload,
244
+ session_sid: @solution[:session_sid],
245
+ sid: @solution[:sid],
246
+ )
247
+ end
248
+
249
+ ##
250
+ # Fetch a ParticipantInstance
251
+ # @return [ParticipantInstance] Fetched ParticipantInstance
252
+ def fetch
253
+ params = Twilio::Values.of({})
254
+
255
+ payload = @version.fetch(
256
+ 'GET',
257
+ @uri,
258
+ params,
259
+ )
260
+
261
+ ParticipantInstance.new(
262
+ @version,
263
+ payload,
264
+ session_sid: @solution[:session_sid],
265
+ sid: @solution[:sid],
266
+ )
267
+ end
268
+
269
+ ##
270
+ # Deletes the ParticipantInstance
271
+ # @return [Boolean] true if delete succeeds, true otherwise
272
+ def delete
273
+ @version.delete('delete', @uri)
274
+ end
275
+
276
+ ##
277
+ # Provide a user friendly representation
278
+ def to_s
279
+ context = @solution.map {|k, v| "#{k}: #{v}"}.join(',')
280
+ "#<Twilio.Messaging.V1.ParticipantContext #{context}>"
281
+ end
282
+ end
283
+
284
+ ##
285
+ # PLEASE NOTE that this class contains preview products that are subject to change. Use them with caution. If you currently do not have developer preview access, please contact help@twilio.com.
286
+ class ParticipantInstance < InstanceResource
287
+ ##
288
+ # Initialize the ParticipantInstance
289
+ # @param [Version] version Version that contains the resource
290
+ # @param [Hash] payload payload that contains response from Twilio
291
+ # @param [String] session_sid The unique id of the
292
+ # [Session](https://www.twilio.com/docs/sessions/api/session) for this
293
+ # participant.
294
+ # @param [String] sid A 34 character string that uniquely identifies this
295
+ # resource.
296
+ # @return [ParticipantInstance] ParticipantInstance
297
+ def initialize(version, payload, session_sid: nil, sid: nil)
298
+ super(version)
299
+
300
+ # Marshaled Properties
301
+ @properties = {
302
+ 'account_sid' => payload['account_sid'],
303
+ 'service_sid' => payload['service_sid'],
304
+ 'messaging_service_sid' => payload['messaging_service_sid'],
305
+ 'session_sid' => payload['session_sid'],
306
+ 'sid' => payload['sid'],
307
+ 'identity' => payload['identity'],
308
+ 'twilio_address' => payload['twilio_address'],
309
+ 'user_address' => payload['user_address'],
310
+ 'attributes' => payload['attributes'],
311
+ 'type' => payload['type'],
312
+ 'date_created' => Twilio.deserialize_iso8601_datetime(payload['date_created']),
313
+ 'date_updated' => Twilio.deserialize_iso8601_datetime(payload['date_updated']),
314
+ 'url' => payload['url'],
315
+ }
316
+
317
+ # Context
318
+ @instance_context = nil
319
+ @params = {'session_sid' => session_sid, 'sid' => sid || @properties['sid'], }
320
+ end
321
+
322
+ ##
323
+ # Generate an instance context for the instance, the context is capable of
324
+ # performing various actions. All instance actions are proxied to the context
325
+ # @return [ParticipantContext] ParticipantContext for this ParticipantInstance
326
+ def context
327
+ unless @instance_context
328
+ @instance_context = ParticipantContext.new(@version, @params['session_sid'], @params['sid'], )
329
+ end
330
+ @instance_context
331
+ end
332
+
333
+ ##
334
+ # @return [String] The unique id of the Account responsible for this session.
335
+ def account_sid
336
+ @properties['account_sid']
337
+ end
338
+
339
+ ##
340
+ # @return [String] The unique id of the Chat Service this session belongs to.
341
+ def service_sid
342
+ @properties['service_sid']
343
+ end
344
+
345
+ ##
346
+ # @return [String] The unique id of the SMS Service this session belongs to.
347
+ def messaging_service_sid
348
+ @properties['messaging_service_sid']
349
+ end
350
+
351
+ ##
352
+ # @return [String] The unique id of the Session for this participant.
353
+ def session_sid
354
+ @properties['session_sid']
355
+ end
356
+
357
+ ##
358
+ # @return [String] A 34 character string that uniquely identifies this resource.
359
+ def sid
360
+ @properties['sid']
361
+ end
362
+
363
+ ##
364
+ # @return [String] A unique string identifier for the session participant as Chat User.
365
+ def identity
366
+ @properties['identity']
367
+ end
368
+
369
+ ##
370
+ # @return [String] The address of the Twilio phone number that the participant is in contact with.
371
+ def twilio_address
372
+ @properties['twilio_address']
373
+ end
374
+
375
+ ##
376
+ # @return [String] The address of the participant's device.
377
+ def user_address
378
+ @properties['user_address']
379
+ end
380
+
381
+ ##
382
+ # @return [String] An optional string metadata field you can use to store any data you wish.
383
+ def attributes
384
+ @properties['attributes']
385
+ end
386
+
387
+ ##
388
+ # @return [participant.ParticipantType] The type of twilio product, participant is a user of.
389
+ def type
390
+ @properties['type']
391
+ end
392
+
393
+ ##
394
+ # @return [Time] The date that this resource was created.
395
+ def date_created
396
+ @properties['date_created']
397
+ end
398
+
399
+ ##
400
+ # @return [Time] The date that this resource was last updated.
401
+ def date_updated
402
+ @properties['date_updated']
403
+ end
404
+
405
+ ##
406
+ # @return [String] An absolute URL for this participant.
407
+ def url
408
+ @properties['url']
409
+ end
410
+
411
+ ##
412
+ # Update the ParticipantInstance
413
+ # @param [String] attributes An optional string metadata field you can use to
414
+ # store any data you wish. The string value must contain structurally valid JSON
415
+ # if specified. **Note** that if the attributes are not set "{}" will be
416
+ # returned.
417
+ # @param [Time] date_created The date that this resource was created. This is
418
+ # useful when bulk-importing messages from another system, as the provided value
419
+ # will be trusted and displayed on SDK clients.
420
+ # @param [Time] date_updated The date that this resource was last updated.
421
+ # @return [ParticipantInstance] Updated ParticipantInstance
422
+ def update(attributes: :unset, date_created: :unset, date_updated: :unset)
423
+ context.update(attributes: attributes, date_created: date_created, date_updated: date_updated, )
424
+ end
425
+
426
+ ##
427
+ # Fetch a ParticipantInstance
428
+ # @return [ParticipantInstance] Fetched ParticipantInstance
429
+ def fetch
430
+ context.fetch
431
+ end
432
+
433
+ ##
434
+ # Deletes the ParticipantInstance
435
+ # @return [Boolean] true if delete succeeds, true otherwise
436
+ def delete
437
+ context.delete
438
+ end
439
+
440
+ ##
441
+ # Provide a user friendly representation
442
+ def to_s
443
+ values = @params.map{|k, v| "#{k}: #{v}"}.join(" ")
444
+ "<Twilio.Messaging.V1.ParticipantInstance #{values}>"
445
+ end
446
+
447
+ ##
448
+ # Provide a detailed, user friendly representation
449
+ def inspect
450
+ values = @properties.map{|k, v| "#{k}: #{v}"}.join(" ")
451
+ "<Twilio.Messaging.V1.ParticipantInstance #{values}>"
452
+ end
453
+ end
454
+ end
455
+ end
456
+ end
457
+ end
458
+ end