xero-ruby 12.4.0 → 14.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 (36) hide show
  1. checksums.yaml +4 -4
  2. data/lib/xero-ruby/api/accounting_api.rb +3 -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/models/accounting/prepayment.rb +11 -1
  6. data/lib/xero-ruby/models/payroll_au/earnings_rate.rb +11 -1
  7. data/lib/xero-ruby/models/payroll_au/employee.rb +1 -13
  8. data/lib/xero-ruby/models/payroll_au/leave_line.rb +11 -1
  9. data/lib/xero-ruby/models/payroll_au/leave_type.rb +14 -4
  10. data/lib/xero-ruby/models/payroll_au/opening_balance_leave_line.rb +232 -0
  11. data/lib/xero-ruby/models/payroll_au/opening_balances.rb +1 -1
  12. data/lib/xero-ruby/models/payroll_au/tax_declaration.rb +14 -4
  13. data/lib/xero-ruby/models/payroll_au_v2/invalid_field.rb +232 -0
  14. data/lib/xero-ruby/models/payroll_au_v2/pagination.rb +252 -0
  15. data/lib/xero-ruby/models/payroll_au_v2/problem.rb +275 -0
  16. data/lib/xero-ruby/models/payroll_au_v2/timesheet.rb +361 -0
  17. data/lib/xero-ruby/models/payroll_au_v2/timesheet_line.rb +277 -0
  18. data/lib/xero-ruby/models/payroll_au_v2/timesheet_line_object.rb +242 -0
  19. data/lib/xero-ruby/models/payroll_au_v2/timesheet_object.rb +242 -0
  20. data/lib/xero-ruby/models/payroll_au_v2/timesheets.rb +244 -0
  21. data/lib/xero-ruby/models/payroll_uk/earnings_rate.rb +3 -2
  22. data/lib/xero-ruby/models/payroll_uk/employee_statutory_leave_summary.rb +3 -2
  23. data/lib/xero-ruby/version.rb +2 -2
  24. data/lib/xero-ruby.rb +10 -10
  25. data/spec/finance/api/finance_api_spec.rb +0 -53
  26. metadata +386 -396
  27. data/spec/finance/models/account_usage_response_spec.rb +0 -58
  28. data/spec/finance/models/account_usage_spec.rb +0 -112
  29. data/spec/finance/models/history_record_response_spec.rb +0 -64
  30. data/spec/finance/models/lock_history_model_spec.rb +0 -52
  31. data/spec/finance/models/lock_history_response_spec.rb +0 -52
  32. data/spec/finance/models/practice_response_spec.rb +0 -64
  33. data/spec/finance/models/report_history_model_spec.rb +0 -52
  34. data/spec/finance/models/report_history_response_spec.rb +0 -52
  35. data/spec/finance/models/user_activities_response_spec.rb +0 -52
  36. data/spec/finance/models/user_response_spec.rb +0 -106
