xero-ruby 3.0.0 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,321 @@
1
+ =begin
2
+ #Xero Accounting API
3
+
4
+ #No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
5
+
6
+ Contact: api@xero.com
7
+ Generated by: https://openapi-generator.tech
8
+ OpenAPI Generator version: 4.3.1
9
+
10
+ =end
11
+
12
+ require 'time'
13
+ require 'date'
14
+
15
+ module XeroRuby::Accounting
16
+ require 'bigdecimal'
17
+
18
+ class Budget
19
+ # Xero identifier
20
+ attr_accessor :budget_id
21
+
22
+ # Type of Budget. OVERALL or TRACKING
23
+ attr_accessor :type
24
+ OVERALL = "OVERALL".freeze
25
+ TRACKING = "TRACKING".freeze
26
+
27
+ # The Budget description
28
+ attr_accessor :description
29
+
30
+ # UTC timestamp of last update to budget
31
+ attr_accessor :updated_date_utc
32
+
33
+
34
+ attr_accessor :budget_lines
35
+
36
+
37
+ attr_accessor :tracking
38
+
39
+ class EnumAttributeValidator
40
+ attr_reader :datatype
41
+ attr_reader :allowable_values
42
+
43
+ def initialize(datatype, allowable_values)
44
+ @allowable_values = allowable_values.map do |value|
45
+ case datatype.to_s
46
+ when /Integer/i
47
+ value.to_i
48
+ when /Float/i
49
+ value.to_f
50
+ else
51
+ value
52
+ end
53
+ end
54
+ end
55
+
56
+ def valid?(value)
57
+ !value || allowable_values.include?(value)
58
+ end
59
+ end
60
+
61
+ # Attribute mapping from ruby-style variable name to JSON key.
62
+ def self.attribute_map
63
+ {
64
+ :'budget_id' => :'BudgetID',
65
+ :'type' => :'Type',
66
+ :'description' => :'Description',
67
+ :'updated_date_utc' => :'UpdatedDateUTC',
68
+ :'budget_lines' => :'BudgetLines',
69
+ :'tracking' => :'Tracking'
70
+ }
71
+ end
72
+
73
+ # Attribute type mapping.
74
+ def self.openapi_types
75
+ {
76
+ :'budget_id' => :'String',
77
+ :'type' => :'String',
78
+ :'description' => :'String',
79
+ :'updated_date_utc' => :'DateTime',
80
+ :'budget_lines' => :'BudgetLines',
81
+ :'tracking' => :'TrackingCategory'
82
+ }
83
+ end
84
+
85
+ # Initializes the object
86
+ # @param [Hash] attributes Model attributes in the form of hash
87
+ def initialize(attributes = {})
88
+ if (!attributes.is_a?(Hash))
89
+ fail ArgumentError, "The input argument (attributes) must be a hash in `XeroRuby::Accounting::Budget` initialize method"
90
+ end
91
+
92
+ # check to see if the attribute exists and convert string to symbol for hash key
93
+ attributes = attributes.each_with_object({}) { |(k, v), h|
94
+ if (!self.class.attribute_map.key?(k.to_sym))
95
+ fail ArgumentError, "`#{k}` is not a valid attribute in `XeroRuby::Accounting::Budget`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
96
+ end
97
+ h[k.to_sym] = v
98
+ }
99
+
100
+ if attributes.key?(:'budget_id')
101
+ self.budget_id = attributes[:'budget_id']
102
+ end
103
+
104
+ if attributes.key?(:'type')
105
+ self.type = attributes[:'type']
106
+ end
107
+
108
+ if attributes.key?(:'description')
109
+ self.description = attributes[:'description']
110
+ end
111
+
112
+ if attributes.key?(:'updated_date_utc')
113
+ self.updated_date_utc = attributes[:'updated_date_utc']
114
+ end
115
+
116
+ if attributes.key?(:'budget_lines')
117
+ self.budget_lines = attributes[:'budget_lines']
118
+ end
119
+
120
+ if attributes.key?(:'tracking')
121
+ self.tracking = attributes[:'tracking']
122
+ end
123
+ end
124
+
125
+ # Show invalid properties with the reasons. Usually used together with valid?
126
+ # @return Array for valid properties with the reasons
127
+ def list_invalid_properties
128
+ invalid_properties = Array.new
129
+ if !@description.nil? && @description.to_s.length > 255
130
+ invalid_properties.push('invalid value for "description", the character length must be smaller than or equal to 255.')
131
+ end
132
+
133
+ invalid_properties
134
+ end
135
+
136
+ # Check to see if the all the properties in the model are valid
137
+ # @return true if the model is valid
138
+ def valid?
139
+ type_validator = EnumAttributeValidator.new('String', ["OVERALL", "TRACKING"])
140
+ return false unless type_validator.valid?(@type)
141
+ return false if !@description.nil? && @description.to_s.length > 255
142
+ true
143
+ end
144
+
145
+ # Custom attribute writer method checking allowed values (enum).
146
+ # @param [Object] type Object to be assigned
147
+ def type=(type)
148
+ validator = EnumAttributeValidator.new('String', ["OVERALL", "TRACKING"])
149
+ unless validator.valid?(type)
150
+ fail ArgumentError, "invalid value for \"type\", must be one of #{validator.allowable_values}."
151
+ end
152
+ @type = type
153
+ end
154
+
155
+ # Custom attribute writer method with validation
156
+ # @param [Object] description Value to be assigned
157
+ def description=(description)
158
+ if !description.nil? && description.to_s.length > 255
159
+ fail ArgumentError, 'invalid value for "description", the character length must be smaller than or equal to 255.'
160
+ end
161
+
162
+ @description = description
163
+ end
164
+
165
+ # Checks equality by comparing each attribute.
166
+ # @param [Object] Object to be compared
167
+ def ==(o)
168
+ return true if self.equal?(o)
169
+ self.class == o.class &&
170
+ budget_id == o.budget_id &&
171
+ type == o.type &&
172
+ description == o.description &&
173
+ updated_date_utc == o.updated_date_utc &&
174
+ budget_lines == o.budget_lines &&
175
+ tracking == o.tracking
176
+ end
177
+
178
+ # @see the `==` method
179
+ # @param [Object] Object to be compared
180
+ def eql?(o)
181
+ self == o
182
+ end
183
+
184
+ # Calculates hash code according to all attributes.
185
+ # @return [Integer] Hash code
186
+ def hash
187
+ [budget_id, type, description, updated_date_utc, budget_lines, tracking].hash
188
+ end
189
+
190
+ # Builds the object from hash
191
+ # @param [Hash] attributes Model attributes in the form of hash
192
+ # @return [Object] Returns the model itself
193
+ def self.build_from_hash(attributes)
194
+ new.build_from_hash(attributes)
195
+ end
196
+
197
+ # Builds the object from hash
198
+ # @param [Hash] attributes Model attributes in the form of hash
199
+ # @return [Object] Returns the model itself
200
+ def build_from_hash(attributes)
201
+ return nil unless attributes.is_a?(Hash)
202
+ self.class.openapi_types.each_pair do |key, type|
203
+ if type =~ /\AArray<(.*)>/i
204
+ # check to ensure the input is an array given that the attribute
205
+ # is documented as an array but the input is not
206
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
207
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
208
+ end
209
+ elsif !attributes[self.class.attribute_map[key]].nil?
210
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
211
+ end # or else data not found in attributes(hash), not an issue as the data can be optional
212
+ end
213
+
214
+ self
215
+ end
216
+
217
+ # Deserializes the data based on type
218
+ # @param string type Data type
219
+ # @param string value Value to be deserialized
220
+ # @return [Object] Deserialized data
221
+ def _deserialize(type, value)
222
+ case type.to_sym
223
+ when :DateTime
224
+ DateTime.parse(parse_date(value))
225
+ when :Date
226
+ Date.parse(parse_date(value))
227
+ when :String
228
+ value.to_s
229
+ when :Integer
230
+ value.to_i
231
+ when :Float
232
+ value.to_f
233
+ when :BigDecimal
234
+ BigDecimal(value.to_s)
235
+ when :Boolean
236
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
237
+ true
238
+ else
239
+ false
240
+ end
241
+ when :Object
242
+ # generic object (usually a Hash), return directly
243
+ value
244
+ when /\AArray<(?<inner_type>.+)>\z/
245
+ inner_type = Regexp.last_match[:inner_type]
246
+ value.map { |v| _deserialize(inner_type, v) }
247
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
248
+ k_type = Regexp.last_match[:k_type]
249
+ v_type = Regexp.last_match[:v_type]
250
+ {}.tap do |hash|
251
+ value.each do |k, v|
252
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
253
+ end
254
+ end
255
+ else # model
256
+ XeroRuby::Accounting.const_get(type).build_from_hash(value)
257
+ end
258
+ end
259
+
260
+ # Returns the string representation of the object
261
+ # @return [String] String presentation of the object
262
+ def to_s
263
+ to_hash.to_s
264
+ end
265
+
266
+ # to_body is an alias to to_hash (backward compatibility)
267
+ # @return [Hash] Returns the object in the form of hash
268
+ def to_body
269
+ to_hash
270
+ end
271
+
272
+ # Returns the object in the form of hash
273
+ # @return [Hash] Returns the object in the form of hash
274
+ def to_hash(downcase: false)
275
+ hash = {}
276
+ self.class.attribute_map.each_pair do |attr, param|
277
+ value = self.send(attr)
278
+ next if value.nil?
279
+ key = downcase ? attr : param
280
+ hash[key] = _to_hash(value, downcase: downcase)
281
+ end
282
+ hash
283
+ end
284
+
285
+ # Returns the object in the form of hash with snake_case
286
+ def to_attributes
287
+ to_hash(downcase: true)
288
+ end
289
+
290
+ # Outputs non-array value in the form of hash
291
+ # For object, use to_hash. Otherwise, just return the value
292
+ # @param [Object] value Any valid value
293
+ # @return [Hash] Returns the value in the form of hash
294
+ def _to_hash(value, downcase: false)
295
+ if value.is_a?(Array)
296
+ value.map do |v|
297
+ v.to_hash(downcase: downcase)
298
+ end
299
+ elsif value.is_a?(Hash)
300
+ {}.tap do |hash|
301
+ value.map { |k, v| hash[k] = _to_hash(v, downcase: downcase) }
302
+ end
303
+ elsif value.respond_to? :to_hash
304
+ value.to_hash(downcase: downcase)
305
+ else
306
+ value
307
+ end
308
+ end
309
+
310
+ def parse_date(datestring)
311
+ if datestring.include?('Date')
312
+ date_pattern = /\/Date\((-?\d+)(\+\d+)?\)\//
313
+ original, date, timezone = *date_pattern.match(datestring)
314
+ date = (date.to_i / 1000)
315
+ Time.at(date).utc.strftime('%Y-%m-%dT%H:%M:%S%z').to_s
316
+ else # handle date 'types' for small subset of payroll API's
317
+ Time.parse(datestring).strftime('%Y-%m-%dT%H:%M:%S').to_s
318
+ end
319
+ end
320
+ end
321
+ end
@@ -0,0 +1,265 @@
1
+ =begin
2
+ #Xero Accounting API
3
+
4
+ #No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
5
+
6
+ Contact: api@xero.com
7
+ Generated by: https://openapi-generator.tech
8
+ OpenAPI Generator version: 4.3.1
9
+
10
+ =end
11
+
12
+ require 'time'
13
+ require 'date'
14
+
15
+ module XeroRuby::Accounting
16
+ require 'bigdecimal'
17
+
18
+ class BudgetLines
19
+ # Period the amount applies to (e.g. “2019-08”)
20
+ attr_accessor :period
21
+
22
+ # LineItem Quantity
23
+ attr_accessor :amount
24
+
25
+ # Budgeted amount
26
+ attr_accessor :unit_amount
27
+
28
+ # Any footnotes associated with this balance
29
+ attr_accessor :notes
30
+
31
+ # Attribute mapping from ruby-style variable name to JSON key.
32
+ def self.attribute_map
33
+ {
34
+ :'period' => :'Period',
35
+ :'amount' => :'Amount',
36
+ :'unit_amount' => :'UnitAmount',
37
+ :'notes' => :'Notes'
38
+ }
39
+ end
40
+
41
+ # Attribute type mapping.
42
+ def self.openapi_types
43
+ {
44
+ :'period' => :'Date',
45
+ :'amount' => :'Integer',
46
+ :'unit_amount' => :'Integer',
47
+ :'notes' => :'String'
48
+ }
49
+ end
50
+
51
+ # Initializes the object
52
+ # @param [Hash] attributes Model attributes in the form of hash
53
+ def initialize(attributes = {})
54
+ if (!attributes.is_a?(Hash))
55
+ fail ArgumentError, "The input argument (attributes) must be a hash in `XeroRuby::Accounting::BudgetLines` initialize method"
56
+ end
57
+
58
+ # check to see if the attribute exists and convert string to symbol for hash key
59
+ attributes = attributes.each_with_object({}) { |(k, v), h|
60
+ if (!self.class.attribute_map.key?(k.to_sym))
61
+ fail ArgumentError, "`#{k}` is not a valid attribute in `XeroRuby::Accounting::BudgetLines`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
62
+ end
63
+ h[k.to_sym] = v
64
+ }
65
+
66
+ if attributes.key?(:'period')
67
+ self.period = attributes[:'period']
68
+ end
69
+
70
+ if attributes.key?(:'amount')
71
+ self.amount = attributes[:'amount']
72
+ end
73
+
74
+ if attributes.key?(:'unit_amount')
75
+ self.unit_amount = attributes[:'unit_amount']
76
+ end
77
+
78
+ if attributes.key?(:'notes')
79
+ self.notes = attributes[:'notes']
80
+ end
81
+ end
82
+
83
+ # Show invalid properties with the reasons. Usually used together with valid?
84
+ # @return Array for valid properties with the reasons
85
+ def list_invalid_properties
86
+ invalid_properties = Array.new
87
+ if !@notes.nil? && @notes.to_s.length > 255
88
+ invalid_properties.push('invalid value for "notes", the character length must be smaller than or equal to 255.')
89
+ end
90
+
91
+ invalid_properties
92
+ end
93
+
94
+ # Check to see if the all the properties in the model are valid
95
+ # @return true if the model is valid
96
+ def valid?
97
+ return false if !@notes.nil? && @notes.to_s.length > 255
98
+ true
99
+ end
100
+
101
+ # Custom attribute writer method with validation
102
+ # @param [Object] notes Value to be assigned
103
+ def notes=(notes)
104
+ if !notes.nil? && notes.to_s.length > 255
105
+ fail ArgumentError, 'invalid value for "notes", the character length must be smaller than or equal to 255.'
106
+ end
107
+
108
+ @notes = notes
109
+ end
110
+
111
+ # Checks equality by comparing each attribute.
112
+ # @param [Object] Object to be compared
113
+ def ==(o)
114
+ return true if self.equal?(o)
115
+ self.class == o.class &&
116
+ period == o.period &&
117
+ amount == o.amount &&
118
+ unit_amount == o.unit_amount &&
119
+ notes == o.notes
120
+ end
121
+
122
+ # @see the `==` method
123
+ # @param [Object] Object to be compared
124
+ def eql?(o)
125
+ self == o
126
+ end
127
+
128
+ # Calculates hash code according to all attributes.
129
+ # @return [Integer] Hash code
130
+ def hash
131
+ [period, amount, unit_amount, notes].hash
132
+ end
133
+
134
+ # Builds the object from hash
135
+ # @param [Hash] attributes Model attributes in the form of hash
136
+ # @return [Object] Returns the model itself
137
+ def self.build_from_hash(attributes)
138
+ new.build_from_hash(attributes)
139
+ end
140
+
141
+ # Builds the object from hash
142
+ # @param [Hash] attributes Model attributes in the form of hash
143
+ # @return [Object] Returns the model itself
144
+ def build_from_hash(attributes)
145
+ return nil unless attributes.is_a?(Hash)
146
+ self.class.openapi_types.each_pair do |key, type|
147
+ if type =~ /\AArray<(.*)>/i
148
+ # check to ensure the input is an array given that the attribute
149
+ # is documented as an array but the input is not
150
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
151
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
152
+ end
153
+ elsif !attributes[self.class.attribute_map[key]].nil?
154
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
155
+ end # or else data not found in attributes(hash), not an issue as the data can be optional
156
+ end
157
+
158
+ self
159
+ end
160
+
161
+ # Deserializes the data based on type
162
+ # @param string type Data type
163
+ # @param string value Value to be deserialized
164
+ # @return [Object] Deserialized data
165
+ def _deserialize(type, value)
166
+ case type.to_sym
167
+ when :DateTime
168
+ DateTime.parse(parse_date(value))
169
+ when :Date
170
+ Date.parse(parse_date(value))
171
+ when :String
172
+ value.to_s
173
+ when :Integer
174
+ value.to_i
175
+ when :Float
176
+ value.to_f
177
+ when :BigDecimal
178
+ BigDecimal(value.to_s)
179
+ when :Boolean
180
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
181
+ true
182
+ else
183
+ false
184
+ end
185
+ when :Object
186
+ # generic object (usually a Hash), return directly
187
+ value
188
+ when /\AArray<(?<inner_type>.+)>\z/
189
+ inner_type = Regexp.last_match[:inner_type]
190
+ value.map { |v| _deserialize(inner_type, v) }
191
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
192
+ k_type = Regexp.last_match[:k_type]
193
+ v_type = Regexp.last_match[:v_type]
194
+ {}.tap do |hash|
195
+ value.each do |k, v|
196
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
197
+ end
198
+ end
199
+ else # model
200
+ XeroRuby::Accounting.const_get(type).build_from_hash(value)
201
+ end
202
+ end
203
+
204
+ # Returns the string representation of the object
205
+ # @return [String] String presentation of the object
206
+ def to_s
207
+ to_hash.to_s
208
+ end
209
+
210
+ # to_body is an alias to to_hash (backward compatibility)
211
+ # @return [Hash] Returns the object in the form of hash
212
+ def to_body
213
+ to_hash
214
+ end
215
+
216
+ # Returns the object in the form of hash
217
+ # @return [Hash] Returns the object in the form of hash
218
+ def to_hash(downcase: false)
219
+ hash = {}
220
+ self.class.attribute_map.each_pair do |attr, param|
221
+ value = self.send(attr)
222
+ next if value.nil?
223
+ key = downcase ? attr : param
224
+ hash[key] = _to_hash(value, downcase: downcase)
225
+ end
226
+ hash
227
+ end
228
+
229
+ # Returns the object in the form of hash with snake_case
230
+ def to_attributes
231
+ to_hash(downcase: true)
232
+ end
233
+
234
+ # Outputs non-array value in the form of hash
235
+ # For object, use to_hash. Otherwise, just return the value
236
+ # @param [Object] value Any valid value
237
+ # @return [Hash] Returns the value in the form of hash
238
+ def _to_hash(value, downcase: false)
239
+ if value.is_a?(Array)
240
+ value.map do |v|
241
+ v.to_hash(downcase: downcase)
242
+ end
243
+ elsif value.is_a?(Hash)
244
+ {}.tap do |hash|
245
+ value.map { |k, v| hash[k] = _to_hash(v, downcase: downcase) }
246
+ end
247
+ elsif value.respond_to? :to_hash
248
+ value.to_hash(downcase: downcase)
249
+ else
250
+ value
251
+ end
252
+ end
253
+
254
+ def parse_date(datestring)
255
+ if datestring.include?('Date')
256
+ date_pattern = /\/Date\((-?\d+)(\+\d+)?\)\//
257
+ original, date, timezone = *date_pattern.match(datestring)
258
+ date = (date.to_i / 1000)
259
+ Time.at(date).utc.strftime('%Y-%m-%dT%H:%M:%S%z').to_s
260
+ else # handle date 'types' for small subset of payroll API's
261
+ Time.parse(datestring).strftime('%Y-%m-%dT%H:%M:%S').to_s
262
+ end
263
+ end
264
+ end
265
+ end