twilio-ruby 5.14.1 → 5.15.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (80) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGES.md +33 -0
  3. data/README.md +2 -2
  4. data/lib/twilio-ruby/rest/api/v2010/account/call/recording.rb +2 -1
  5. data/lib/twilio-ruby/rest/authy.rb +55 -0
  6. data/lib/twilio-ruby/rest/authy/v1.rb +59 -0
  7. data/lib/twilio-ruby/rest/authy/v1/form.rb +190 -0
  8. data/lib/twilio-ruby/rest/authy/v1/service.rb +378 -0
  9. data/lib/twilio-ruby/rest/authy/v1/service/entity.rb +372 -0
  10. data/lib/twilio-ruby/rest/authy/v1/service/entity/factor.rb +474 -0
  11. data/lib/twilio-ruby/rest/authy/v1/service/entity/factor/challenge.rb +405 -0
  12. data/lib/twilio-ruby/rest/autopilot.rb +47 -0
  13. data/lib/twilio-ruby/rest/autopilot/v1.rb +43 -0
  14. data/lib/twilio-ruby/rest/autopilot/v1/assistant.rb +606 -0
  15. data/lib/twilio-ruby/rest/autopilot/v1/assistant/defaults.rb +215 -0
  16. data/lib/twilio-ruby/rest/autopilot/v1/assistant/dialogue.rb +205 -0
  17. data/lib/twilio-ruby/rest/autopilot/v1/assistant/field_type.rb +417 -0
  18. data/lib/twilio-ruby/rest/autopilot/v1/assistant/field_type/field_value.rb +393 -0
  19. data/lib/twilio-ruby/rest/autopilot/v1/assistant/model_build.rb +390 -0
  20. data/lib/twilio-ruby/rest/autopilot/v1/assistant/query.rb +443 -0
  21. data/lib/twilio-ruby/rest/autopilot/v1/assistant/style_sheet.rb +215 -0
  22. data/lib/twilio-ruby/rest/{preview/understand/assistant/intent.rb → autopilot/v1/assistant/task.rb} +91 -84
  23. data/lib/twilio-ruby/rest/autopilot/v1/assistant/task/field.rb +377 -0
  24. data/lib/twilio-ruby/rest/autopilot/v1/assistant/task/sample.rb +442 -0
  25. data/lib/twilio-ruby/rest/autopilot/v1/assistant/task/task_actions.rb +244 -0
  26. data/lib/twilio-ruby/rest/{preview/understand/assistant/intent/intent_statistics.rb → autopilot/v1/assistant/task/task_statistics.rb} +49 -51
  27. data/lib/twilio-ruby/rest/chat/v1/service.rb +1 -1
  28. data/lib/twilio-ruby/rest/chat/v2/service/channel.rb +12 -6
  29. data/lib/twilio-ruby/rest/client.rb +14 -0
  30. data/lib/twilio-ruby/rest/ip_messaging/v1/service.rb +1 -1
  31. data/lib/twilio-ruby/rest/ip_messaging/v2/service/channel.rb +12 -6
  32. data/lib/twilio-ruby/rest/preview/understand.rb +2 -1
  33. data/lib/twilio-ruby/rest/preview/understand/assistant.rb +59 -29
  34. data/lib/twilio-ruby/rest/preview/understand/assistant/query.rb +17 -13
  35. data/lib/twilio-ruby/rest/preview/understand/assistant/style_sheet.rb +215 -0
  36. data/lib/twilio-ruby/rest/preview/understand/assistant/task.rb +505 -0
  37. data/lib/twilio-ruby/rest/preview/understand/assistant/{intent → task}/field.rb +25 -25
  38. data/lib/twilio-ruby/rest/preview/understand/assistant/{intent → task}/sample.rb +30 -30
  39. data/lib/twilio-ruby/rest/preview/understand/assistant/{intent/intent_actions.rb → task/task_actions.rb} +50 -54
  40. data/lib/twilio-ruby/rest/preview/understand/assistant/task/task_statistics.rb +224 -0
  41. data/lib/twilio-ruby/rest/taskrouter/v1/workspace/task_queue.rb +7 -7
  42. data/lib/twilio-ruby/rest/verify/v1/service.rb +45 -6
  43. data/lib/twilio-ruby/rest/verify/v1/service/verification.rb +9 -2
  44. data/lib/twilio-ruby/rest/wireless/v1/command.rb +32 -5
  45. data/lib/twilio-ruby/twiml/voice_response.rb +66 -5
  46. data/lib/twilio-ruby/version.rb +1 -1
  47. data/spec/integration/api/v2010/account/call/recording_spec.rb +3 -3
  48. data/spec/integration/api/v2010/account/conference/participant_spec.rb +42 -1
  49. data/spec/integration/api/v2010/account/conference/recording_spec.rb +2 -2
  50. data/spec/integration/authy/v1/form_spec.rb +48 -0
  51. data/spec/integration/authy/v1/service/entity/factor/challenge_spec.rb +267 -0
  52. data/spec/integration/authy/v1/service/entity/factor_spec.rb +269 -0
  53. data/spec/integration/authy/v1/service/entity_spec.rb +201 -0
  54. data/spec/integration/authy/v1/service_spec.rb +227 -0
  55. data/spec/integration/autopilot/v1/assistant/defaults_spec.rb +81 -0
  56. data/spec/integration/autopilot/v1/assistant/dialogue_spec.rb +47 -0
  57. data/spec/integration/autopilot/v1/assistant/field_type/field_value_spec.rb +210 -0
  58. data/spec/integration/autopilot/v1/assistant/field_type_spec.rb +246 -0
  59. data/spec/integration/autopilot/v1/assistant/model_build_spec.rb +241 -0
  60. data/spec/integration/autopilot/v1/assistant/query_spec.rb +306 -0
  61. data/spec/integration/autopilot/v1/assistant/style_sheet_spec.rb +81 -0
  62. data/spec/integration/autopilot/v1/assistant/task/field_spec.rb +207 -0
  63. data/spec/integration/autopilot/v1/assistant/task/sample_spec.rb +253 -0
  64. data/spec/integration/autopilot/v1/assistant/task/task_actions_spec.rb +87 -0
  65. data/spec/integration/autopilot/v1/assistant/task/task_statistics_spec.rb +50 -0
  66. data/spec/integration/autopilot/v1/assistant/task_spec.rb +262 -0
  67. data/spec/integration/autopilot/v1/assistant_spec.rb +270 -0
  68. data/spec/integration/preview/understand/assistant/query_spec.rb +8 -8
  69. data/spec/integration/preview/understand/assistant/style_sheet_spec.rb +81 -0
  70. data/spec/integration/preview/understand/assistant/{intent → task}/field_spec.rb +23 -23
  71. data/spec/integration/preview/understand/assistant/{intent → task}/sample_spec.rb +28 -28
  72. data/spec/integration/preview/understand/assistant/{intent/intent_actions_spec.rb → task/task_actions_spec.rb} +15 -15
  73. data/spec/integration/preview/understand/assistant/{intent/intent_statistics_spec.rb → task/task_statistics_spec.rb} +6 -6
  74. data/spec/integration/preview/understand/assistant/{intent_spec.rb → task_spec.rb} +53 -49
  75. data/spec/integration/preview/understand/assistant_spec.rb +12 -8
  76. data/spec/integration/taskrouter/v1/workspace/task_queue_spec.rb +3 -7
  77. data/spec/integration/verify/v1/service_spec.rb +30 -0
  78. data/spec/integration/wireless/v1/command_spec.rb +99 -2
  79. data/spec/twiml/voice_response_spec.rb +25 -2
  80. metadata +78 -17
