twilio-ruby 5.31.1 → 5.31.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +1 -1
  3. data/.rubocop_todo.yml +4 -3
  4. data/CHANGES.md +16 -0
  5. data/LICENSE.md +1 -1
  6. data/README.md +2 -2
  7. data/lib/twilio-ruby.rb +5 -5
  8. data/lib/twilio-ruby/rest/client.rb +7 -0
  9. data/lib/twilio-ruby/rest/numbers.rb +44 -0
  10. data/lib/twilio-ruby/rest/numbers/v2.rb +35 -0
  11. data/lib/twilio-ruby/rest/numbers/v2/regulatory_compliance.rb +189 -0
  12. data/lib/twilio-ruby/rest/numbers/v2/regulatory_compliance/bundle.rb +482 -0
  13. data/lib/twilio-ruby/rest/numbers/v2/regulatory_compliance/bundle/item_assignment.rb +333 -0
  14. data/lib/twilio-ruby/rest/numbers/v2/regulatory_compliance/end_user.rb +361 -0
  15. data/lib/twilio-ruby/rest/numbers/v2/regulatory_compliance/end_user_type.rb +281 -0
  16. data/lib/twilio-ruby/rest/numbers/v2/regulatory_compliance/supporting_document.rb +374 -0
  17. data/lib/twilio-ruby/rest/numbers/v2/regulatory_compliance/supporting_document_type.rb +281 -0
  18. data/lib/twilio-ruby/rest/serverless/v1/service/environment/log.rb +30 -5
  19. data/lib/twilio-ruby/rest/studio.rb +16 -3
  20. data/lib/twilio-ruby/rest/studio/v2.rb +50 -0
  21. data/lib/twilio-ruby/rest/studio/v2/flow.rb +451 -0
  22. data/lib/twilio-ruby/rest/studio/v2/flow/flow_revision.rb +343 -0
  23. data/lib/twilio-ruby/rest/studio/v2/flow_validate.rb +126 -0
  24. data/lib/twilio-ruby/twiml/voice_response.rb +3 -2
  25. data/lib/twilio-ruby/version.rb +1 -1
  26. data/spec/integration/numbers/v2/regulatory_compliance/bundle/item_assignment_spec.rb +198 -0
  27. data/spec/integration/numbers/v2/regulatory_compliance/bundle_spec.rb +226 -0
  28. data/spec/integration/numbers/v2/regulatory_compliance/end_user_spec.rb +214 -0
  29. data/spec/integration/numbers/v2/regulatory_compliance/end_user_type_spec.rb +143 -0
  30. data/spec/integration/numbers/v2/regulatory_compliance/supporting_document_spec.rb +226 -0
  31. data/spec/integration/numbers/v2/regulatory_compliance/supporting_document_type_spec.rb +133 -0
  32. data/spec/integration/numbers/v2/regulatory_compliance_spec.rb +12 -0
  33. data/spec/integration/serverless/v1/service/environment/log_spec.rb +2 -2
  34. data/spec/integration/studio/v2/flow/flow_revision_spec.rb +112 -0
  35. data/spec/integration/studio/v2/flow_spec.rb +234 -0
  36. data/spec/integration/studio/v2/flow_validate_spec.rb +42 -0
  37. data/twilio-ruby.gemspec +2 -2
  38. metadata +39 -6
