xero-ruby 12.0.0 → 13.0.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.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/lib/xero-ruby/api/accounting_api.rb +11 -0
  3. data/lib/xero-ruby/api/finance_api.rb +0 -299
  4. data/lib/xero-ruby/api/payroll_au_v2_api.rb +751 -0
  5. data/lib/xero-ruby/api/payroll_nz_api.rb +0 -86
  6. data/lib/xero-ruby/api/payroll_uk_api.rb +0 -86
  7. data/lib/xero-ruby/models/accounting/contact.rb +27 -1
  8. data/lib/xero-ruby/models/accounting/overpayment.rb +11 -1
  9. data/lib/xero-ruby/models/assets/book_depreciation_detail.rb +54 -4
  10. data/lib/xero-ruby/models/payroll_au/earnings_rate.rb +11 -1
  11. data/lib/xero-ruby/models/payroll_au/employee.rb +1 -13
  12. data/lib/xero-ruby/models/payroll_au/leave_line.rb +11 -1
  13. data/lib/xero-ruby/models/payroll_au/leave_type.rb +14 -4
  14. data/lib/xero-ruby/models/payroll_au/opening_balance_leave_line.rb +232 -0
  15. data/lib/xero-ruby/models/payroll_au/opening_balances.rb +1 -1
  16. data/lib/xero-ruby/models/payroll_au/tax_declaration.rb +14 -4
  17. data/lib/xero-ruby/models/payroll_au_v2/invalid_field.rb +232 -0
  18. data/lib/xero-ruby/models/payroll_au_v2/pagination.rb +252 -0
  19. data/lib/xero-ruby/models/payroll_au_v2/problem.rb +275 -0
  20. data/lib/xero-ruby/models/payroll_au_v2/timesheet.rb +361 -0
  21. data/lib/xero-ruby/models/payroll_au_v2/timesheet_line.rb +277 -0
  22. data/lib/xero-ruby/models/payroll_au_v2/timesheet_line_object.rb +242 -0
  23. data/lib/xero-ruby/models/payroll_au_v2/timesheet_object.rb +242 -0
  24. data/lib/xero-ruby/models/payroll_au_v2/timesheets.rb +244 -0
  25. data/lib/xero-ruby/models/payroll_nz/employee_leave_setup.rb +1 -21
  26. data/lib/xero-ruby/models/payroll_nz/employee_leave_type.rb +3 -13
  27. data/lib/xero-ruby/models/payroll_uk/contract_type.rb +38 -0
  28. data/lib/xero-ruby/models/payroll_uk/contracts.rb +297 -0
  29. data/lib/xero-ruby/models/payroll_uk/developmental_role_details.rb +267 -0
  30. data/lib/xero-ruby/models/payroll_uk/employee.rb +16 -4
  31. data/lib/xero-ruby/models/payroll_uk/employment.rb +16 -4
  32. data/lib/xero-ruby/models/payroll_uk/employment_status.rb +37 -0
  33. data/lib/xero-ruby/version.rb +2 -2
  34. data/lib/xero-ruby.rb +14 -10
  35. data/spec/finance/api/finance_api_spec.rb +0 -53
  36. metadata +379 -385
  37. data/spec/finance/models/account_usage_response_spec.rb +0 -58
  38. data/spec/finance/models/account_usage_spec.rb +0 -112
  39. data/spec/finance/models/history_record_response_spec.rb +0 -64
  40. data/spec/finance/models/lock_history_model_spec.rb +0 -52
  41. data/spec/finance/models/lock_history_response_spec.rb +0 -52
  42. data/spec/finance/models/practice_response_spec.rb +0 -64
  43. data/spec/finance/models/report_history_model_spec.rb +0 -52
  44. data/spec/finance/models/report_history_response_spec.rb +0 -52
  45. data/spec/finance/models/user_activities_response_spec.rb +0 -52
  46. data/spec/finance/models/user_response_spec.rb +0 -106
