xero-ruby 3.9.0 → 7.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -2
  3. data/lib/xero-ruby/api/accounting_api.rb +1136 -46
  4. data/lib/xero-ruby/api/app_store_api.rb +244 -0
  5. data/lib/xero-ruby/api/asset_api.rb +16 -6
  6. data/lib/xero-ruby/api/files_api.rb +156 -20
  7. data/lib/xero-ruby/api/payroll_au_api.rb +326 -30
  8. data/lib/xero-ruby/api/payroll_nz_api.rb +87 -0
  9. data/lib/xero-ruby/api/payroll_uk_api.rb +81 -0
  10. data/lib/xero-ruby/api/project_api.rb +286 -2
  11. data/lib/xero-ruby/api_client.rb +9 -3
  12. data/lib/xero-ruby/models/accounting/account.rb +1 -1
  13. data/lib/xero-ruby/models/accounting/account_type.rb +0 -4
  14. data/lib/xero-ruby/models/accounting/allocation.rb +21 -1
  15. data/lib/xero-ruby/models/accounting/batch_payment.rb +2 -2
  16. data/lib/xero-ruby/models/accounting/batch_payment_delete.rb +244 -0
  17. data/lib/xero-ruby/models/accounting/batch_payment_delete_by_url_param.rb +229 -0
  18. data/lib/xero-ruby/models/accounting/contact.rb +1 -11
  19. data/lib/xero-ruby/models/accounting/currency_code.rb +10 -8
  20. data/lib/xero-ruby/models/accounting/journal_line.rb +1 -1
  21. data/lib/xero-ruby/models/accounting/line_item.rb +2 -2
  22. data/lib/xero-ruby/models/accounting/organisation.rb +6 -2
  23. data/lib/xero-ruby/models/accounting/payment.rb +26 -4
  24. data/lib/xero-ruby/models/accounting/repeating_invoice.rb +53 -5
  25. data/lib/xero-ruby/models/accounting/tax_rate.rb +23 -5
  26. data/lib/xero-ruby/models/accounting/tax_type.rb +60 -3
  27. data/lib/xero-ruby/models/accounting/ten_ninety_nine_contact.rb +75 -4
  28. data/lib/xero-ruby/models/accounting/time_zone.rb +123 -91
  29. data/lib/xero-ruby/models/app_store/create_usage_record.rb +243 -0
  30. data/lib/xero-ruby/models/app_store/update_usage_record.rb +228 -0
  31. data/lib/xero-ruby/models/app_store/usage_record.rb +332 -0
  32. data/lib/xero-ruby/models/app_store/usage_records_list.rb +230 -0
  33. data/lib/xero-ruby/models/files/association.rb +31 -1
  34. data/lib/xero-ruby/models/finance/problem_type.rb +1 -0
  35. data/lib/xero-ruby/models/finance/statement_line_response.rb +11 -1
  36. data/lib/xero-ruby/models/finance/statement_response.rb +24 -4
  37. data/lib/xero-ruby/models/payroll_au/allowance_type.rb +0 -1
  38. data/lib/xero-ruby/models/payroll_au/country_of_residence.rb +284 -0
  39. data/lib/xero-ruby/models/payroll_au/earnings_rate.rb +21 -1
  40. data/lib/xero-ruby/models/payroll_au/earnings_type.rb +2 -0
  41. data/lib/xero-ruby/models/payroll_au/employee.rb +42 -2
  42. data/lib/xero-ruby/models/payroll_au/employment_basis.rb +1 -0
  43. data/lib/xero-ruby/models/payroll_au/employment_type.rb +36 -0
  44. data/lib/xero-ruby/models/payroll_au/income_type.rb +39 -0
  45. data/lib/xero-ruby/models/payroll_au/leave_application.rb +11 -1
  46. data/lib/xero-ruby/models/payroll_au/leave_category_code.rb +46 -0
  47. data/lib/xero-ruby/models/payroll_au/leave_earnings_line.rb +14 -4
  48. data/lib/xero-ruby/models/payroll_au/leave_line_calculation_type.rb +0 -1
  49. data/lib/xero-ruby/models/payroll_au/leave_period_status.rb +2 -0
  50. data/lib/xero-ruby/models/payroll_au/leave_type.rb +24 -4
  51. data/lib/xero-ruby/models/payroll_au/opening_balances.rb +16 -4
  52. data/lib/xero-ruby/models/payroll_au/paid_leave_earnings_line.rb +272 -0
  53. data/lib/xero-ruby/models/payroll_au/pay_out_type.rb +36 -0
  54. data/lib/xero-ruby/models/payroll_au/senior_marital_status.rb +37 -0
  55. data/lib/xero-ruby/models/payroll_au/settings.rb +14 -4
  56. data/lib/xero-ruby/models/payroll_au/tax_declaration.rb +51 -1
  57. data/lib/xero-ruby/models/payroll_au/tax_scale_type.rb +40 -0
  58. data/lib/xero-ruby/models/payroll_au/work_condition.rb +37 -0
  59. data/lib/xero-ruby/models/payroll_nz/employee.rb +14 -4
  60. data/lib/xero-ruby/models/payroll_uk/earnings_rate.rb +3 -3
  61. data/lib/xero-ruby/models/projects/currency_code.rb +0 -1
  62. data/lib/xero-ruby/models/projects/task.rb +6 -6
  63. data/lib/xero-ruby/models/projects/task_create_or_update.rb +1 -1
  64. data/lib/xero-ruby/version.rb +2 -2
  65. data/lib/xero-ruby/where.rb +2 -0
  66. data/lib/xero-ruby.rb +15 -0
  67. metadata +30 -15