@@ -0,0 +1,281 @@
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 Numbers < Domain
12
+ class V2 < Version
13
+ class RegulatoryComplianceList < ListResource
14
+ class SupportingDocumentTypeList < ListResource
15
+ ##
16
+ # Initialize the SupportingDocumentTypeList
17
+ # @param [Version] version Version that contains the resource
18
+ # @return [SupportingDocumentTypeList] SupportingDocumentTypeList
19
+ def initialize(version)
20
+ super(version)
21
+
22
+ # Path Solution
23
+ @solution = {}
24
+ @uri = "/RegulatoryCompliance/SupportingDocumentTypes"
25
+ end
26
+
27
+ ##
28
+ # Lists SupportingDocumentTypeInstance records from the API as a list.
29
+ # Unlike stream(), this operation is eager and will load `limit` records into
30
+ # memory before returning.
31
+ # @param [Integer] limit Upper limit for the number of records to return. stream()
32
+ # guarantees to never return more than limit. Default is no limit
33
+ # @param [Integer] page_size Number of records to fetch per request, when
34
+ # not set will use the default value of 50 records. If no page_size is defined
35
+ # but a limit is defined, stream() will attempt to read the limit with the most
36
+ # efficient page size, i.e. min(limit, 1000)
37
+ # @return [Array] Array of up to limit results
38
+ def list(limit: nil, page_size: nil)
39
+ self.stream(limit: limit, page_size: page_size).entries
40
+ end
41
+
42
+ ##
43
+ # Streams SupportingDocumentTypeInstance records from the API as an Enumerable.
44
+ # This operation lazily loads records as efficiently as possible until the limit
45
+ # is reached.
46
+ # @param [Integer] limit Upper limit for the number of records to return. stream()
47
+ # guarantees to never return more than limit. Default is no limit.
48
+ # @param [Integer] page_size Number of records to fetch per request, when
49
+ # not set will use the default value of 50 records. If no page_size is defined
50
+ # but a limit is defined, stream() will attempt to read the limit with the most
51
+ # efficient page size, i.e. min(limit, 1000)
52
+ # @return [Enumerable] Enumerable that will yield up to limit results
53
+ def stream(limit: nil, page_size: nil)
54
+ limits = @version.read_limits(limit, page_size)
55
+
56
+ page = self.page(page_size: limits[:page_size], )
57
+
58
+ @version.stream(page, limit: limits[:limit], page_limit: limits[:page_limit])
59
+ end
60
+
61
+ ##
62
+ # When passed a block, yields SupportingDocumentTypeInstance records from the API.
63
+ # This operation lazily loads records as efficiently as possible until the limit
64
+ # is reached.
65
+ def each
66
+ limits = @version.read_limits
67
+
68
+ page = self.page(page_size: limits[:page_size], )
69
+
70
+ @version.stream(page,
71
+ limit: limits[:limit],
72
+ page_limit: limits[:page_limit]).each {|x| yield x}
73
+ end
74
+
75
+ ##
76
+ # Retrieve a single page of SupportingDocumentTypeInstance records from the API.
77
+ # Request is executed immediately.
78
+ # @param [String] page_token PageToken provided by the API
79
+ # @param [Integer] page_number Page Number, this value is simply for client state
80
+ # @param [Integer] page_size Number of records to return, defaults to 50
81
+ # @return [Page] Page of SupportingDocumentTypeInstance
82
+ def page(page_token: :unset, page_number: :unset, page_size: :unset)
83
+ params = Twilio::Values.of({
84
+ 'PageToken' => page_token,
85
+ 'Page' => page_number,
86
+ 'PageSize' => page_size,
87
+ })
88
+ response = @version.page(
89
+ 'GET',
90
+ @uri,
91
+ params
92
+ )
93
+ SupportingDocumentTypePage.new(@version, response, @solution)
94
+ end
95
+
96
+ ##
97
+ # Retrieve a single page of SupportingDocumentTypeInstance records from the API.
98
+ # Request is executed immediately.
99
+ # @param [String] target_url API-generated URL for the requested results page
100
+ # @return [Page] Page of SupportingDocumentTypeInstance
101
+ def get_page(target_url)
102
+ response = @version.domain.request(
103
+ 'GET',
104
+ target_url
105
+ )
106
+ SupportingDocumentTypePage.new(@version, response, @solution)
107
+ end
108
+
109
+ ##
110
+ # Provide a user friendly representation
111
+ def to_s
112
+ '#<Twilio.Numbers.V2.SupportingDocumentTypeList>'
113
+ end
114
+ end
115
+
116
+ class SupportingDocumentTypePage < Page
117
+ ##
118
+ # Initialize the SupportingDocumentTypePage
119
+ # @param [Version] version Version that contains the resource
120
+ # @param [Response] response Response from the API
121
+ # @param [Hash] solution Path solution for the resource
122
+ # @return [SupportingDocumentTypePage] SupportingDocumentTypePage
123
+ def initialize(version, response, solution)
124
+ super(version, response)
125
+
126
+ # Path Solution
127
+ @solution = solution
128
+ end
129
+
130
+ ##
131
+ # Build an instance of SupportingDocumentTypeInstance
132
+ # @param [Hash] payload Payload response from the API
133
+ # @return [SupportingDocumentTypeInstance] SupportingDocumentTypeInstance
134
+ def get_instance(payload)
135
+ SupportingDocumentTypeInstance.new(@version, payload, )
136
+ end
137
+
138
+ ##
139
+ # Provide a user friendly representation
140
+ def to_s
141
+ '<Twilio.Numbers.V2.SupportingDocumentTypePage>'
142
+ end
143
+ end
144
+
145
+ class SupportingDocumentTypeContext < InstanceContext
146
+ ##
147
+ # Initialize the SupportingDocumentTypeContext
148
+ # @param [Version] version Version that contains the resource
149
+ # @param [String] sid The unique string that identifies the Supporting Document
150
+ # Type resource.
151
+ # @return [SupportingDocumentTypeContext] SupportingDocumentTypeContext
152
+ def initialize(version, sid)
153
+ super(version)
154
+
155
+ # Path Solution
156
+ @solution = {sid: sid, }
157
+ @uri = "/RegulatoryCompliance/SupportingDocumentTypes/#{@solution[:sid]}"
158
+ end
159
+
160
+ ##
161
+ # Fetch a SupportingDocumentTypeInstance
162
+ # @return [SupportingDocumentTypeInstance] Fetched SupportingDocumentTypeInstance
163
+ def fetch
164
+ params = Twilio::Values.of({})
165
+
166
+ payload = @version.fetch(
167
+ 'GET',
168
+ @uri,
169
+ params,
170
+ )
171
+
172
+ SupportingDocumentTypeInstance.new(@version, payload, sid: @solution[:sid], )
173
+ end
174
+
175
+ ##
176
+ # Provide a user friendly representation
177
+ def to_s
178
+ context = @solution.map {|k, v| "#{k}: #{v}"}.join(',')
179
+ "#<Twilio.Numbers.V2.SupportingDocumentTypeContext #{context}>"
180
+ end
181
+
182
+ ##
183
+ # Provide a detailed, user friendly representation
184
+ def inspect
185
+ context = @solution.map {|k, v| "#{k}: #{v}"}.join(',')
186
+ "#<Twilio.Numbers.V2.SupportingDocumentTypeContext #{context}>"
187
+ end
188
+ end
189
+
190
+ class SupportingDocumentTypeInstance < InstanceResource
191
+ ##
192
+ # Initialize the SupportingDocumentTypeInstance
193
+ # @param [Version] version Version that contains the resource
194
+ # @param [Hash] payload payload that contains response from Twilio
195
+ # @param [String] sid The unique string that identifies the Supporting Document
196
+ # Type resource.
197
+ # @return [SupportingDocumentTypeInstance] SupportingDocumentTypeInstance
198
+ def initialize(version, payload, sid: nil)
199
+ super(version)
200
+
201
+ # Marshaled Properties
202
+ @properties = {
203
+ 'sid' => payload['sid'],
204
+ 'friendly_name' => payload['friendly_name'],
205
+ 'machine_name' => payload['machine_name'],
206
+ 'fields' => payload['fields'],
207
+ 'url' => payload['url'],
208
+ }
209
+
210
+ # Context
211
+ @instance_context = nil
212
+ @params = {'sid' => sid || @properties['sid'], }
213
+ end
214
+
215
+ ##
216
+ # Generate an instance context for the instance, the context is capable of
217
+ # performing various actions. All instance actions are proxied to the context
218
+ # @return [SupportingDocumentTypeContext] SupportingDocumentTypeContext for this SupportingDocumentTypeInstance
219
+ def context
220
+ unless @instance_context
221
+ @instance_context = SupportingDocumentTypeContext.new(@version, @params['sid'], )
222
+ end
223
+ @instance_context
224
+ end
225
+
226
+ ##
227
+ # @return [String] The unique string that identifies the Supporting Document Type resource
228
+ def sid
229
+ @properties['sid']
230
+ end
231
+
232
+ ##
233
+ # @return [String] A human-readable description of the Supporting Document Type resource
234
+ def friendly_name
235
+ @properties['friendly_name']
236
+ end
237
+
238
+ ##
239
+ # @return [String] The machine-readable description of the Supporting Document Type resource
240
+ def machine_name
241
+ @properties['machine_name']
242
+ end
243
+
244
+ ##
245
+ # @return [Hash] The required information for creating a Supporting Document
246
+ def fields
247
+ @properties['fields']
248
+ end
249
+
250
+ ##
251
+ # @return [String] The absolute URL of the Supporting Document Type resource
252
+ def url
253
+ @properties['url']
254
+ end
255
+
256
+ ##
257
+ # Fetch a SupportingDocumentTypeInstance
258
+ # @return [SupportingDocumentTypeInstance] Fetched SupportingDocumentTypeInstance
259
+ def fetch
260
+ context.fetch
261
+ end
262
+
263
+ ##
264
+ # Provide a user friendly representation
265
+ def to_s
266
+ values = @params.map{|k, v| "#{k}: #{v}"}.join(" ")
267
+ "<Twilio.Numbers.V2.SupportingDocumentTypeInstance #{values}>"
268
+ end
269
+
270
+ ##
271
+ # Provide a detailed, user friendly representation
272
+ def inspect
273
+ values = @properties.map{|k, v| "#{k}: #{v}"}.join(" ")
274
+ "<Twilio.Numbers.V2.SupportingDocumentTypeInstance #{values}>"
275
+ end
276
+ end
277
+ end
278
+ end
279
+ end
280
+ end
281
+ end
@@ -37,6 +37,10 @@ module Twilio
37
37
  # memory before returning.