@@ -0,0 +1,372 @@
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 Authy < Domain
12
+ class V1 < Version
13
+ class ServiceContext < 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 EntityList < ListResource
17
+ ##
18
+ # Initialize the EntityList
19
+ # @param [Version] version Version that contains the resource
20
+ # @param [String] service_sid The unique SID identifier of the Service.
21
+ # @return [EntityList] EntityList
22
+ def initialize(version, service_sid: nil)
23
+ super(version)
24
+
25
+ # Path Solution
26
+ @solution = {service_sid: service_sid}
27
+ @uri = "/Services/#{@solution[:service_sid]}/Entities"
28
+ end
29
+
30
+ ##
31
+ # Retrieve a single page of EntityInstance records from the API.
32
+ # Request is executed immediately.
33
+ # @param [String] identity Customer unique identity for the Entity of the Service
34
+ # @return [EntityInstance] Newly created EntityInstance
35
+ def create(identity: nil)
36
+ data = Twilio::Values.of({'Identity' => identity, })
37
+
38
+ payload = @version.create(
39
+ 'POST',
40
+ @uri,
41
+ data: data
42
+ )
43
+
44
+ EntityInstance.new(@version, payload, service_sid: @solution[:service_sid], )
45
+ end
46
+
47
+ ##
48
+ # Lists EntityInstance records from the API as a list.
49
+ # Unlike stream(), this operation is eager and will load `limit` records into
50
+ # memory before returning.
51
+ # @param [Integer] limit Upper limit for the number of records to return. stream()
52
+ # guarantees to never return more than limit. Default is no limit
53
+ # @param [Integer] page_size Number of records to fetch per request, when
54
+ # not set will use the default value of 50 records. If no page_size is defined
55
+ # but a limit is defined, stream() will attempt to read the limit with the most
56
+ # efficient page size, i.e. min(limit, 1000)
57
+ # @return [Array] Array of up to limit results
58
+ def list(limit: nil, page_size: nil)
59
+ self.stream(limit: limit, page_size: page_size).entries
60
+ end
61
+
62
+ ##
63
+ # Streams EntityInstance records from the API as an Enumerable.
64
+ # This operation lazily loads records as efficiently as possible until the limit
65
+ # is reached.
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 [Enumerable] Enumerable that will yield up to limit results
73
+ def stream(limit: nil, page_size: nil)
74
+ limits = @version.read_limits(limit, page_size)
75
+
76
+ page = self.page(page_size: limits[:page_size], )
77
+
78
+ @version.stream(page, limit: limits[:limit], page_limit: limits[:page_limit])
79
+ end
80
+
81
+ ##
82
+ # When passed a block, yields EntityInstance records from the API.
83
+ # This operation lazily loads records as efficiently as possible until the limit
84
+ # is reached.
85
+ def each
86
+ limits = @version.read_limits
87
+
88
+ page = self.page(page_size: limits[:page_size], )
89
+
90
+ @version.stream(page,
91
+ limit: limits[:limit],
92
+ page_limit: limits[:page_limit]).each {|x| yield x}
93
+ end
94
+
95
+ ##
96
+ # Retrieve a single page of EntityInstance records from the API.
97
+ # Request is executed immediately.
98
+ # @param [String] page_token PageToken provided by the API
99
+ # @param [Integer] page_number Page Number, this value is simply for client state
100
+ # @param [Integer] page_size Number of records to return, defaults to 50
101
+ # @return [Page] Page of EntityInstance
102
+ def page(page_token: :unset, page_number: :unset, page_size: :unset)
103
+ params = Twilio::Values.of({
104
+ 'PageToken' => page_token,
105
+ 'Page' => page_number,
106
+ 'PageSize' => page_size,
107
+ })
108
+ response = @version.page(
109
+ 'GET',
110
+ @uri,
111
+ params
112
+ )
113
+ EntityPage.new(@version, response, @solution)
114
+ end
115
+
116
+ ##
117
+ # Retrieve a single page of EntityInstance records from the API.
118
+ # Request is executed immediately.
119
+ # @param [String] target_url API-generated URL for the requested results page
120
+ # @return [Page] Page of EntityInstance
121
+ def get_page(target_url)
122
+ response = @version.domain.request(
123
+ 'GET',
124
+ target_url
125
+ )
126
+ EntityPage.new(@version, response, @solution)
127
+ end
128
+
129
+ ##
130
+ # Provide a user friendly representation
131
+ def to_s
132
+ '#<Twilio.Authy.V1.EntityList>'
133
+ end
134
+ end
135
+
136
+ ##
137
+ # 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.
138
+ class EntityPage < Page
139
+ ##
140
+ # Initialize the EntityPage
141
+ # @param [Version] version Version that contains the resource
142
+ # @param [Response] response Response from the API
143
+ # @param [Hash] solution Path solution for the resource
144
+ # @return [EntityPage] EntityPage
145
+ def initialize(version, response, solution)
146
+ super(version, response)
147
+
148
+ # Path Solution
149
+ @solution = solution
150
+ end
151
+
152
+ ##
153
+ # Build an instance of EntityInstance
154
+ # @param [Hash] payload Payload response from the API
155
+ # @return [EntityInstance] EntityInstance
156
+ def get_instance(payload)
157
+ EntityInstance.new(@version, payload, service_sid: @solution[:service_sid], )
158
+ end
159
+
160
+ ##
161
+ # Provide a user friendly representation
162
+ def to_s
163
+ '<Twilio.Authy.V1.EntityPage>'
164
+ end
165
+ end
166
+
167
+ ##
168
+ # 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.
169
+ class EntityContext < InstanceContext
170
+ ##
171
+ # Initialize the EntityContext
172
+ # @param [Version] version Version that contains the resource
173
+ # @param [String] service_sid The unique SID identifier of the Service.
174
+ # @param [String] identity Customer unique identity for the Entity of the Service
175
+ # @return [EntityContext] EntityContext
176
+ def initialize(version, service_sid, identity)
177
+ super(version)
178
+
179
+ # Path Solution
180
+ @solution = {service_sid: service_sid, identity: identity, }
181
+ @uri = "/Services/#{@solution[:service_sid]}/Entities/#{@solution[:identity]}"
182
+
183
+ # Dependents
184
+ @factors = nil
185
+ end
186
+
187
+ ##
188
+ # Deletes the EntityInstance
189
+ # @return [Boolean] true if delete succeeds, true otherwise
190
+ def delete
191
+ @version.delete('delete', @uri)
192
+ end
193
+
194
+ ##
195
+ # Fetch a EntityInstance
196
+ # @return [EntityInstance] Fetched EntityInstance
197
+ def fetch
198
+ params = Twilio::Values.of({})
199
+
200
+ payload = @version.fetch(
201
+ 'GET',
202
+ @uri,
203
+ params,
204
+ )
205
+
206
+ EntityInstance.new(
207
+ @version,
208
+ payload,
209
+ service_sid: @solution[:service_sid],
210
+ identity: @solution[:identity],
211
+ )
212
+ end
213
+
214
+ ##
215
+ # Access the factors
216
+ # @return [FactorList]
217
+ # @return [FactorContext] if sid was passed.
218
+ def factors(sid=:unset)
219
+ raise ArgumentError, 'sid cannot be nil' if sid.nil?
220
+
221
+ if sid != :unset
222
+ return FactorContext.new(@version, @solution[:service_sid], @solution[:identity], sid, )
223
+ end
224
+
225
+ unless @factors
226
+ @factors = FactorList.new(
227
+ @version,
228
+ service_sid: @solution[:service_sid],
229
+ identity: @solution[:identity],
230
+ )
231
+ end
232
+
233
+ @factors
234
+ end
235
+
236
+ ##
237
+ # Provide a user friendly representation
238
+ def to_s
239
+ context = @solution.map {|k, v| "#{k}: #{v}"}.join(',')
240
+ "#<Twilio.Authy.V1.EntityContext #{context}>"
241
+ end
242
+ end
243
+
244
+ ##
245
+ # 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.
246
+ class EntityInstance < InstanceResource
247
+ ##
248
+ # Initialize the EntityInstance
249
+ # @param [Version] version Version that contains the resource
250
+ # @param [Hash] payload payload that contains response from Twilio
251
+ # @param [String] service_sid The unique SID identifier of the Service.
252
+ # @param [String] identity Customer unique identity for the Entity of the Service
253
+ # @return [EntityInstance] EntityInstance
254
+ def initialize(version, payload, service_sid: nil, identity: nil)
255
+ super(version)
256
+
257
+ # Marshaled Properties
258
+ @properties = {
259
+ 'sid' => payload['sid'],
260
+ 'identity' => payload['identity'],
261
+ 'account_sid' => payload['account_sid'],
262
+ 'service_sid' => payload['service_sid'],
263
+ 'date_created' => Twilio.deserialize_iso8601_datetime(payload['date_created']),
264
+ 'date_updated' => Twilio.deserialize_iso8601_datetime(payload['date_updated']),
265
+ 'url' => payload['url'],
266
+ 'links' => payload['links'],
267
+ }
268
+
269
+ # Context
270
+ @instance_context = nil
271
+ @params = {'service_sid' => service_sid, 'identity' => identity || @properties['identity'], }
272
+ end
273
+
274
+ ##
275
+ # Generate an instance context for the instance, the context is capable of
276
+ # performing various actions. All instance actions are proxied to the context
277
+ # @return [EntityContext] EntityContext for this EntityInstance
278
+ def context
279
+ unless @instance_context
280
+ @instance_context = EntityContext.new(@version, @params['service_sid'], @params['identity'], )
281
+ end
282
+ @instance_context
283
+ end
284
+
285
+ ##
286
+ # @return [String] A string that uniquely identifies this Entity.
287
+ def sid
288
+ @properties['sid']
289
+ end
290
+
291
+ ##
292
+ # @return [String] Unique identity of the Entity
293
+ def identity
294
+ @properties['identity']
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 Entity was created
311
+ def date_created
312
+ @properties['date_created']
313
+ end
314
+
315
+ ##
316
+ # @return [Time] The date this Entity was updated
317
+ def date_updated
318
+ @properties['date_updated']
319
+ end
320
+
321
+ ##
322
+ # @return [String] The URL of this resource.
323
+ def url
324
+ @properties['url']
325
+ end
326
+
327
+ ##
328
+ # @return [String] Nested resource URLs.
329
+ def links
330
+ @properties['links']
331
+ end
332
+
333
+ ##
334
+ # Deletes the EntityInstance
335
+ # @return [Boolean] true if delete succeeds, true otherwise
336
+ def delete
337
+ context.delete
338
+ end
339
+
340
+ ##
341
+ # Fetch a EntityInstance
342
+ # @return [EntityInstance] Fetched EntityInstance
343
+ def fetch
344
+ context.fetch
345
+ end
346
+
347
+ ##
348
+ # Access the factors
349
+ # @return [factors] factors
350
+ def factors
351
+ context.factors
352
+ end
353
+
354
+ ##
355
+ # Provide a user friendly representation
356
+ def to_s
357
+ values = @params.map{|k, v| "#{k}: #{v}"}.join(" ")
358
+ "<Twilio.Authy.V1.EntityInstance #{values}>"
359
+ end
360
+
361
+ ##
362
+ # Provide a detailed, user friendly representation
363
+ def inspect
364
+ values = @properties.map{|k, v| "#{k}: #{v}"}.join(" ")
365
+ "<Twilio.Authy.V1.EntityInstance #{values}>"
366
+ end
367
+ end
368
+ end
369
+ end
370
+ end
371
+ end
372
+ end
@@ -0,0 +1,474 @@
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 Authy < Domain
12
+ class V1 < Version
13
+ class ServiceContext < InstanceContext
14
+ class EntityContext < InstanceContext
15
+ ##
16
+ # 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.
17
+ class FactorList < ListResource
18
+ ##
19
+ # Initialize the FactorList
20
+ # @param [Version] version Version that contains the resource
21
+ # @param [String] service_sid The unique SID identifier of the Service.
22
+ # @param [String] identity Customer unique identity for the Entity owner of the
23
+ # Factor
24
+ # @return [FactorList] FactorList
25
+ def initialize(version, service_sid: nil, identity: nil)
26
+ super(version)
27
+
28
+ # Path Solution
29
+ @solution = {service_sid: service_sid, identity: identity}
30
+ @uri = "/Services/#{@solution[:service_sid]}/Entities/#{@solution[:identity]}/Factors"
31
+ end
32
+
33
+ ##
34
+ # Retrieve a single page of FactorInstance records from the API.
35
+ # Request is executed immediately.
36
+ # @param [String] binding A unique binding for this Factor that identifies it.
37
+ # E.g. a phone number for `sms` factors. Required when creating a new Factor. This
38
+ # value is never returned because it can contain customer secrets.
39
+ # @param [String] factor_type The Type of this Factor. One of `app-push`, `sms`,
40
+ # `totp`, etc.
41
+ # @param [String] friendly_name The friendly name of this Factor
42
+ # @param [String] config Optional configuration for the Factor
43
+ # @return [FactorInstance] Newly created FactorInstance
44
+ def create(binding: nil, factor_type: nil, friendly_name: nil, config: :unset)
45
+ data = Twilio::Values.of({
46
+ 'Binding' => binding,
47
+ 'FactorType' => factor_type,
48
+ 'FriendlyName' => friendly_name,
49
+ 'Config' => config,
50
+ })
51
+
52
+ payload = @version.create(
53
+ 'POST',
54
+ @uri,
55
+ data: data
56
+ )
57
+
58
+ FactorInstance.new(
59
+ @version,
60
+ payload,
61
+ service_sid: @solution[:service_sid],
62
+ identity: @solution[:identity],
63
+ )
64
+ end
65
+
66
+ ##
67
+ # Lists FactorInstance records from the API as a list.
68
+ # Unlike stream(), this operation is eager and will load `limit` records into
69
+ # memory before returning.
70
+ # @param [Integer] limit Upper limit for the number of records to return. stream()
71
+ # guarantees to never return more than limit. Default is no limit
72
+ # @param [Integer] page_size Number of records to fetch per request, when
73
+ # not set will use the default value of 50 records. If no page_size is defined
74
+ # but a limit is defined, stream() will attempt to read the limit with the most
75
+ # efficient page size, i.e. min(limit, 1000)
76
+ # @return [Array] Array of up to limit results
77
+ def list(limit: nil, page_size: nil)
78
+ self.stream(limit: limit, page_size: page_size).entries
79
+ end
80
+
81
+ ##
82
+ # Streams FactorInstance records from the API as an Enumerable.
83
+ # This operation lazily loads records as efficiently as possible until the limit
84
+ # is reached.
85
+ # @param [Integer] limit Upper limit for the number of records to return. stream()
86
+ # guarantees to never return more than limit. Default is no limit.
87
+ # @param [Integer] page_size Number of records to fetch per request, when
88
+ # not set will use the default value of 50 records. If no page_size is defined
89
+ # but a limit is defined, stream() will attempt to read the limit with the most
90
+ # efficient page size, i.e. min(limit, 1000)
91
+ # @return [Enumerable] Enumerable that will yield up to limit results
92
+ def stream(limit: nil, page_size: nil)
93
+ limits = @version.read_limits(limit, page_size)
94
+
95
+ page = self.page(page_size: limits[:page_size], )
96
+
97
+ @version.stream(page, limit: limits[:limit], page_limit: limits[:page_limit])
98
+ end
99
+
100
+ ##
101
+ # When passed a block, yields FactorInstance records from the API.
102
+ # This operation lazily loads records as efficiently as possible until the limit
103
+ # is reached.
104
+ def each
105
+ limits = @version.read_limits
106
+
107
+ page = self.page(page_size: limits[:page_size], )
108
+
109
+ @version.stream(page,
110
+ limit: limits[:limit],
111
+ page_limit: limits[:page_limit]).each {|x| yield x}
112
+ end
113
+
114
+ ##
115
+ # Retrieve a single page of FactorInstance records from the API.
116
+ # Request is executed immediately.
117
+ # @param [String] page_token PageToken provided by the API
118
+ # @param [Integer] page_number Page Number, this value is simply for client state
119
+ # @param [Integer] page_size Number of records to return, defaults to 50
120
+ # @return [Page] Page of FactorInstance
121
+ def page(page_token: :unset, page_number: :unset, page_size: :unset)
122
+ params = Twilio::Values.of({
123
+ 'PageToken' => page_token,
124
+ 'Page' => page_number,
125
+ 'PageSize' => page_size,
126
+ })
127
+ response = @version.page(
128
+ 'GET',
129
+ @uri,
130
+ params
131
+ )
132
+ FactorPage.new(@version, response, @solution)
133
+ end
134
+
135
+ ##
136
+ # Retrieve a single page of FactorInstance records from the API.
137
+ # Request is executed immediately.
138
+ # @param [String] target_url API-generated URL for the requested results page
139
+ # @return [Page] Page of FactorInstance
140
+ def get_page(target_url)
141
+ response = @version.domain.request(
142
+ 'GET',
143
+ target_url
144
+ )
145
+ FactorPage.new(@version, response, @solution)
146
+ end
147
+
148
+ ##
149
+ # Provide a user friendly representation
150
+ def to_s
151
+ '#<Twilio.Authy.V1.FactorList>'
152
+ end
153
+ end
154
+
155
+ ##
156
+ # 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.
157
+ class FactorPage < Page
158
+ ##
159
+ # Initialize the FactorPage
160
+ # @param [Version] version Version that contains the resource
161
+ # @param [Response] response Response from the API
162
+ # @param [Hash] solution Path solution for the resource
163
+ # @return [FactorPage] FactorPage
164
+ def initialize(version, response, solution)
165
+ super(version, response)
166
+
167
+ # Path Solution
168
+ @solution = solution
169
+ end
170
+
171
+ ##
172
+ # Build an instance of FactorInstance
173
+ # @param [Hash] payload Payload response from the API
174
+ # @return [FactorInstance] FactorInstance
175
+ def get_instance(payload)
176
+ FactorInstance.new(
177
+ @version,
178
+ payload,
179
+ service_sid: @solution[:service_sid],
180
+ identity: @solution[:identity],
181
+ )
182
+ end
183
+
184
+ ##
185
+ # Provide a user friendly representation
186
+ def to_s
187
+ '<Twilio.Authy.V1.FactorPage>'
188
+ end
189
+ end
190
+
191
+ ##
192
+ # 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.
193
+ class FactorContext < InstanceContext
194
+ ##
195
+ # Initialize the FactorContext
196
+ # @param [Version] version Version that contains the resource
197
+ # @param [String] service_sid The unique SID identifier of the Service.
198
+ # @param [String] identity Customer unique identity for the Entity owner of the
199
+ # Factor
200
+ # @param [String] sid A 34 character string that uniquely identifies this Factor.
201
+ # @return [FactorContext] FactorContext
202
+ def initialize(version, service_sid, identity, sid)
203
+ super(version)
204
+
205
+ # Path Solution
206
+ @solution = {service_sid: service_sid, identity: identity, sid: sid, }
207
+ @uri = "/Services/#{@solution[:service_sid]}/Entities/#{@solution[:identity]}/Factors/#{@solution[:sid]}"
208
+
209
+ # Dependents
210
+ @challenges = nil
211
+ end
212
+
213
+ ##
214
+ # Deletes the FactorInstance
215
+ # @return [Boolean] true if delete succeeds, true otherwise
216
+ def delete
217
+ @version.delete('delete', @uri)
218
+ end
219
+
220
+ ##
221
+ # Fetch a FactorInstance
222
+ # @return [FactorInstance] Fetched FactorInstance
223
+ def fetch
224
+ params = Twilio::Values.of({})
225
+
226
+ payload = @version.fetch(
227
+ 'GET',
228
+ @uri,
229
+ params,
230
+ )
231
+
232
+ FactorInstance.new(
233
+ @version,
234
+ payload,
235
+ service_sid: @solution[:service_sid],
236
+ identity: @solution[:identity],
237
+ sid: @solution[:sid],
238
+ )
239
+ end
240
+
241
+ ##
242
+ # Update the FactorInstance
243
+ # @param [String] auth_payload The optional payload needed to verify the Factor
244
+ # for the first time. E.g. for a TOTP, the numeric code.
245
+ # @return [FactorInstance] Updated FactorInstance
246
+ def update(auth_payload: :unset)
247
+ data = Twilio::Values.of({'AuthPayload' => auth_payload, })
248
+
249
+ payload = @version.update(
250
+ 'POST',
251
+ @uri,
252
+ data: data,
253
+ )
254
+
255
+ FactorInstance.new(
256
+ @version,
257
+ payload,
258
+ service_sid: @solution[:service_sid],
259
+ identity: @solution[:identity],
260
+ sid: @solution[:sid],
261
+ )
262
+ end
263
+
264
+ ##
265
+ # Access the challenges
266
+ # @return [ChallengeList]
267
+ # @return [ChallengeContext] if sid was passed.
268
+ def challenges(sid=:unset)
269
+ raise ArgumentError, 'sid cannot be nil' if sid.nil?
270
+
271
+ if sid != :unset
272
+ return ChallengeContext.new(
273
+ @version,
274
+ @solution[:service_sid],
275
+ @solution[:identity],
276
+ @solution[:sid],
277
+ sid,
278
+ )
279
+ end
280
+
281
+ unless @challenges
282
+ @challenges = ChallengeList.new(
283
+ @version,
284
+ service_sid: @solution[:service_sid],
285
+ identity: @solution[:identity],
286
+ factor_sid: @solution[:sid],
287
+ )
288
+ end
289
+
290
+ @challenges
291
+ end
292
+
293
+ ##
294
+ # Provide a user friendly representation
295
+ def to_s
296
+ context = @solution.map {|k, v| "#{k}: #{v}"}.join(',')
297
+ "#<Twilio.Authy.V1.FactorContext #{context}>"
298
+ end
299
+ end
300
+
301
+ ##
302
+ # 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.
303
+ class FactorInstance < InstanceResource
304
+ ##
305
+ # Initialize the FactorInstance
306
+ # @param [Version] version Version that contains the resource
307
+ # @param [Hash] payload payload that contains response from Twilio
308
+ # @param [String] service_sid The unique SID identifier of the Service.
309
+ # @param [String] identity Customer unique identity for the Entity owner of the
310
+ # Factor
311
+ # @param [String] sid A 34 character string that uniquely identifies this Factor.
312
+ # @return [FactorInstance] FactorInstance
313
+ def initialize(version, payload, service_sid: nil, identity: nil, sid: nil)
314
+ super(version)
315
+
316
+ # Marshaled Properties
317
+ @properties = {
318
+ 'sid' => payload['sid'],
319
+ 'account_sid' => payload['account_sid'],
320
+ 'service_sid' => payload['service_sid'],
321
+ 'entity_sid' => payload['entity_sid'],
322
+ 'identity' => payload['identity'],
323
+ 'date_created' => Twilio.deserialize_iso8601_datetime(payload['date_created']),
324
+ 'date_updated' => Twilio.deserialize_iso8601_datetime(payload['date_updated']),
325
+ 'friendly_name' => payload['friendly_name'],
326
+ 'status' => payload['status'],
327
+ 'type' => payload['type'],
328
+ 'url' => payload['url'],
329
+ 'links' => payload['links'],
330
+ }
331
+
332
+ # Context
333
+ @instance_context = nil
334
+ @params = {'service_sid' => service_sid, 'identity' => identity, 'sid' => sid || @properties['sid'], }
335
+ end
336
+
337
+ ##
338
+ # Generate an instance context for the instance, the context is capable of
339
+ # performing various actions. All instance actions are proxied to the context
340
+ # @return [FactorContext] FactorContext for this FactorInstance
341
+ def context
342
+ unless @instance_context
343
+ @instance_context = FactorContext.new(
344
+ @version,
345
+ @params['service_sid'],
346
+ @params['identity'],
347
+ @params['sid'],
348
+ )
349
+ end
350
+ @instance_context
351
+ end
352
+
353
+ ##
354
+ # @return [String] A string that uniquely identifies this Factor.
355
+ def sid
356
+ @properties['sid']
357
+ end
358
+
359
+ ##
360
+ # @return [String] Account Sid.
361
+ def account_sid
362
+ @properties['account_sid']
363
+ end
364
+
365
+ ##
366
+ # @return [String] Service Sid.
367
+ def service_sid
368
+ @properties['service_sid']
369
+ end
370
+
371
+ ##
372
+ # @return [String] Entity Sid.
373
+ def entity_sid
374
+ @properties['entity_sid']
375
+ end
376
+
377
+ ##
378
+ # @return [String] Unique identity of the Entity
379
+ def identity
380
+ @properties['identity']
381
+ end
382
+
383
+ ##
384
+ # @return [Time] The date this Factor was created
385
+ def date_created
386
+ @properties['date_created']
387
+ end
388
+
389
+ ##
390
+ # @return [Time] The date this Factor was updated
391
+ def date_updated
392
+ @properties['date_updated']
393
+ end
394
+
395
+ ##
396
+ # @return [String] A human readable description of this resource.
397
+ def friendly_name
398
+ @properties['friendly_name']
399
+ end
400
+
401
+ ##
402
+ # @return [factor.FactorStatus] The Status of this Factor
403
+ def status
404
+ @properties['status']
405
+ end
406
+
407
+ ##
408
+ # @return [String] The Type of this Factor
409
+ def type
410
+ @properties['type']
411
+ end
412
+
413
+ ##
414
+ # @return [String] The URL of this resource.
415
+ def url
416
+ @properties['url']
417
+ end
418
+
419
+ ##
420
+ # @return [String] Nested resource URLs.
421
+ def links
422
+ @properties['links']
423
+ end
424
+
425
+ ##
426
+ # Deletes the FactorInstance
427
+ # @return [Boolean] true if delete succeeds, true otherwise
428
+ def delete
429
+ context.delete
430
+ end
431
+
432
+ ##
433
+ # Fetch a FactorInstance
434
+ # @return [FactorInstance] Fetched FactorInstance
435
+ def fetch
436
+ context.fetch
437
+ end
438
+
439
+ ##
440
+ # Update the FactorInstance
441
+ # @param [String] auth_payload The optional payload needed to verify the Factor
442
+ # for the first time. E.g. for a TOTP, the numeric code.
443
+ # @return [FactorInstance] Updated FactorInstance
444
+ def update(auth_payload: :unset)
445
+ context.update(auth_payload: auth_payload, )
446
+ end
447
+
448
+ ##
449
+ # Access the challenges
450
+ # @return [challenges] challenges
451
+ def challenges
452
+ context.challenges
453
+ end
454
+
455
+ ##
456
+ # Provide a user friendly representation
457
+ def to_s
458
+ values = @params.map{|k, v| "#{k}: #{v}"}.join(" ")
459
+ "<Twilio.Authy.V1.FactorInstance #{values}>"
460
+ end
461
+
462
+ ##
463
+ # Provide a detailed, user friendly representation
464
+ def inspect
465
+ values = @properties.map{|k, v| "#{k}: #{v}"}.join(" ")
466
+ "<Twilio.Authy.V1.FactorInstance #{values}>"
467
+ end
468
+ end
469
+ end
470
+ end
471
+ end
472
+ end
473
+ end
474
+ end