phrase 4.9.0 → 4.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,355 @@
1
+ require 'date'
2
+
3
+ module Phrase
4
+ class Automation
5
+ attr_accessor :id
6
+
7
+ attr_accessor :name
8
+
9
+ attr_accessor :status
10
+
11
+ attr_accessor :trigger
12
+
13
+ # translation key statuses used to filter keys that are added to jobs
14
+ attr_accessor :status_filters
15
+
16
+ attr_accessor :project_id
17
+
18
+ attr_accessor :job_template_id
19
+
20
+ attr_accessor :tags
21
+
22
+ attr_accessor :cron_schedule
23
+
24
+ attr_accessor :time_zone
25
+
26
+ attr_accessor :account
27
+
28
+ attr_accessor :created_at
29
+
30
+ attr_accessor :updated_at
31
+
32
+ class EnumAttributeValidator
33
+ attr_reader :datatype
34
+ attr_reader :allowable_values
35
+
36
+ def initialize(datatype, allowable_values)
37
+ @allowable_values = allowable_values.map do |value|
38
+ case datatype.to_s
39
+ when /Integer/i
40
+ value.to_i
41
+ when /Float/i
42
+ value.to_f
43
+ else
44
+ value
45
+ end
46
+ end
47
+ end
48
+
49
+ def valid?(value)
50
+ !value || allowable_values.include?(value)
51
+ end
52
+ end
53
+
54
+ # Attribute mapping from ruby-style variable name to JSON key.
55
+ def self.attribute_map
56
+ {
57
+ :'id' => :'id',
58
+ :'name' => :'name',
59
+ :'status' => :'status',
60
+ :'trigger' => :'trigger',
61
+ :'status_filters' => :'status_filters',
62
+ :'project_id' => :'project_id',
63
+ :'job_template_id' => :'job_template_id',
64
+ :'tags' => :'tags',
65
+ :'cron_schedule' => :'cron_schedule',
66
+ :'time_zone' => :'time_zone',
67
+ :'account' => :'account',
68
+ :'created_at' => :'created_at',
69
+ :'updated_at' => :'updated_at'
70
+ }
71
+ end
72
+
73
+ # Attribute type mapping.
74
+ def self.openapi_types
75
+ {
76
+ :'id' => :'String',
77
+ :'name' => :'String',
78
+ :'status' => :'String',
79
+ :'trigger' => :'String',
80
+ :'status_filters' => :'Array<String>',
81
+ :'project_id' => :'String',
82
+ :'job_template_id' => :'String',
83
+ :'tags' => :'Array<String>',
84
+ :'cron_schedule' => :'String',
85
+ :'time_zone' => :'String',
86
+ :'account' => :'Account',
87
+ :'created_at' => :'DateTime',
88
+ :'updated_at' => :'DateTime'
89
+ }
90
+ end
91
+
92
+ # List of attributes with nullable: true
93
+ def self.openapi_nullable
94
+ Set.new([
95
+ ])
96
+ end
97
+
98
+ # Initializes the object
99
+ # @param [Hash] attributes Model attributes in the form of hash
100
+ def initialize(attributes = {})
101
+ if (!attributes.is_a?(Hash))
102
+ fail ArgumentError, "The input argument (attributes) must be a hash in `Phrase::Automation` initialize method"
103
+ end
104
+
105
+ # check to see if the attribute exists and convert string to symbol for hash key
106
+ attributes = attributes.each_with_object({}) { |(k, v), h|
107
+ if (!self.class.attribute_map.key?(k.to_sym))
108
+ fail ArgumentError, "`#{k}` is not a valid attribute in `Phrase::Automation`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
109
+ end
110
+ h[k.to_sym] = v
111
+ }
112
+
113
+ if attributes.key?(:'id')
114
+ self.id = attributes[:'id']
115
+ end
116
+
117
+ if attributes.key?(:'name')
118
+ self.name = attributes[:'name']
119
+ end
120
+
121
+ if attributes.key?(:'status')
122
+ self.status = attributes[:'status']
123
+ end
124
+
125
+ if attributes.key?(:'trigger')
126
+ self.trigger = attributes[:'trigger']
127
+ end
128
+
129
+ if attributes.key?(:'status_filters')
130
+ if (value = attributes[:'status_filters']).is_a?(Array)
131
+ self.status_filters = value
132
+ end
133
+ end
134
+
135
+ if attributes.key?(:'project_id')
136
+ self.project_id = attributes[:'project_id']
137
+ end
138
+
139
+ if attributes.key?(:'job_template_id')
140
+ self.job_template_id = attributes[:'job_template_id']
141
+ end
142
+
143
+ if attributes.key?(:'tags')
144
+ if (value = attributes[:'tags']).is_a?(Array)
145
+ self.tags = value
146
+ end
147
+ end
148
+
149
+ if attributes.key?(:'cron_schedule')
150
+ self.cron_schedule = attributes[:'cron_schedule']
151
+ end
152
+
153
+ if attributes.key?(:'time_zone')
154
+ self.time_zone = attributes[:'time_zone']
155
+ end
156
+
157
+ if attributes.key?(:'account')
158
+ self.account = attributes[:'account']
159
+ end
160
+
161
+ if attributes.key?(:'created_at')
162
+ self.created_at = attributes[:'created_at']
163
+ end
164
+
165
+ if attributes.key?(:'updated_at')
166
+ self.updated_at = attributes[:'updated_at']
167
+ end
168
+ end
169
+
170
+ # Show invalid properties with the reasons. Usually used together with valid?
171
+ # @return Array for valid properties with the reasons
172
+ def list_invalid_properties
173
+ invalid_properties = Array.new
174
+ invalid_properties
175
+ end
176
+
177
+ # Check to see if the all the properties in the model are valid
178
+ # @return true if the model is valid
179
+ def valid?
180
+ status_validator = EnumAttributeValidator.new('String', ["inactive", "active", "error"])
181
+ return false unless status_validator.valid?(@status)
182
+ trigger_validator = EnumAttributeValidator.new('String', ["schedule", "upload"])
183
+ return false unless trigger_validator.valid?(@trigger)
184
+ true
185
+ end
186
+
187
+ # Custom attribute writer method checking allowed values (enum).
188
+ # @param [Object] status Object to be assigned
189
+ def status=(status)
190
+ validator = EnumAttributeValidator.new('String', ["inactive", "active", "error"])
191
+ unless validator.valid?(status)
192
+ fail ArgumentError, "invalid value for \"status\", must be one of #{validator.allowable_values}."
193
+ end
194
+ @status = status
195
+ end
196
+
197
+ # Custom attribute writer method checking allowed values (enum).
198
+ # @param [Object] trigger Object to be assigned
199
+ def trigger=(trigger)
200
+ validator = EnumAttributeValidator.new('String', ["schedule", "upload"])
201
+ unless validator.valid?(trigger)
202
+ fail ArgumentError, "invalid value for \"trigger\", must be one of #{validator.allowable_values}."
203
+ end
204
+ @trigger = trigger
205
+ end
206
+
207
+ # Checks equality by comparing each attribute.
208
+ # @param [Object] Object to be compared
209
+ def ==(o)
210
+ return true if self.equal?(o)
211
+ self.class == o.class &&
212
+ id == o.id &&
213
+ name == o.name &&
214
+ status == o.status &&
215
+ trigger == o.trigger &&
216
+ status_filters == o.status_filters &&
217
+ project_id == o.project_id &&
218
+ job_template_id == o.job_template_id &&
219
+ tags == o.tags &&
220
+ cron_schedule == o.cron_schedule &&
221
+ time_zone == o.time_zone &&
222
+ account == o.account &&
223
+ created_at == o.created_at &&
224
+ updated_at == o.updated_at
225
+ end
226
+
227
+ # @see the `==` method
228
+ # @param [Object] Object to be compared
229
+ def eql?(o)
230
+ self == o
231
+ end
232
+
233
+ # Calculates hash code according to all attributes.
234
+ # @return [Integer] Hash code
235
+ def hash
236
+ [id, name, status, trigger, status_filters, project_id, job_template_id, tags, cron_schedule, time_zone, account, created_at, updated_at].hash
237
+ end
238
+
239
+ # Builds the object from hash
240
+ # @param [Hash] attributes Model attributes in the form of hash
241
+ # @return [Object] Returns the model itself
242
+ def self.build_from_hash(attributes)
243
+ new.build_from_hash(attributes)
244
+ end
245
+
246
+ # Builds the object from hash
247
+ # @param [Hash] attributes Model attributes in the form of hash
248
+ # @return [Object] Returns the model itself
249
+ def build_from_hash(attributes)
250
+ return nil unless attributes.is_a?(Hash)
251
+ self.class.openapi_types.each_pair do |key, type|
252
+ if type =~ /\AArray<(.*)>/i
253
+ # check to ensure the input is an array given that the attribute
254
+ # is documented as an array but the input is not
255
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
256
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
257
+ end
258
+ elsif !attributes[self.class.attribute_map[key]].nil?
259
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
260
+ end # or else data not found in attributes(hash), not an issue as the data can be optional
261
+ end
262
+
263
+ self
264
+ end
265
+
266
+ # Deserializes the data based on type
267
+ # @param string type Data type
268
+ # @param string value Value to be deserialized
269
+ # @return [Object] Deserialized data
270
+ def _deserialize(type, value)
271
+ case type.to_sym
272
+ when :DateTime
273
+ DateTime.parse(value)
274
+ when :Date
275
+ Date.parse(value)
276
+ when :Time
277
+ Time.parse(value)
278
+ when :String
279
+ value.to_s
280
+ when :Integer
281
+ value.to_i
282
+ when :Float
283
+ value.to_f
284
+ when :Boolean
285
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
286
+ true
287
+ else
288
+ false
289
+ end
290
+ when :Object
291
+ # generic object (usually a Hash), return directly
292
+ value
293
+ when /\AArray<(?<inner_type>.+)>\z/
294
+ inner_type = Regexp.last_match[:inner_type]
295
+ value.map { |v| _deserialize(inner_type, v) }
296
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
297
+ k_type = Regexp.last_match[:k_type]
298
+ v_type = Regexp.last_match[:v_type]
299
+ {}.tap do |hash|
300
+ value.each do |k, v|
301
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
302
+ end
303
+ end
304
+ else # model
305
+ Phrase.const_get(type).build_from_hash(value)
306
+ end
307
+ end
308
+
309
+ # Returns the string representation of the object
310
+ # @return [String] String presentation of the object
311
+ def to_s
312
+ to_hash.to_s
313
+ end
314
+
315
+ # to_body is an alias to to_hash (backward compatibility)
316
+ # @return [Hash] Returns the object in the form of hash
317
+ def to_body
318
+ to_hash
319
+ end
320
+
321
+ # Returns the object in the form of hash
322
+ # @return [Hash] Returns the object in the form of hash
323
+ def to_hash
324
+ hash = {}
325
+ self.class.attribute_map.each_pair do |attr, param|
326
+ value = self.send(attr)
327
+ if value.nil?
328
+ is_nullable = self.class.openapi_nullable.include?(attr)
329
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
330
+ end
331
+
332
+ hash[param] = _to_hash(value)
333
+ end
334
+ hash
335
+ end
336
+
337
+ # Outputs non-array value in the form of hash
338
+ # For object, use to_hash. Otherwise, just return the value
339
+ # @param [Object] value Any valid value
340
+ # @return [Hash] Returns the value in the form of hash
341
+ def _to_hash(value)
342
+ if value.is_a?(Array)
343
+ value.compact.map { |v| _to_hash(v) }
344
+ elsif value.is_a?(Hash)
345
+ {}.tap do |hash|
346
+ value.each { |k, v| hash[k] = _to_hash(v) }
347
+ end
348
+ elsif value.respond_to? :to_hash
349
+ value.to_hash
350
+ else
351
+ value
352
+ end
353
+ end
354
+ end
355
+ end
@@ -0,0 +1,326 @@
1
+ require 'date'
2
+
3
+ module Phrase
4
+ class AutomationsCreateParameters
5
+ # name of the automation
6
+ attr_accessor :name
7
+
8
+ attr_accessor :trigger
9
+
10
+ # List of project IDs to associate with the automation. Currently, only the first ID in the array is used. The array format leaves room for future support of multiple projects.
11
+ attr_accessor :project_ids
12
+
13
+ # id of job template that the automation uses to create jobs from
14
+ attr_accessor :job_template_id
15
+
16
+ # Translation states used when selecting keys for a job. States are derived from associated translations, not the keys themselves. When review workflow is enabled, `ready_for_review` is internally treated as `translated`.
17
+ attr_accessor :status_filters
18
+
19
+ # used to filter which keys are added to jobs
20
+ attr_accessor :tags
21
+
22
+ # along with time_zone, specifies when the scheduled automation is supposed to run
23
+ attr_accessor :cron_schedule
24
+
25
+ # along with cron_schedule, specifies when the scheduled automation is supposed to run
26
+ attr_accessor :time_zone
27
+
28
+ class EnumAttributeValidator
29
+ attr_reader :datatype
30
+ attr_reader :allowable_values
31
+
32
+ def initialize(datatype, allowable_values)
33
+ @allowable_values = allowable_values.map do |value|
34
+ case datatype.to_s
35
+ when /Integer/i
36
+ value.to_i
37
+ when /Float/i
38
+ value.to_f
39
+ else
40
+ value
41
+ end
42
+ end
43
+ end
44
+
45
+ def valid?(value)
46
+ !value || allowable_values.include?(value)
47
+ end
48
+ end
49
+
50
+ # Attribute mapping from ruby-style variable name to JSON key.
51
+ def self.attribute_map
52
+ {
53
+ :'name' => :'name',
54
+ :'trigger' => :'trigger',
55
+ :'project_ids' => :'project_ids',
56
+ :'job_template_id' => :'job_template_id',
57
+ :'status_filters' => :'status_filters',
58
+ :'tags' => :'tags',
59
+ :'cron_schedule' => :'cron_schedule',
60
+ :'time_zone' => :'time_zone'
61
+ }
62
+ end
63
+
64
+ # Attribute type mapping.
65
+ def self.openapi_types
66
+ {
67
+ :'name' => :'String',
68
+ :'trigger' => :'String',
69
+ :'project_ids' => :'Array<String>',
70
+ :'job_template_id' => :'String',
71
+ :'status_filters' => :'Array<String>',
72
+ :'tags' => :'Array<String>',
73
+ :'cron_schedule' => :'String',
74
+ :'time_zone' => :'String'
75
+ }
76
+ end
77
+
78
+ # List of attributes with nullable: true
79
+ def self.openapi_nullable
80
+ Set.new([
81
+ ])
82
+ end
83
+
84
+ # Initializes the object
85
+ # @param [Hash] attributes Model attributes in the form of hash
86
+ def initialize(attributes = {})
87
+ if (!attributes.is_a?(Hash))
88
+ fail ArgumentError, "The input argument (attributes) must be a hash in `Phrase::AutomationsCreateParameters` initialize method"
89
+ end
90
+
91
+ # check to see if the attribute exists and convert string to symbol for hash key
92
+ attributes = attributes.each_with_object({}) { |(k, v), h|
93
+ if (!self.class.attribute_map.key?(k.to_sym))
94
+ fail ArgumentError, "`#{k}` is not a valid attribute in `Phrase::AutomationsCreateParameters`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
95
+ end
96
+ h[k.to_sym] = v
97
+ }
98
+
99
+ if attributes.key?(:'name')
100
+ self.name = attributes[:'name']
101
+ end
102
+
103
+ if attributes.key?(:'trigger')
104
+ self.trigger = attributes[:'trigger']
105
+ end
106
+
107
+ if attributes.key?(:'project_ids')
108
+ if (value = attributes[:'project_ids']).is_a?(Array)
109
+ self.project_ids = value
110
+ end
111
+ end
112
+
113
+ if attributes.key?(:'job_template_id')
114
+ self.job_template_id = attributes[:'job_template_id']
115
+ end
116
+
117
+ if attributes.key?(:'status_filters')
118
+ if (value = attributes[:'status_filters']).is_a?(Array)
119
+ self.status_filters = value
120
+ end
121
+ end
122
+
123
+ if attributes.key?(:'tags')
124
+ if (value = attributes[:'tags']).is_a?(Array)
125
+ self.tags = value
126
+ end
127
+ end
128
+
129
+ if attributes.key?(:'cron_schedule')
130
+ self.cron_schedule = attributes[:'cron_schedule']
131
+ end
132
+
133
+ if attributes.key?(:'time_zone')
134
+ self.time_zone = attributes[:'time_zone']
135
+ end
136
+ end
137
+
138
+ # Show invalid properties with the reasons. Usually used together with valid?
139
+ # @return Array for valid properties with the reasons
140
+ def list_invalid_properties
141
+ invalid_properties = Array.new
142
+ if @name.nil?
143
+ invalid_properties.push('invalid value for "name", name cannot be nil.')
144
+ end
145
+
146
+ if @trigger.nil?
147
+ invalid_properties.push('invalid value for "trigger", trigger cannot be nil.')
148
+ end
149
+
150
+ if @project_ids.nil?
151
+ invalid_properties.push('invalid value for "project_ids", project_ids cannot be nil.')
152
+ end
153
+
154
+ if @status_filters.nil?
155
+ invalid_properties.push('invalid value for "status_filters", status_filters cannot be nil.')
156
+ end
157
+
158
+ invalid_properties
159
+ end
160
+
161
+ # Check to see if the all the properties in the model are valid
162
+ # @return true if the model is valid
163
+ def valid?
164
+ return false if @name.nil?
165
+ return false if @trigger.nil?
166
+ trigger_validator = EnumAttributeValidator.new('String', ["schedule", "upload"])
167
+ return false unless trigger_validator.valid?(@trigger)
168
+ return false if @project_ids.nil?
169
+ return false if @status_filters.nil?
170
+ true
171
+ end
172
+
173
+ # Custom attribute writer method checking allowed values (enum).
174
+ # @param [Object] trigger Object to be assigned
175
+ def trigger=(trigger)
176
+ validator = EnumAttributeValidator.new('String', ["schedule", "upload"])
177
+ unless validator.valid?(trigger)
178
+ fail ArgumentError, "invalid value for \"trigger\", must be one of #{validator.allowable_values}."
179
+ end
180
+ @trigger = trigger
181
+ end
182
+
183
+ # Checks equality by comparing each attribute.
184
+ # @param [Object] Object to be compared
185
+ def ==(o)
186
+ return true if self.equal?(o)
187
+ self.class == o.class &&
188
+ name == o.name &&
189
+ trigger == o.trigger &&
190
+ project_ids == o.project_ids &&
191
+ job_template_id == o.job_template_id &&
192
+ status_filters == o.status_filters &&
193
+ tags == o.tags &&
194
+ cron_schedule == o.cron_schedule &&
195
+ time_zone == o.time_zone
196
+ end
197
+
198
+ # @see the `==` method
199
+ # @param [Object] Object to be compared
200
+ def eql?(o)
201
+ self == o
202
+ end
203
+
204
+ # Calculates hash code according to all attributes.
205
+ # @return [Integer] Hash code
206
+ def hash
207
+ [name, trigger, project_ids, job_template_id, status_filters, tags, cron_schedule, time_zone].hash
208
+ end
209
+
210
+ # Builds the object from hash
211
+ # @param [Hash] attributes Model attributes in the form of hash
212
+ # @return [Object] Returns the model itself
213
+ def self.build_from_hash(attributes)
214
+ new.build_from_hash(attributes)
215
+ end
216
+
217
+ # Builds the object from hash
218
+ # @param [Hash] attributes Model attributes in the form of hash
219
+ # @return [Object] Returns the model itself
220
+ def build_from_hash(attributes)
221
+ return nil unless attributes.is_a?(Hash)
222
+ self.class.openapi_types.each_pair do |key, type|
223
+ if type =~ /\AArray<(.*)>/i
224
+ # check to ensure the input is an array given that the attribute
225
+ # is documented as an array but the input is not
226
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
227
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
228
+ end
229
+ elsif !attributes[self.class.attribute_map[key]].nil?
230
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
231
+ end # or else data not found in attributes(hash), not an issue as the data can be optional
232
+ end
233
+
234
+ self
235
+ end
236
+
237
+ # Deserializes the data based on type
238
+ # @param string type Data type
239
+ # @param string value Value to be deserialized
240
+ # @return [Object] Deserialized data
241
+ def _deserialize(type, value)
242
+ case type.to_sym
243
+ when :DateTime
244
+ DateTime.parse(value)
245
+ when :Date
246
+ Date.parse(value)
247
+ when :Time
248
+ Time.parse(value)
249
+ when :String
250
+ value.to_s
251
+ when :Integer
252
+ value.to_i
253
+ when :Float
254
+ value.to_f
255
+ when :Boolean
256
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
257
+ true
258
+ else
259
+ false
260
+ end
261
+ when :Object
262
+ # generic object (usually a Hash), return directly
263
+ value
264
+ when /\AArray<(?<inner_type>.+)>\z/
265
+ inner_type = Regexp.last_match[:inner_type]
266
+ value.map { |v| _deserialize(inner_type, v) }
267
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
268
+ k_type = Regexp.last_match[:k_type]
269
+ v_type = Regexp.last_match[:v_type]
270
+ {}.tap do |hash|
271
+ value.each do |k, v|
272
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
273
+ end
274
+ end
275
+ else # model
276
+ Phrase.const_get(type).build_from_hash(value)
277
+ end
278
+ end
279
+
280
+ # Returns the string representation of the object
281
+ # @return [String] String presentation of the object
282
+ def to_s
283
+ to_hash.to_s
284
+ end
285
+
286
+ # to_body is an alias to to_hash (backward compatibility)
287
+ # @return [Hash] Returns the object in the form of hash
288
+ def to_body
289
+ to_hash
290
+ end
291
+
292
+ # Returns the object in the form of hash
293
+ # @return [Hash] Returns the object in the form of hash
294
+ def to_hash
295
+ hash = {}
296
+ self.class.attribute_map.each_pair do |attr, param|
297
+ value = self.send(attr)
298
+ if value.nil?
299
+ is_nullable = self.class.openapi_nullable.include?(attr)
300
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
301
+ end
302
+
303
+ hash[param] = _to_hash(value)
304
+ end
305
+ hash
306
+ end
307
+
308
+ # Outputs non-array value in the form of hash
309
+ # For object, use to_hash. Otherwise, just return the value
310
+ # @param [Object] value Any valid value
311
+ # @return [Hash] Returns the value in the form of hash
312
+ def _to_hash(value)
313
+ if value.is_a?(Array)
314
+ value.compact.map { |v| _to_hash(v) }
315
+ elsif value.is_a?(Hash)
316
+ {}.tap do |hash|
317
+ value.each { |k, v| hash[k] = _to_hash(v) }
318
+ end
319
+ elsif value.respond_to? :to_hash
320
+ value.to_hash
321
+ else
322
+ value
323
+ end
324
+ end
325
+ end
326
+ end