38
38
  # @param [String] function_sid The SID of the function whose invocation produced
39
39
  # the Log resources to read.
40
+ # @param [Time] start_date The date/time (in GMT, ISO 8601) after which the Log
41
+ # resources must have been created. Defaults to 1 day prior to current date/time.
42
+ # @param [Time] end_date The date/time (in GMT, ISO 8601) before which the Log
43
+ # resources must have been created. Defaults to current date/time.
40
44
  # @param [Integer] limit Upper limit for the number of records to return. stream()
41
45
  # guarantees to never return more than limit. Default is no limit
42
46
  # @param [Integer] page_size Number of records to fetch per request, when
@@ -44,8 +48,14 @@ module Twilio
44
48
  # but a limit is defined, stream() will attempt to read the limit with the most
45
49
  # efficient page size, i.e. min(limit, 1000)
46
50
  # @return [Array] Array of up to limit results
47
- def list(function_sid: :unset, limit: nil, page_size: nil)
48
- self.stream(function_sid: function_sid, limit: limit, page_size: page_size).entries
51
+ def list(function_sid: :unset, start_date: :unset, end_date: :unset, limit: nil, page_size: nil)
52
+ self.stream(
53
+ function_sid: function_sid,
54
+ start_date: start_date,
55
+ end_date: end_date,
56
+ limit: limit,
57
+ page_size: page_size
58
+ ).entries
49
59
  end