@@ -0,0 +1,275 @@
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
+ # The object returned for a bad request
17
+ require 'bigdecimal'
18
+
19
+ class Problem
20
+ # The type of error format
21
+ attr_accessor :type
22
+
23
+ # The type of the error
24
+ attr_accessor :title
25
+
26
+ # The error status code
27
+ attr_accessor :status
28
+
29
+ # A description of the error
30
+ attr_accessor :detail
31
+
32
+
33
+ attr_accessor :instance
34
+
35
+
36
+ attr_accessor :invalid_fields
37
+
38
+ # Attribute mapping from ruby-style variable name to JSON key.
39
+ def self.attribute_map
40
+ {
41
+ :'type' => :'type',
42
+ :'title' => :'title',
43
+ :'status' => :'status',
44
+ :'detail' => :'detail',
45
+ :'instance' => :'instance',
46
+ :'invalid_fields' => :'invalidFields'
47
+ }
48
+ end
49
+
50
+ # Attribute type mapping.
51
+ def self.openapi_types
52
+ {
53
+ :'type' => :'String',
54
+ :'title' => :'String',
55
+ :'status' => :'String',
56
+ :'detail' => :'String',
57
+ :'instance' => :'String',
58
+ :'invalid_fields' => :'Array<InvalidField>'
59
+ }
60
+ end
61
+
62
+ # Initializes the object
63
+ # @param [Hash] attributes Model attributes in the form of hash
64
+ def initialize(attributes = {})
65
+ if (!attributes.is_a?(Hash))
66
+ fail ArgumentError, "The input argument (attributes) must be a hash in `XeroRuby::PayrollAuV2::Problem` initialize method"
67
+ end
68
+
69
+ # check to see if the attribute exists and convert string to symbol for hash key
70
+ attributes = attributes.each_with_object({}) { |(k, v), h|
71
+ if (!self.class.attribute_map.key?(k.to_sym))
72
+ fail ArgumentError, "`#{k}` is not a valid attribute in `XeroRuby::PayrollAuV2::Problem`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
73
+ end
74
+ h[k.to_sym] = v
75
+ }
76
+
77
+ if attributes.key?(:'type')
78
+ self.type = attributes[:'type']
79
+ end
80
+
81
+ if attributes.key?(:'title')
82
+ self.title = attributes[:'title']
83
+ end
84
+
85
+ if attributes.key?(:'status')
86
+ self.status = attributes[:'status']
87
+ end
88
+
89
+ if attributes.key?(:'detail')
90
+ self.detail = attributes[:'detail']
91
+ end
92
+
93
+ if attributes.key?(:'instance')
94
+ self.instance = attributes[:'instance']
95
+ end
96
+
97
+ if attributes.key?(:'invalid_fields')
98
+ if (value = attributes[:'invalid_fields']).is_a?(Array)
99
+ self.invalid_fields = value
100
+ end
101
+ end
102
+ end
103
+
104
+ # Show invalid properties with the reasons. Usually used together with valid?
105
+ # @return Array for valid properties with the reasons
106
+ def list_invalid_properties
107
+ invalid_properties = Array.new
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
+ true
115
+ end
116
+
117
+ # Checks equality by comparing each attribute.
118
+ # @param [Object] Object to be compared
119
+ def ==(o)
120
+ return true if self.equal?(o)
121
+ self.class == o.class &&
122
+ type == o.type &&
123
+ title == o.title &&
124
+ status == o.status &&
125
+ detail == o.detail &&
126
+ instance == o.instance &&
127
+ invalid_fields == o.invalid_fields
128
+ end
129
+
130
+ # @see the `==` method
131
+ # @param [Object] Object to be compared
132
+ def eql?(o)
133
+ self == o
134
+ end
135
+
136
+ # Calculates hash code according to all attributes.
137
+ # @return [Integer] Hash code
138
+ def hash
139
+ [type, title, status, detail, instance, invalid_fields].hash
140
+ end
141
+
142
+ # Builds the object from hash
143
+ # @param [Hash] attributes Model attributes in the form of hash
144
+ # @return [Object] Returns the model itself
145
+ def self.build_from_hash(attributes)
146
+ new.build_from_hash(attributes)
147
+ end
148
+
149
+ # Builds the object from hash
150
+ # @param [Hash] attributes Model attributes in the form of hash
151
+ # @return [Object] Returns the model itself
152
+ def build_from_hash(attributes)
153
+ return nil unless attributes.is_a?(Hash)
154
+ self.class.openapi_types.each_pair do |key, type|
155
+ if type =~ /\AArray<(.*)>/i
156
+ # check to ensure the input is an array given that the attribute
157
+ # is documented as an array but the input is not
158
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
159
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
160
+ end
161
+ elsif !attributes[self.class.attribute_map[key]].nil?
162
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
163
+ end # or else data not found in attributes(hash), not an issue as the data can be optional
164
+ end
165
+
166
+ self
167
+ end
168
+
169
+ # Deserializes the data based on type
170
+ # @param string type Data type
171
+ # @param string value Value to be deserialized
172
+ # @return [Object] Deserialized data
173
+ def _deserialize(type, value)
174
+ case type.to_sym
175
+ when :DateTime
176
+ DateTime.parse(parse_date(value))
177
+ when :Date
178
+ Date.parse(parse_date(value))
179
+ when :String
180
+ value.to_s
181
+ when :Integer
182
+ value.to_i
183
+ when :Float
184
+ value.to_f
185
+ when :BigDecimal
186
+ BigDecimal(value.to_s)
187
+ when :Boolean
188
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
189
+ true
190
+ else
191
+ false
192
+ end
193
+ when :Object
194
+ # generic object (usually a Hash), return directly
195
+ value
196
+ when /\AArray<(?<inner_type>.+)>\z/
197
+ inner_type = Regexp.last_match[:inner_type]
198
+ value.map { |v| _deserialize(inner_type, v) }
199
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
200
+ k_type = Regexp.last_match[:k_type]
201
+ v_type = Regexp.last_match[:v_type]
202
+ {}.tap do |hash|
203
+ value.each do |k, v|
204
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
205
+ end
206
+ end
207
+ else # model
208
+ XeroRuby::PayrollAuV2.const_get(type).build_from_hash(value)
209
+ end
210
+ end
211
+
212
+ # Returns the string representation of the object
213
+ # @return [String] String presentation of the object
214
+ def to_s
215
+ to_hash.to_s
216
+ end
217
+
218
+ # to_body is an alias to to_hash (backward compatibility)
219
+ # @return [Hash] Returns the object in the form of hash
220
+ def to_body
221
+ to_hash
222
+ end
223
+
224
+ # Returns the object in the form of hash
225
+ # @return [Hash] Returns the object in the form of hash
226
+ def to_hash(downcase: false)
227
+ hash = {}
228
+ self.class.attribute_map.each_pair do |attr, param|
229
+ value = self.send(attr)
230
+ next if value.nil?
231
+ key = downcase ? attr : param
232
+ hash[key] = _to_hash(value, downcase: downcase)
233
+ end
234
+ hash
235
+ end
236
+
237
+ # Returns the object in the form of hash with snake_case
238
+ def to_attributes
239
+ to_hash(downcase: true)
240
+ end
241
+
242
+ # Outputs non-array value in the form of hash
243
+ # For object, use to_hash. Otherwise, just return the value
244
+ # @param [Object] value Any valid value
245
+ # @return [Hash] Returns the value in the form of hash
246
+ def _to_hash(value, downcase: false)
247
+ if value.is_a?(Array)
248
+ value.map do |v|
249
+ v.to_hash(downcase: downcase)
250
+ end
251
+ elsif value.is_a?(Hash)
252
+ {}.tap do |hash|
253
+ value.map { |k, v| hash[k] = _to_hash(v, downcase: downcase) }
254
+ end
255
+ elsif value.respond_to? :to_hash
256
+ value.to_hash(downcase: downcase)
257
+ else
258
+ value
259
+ end
260
+ end
261
+
262
+ def parse_date(datestring)
263
+ if datestring.include?('Date')
264
+ date_pattern = /\/Date\((-?\d+)(\+\d+)?\)\//
265
+ original, date, timezone = *date_pattern.match(datestring)
266
+ date = (date.to_i / 1000)
267
+ Time.at(date).utc.strftime('%Y-%m-%dT%H:%M:%S%z').to_s
268
+ elsif /(\d\d\d\d)-(\d\d)/.match(datestring) # handles dates w/out Days: YYYY-MM*-DD
269
+ Time.parse(datestring + '-01').strftime('%Y-%m-%dT%H:%M:%S').to_s
270
+ else # handle date 'types' for small subset of payroll API's
271
+ Time.parse(datestring).strftime('%Y-%m-%dT%H:%M:%S').to_s
272
+ end
273
+ end
274
+ end
275
+ end
@@ -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