@@ -0,0 +1,228 @@
1
+ =begin
2
+ #Xero AppStore API
3
+
4
+ #These endpoints are for Xero Partners to interact with the App Store Billing platform
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::AppStore
16
+ # Data transfer object for public update usage end point
17
+ require 'bigdecimal'
18
+
19
+ class UpdateUsageRecord
20
+ # The new quantity for the usage record. Must be a whole number that is greater than or equal to 0
21
+ attr_accessor :quantity
22
+
23
+ # Attribute mapping from ruby-style variable name to JSON key.
24
+ def self.attribute_map
25
+ {
26
+ :'quantity' => :'quantity'
27
+ }
28
+ end
29
+
30
+ # Attribute type mapping.
31
+ def self.openapi_types
32
+ {
33
+ :'quantity' => :'Integer'
34
+ }
35
+ end
36
+
37
+ # Initializes the object
38
+ # @param [Hash] attributes Model attributes in the form of hash
39
+ def initialize(attributes = {})
40
+ if (!attributes.is_a?(Hash))
41
+ fail ArgumentError, "The input argument (attributes) must be a hash in `XeroRuby::AppStore::UpdateUsageRecord` initialize method"
42
+ end
43
+
44
+ # check to see if the attribute exists and convert string to symbol for hash key
45
+ attributes = attributes.each_with_object({}) { |(k, v), h|
46
+ if (!self.class.attribute_map.key?(k.to_sym))
47
+ fail ArgumentError, "`#{k}` is not a valid attribute in `XeroRuby::AppStore::UpdateUsageRecord`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
48
+ end
49
+ h[k.to_sym] = v
50
+ }
51
+
52
+ if attributes.key?(:'quantity')
53
+ self.quantity = attributes[:'quantity']
54
+ end
55
+ end
56
+
57
+ # Show invalid properties with the reasons. Usually used together with valid?
58
+ # @return Array for valid properties with the reasons
59
+ def list_invalid_properties
60
+ invalid_properties = Array.new
61
+ if @quantity.nil?
62
+ invalid_properties.push('invalid value for "quantity", quantity cannot be nil.')
63
+ end
64
+
65
+ invalid_properties
66
+ end
67
+
68
+ # Check to see if the all the properties in the model are valid
69
+ # @return true if the model is valid
70
+ def valid?
71
+ return false if @quantity.nil?
72
+ true
73
+ end
74
+
75
+ # Checks equality by comparing each attribute.
76
+ # @param [Object] Object to be compared
77
+ def ==(o)
78
+ return true if self.equal?(o)
79
+ self.class == o.class &&
80
+ quantity == o.quantity
81
+ end
82
+
83
+ # @see the `==` method
84
+ # @param [Object] Object to be compared
85
+ def eql?(o)
86
+ self == o
87
+ end
88
+
89
+ # Calculates hash code according to all attributes.
90
+ # @return [Integer] Hash code
91
+ def hash
92
+ [quantity].hash
93
+ end
94
+
95
+ # Builds the object from hash
96
+ # @param [Hash] attributes Model attributes in the form of hash
97
+ # @return [Object] Returns the model itself
98
+ def self.build_from_hash(attributes)
99
+ new.build_from_hash(attributes)
100
+ end
101
+
102
+ # Builds the object from hash
103
+ # @param [Hash] attributes Model attributes in the form of hash
104
+ # @return [Object] Returns the model itself
105
+ def build_from_hash(attributes)
106
+ return nil unless attributes.is_a?(Hash)
107
+ self.class.openapi_types.each_pair do |key, type|
108
+ if type =~ /\AArray<(.*)>/i
109
+ # check to ensure the input is an array given that the attribute
110
+ # is documented as an array but the input is not
111
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
112
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
113
+ end
114
+ elsif !attributes[self.class.attribute_map[key]].nil?
115
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
116
+ end # or else data not found in attributes(hash), not an issue as the data can be optional
117
+ end
118
+
119
+ self
120
+ end
121
+
122
+ # Deserializes the data based on type
123
+ # @param string type Data type
124
+ # @param string value Value to be deserialized
125
+ # @return [Object] Deserialized data
126
+ def _deserialize(type, value)
127
+ case type.to_sym
128
+ when :DateTime
129
+ DateTime.parse(parse_date(value))
130
+ when :Date
131
+ Date.parse(parse_date(value))
132
+ when :String
133
+ value.to_s
134
+ when :Integer
135
+ value.to_i
136
+ when :Float
137
+ value.to_f
138
+ when :BigDecimal
139
+ BigDecimal(value.to_s)
140
+ when :Boolean
141
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
142
+ true
143
+ else
144
+ false
145
+ end
146
+ when :Object
147
+ # generic object (usually a Hash), return directly
148
+ value
149
+ when /\AArray<(?<inner_type>.+)>\z/
150
+ inner_type = Regexp.last_match[:inner_type]
151
+ value.map { |v| _deserialize(inner_type, v) }
152
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
153
+ k_type = Regexp.last_match[:k_type]
154
+ v_type = Regexp.last_match[:v_type]
155
+ {}.tap do |hash|
156
+ value.each do |k, v|
157
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
158
+ end
159
+ end
160
+ else # model
161
+ XeroRuby::AppStore.const_get(type).build_from_hash(value)
162
+ end
163
+ end
164
+
165
+ # Returns the string representation of the object
166
+ # @return [String] String presentation of the object
167
+ def to_s
168
+ to_hash.to_s
169
+ end
170
+
171
+ # to_body is an alias to to_hash (backward compatibility)
172
+ # @return [Hash] Returns the object in the form of hash
173
+ def to_body
174
+ to_hash
175
+ end
176
+
177
+ # Returns the object in the form of hash
178
+ # @return [Hash] Returns the object in the form of hash
179
+ def to_hash(downcase: false)
180
+ hash = {}
181
+ self.class.attribute_map.each_pair do |attr, param|
182
+ value = self.send(attr)
183
+ next if value.nil?
184
+ key = downcase ? attr : param
185
+ hash[key] = _to_hash(value, downcase: downcase)
186
+ end
187
+ hash
188
+ end
189
+
190
+ # Returns the object in the form of hash with snake_case
191
+ def to_attributes
192
+ to_hash(downcase: true)
193
+ end
194
+
195
+ # Outputs non-array value in the form of hash
196
+ # For object, use to_hash. Otherwise, just return the value
197
+ # @param [Object] value Any valid value
198
+ # @return [Hash] Returns the value in the form of hash
199
+ def _to_hash(value, downcase: false)
200
+ if value.is_a?(Array)
201
+ value.map do |v|
202
+ v.to_hash(downcase: downcase)
203
+ end
204
+ elsif value.is_a?(Hash)
205
+ {}.tap do |hash|
206
+ value.map { |k, v| hash[k] = _to_hash(v, downcase: downcase) }
207
+ end
208
+ elsif value.respond_to? :to_hash
209
+ value.to_hash(downcase: downcase)
210
+ else
211
+ value
212
+ end
213
+ end
214
+
215
+ def parse_date(datestring)
216
+ if datestring.include?('Date')
217
+ date_pattern = /\/Date\((-?\d+)(\+\d+)?\)\//
218
+ original, date, timezone = *date_pattern.match(datestring)
219
+ date = (date.to_i / 1000)
220
+ Time.at(date).utc.strftime('%Y-%m-%dT%H:%M:%S%z').to_s
221
+ elsif /(\d\d\d\d)-(\d\d)/.match(datestring) # handles dates w/out Days: YYYY-MM*-DD
222
+ Time.parse(datestring + '-01').strftime('%Y-%m-%dT%H:%M:%S').to_s
223
+ else # handle date 'types' for small subset of payroll API's
224
+ Time.parse(datestring).strftime('%Y-%m-%dT%H:%M:%S').to_s
225
+ end
226
+ end
227
+ end
228
+ end
@@ -0,0 +1,332 @@
1
+ =begin
2
+ #Xero AppStore API
3
+
4
+ #These endpoints are for Xero Partners to interact with the App Store Billing platform
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::AppStore
16
+ require 'bigdecimal'
17
+
18
+ class UsageRecord
19
+ # The quantity recorded
20
+ attr_accessor :quantity
21
+
22
+ # The unique identifier of the Subscription.
23
+ attr_accessor :subscription_id
24
+
25
+ # The unique identifier of the SubscriptionItem.
26
+ attr_accessor :subscription_item_id
27
+
28
+ # If the subscription is a test subscription
29
+ attr_accessor :test_mode
30
+
31
+ # The time when this usage was recorded in UTC
32
+ attr_accessor :recorded_at
33
+
34
+ # The unique identifier of the usageRecord.
35
+ attr_accessor :usage_record_id
36
+
37
+ # The price per unit
38
+ attr_accessor :price_per_unit
39
+
40
+ # The unique identifier of the linked Product
41
+ attr_accessor :product_id
42
+
43
+ # Attribute mapping from ruby-style variable name to JSON key.
44
+ def self.attribute_map
45
+ {
46
+ :'quantity' => :'quantity',
47
+ :'subscription_id' => :'subscriptionId',
48
+ :'subscription_item_id' => :'subscriptionItemId',
49
+ :'test_mode' => :'testMode',
50
+ :'recorded_at' => :'recordedAt',
51
+ :'usage_record_id' => :'usageRecordId',
52
+ :'price_per_unit' => :'pricePerUnit',
53
+ :'product_id' => :'productId'
54
+ }
55
+ end
56
+
57
+ # Attribute type mapping.
58
+ def self.openapi_types
59
+ {
60
+ :'quantity' => :'Integer',
61
+ :'subscription_id' => :'String',
62
+ :'subscription_item_id' => :'String',
63
+ :'test_mode' => :'Boolean',
64
+ :'recorded_at' => :'DateTime',
65
+ :'usage_record_id' => :'String',
66
+ :'price_per_unit' => :'Float',
67
+ :'product_id' => :'String'
68
+ }
69
+ end
70
+
71
+ # Initializes the object
72
+ # @param [Hash] attributes Model attributes in the form of hash
73
+ def initialize(attributes = {})
74
+ if (!attributes.is_a?(Hash))
75
+ fail ArgumentError, "The input argument (attributes) must be a hash in `XeroRuby::AppStore::UsageRecord` initialize method"
76
+ end
77
+
78
+ # check to see if the attribute exists and convert string to symbol for hash key
79
+ attributes = attributes.each_with_object({}) { |(k, v), h|
80
+ if (!self.class.attribute_map.key?(k.to_sym))
81
+ fail ArgumentError, "`#{k}` is not a valid attribute in `XeroRuby::AppStore::UsageRecord`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
82
+ end
83
+ h[k.to_sym] = v
84
+ }
85
+
86
+ if attributes.key?(:'quantity')
87
+ self.quantity = attributes[:'quantity']
88
+ end
89
+
90
+ if attributes.key?(:'subscription_id')
91
+ self.subscription_id = attributes[:'subscription_id']
92
+ end
93
+
94
+ if attributes.key?(:'subscription_item_id')
95
+ self.subscription_item_id = attributes[:'subscription_item_id']
96
+ end
97
+
98
+ if attributes.key?(:'test_mode')
99
+ self.test_mode = attributes[:'test_mode']
100
+ end
101
+
102
+ if attributes.key?(:'recorded_at')
103
+ self.recorded_at = attributes[:'recorded_at']
104
+ end
105
+
106
+ if attributes.key?(:'usage_record_id')
107
+ self.usage_record_id = attributes[:'usage_record_id']
108
+ end
109
+
110
+ if attributes.key?(:'price_per_unit')
111
+ self.price_per_unit = attributes[:'price_per_unit']
112
+ end
113
+
114
+ if attributes.key?(:'product_id')
115
+ self.product_id = attributes[:'product_id']
116
+ end
117
+ end
118
+
119
+ # Show invalid properties with the reasons. Usually used together with valid?
120
+ # @return Array for valid properties with the reasons
121
+ def list_invalid_properties
122
+ invalid_properties = Array.new
123
+ if @quantity.nil?
124
+ invalid_properties.push('invalid value for "quantity", quantity cannot be nil.')
125
+ end
126
+
127
+ if @subscription_id.nil?
128
+ invalid_properties.push('invalid value for "subscription_id", subscription_id cannot be nil.')
129
+ end
130
+
131
+ if @subscription_item_id.nil?
132
+ invalid_properties.push('invalid value for "subscription_item_id", subscription_item_id cannot be nil.')
133
+ end
134
+
135
+ if @test_mode.nil?
136
+ invalid_properties.push('invalid value for "test_mode", test_mode cannot be nil.')
137
+ end
138
+
139
+ if @recorded_at.nil?
140
+ invalid_properties.push('invalid value for "recorded_at", recorded_at cannot be nil.')
141
+ end
142
+
143
+ if @usage_record_id.nil?
144
+ invalid_properties.push('invalid value for "usage_record_id", usage_record_id cannot be nil.')
145
+ end
146
+
147
+ if @price_per_unit.nil?
148
+ invalid_properties.push('invalid value for "price_per_unit", price_per_unit cannot be nil.')
149
+ end
150
+
151
+ if @product_id.nil?
152
+ invalid_properties.push('invalid value for "product_id", product_id cannot be nil.')
153
+ end
154
+
155
+ invalid_properties
156
+ end
157
+
158
+ # Check to see if the all the properties in the model are valid
159
+ # @return true if the model is valid
160
+ def valid?
161
+ return false if @quantity.nil?
162
+ return false if @subscription_id.nil?
163
+ return false if @subscription_item_id.nil?
164
+ return false if @test_mode.nil?
165
+ return false if @recorded_at.nil?
166
+ return false if @usage_record_id.nil?
167
+ return false if @price_per_unit.nil?
168
+ return false if @product_id.nil?
169
+ true
170
+ end
171
+
172
+ # Checks equality by comparing each attribute.
173
+ # @param [Object] Object to be compared
174
+ def ==(o)
175
+ return true if self.equal?(o)
176
+ self.class == o.class &&
177
+ quantity == o.quantity &&
178
+ subscription_id == o.subscription_id &&
179
+ subscription_item_id == o.subscription_item_id &&
180
+ test_mode == o.test_mode &&
181
+ recorded_at == o.recorded_at &&
182
+ usage_record_id == o.usage_record_id &&
183
+ price_per_unit == o.price_per_unit &&
184
+ product_id == o.product_id
185
+ end
186
+
187
+ # @see the `==` method
188
+ # @param [Object] Object to be compared
189
+ def eql?(o)
190
+ self == o
191
+ end
192
+
193
+ # Calculates hash code according to all attributes.
194
+ # @return [Integer] Hash code
195
+ def hash
196
+ [quantity, subscription_id, subscription_item_id, test_mode, recorded_at, usage_record_id, price_per_unit, product_id].hash
197
+ end
198
+
199
+ # Builds the object from hash
200
+ # @param [Hash] attributes Model attributes in the form of hash
201
+ # @return [Object] Returns the model itself
202
+ def self.build_from_hash(attributes)
203
+ new.build_from_hash(attributes)
204
+ end
205
+
206
+ # Builds the object from hash
207
+ # @param [Hash] attributes Model attributes in the form of hash
208
+ # @return [Object] Returns the model itself
209
+ def build_from_hash(attributes)
210
+ return nil unless attributes.is_a?(Hash)
211
+ self.class.openapi_types.each_pair do |key, type|
212
+ if type =~ /\AArray<(.*)>/i
213
+ # check to ensure the input is an array given that the attribute
214
+ # is documented as an array but the input is not
215
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
216
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
217
+ end
218
+ elsif !attributes[self.class.attribute_map[key]].nil?
219
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
220
+ end # or else data not found in attributes(hash), not an issue as the data can be optional
221
+ end
222
+
223
+ self
224
+ end
225
+
226
+ # Deserializes the data based on type
227
+ # @param string type Data type
228
+ # @param string value Value to be deserialized
229
+ # @return [Object] Deserialized data
230
+ def _deserialize(type, value)
231
+ case type.to_sym
232
+ when :DateTime
233
+ DateTime.parse(parse_date(value))
234
+ when :Date
235
+ Date.parse(parse_date(value))
236
+ when :String
237
+ value.to_s
238
+ when :Integer
239
+ value.to_i
240
+ when :Float
241
+ value.to_f
242
+ when :BigDecimal
243
+ BigDecimal(value.to_s)
244
+ when :Boolean
245
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
246
+ true
247
+ else
248
+ false
249
+ end
250
+ when :Object
251
+ # generic object (usually a Hash), return directly
252
+ value
253
+ when /\AArray<(?<inner_type>.+)>\z/
254
+ inner_type = Regexp.last_match[:inner_type]
255
+ value.map { |v| _deserialize(inner_type, v) }
256
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
257
+ k_type = Regexp.last_match[:k_type]
258
+ v_type = Regexp.last_match[:v_type]
259
+ {}.tap do |hash|
260
+ value.each do |k, v|
261
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
262
+ end
263
+ end
264
+ else # model
265
+ XeroRuby::AppStore.const_get(type).build_from_hash(value)
266
+ end
267
+ end
268
+
269
+ # Returns the string representation of the object
270
+ # @return [String] String presentation of the object
271
+ def to_s
272
+ to_hash.to_s
273
+ end
274
+
275
+ # to_body is an alias to to_hash (backward compatibility)
276
+ # @return [Hash] Returns the object in the form of hash
277
+ def to_body
278
+ to_hash
279
+ end
280
+
281
+ # Returns the object in the form of hash
282
+ # @return [Hash] Returns the object in the form of hash
283
+ def to_hash(downcase: false)
284
+ hash = {}
285
+ self.class.attribute_map.each_pair do |attr, param|
286
+ value = self.send(attr)
287
+ next if value.nil?
288
+ key = downcase ? attr : param
289
+ hash[key] = _to_hash(value, downcase: downcase)
290
+ end
291
+ hash
292
+ end
293
+
294
+ # Returns the object in the form of hash with snake_case
295
+ def to_attributes
296
+ to_hash(downcase: true)
297
+ end
298
+
299
+ # Outputs non-array value in the form of hash
300
+ # For object, use to_hash. Otherwise, just return the value
301
+ # @param [Object] value Any valid value
302
+ # @return [Hash] Returns the value in the form of hash
303
+ def _to_hash(value, downcase: false)
304
+ if value.is_a?(Array)
305
+ value.map do |v|
306
+ v.to_hash(downcase: downcase)
307
+ end
308
+ elsif value.is_a?(Hash)
309
+ {}.tap do |hash|
310
+ value.map { |k, v| hash[k] = _to_hash(v, downcase: downcase) }
311
+ end
312
+ elsif value.respond_to? :to_hash
313
+ value.to_hash(downcase: downcase)
314
+ else
315
+ value
316
+ end
317
+ end
318
+
319
+ def parse_date(datestring)
320
+ if datestring.include?('Date')
321
+ date_pattern = /\/Date\((-?\d+)(\+\d+)?\)\//
322
+ original, date, timezone = *date_pattern.match(datestring)
323
+ date = (date.to_i / 1000)
324
+ Time.at(date).utc.strftime('%Y-%m-%dT%H:%M:%S%z').to_s
325
+ elsif /(\d\d\d\d)-(\d\d)/.match(datestring) # handles dates w/out Days: YYYY-MM*-DD
326
+ Time.parse(datestring + '-01').strftime('%Y-%m-%dT%H:%M:%S').to_s
327
+ else # handle date 'types' for small subset of payroll API's
328
+ Time.parse(datestring).strftime('%Y-%m-%dT%H:%M:%S').to_s
329
+ end
330
+ end
331
+ end
332
+ end