50
60
 
51
61
  ##
@@ -54,6 +64,10 @@ module Twilio
54
64
  # is reached.
55
65
  # @param [String] function_sid The SID of the function whose invocation produced
56
66
  # the Log resources to read.
67
+ # @param [Time] start_date The date/time (in GMT, ISO 8601) after which the Log
68
+ # resources must have been created. Defaults to 1 day prior to current date/time.
69
+ # @param [Time] end_date The date/time (in GMT, ISO 8601) before which the Log
70
+ # resources must have been created. Defaults to current date/time.
57
71
  # @param [Integer] limit Upper limit for the number of records to return. stream()
58
72
  # guarantees to never return more than limit. Default is no limit.
59
73
  # @param [Integer] page_size Number of records to fetch per request, when
@@ -61,10 +75,15 @@ module Twilio
61
75
  # but a limit is defined, stream() will attempt to read the limit with the most
62
76
  # efficient page size, i.e. min(limit, 1000)
63
77
  # @return [Enumerable] Enumerable that will yield up to limit results
64
- def stream(function_sid: :unset, limit: nil, page_size: nil)
78
+ def stream(function_sid: :unset, start_date: :unset, end_date: :unset, limit: nil, page_size: nil)
65
79
  limits = @version.read_limits(limit, page_size)
66
80
 
67
- page = self.page(function_sid: function_sid, page_size: limits[:page_size], )
81
+ page = self.page(
82
+ function_sid: function_sid,
83
+ start_date: start_date,
84
+ end_date: end_date,
85
+ page_size: limits[:page_size],
86
+ )
68
87
 
69
88
  @version.stream(page, limit: limits[:limit], page_limit: limits[:page_limit])
70
89
  end
@@ -88,13 +107,19 @@ module Twilio
88
107
  # Request is executed immediately.
89
108
  # @param [String] function_sid The SID of the function whose invocation produced
90
109
  # the Log resources to read.
110
+ # @param [Time] start_date The date/time (in GMT, ISO 8601) after which the Log
111
+ # resources must have been created. Defaults to 1 day prior to current date/time.
112
+ # @param [Time] end_date The date/time (in GMT, ISO 8601) before which the Log
113
+ # resources must have been created. Defaults to current date/time.
91
114
  # @param [String] page_token PageToken provided by the API
92
115
  # @param [Integer] page_number Page Number, this value is simply for client state
93
116
  # @param [Integer] page_size Number of records to return, defaults to 50
94
117
  # @return [Page] Page of LogInstance