@@ -0,0 +1,361 @@
1
+ =begin
2
+ #Xero Payroll AU API 2.0
3
+
4
+ #This is the Xero Payroll API 2.0 for orgs in Australia region.
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::PayrollAuV2
16
+ require 'bigdecimal'
17
+
18
+ class Timesheet
19
+ # The Xero identifier for a Timesheet
20
+ attr_accessor :timesheet_id
21
+
22
+ # The Xero identifier for the Payroll Calendar that the Timesheet applies to
23
+ attr_accessor :payroll_calendar_id
24
+
25
+ # The Xero identifier for the Employee that the Timesheet is for
26
+ attr_accessor :employee_id
27
+
28
+ # The Start Date of the Timesheet period (YYYY-MM-DD)
29
+ attr_accessor :start_date
30
+
31
+ # The End Date of the Timesheet period (YYYY-MM-DD)
32
+ attr_accessor :end_date
33
+
34
+ # Status of the timesheet
35
+ attr_accessor :status
36
+ DRAFT ||= "Draft".freeze
37
+ APPROVED ||= "Approved".freeze
38
+ COMPLETED ||= "Completed".freeze
39
+
40
+ # The Total Hours of the Timesheet
41
+ attr_accessor :total_hours
42
+
43
+ # The UTC date time that the Timesheet was last updated
44
+ attr_accessor :updated_date_utc
45
+
46
+
47
+ attr_accessor :timesheet_lines
48
+
49
+ class EnumAttributeValidator
50
+ attr_reader :datatype
51
+ attr_reader :allowable_values
52
+
53
+ def initialize(datatype, allowable_values)
54
+ @allowable_values = allowable_values.map do |value|
55
+ case datatype.to_s
56
+ when /Integer/i
57
+ value.to_i
58
+ when /Float/i
59
+ value.to_f
60
+ else
61
+ value
62
+ end
63
+ end
64
+ end
65
+
66
+ def valid?(value)
67
+ !value || allowable_values.include?(value)
68
+ end
69
+ end
70
+
71
+ # Attribute mapping from ruby-style variable name to JSON key.
72
+ def self.attribute_map
73
+ {
74
+ :'timesheet_id' => :'timesheetID',
75
+ :'payroll_calendar_id' => :'payrollCalendarID',
76
+ :'employee_id' => :'employeeID',
77
+ :'start_date' => :'startDate',
78
+ :'end_date' => :'endDate',
79
+ :'status' => :'status',
80
+ :'total_hours' => :'totalHours',
81
+ :'updated_date_utc' => :'updatedDateUTC',
82
+ :'timesheet_lines' => :'timesheetLines'
83
+ }
84
+ end
85
+
86
+ # Attribute type mapping.
87
+ def self.openapi_types
88
+ {
89
+ :'timesheet_id' => :'String',
90
+ :'payroll_calendar_id' => :'String',
91
+ :'employee_id' => :'String',
92
+ :'start_date' => :'Date',
93
+ :'end_date' => :'Date',
94
+ :'status' => :'String',
95
+ :'total_hours' => :'Float',
96
+ :'updated_date_utc' => :'DateTime',
97
+ :'timesheet_lines' => :'Array<TimesheetLine>'
98
+ }
99
+ end
100
+
101
+ # Initializes the object
102
+ # @param [Hash] attributes Model attributes in the form of hash
103
+ def initialize(attributes = {})
104
+ if (!attributes.is_a?(Hash))
105
+ fail ArgumentError, "The input argument (attributes) must be a hash in `XeroRuby::PayrollAuV2::Timesheet` initialize method"
106
+ end
107
+
108
+ # check to see if the attribute exists and convert string to symbol for hash key
109
+ attributes = attributes.each_with_object({}) { |(k, v), h|
110
+ if (!self.class.attribute_map.key?(k.to_sym))
111
+ fail ArgumentError, "`#{k}` is not a valid attribute in `XeroRuby::PayrollAuV2::Timesheet`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
112
+ end
113
+ h[k.to_sym] = v
114
+ }
115
+
116
+ if attributes.key?(:'timesheet_id')
117
+ self.timesheet_id = attributes[:'timesheet_id']
118
+ end
119
+
120
+ if attributes.key?(:'payroll_calendar_id')
121
+ self.payroll_calendar_id = attributes[:'payroll_calendar_id']
122
+ end
123
+
124
+ if attributes.key?(:'employee_id')
125
+ self.employee_id = attributes[:'employee_id']
126
+ end
127
+
128
+ if attributes.key?(:'start_date')
129
+ self.start_date = attributes[:'start_date']
130
+ end
131
+
132
+ if attributes.key?(:'end_date')
133
+ self.end_date = attributes[:'end_date']
134
+ end
135
+
136
+ if attributes.key?(:'status')
137
+ self.status = attributes[:'status']
138
+ end
139
+
140
+ if attributes.key?(:'total_hours')
141
+ self.total_hours = attributes[:'total_hours']
142
+ end
143
+
144
+ if attributes.key?(:'updated_date_utc')
145
+ self.updated_date_utc = attributes[:'updated_date_utc']
146
+ end
147
+
148
+ if attributes.key?(:'timesheet_lines')
149
+ if (value = attributes[:'timesheet_lines']).is_a?(Array)
150
+ self.timesheet_lines = value
151
+ end
152
+ end
153
+ end
154
+
155
+ # Show invalid properties with the reasons. Usually used together with valid?
156
+ # @return Array for valid properties with the reasons
157
+ def list_invalid_properties
158
+ invalid_properties = Array.new
159
+ if @payroll_calendar_id.nil?
160
+ invalid_properties.push('invalid value for "payroll_calendar_id", payroll_calendar_id cannot be nil.')
161
+ end
162
+
163
+ if @employee_id.nil?
164
+ invalid_properties.push('invalid value for "employee_id", employee_id cannot be nil.')
165
+ end
166
+
167
+ if @start_date.nil?
168
+ invalid_properties.push('invalid value for "start_date", start_date cannot be nil.')
169
+ end
170
+
171
+ if @end_date.nil?
172
+ invalid_properties.push('invalid value for "end_date", end_date cannot be nil.')
173
+ end
174
+
175
+ invalid_properties
176
+ end
177
+
178
+ # Check to see if the all the properties in the model are valid
179
+ # @return true if the model is valid
180
+ def valid?
181
+ return false if @payroll_calendar_id.nil?
182
+ return false if @employee_id.nil?
183
+ return false if @start_date.nil?
184
+ return false if @end_date.nil?
185
+ status_validator = EnumAttributeValidator.new('String', ["Draft", "Approved", "Completed"])
186
+ return false unless status_validator.valid?(@status)
187
+ true
188
+ end
189
+
190
+ # Custom attribute writer method checking allowed values (enum).
191
+ # @param [Object] status Object to be assigned
192
+ def status=(status)
193
+ validator = EnumAttributeValidator.new('String', ["Draft", "Approved", "Completed"])
194
+ unless validator.valid?(status)
195
+ fail ArgumentError, "invalid value for \"status\", must be one of #{validator.allowable_values}."
196
+ end
197
+ @status = status
198
+ end
199
+
200
+ # Checks equality by comparing each attribute.
201
+ # @param [Object] Object to be compared
202
+ def ==(o)
203
+ return true if self.equal?(o)
204
+ self.class == o.class &&
205
+ timesheet_id == o.timesheet_id &&
206
+ payroll_calendar_id == o.payroll_calendar_id &&
207
+ employee_id == o.employee_id &&
208
+ start_date == o.start_date &&
209
+ end_date == o.end_date &&
210
+ status == o.status &&
211
+ total_hours == o.total_hours &&
212
+ updated_date_utc == o.updated_date_utc &&
213
+ timesheet_lines == o.timesheet_lines
214
+ end
215
+
216
+ # @see the `==` method
217
+ # @param [Object] Object to be compared
218
+ def eql?(o)
219
+ self == o
220
+ end
221
+
222
+ # Calculates hash code according to all attributes.
223
+ # @return [Integer] Hash code
224
+ def hash
225
+ [timesheet_id, payroll_calendar_id, employee_id, start_date, end_date, status, total_hours, updated_date_utc, timesheet_lines].hash
226
+ end
227
+
228
+ # Builds the object from hash
229
+ # @param [Hash] attributes Model attributes in the form of hash
230
+ # @return [Object] Returns the model itself
231
+ def self.build_from_hash(attributes)
232
+ new.build_from_hash(attributes)
233
+ end
234
+
235
+ # Builds the object from hash
236
+ # @param [Hash] attributes Model attributes in the form of hash
237
+ # @return [Object] Returns the model itself
238
+ def build_from_hash(attributes)
239
+ return nil unless attributes.is_a?(Hash)
240
+ self.class.openapi_types.each_pair do |key, type|
241
+ if type =~ /\AArray<(.*)>/i
242
+ # check to ensure the input is an array given that the attribute
243
+ # is documented as an array but the input is not
244
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
245
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
246
+ end
247
+ elsif !attributes[self.class.attribute_map[key]].nil?
248
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
249
+ end # or else data not found in attributes(hash), not an issue as the data can be optional
250
+ end
251
+
252
+ self
253
+ end
254
+
255
+ # Deserializes the data based on type
256
+ # @param string type Data type
257
+ # @param string value Value to be deserialized
258
+ # @return [Object] Deserialized data
259
+ def _deserialize(type, value)
260
+ case type.to_sym
261
+ when :DateTime
262
+ DateTime.parse(parse_date(value))
263
+ when :Date
264
+ Date.parse(parse_date(value))
265
+ when :String
266
+ value.to_s
267
+ when :Integer
268
+ value.to_i
269
+ when :Float
270
+ value.to_f
271
+ when :BigDecimal
272
+ BigDecimal(value.to_s)
273
+ when :Boolean
274
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
275
+ true
276
+ else
277
+ false
278
+ end
279
+ when :Object
280
+ # generic object (usually a Hash), return directly
281
+ value
282
+ when /\AArray<(?<inner_type>.+)>\z/
283
+ inner_type = Regexp.last_match[:inner_type]
284
+ value.map { |v| _deserialize(inner_type, v) }
285
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
286
+ k_type = Regexp.last_match[:k_type]
287
+ v_type = Regexp.last_match[:v_type]
288
+ {}.tap do |hash|
289
+ value.each do |k, v|
290
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
291
+ end
292
+ end
293
+ else # model
294
+ XeroRuby::PayrollAuV2.const_get(type).build_from_hash(value)
295
+ end
296
+ end
297
+
298
+ # Returns the string representation of the object
299
+ # @return [String] String presentation of the object
300
+ def to_s
301
+ to_hash.to_s
302
+ end
303
+
304
+ # to_body is an alias to to_hash (backward compatibility)
305
+ # @return [Hash] Returns the object in the form of hash
306
+ def to_body
307
+ to_hash
308
+ end
309
+
310
+ # Returns the object in the form of hash
311
+ # @return [Hash] Returns the object in the form of hash
312
+ def to_hash(downcase: false)
313
+ hash = {}
314
+ self.class.attribute_map.each_pair do |attr, param|
315
+ value = self.send(attr)
316
+ next if value.nil?
317
+ key = downcase ? attr : param
318
+ hash[key] = _to_hash(value, downcase: downcase)
319
+ end
320
+ hash
321
+ end
322
+
323
+ # Returns the object in the form of hash with snake_case
324
+ def to_attributes
325
+ to_hash(downcase: true)
326
+ end
327
+
328
+ # Outputs non-array value in the form of hash
329
+ # For object, use to_hash. Otherwise, just return the value
330
+ # @param [Object] value Any valid value
331
+ # @return [Hash] Returns the value in the form of hash
332
+ def _to_hash(value, downcase: false)
333
+ if value.is_a?(Array)
334
+ value.map do |v|
335
+ v.to_hash(downcase: downcase)
336
+ end
337
+ elsif value.is_a?(Hash)
338
+ {}.tap do |hash|
339
+ value.map { |k, v| hash[k] = _to_hash(v, downcase: downcase) }
340
+ end
341
+ elsif value.respond_to? :to_hash
342
+ value.to_hash(downcase: downcase)
343
+ else
344
+ value
345
+ end
346
+ end
347
+
348
+ def parse_date(datestring)
349
+ if datestring.include?('Date')
350
+ date_pattern = /\/Date\((-?\d+)(\+\d+)?\)\//
351
+ original, date, timezone = *date_pattern.match(datestring)
352
+ date = (date.to_i / 1000)
353
+ Time.at(date).utc.strftime('%Y-%m-%dT%H:%M:%S%z').to_s
354
+ elsif /(\d\d\d\d)-(\d\d)/.match(datestring) # handles dates w/out Days: YYYY-MM*-DD
355
+ Time.parse(datestring + '-01').strftime('%Y-%m-%dT%H:%M:%S').to_s
356
+ else # handle date 'types' for small subset of payroll API's
357
+ Time.parse(datestring).strftime('%Y-%m-%dT%H:%M:%S').to_s
358
+ end
359
+ end
360
+ end
361
+ end
@@ -0,0 +1,277 @@
1
+ =begin
2
+ #Xero Payroll AU API 2.0
3
+
4
+ #This is the Xero Payroll API 2.0 for orgs in Australia region.
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::PayrollAuV2
16
+ require 'bigdecimal'
17
+
18
+ class TimesheetLine
19
+ # The Xero identifier for a Timesheet Line
20
+ attr_accessor :timesheet_line_id
21
+
22
+ # The Date that this Timesheet Line is for (YYYY-MM-DD)
23
+ attr_accessor :date
24
+
25
+ # The Xero identifier for the Earnings Rate that the Timesheet is for
26
+ attr_accessor :earnings_rate_id
27
+
28
+ # The Xero identifier for the Tracking Item that the Timesheet is for
29
+ attr_accessor :tracking_item_id
30
+
31
+ # The Number of Units of the Timesheet Line
32
+ attr_accessor :number_of_units
33
+
34
+ # Attribute mapping from ruby-style variable name to JSON key.
35
+ def self.attribute_map
36
+ {
37
+ :'timesheet_line_id' => :'timesheetLineID',
38
+ :'date' => :'date',
39
+ :'earnings_rate_id' => :'earningsRateID',
40
+ :'tracking_item_id' => :'trackingItemID',
41
+ :'number_of_units' => :'numberOfUnits'
42
+ }
43
+ end
44
+
45
+ # Attribute type mapping.
46
+ def self.openapi_types
47
+ {
48
+ :'timesheet_line_id' => :'String',
49
+ :'date' => :'Date',
50
+ :'earnings_rate_id' => :'String',
51
+ :'tracking_item_id' => :'String',
52
+ :'number_of_units' => :'Float'
53
+ }
54
+ end
55
+
56
+ # Initializes the object
57
+ # @param [Hash] attributes Model attributes in the form of hash
58
+ def initialize(attributes = {})
59
+ if (!attributes.is_a?(Hash))
60
+ fail ArgumentError, "The input argument (attributes) must be a hash in `XeroRuby::PayrollAuV2::TimesheetLine` initialize method"
61
+ end
62
+
63
+ # check to see if the attribute exists and convert string to symbol for hash key
64
+ attributes = attributes.each_with_object({}) { |(k, v), h|
65
+ if (!self.class.attribute_map.key?(k.to_sym))
66
+ fail ArgumentError, "`#{k}` is not a valid attribute in `XeroRuby::PayrollAuV2::TimesheetLine`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
67
+ end
68
+ h[k.to_sym] = v
69
+ }
70
+
71
+ if attributes.key?(:'timesheet_line_id')
72
+ self.timesheet_line_id = attributes[:'timesheet_line_id']
73
+ end
74
+
75
+ if attributes.key?(:'date')
76
+ self.date = attributes[:'date']
77
+ end
78
+
79
+ if attributes.key?(:'earnings_rate_id')
80
+ self.earnings_rate_id = attributes[:'earnings_rate_id']
81
+ end
82
+
83
+ if attributes.key?(:'tracking_item_id')
84
+ self.tracking_item_id = attributes[:'tracking_item_id']
85
+ end
86
+
87
+ if attributes.key?(:'number_of_units')
88
+ self.number_of_units = attributes[:'number_of_units']
89
+ end
90
+ end
91
+
92
+ # Show invalid properties with the reasons. Usually used together with valid?
93
+ # @return Array for valid properties with the reasons
94
+ def list_invalid_properties
95
+ invalid_properties = Array.new
96
+ if @date.nil?
97
+ invalid_properties.push('invalid value for "date", date cannot be nil.')
98
+ end
99
+
100
+ if @earnings_rate_id.nil?
101
+ invalid_properties.push('invalid value for "earnings_rate_id", earnings_rate_id cannot be nil.')
102
+ end
103
+
104
+ if @number_of_units.nil?
105
+ invalid_properties.push('invalid value for "number_of_units", number_of_units cannot be nil.')
106
+ end
107
+
108
+ invalid_properties
109
+ end
110
+
111
+ # Check to see if the all the properties in the model are valid
112
+ # @return true if the model is valid
113
+ def valid?
114
+ return false if @date.nil?
115
+ return false if @earnings_rate_id.nil?
116
+ return false if @number_of_units.nil?
117
+ true
118
+ end
119
+
120
+ # Checks equality by comparing each attribute.
121
+ # @param [Object] Object to be compared
122
+ def ==(o)
123
+ return true if self.equal?(o)
124
+ self.class == o.class &&
125
+ timesheet_line_id == o.timesheet_line_id &&
126
+ date == o.date &&
127
+ earnings_rate_id == o.earnings_rate_id &&
128
+ tracking_item_id == o.tracking_item_id &&
129
+ number_of_units == o.number_of_units
130
+ end
131
+
132
+ # @see the `==` method
133
+ # @param [Object] Object to be compared
134
+ def eql?(o)
135
+ self == o
136
+ end
137
+
138
+ # Calculates hash code according to all attributes.
139
+ # @return [Integer] Hash code
140
+ def hash
141
+ [timesheet_line_id, date, earnings_rate_id, tracking_item_id, number_of_units].hash
142
+ end
143
+
144
+ # Builds the object from hash
145
+ # @param [Hash] attributes Model attributes in the form of hash
146
+ # @return [Object] Returns the model itself
147
+ def self.build_from_hash(attributes)
148
+ new.build_from_hash(attributes)
149
+ end
150
+
151
+ # Builds the object from hash
152
+ # @param [Hash] attributes Model attributes in the form of hash
153
+ # @return [Object] Returns the model itself
154
+ def build_from_hash(attributes)
155
+ return nil unless attributes.is_a?(Hash)
156
+ self.class.openapi_types.each_pair do |key, type|
157
+ if type =~ /\AArray<(.*)>/i
158
+ # check to ensure the input is an array given that the attribute
159
+ # is documented as an array but the input is not
160
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
161
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
162
+ end
163
+ elsif !attributes[self.class.attribute_map[key]].nil?
164
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
165
+ end # or else data not found in attributes(hash), not an issue as the data can be optional
166
+ end
167
+
168
+ self
169
+ end
170
+
171
+ # Deserializes the data based on type
172
+ # @param string type Data type
173
+ # @param string value Value to be deserialized
174
+ # @return [Object] Deserialized data
175
+ def _deserialize(type, value)
176
+ case type.to_sym
177
+ when :DateTime
178
+ DateTime.parse(parse_date(value))
179
+ when :Date
180
+ Date.parse(parse_date(value))
181
+ when :String
182
+ value.to_s
183
+ when :Integer
184
+ value.to_i
185
+ when :Float
186
+ value.to_f
187
+ when :BigDecimal
188
+ BigDecimal(value.to_s)
189
+ when :Boolean
190
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
191
+ true
192
+ else
193
+ false
194
+ end
195
+ when :Object
196
+ # generic object (usually a Hash), return directly
197
+ value
198
+ when /\AArray<(?<inner_type>.+)>\z/
199
+ inner_type = Regexp.last_match[:inner_type]
200
+ value.map { |v| _deserialize(inner_type, v) }
201
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
202
+ k_type = Regexp.last_match[:k_type]
203
+ v_type = Regexp.last_match[:v_type]
204
+ {}.tap do |hash|
205
+ value.each do |k, v|
206
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
207
+ end
208
+ end
209
+ else # model
210
+ XeroRuby::PayrollAuV2.const_get(type).build_from_hash(value)
211
+ end
212
+ end
213
+
214
+ # Returns the string representation of the object
215
+ # @return [String] String presentation of the object
216
+ def to_s
217
+ to_hash.to_s
218
+ end
219
+
220
+ # to_body is an alias to to_hash (backward compatibility)
221
+ # @return [Hash] Returns the object in the form of hash
222
+ def to_body
223
+ to_hash
224
+ end
225
+
226
+ # Returns the object in the form of hash
227
+ # @return [Hash] Returns the object in the form of hash
228
+ def to_hash(downcase: false)
229
+ hash = {}
230
+ self.class.attribute_map.each_pair do |attr, param|
231
+ value = self.send(attr)
232
+ next if value.nil?
233
+ key = downcase ? attr : param
234
+ hash[key] = _to_hash(value, downcase: downcase)
235
+ end
236
+ hash
237
+ end
238
+
239
+ # Returns the object in the form of hash with snake_case
240
+ def to_attributes
241
+ to_hash(downcase: true)
242
+ end
243
+
244
+ # Outputs non-array value in the form of hash
245
+ # For object, use to_hash. Otherwise, just return the value
246
+ # @param [Object] value Any valid value
247
+ # @return [Hash] Returns the value in the form of hash
248
+ def _to_hash(value, downcase: false)
249
+ if value.is_a?(Array)
250
+ value.map do |v|
251
+ v.to_hash(downcase: downcase)
252
+ end
253
+ elsif value.is_a?(Hash)
254
+ {}.tap do |hash|
255
+ value.map { |k, v| hash[k] = _to_hash(v, downcase: downcase) }
256
+ end
257
+ elsif value.respond_to? :to_hash
258
+ value.to_hash(downcase: downcase)
259
+ else
260
+ value
261
+ end
262
+ end
263
+
264
+ def parse_date(datestring)
265
+ if datestring.include?('Date')
266
+ date_pattern = /\/Date\((-?\d+)(\+\d+)?\)\//
267
+ original, date, timezone = *date_pattern.match(datestring)
268
+ date = (date.to_i / 1000)
269
+ Time.at(date).utc.strftime('%Y-%m-%dT%H:%M:%S%z').to_s
270
+ elsif /(\d\d\d\d)-(\d\d)/.match(datestring) # handles dates w/out Days: YYYY-MM*-DD
271
+ Time.parse(datestring + '-01').strftime('%Y-%m-%dT%H:%M:%S').to_s
272
+ else # handle date 'types' for small subset of payroll API's
273
+ Time.parse(datestring).strftime('%Y-%m-%dT%H:%M:%S').to_s
274
+ end
275
+ end
276
+ end
277
+ end