95
- def page(function_sid: :unset, page_token: :unset, page_number: :unset, page_size: :unset)
118
+ def page(function_sid: :unset, start_date: :unset, end_date: :unset, page_token: :unset, page_number: :unset, page_size: :unset)
96
119
  params = Twilio::Values.of({
97
120
  'FunctionSid' => function_sid,
121
+ 'StartDate' => Twilio.serialize_iso8601_datetime(start_date),
122
+ 'EndDate' => Twilio.serialize_iso8601_datetime(end_date),
98
123
  'PageToken' => page_token,
99
124
  'Page' => page_number,
100
125
  'PageSize' => page_size,
@@ -20,6 +20,7 @@ module Twilio
20
20
 
21
21
  # Versions
22
22
  @v1 = nil
23
+ @v2 = nil
23
24
  end
24
25
 
25
26
  ##
@@ -28,13 +29,25 @@ module Twilio
28
29
  @v1 ||= V1.new self
29
30
  end
30
31
 
32
+ ##
33
+ # Version v2 of studio
34
+ def v2
35
+ @v2 ||= V2.new self
36
+ end
37
+
31
38
  ##
32
39
  # @param [String] sid The unique string that we created to identify the Flow
33
40
  # resource.
34
- # @return [Twilio::REST::Studio::V1::FlowInstance] if sid was passed.
35
- # @return [Twilio::REST::Studio::V1::FlowList]
41
+ # @return [Twilio::REST::Studio::V2::FlowInstance] if sid was passed.
42
+ # @return [Twilio::REST::Studio::V2::FlowList]
36
43
  def flows(sid=:unset)
37
- self.v1.flows(sid)
44
+ self.v2.flows(sid)
45
+ end
46
+
47
+ ##
48
+ # @return [Twilio::REST::Studio::V2::FlowValidateInstance]
49
+ def flow_valid
50
+ self.v2.flow_valid()
38
51
  end
39
52
 
40
53
  ##
@@ -0,0 +1,50 @@
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 Studio
12
+ class V2 < Version
13
+ ##
14
+ # Initialize the V2 version of Studio
15
+ def initialize(domain)
16
+ super
17
+ @version = 'v2'
18
+ @flows = nil
19
+ @flow_valid = nil
20
+ end
21
+
22
+ ##
23
+ # @param [String] sid The SID of the Flow resource to fetch.
24
+ # @return [Twilio::REST::Studio::V2::FlowContext] if sid was passed.
25
+ # @return [Twilio::REST::Studio::V2::FlowList]
26
+ def flows(sid=:unset)
27
+ if sid.nil?
28
+ raise ArgumentError, 'sid cannot be nil'
29
+ elsif sid == :unset
30
+ @flows ||= FlowList.new self
31
+ else
32
+ FlowContext.new(self, sid)
33
+ end
34
+ end
35
+
36
+ ##
37
+ # @return [Twilio::REST::Studio::V2::FlowValidateContext]
38
+ def flow_valid
39
+ @flow_valid ||= FlowValidateList.new self
40
+ end
41
+
42
+ ##
43
+ # Provide a user friendly representation
44
+ def to_s
45
+ '<Twilio::REST::Studio::V2>'
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,451 @@
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 Studio < Domain
12
+ class V2 < Version
13
+ ##
14
+ # PLEASE NOTE that this class contains beta products that are subject to change. Use them with caution.
15
+ class FlowList < ListResource
16
+ ##
17
+ # Initialize the FlowList
18
+ # @param [Version] version Version that contains the resource
19
+ # @return [FlowList] FlowList
20
+ def initialize(version)
21
+ super(version)
22
+
23
+ # Path Solution
24
+ @solution = {}
25
+ @uri = "/Flows"
26
+ end
27
+
28
+ ##
29
+ # Retrieve a single page of FlowInstance records from the API.
30
+ # Request is executed immediately.
31
+ # @param [String] friendly_name The string that you assigned to describe the Flow.
32
+ # @param [flow.Status] status The status of the Flow. Can be: `draft` or
33
+ # `published`.
34
+ # @param [String] definition JSON representation of flow definition.
35
+ # @param [String] commit_message Description on change made in the revision.
36
+ # @return [FlowInstance] Newly created FlowInstance
37
+ def create(friendly_name: nil, status: nil, definition: nil, commit_message: :unset)
38
+ data = Twilio::Values.of({
39
+ 'FriendlyName' => friendly_name,
40
+ 'Status' => status,
41
+ 'Definition' => definition,
42
+ 'CommitMessage' => commit_message,
43
+ })
44
+
45
+ payload = @version.create(
46
+ 'POST',
47
+ @uri,
48
+ data: data
49
+ )
50
+
51
+ FlowInstance.new(@version, payload, )
52
+ end
53
+
54
+ ##
55
+ # Lists FlowInstance 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(limit: limit, page_size: page_size).entries
67
+ end
68
+
69
+ ##
70
+ # Streams FlowInstance records from the API as an Enumerable.
71
+ # This operation lazily loads records as efficiently as possible until the limit
72
+ # is reached.
73
+ # @param [Integer] limit Upper limit for the number of records to return. stream()
74
+ # guarantees to never return more than limit. Default is no limit.
75
+ # @param [Integer] page_size Number of records to fetch per request, when
76
+ # not set will use the default value of 50 records. If no page_size is defined
77
+ # but a limit is defined, stream() will attempt to read the limit with the most
78
+ # efficient page size, i.e. min(limit, 1000)
79
+ # @return [Enumerable] Enumerable that will yield up to limit results
80
+ def stream(limit: nil, page_size: nil)
81
+ limits = @version.read_limits(limit, page_size)
82
+
83
+ page = self.page(page_size: limits[:page_size], )
84
+
85
+ @version.stream(page, limit: limits[:limit], page_limit: limits[:page_limit])
86
+ end
87
+
88
+ ##
89
+ # When passed a block, yields FlowInstance records from the API.
90
+ # This operation lazily loads records as efficiently as possible until the limit
91
+ # is reached.
92
+ def each
93
+ limits = @version.read_limits
94
+
95
+ page = self.page(page_size: limits[:page_size], )
96
+
97
+ @version.stream(page,
98
+ limit: limits[:limit],
99
+ page_limit: limits[:page_limit]).each {|x| yield x}
100
+ end
101
+
102
+ ##
103
+ # Retrieve a single page of FlowInstance records from the API.
104
+ # Request is executed immediately.
105
+ # @param [String] page_token PageToken provided by the API
106
+ # @param [Integer] page_number Page Number, this value is simply for client state
107
+ # @param [Integer] page_size Number of records to return, defaults to 50
108
+ # @return [Page] Page of FlowInstance
109
+ def page(page_token: :unset, page_number: :unset, page_size: :unset)
110
+ params = Twilio::Values.of({
111
+ 'PageToken' => page_token,
112
+ 'Page' => page_number,
113
+ 'PageSize' => page_size,
114
+ })
115
+ response = @version.page(
116
+ 'GET',
117
+ @uri,
118
+ params
119
+ )
120
+ FlowPage.new(@version, response, @solution)
121
+ end
122
+
123
+ ##
124
+ # Retrieve a single page of FlowInstance records from the API.
125
+ # Request is executed immediately.
126
+ # @param [String] target_url API-generated URL for the requested results page
127
+ # @return [Page] Page of FlowInstance
128
+ def get_page(target_url)
129
+ response = @version.domain.request(
130
+ 'GET',
131
+ target_url
132
+ )
133
+ FlowPage.new(@version, response, @solution)
134
+ end
135
+
136
+ ##
137
+ # Provide a user friendly representation
138
+ def to_s
139
+ '#<Twilio.Studio.V2.FlowList>'
140
+ end
141
+ end
142
+
143
+ ##
144
+ # PLEASE NOTE that this class contains beta products that are subject to change. Use them with caution.
145
+ class FlowPage < Page
146
+ ##
147
+ # Initialize the FlowPage
148
+ # @param [Version] version Version that contains the resource
149
+ # @param [Response] response Response from the API
150
+ # @param [Hash] solution Path solution for the resource
151
+ # @return [FlowPage] FlowPage
152
+ def initialize(version, response, solution)
153
+ super(version, response)
154
+
155
+ # Path Solution
156
+ @solution = solution
157
+ end
158
+
159
+ ##
160
+ # Build an instance of FlowInstance
161
+ # @param [Hash] payload Payload response from the API
162
+ # @return [FlowInstance] FlowInstance
163
+ def get_instance(payload)
164
+ FlowInstance.new(@version, payload, )
165
+ end
166
+
167
+ ##
168
+ # Provide a user friendly representation
169
+ def to_s
170
+ '<Twilio.Studio.V2.FlowPage>'
171
+ end
172
+ end
173
+
174
+ ##
175
+ # PLEASE NOTE that this class contains beta products that are subject to change. Use them with caution.
176
+ class FlowContext < InstanceContext
177
+ ##
178
+ # Initialize the FlowContext
179
+ # @param [Version] version Version that contains the resource
180
+ # @param [String] sid The SID of the Flow resource to fetch.
181
+ # @return [FlowContext] FlowContext
182
+ def initialize(version, sid)
183
+ super(version)
184
+
185
+ # Path Solution
186
+ @solution = {sid: sid, }
187
+ @uri = "/Flows/#{@solution[:sid]}"
188
+
189
+ # Dependents
190
+ @revisions = nil
191
+ end
192
+
193
+ ##
194
+ # Update the FlowInstance
195
+ # @param [flow.Status] status The status of the Flow. Can be: `draft` or
196
+ # `published`.
197
+ # @param [String] friendly_name The string that you assigned to describe the Flow.
198
+ # @param [String] definition JSON representation of flow definition.
199
+ # @param [String] commit_message Description on change made in the revision.
200
+ # @return [FlowInstance] Updated FlowInstance
201
+ def update(status: nil, friendly_name: :unset, definition: :unset, commit_message: :unset)
202
+ data = Twilio::Values.of({
203
+ 'Status' => status,
204
+ 'FriendlyName' => friendly_name,
205
+ 'Definition' => definition,
206
+ 'CommitMessage' => commit_message,
207
+ })
208
+
209
+ payload = @version.update(
210
+ 'POST',
211
+ @uri,
212
+ data: data,
213
+ )
214
+
215
+ FlowInstance.new(@version, payload, sid: @solution[:sid], )
216
+ end
217
+
218
+ ##
219
+ # Fetch a FlowInstance
220
+ # @return [FlowInstance] Fetched FlowInstance
221
+ def fetch
222
+ params = Twilio::Values.of({})
223
+
224
+ payload = @version.fetch(
225
+ 'GET',
226
+ @uri,
227
+ params,
228
+ )
229
+
230
+ FlowInstance.new(@version, payload, sid: @solution[:sid], )
231
+ end
232
+
233
+ ##
234
+ # Deletes the FlowInstance
235
+ # @return [Boolean] true if delete succeeds, false otherwise
236
+ def delete
237
+ @version.delete('delete', @uri)
238
+ end
239
+
240
+ ##
241
+ # Access the revisions
242
+ # @return [FlowRevisionList]
243
+ # @return [FlowRevisionContext] if revision was passed.
244
+ def revisions(revision=:unset)
245
+ raise ArgumentError, 'revision cannot be nil' if revision.nil?
246
+
247
+ if revision != :unset
248
+ return FlowRevisionContext.new(@version, @solution[:sid], revision, )
249
+ end
250
+
251
+ unless @revisions
252
+ @revisions = FlowRevisionList.new(@version, sid: @solution[:sid], )
253
+ end
254
+
255
+ @revisions
256
+ end
257
+
258
+ ##
259
+ # Provide a user friendly representation
260
+ def to_s
261
+ context = @solution.map {|k, v| "#{k}: #{v}"}.join(',')
262
+ "#<Twilio.Studio.V2.FlowContext #{context}>"
263
+ end
264
+
265
+ ##
266
+ # Provide a detailed, user friendly representation
267
+ def inspect
268
+ context = @solution.map {|k, v| "#{k}: #{v}"}.join(',')
269
+ "#<Twilio.Studio.V2.FlowContext #{context}>"
270
+ end
271
+ end
272
+
273
+ ##
274
+ # PLEASE NOTE that this class contains beta products that are subject to change. Use them with caution.
275
+ class FlowInstance < InstanceResource
276
+ ##
277
+ # Initialize the FlowInstance
278
+ # @param [Version] version Version that contains the resource
279
+ # @param [Hash] payload payload that contains response from Twilio
280
+ # @param [String] sid The SID of the Flow resource to fetch.
281
+ # @return [FlowInstance] FlowInstance
282
+ def initialize(version, payload, sid: nil)
283
+ super(version)
284
+
285
+ # Marshaled Properties
286
+ @properties = {
287
+ 'sid' => payload['sid'],
288
+ 'account_sid' => payload['account_sid'],
289
+ 'friendly_name' => payload['friendly_name'],
290
+ 'definition' => payload['definition'],
291
+ 'status' => payload['status'],
292
+ 'revision' => payload['revision'].to_i,
293
+ 'commit_message' => payload['commit_message'],
294
+ 'valid' => payload['valid'],
295
+ 'errors' => payload['errors'],
296
+ 'date_created' => Twilio.deserialize_iso8601_datetime(payload['date_created']),
297
+ 'date_updated' => Twilio.deserialize_iso8601_datetime(payload['date_updated']),
298
+ 'url' => payload['url'],
299
+ 'links' => payload['links'],
300
+ }
301
+
302
+ # Context
303
+ @instance_context = nil
304
+ @params = {'sid' => sid || @properties['sid'], }
305
+ end
306
+
307
+ ##
308
+ # Generate an instance context for the instance, the context is capable of
309
+ # performing various actions. All instance actions are proxied to the context
310
+ # @return [FlowContext] FlowContext for this FlowInstance
311
+ def context
312
+ unless @instance_context
313
+ @instance_context = FlowContext.new(@version, @params['sid'], )
314
+ end
315
+ @instance_context
316
+ end
317
+
318
+ ##
319
+ # @return [String] The unique string that identifies the resource
320
+ def sid
321
+ @properties['sid']
322
+ end
323
+
324
+ ##
325
+ # @return [String] The SID of the Account that created the resource
326
+ def account_sid
327
+ @properties['account_sid']
328
+ end
329
+
330
+ ##
331
+ # @return [String] The string that you assigned to describe the Flow
332
+ def friendly_name
333
+ @properties['friendly_name']
334
+ end
335
+
336
+ ##
337
+ # @return [Hash] JSON representation of flow definition
338
+ def definition
339
+ @properties['definition']
340
+ end
341
+
342
+ ##
343
+ # @return [flow.Status] The status of the Flow
344
+ def status
345
+ @properties['status']
346
+ end
347
+
348
+ ##
349
+ # @return [String] The latest revision number of the Flow's definition
350
+ def revision
351
+ @properties['revision']
352
+ end
353
+
354
+ ##
355
+ # @return [String] Description on change made in the revision
356
+ def commit_message
357
+ @properties['commit_message']
358
+ end
359
+
360
+ ##
361
+ # @return [Boolean] Boolean if the flow definition is valid
362
+ def valid
363
+ @properties['valid']
364
+ end
365
+
366
+ ##
367
+ # @return [Hash] List of error in the flow definition
368
+ def errors
369
+ @properties['errors']
370
+ end
371
+
372
+ ##
373
+ # @return [Time] The ISO 8601 date and time in GMT when the resource was created
374
+ def date_created
375
+ @properties['date_created']
376
+ end
377
+
378
+ ##
379
+ # @return [Time] The ISO 8601 date and time in GMT when the resource was last updated
380
+ def date_updated
381
+ @properties['date_updated']
382
+ end
383
+
384
+ ##
385
+ # @return [String] The absolute URL of the resource
386
+ def url
387
+ @properties['url']
388
+ end
389
+
390
+ ##
391
+ # @return [String] Nested resource URLs
392
+ def links
393
+ @properties['links']
394
+ end
395
+
396
+ ##
397
+ # Update the FlowInstance
398
+ # @param [flow.Status] status The status of the Flow. Can be: `draft` or
399
+ # `published`.
400
+ # @param [String] friendly_name The string that you assigned to describe the Flow.
401
+ # @param [String] definition JSON representation of flow definition.
402
+ # @param [String] commit_message Description on change made in the revision.
403
+ # @return [FlowInstance] Updated FlowInstance
404
+ def update(status: nil, friendly_name: :unset, definition: :unset, commit_message: :unset)
405
+ context.update(
406
+ status: status,
407
+ friendly_name: friendly_name,
408
+ definition: definition,
409
+ commit_message: commit_message,
410
+ )
411
+ end
412
+
413
+ ##
414
+ # Fetch a FlowInstance
415
+ # @return [FlowInstance] Fetched FlowInstance
416
+ def fetch
417
+ context.fetch
418
+ end
419
+
420
+ ##
421
+ # Deletes the FlowInstance
422
+ # @return [Boolean] true if delete succeeds, false otherwise
423
+ def delete
424
+ context.delete
425
+ end
426
+
427
+ ##
428
+ # Access the revisions
429
+ # @return [revisions] revisions
430
+ def revisions
431
+ context.revisions
432
+ end
433
+
434
+ ##
435
+ # Provide a user friendly representation
436
+ def to_s
437
+ values = @params.map{|k, v| "#{k}: #{v}"}.join(" ")
438
+ "<Twilio.Studio.V2.FlowInstance #{values}>"
439
+ end
440
+
441
+ ##
442
+ # Provide a detailed, user friendly representation
443
+ def inspect
444
+ values = @properties.map{|k, v| "#{k}: #{v}"}.join(" ")
445
+ "<Twilio.Studio.V2.FlowInstance #{values}>"
446
+ end
447
+ end
448
+ end
449
+ end
450
+ end
451
+ end