xero-ruby 18.3.0 → 18.5.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 (42) hide show
  1. checksums.yaml +4 -4
  2. data/lib/xero-ruby/api/account_data_api.rb +419 -0
  3. data/lib/xero-ruby/api/feed_connections_api.rb +410 -0
  4. data/lib/xero-ruby/api_client.rb +19 -0
  5. data/lib/xero-ruby/configuration.rb +4 -0
  6. data/lib/xero-ruby/models/account_data/account.rb +351 -0
  7. data/lib/xero-ruby/models/account_data/account_balance.rb +287 -0
  8. data/lib/xero-ruby/models/account_data/account_balances_response.rb +229 -0
  9. data/lib/xero-ruby/models/account_data/account_movement.rb +347 -0
  10. data/lib/xero-ruby/models/account_data/account_movements_response.rb +229 -0
  11. data/lib/xero-ruby/models/account_data/account_transaction_line.rb +359 -0
  12. data/lib/xero-ruby/models/account_data/account_transactions_response.rb +269 -0
  13. data/lib/xero-ruby/models/account_data/account_transactions_response_pagination.rb +243 -0
  14. data/lib/xero-ruby/models/account_data/accounting_date_range.rb +242 -0
  15. data/lib/xero-ruby/models/account_data/field_problem.rb +273 -0
  16. data/lib/xero-ruby/models/account_data/gateway_problem.rb +285 -0
  17. data/lib/xero-ruby/models/account_data/ledger_decimal.rb +278 -0
  18. data/lib/xero-ruby/models/account_data/line_source.rb +273 -0
  19. data/lib/xero-ruby/models/account_data/line_tax_rate.rb +243 -0
  20. data/lib/xero-ruby/models/account_data/problem_details.rb +273 -0
  21. data/lib/xero-ruby/models/account_data/tracking_item_details.rb +257 -0
  22. data/lib/xero-ruby/models/account_data/transaction_account.rb +366 -0
  23. data/lib/xero-ruby/models/account_data/validation_problem.rb +275 -0
  24. data/lib/xero-ruby/models/accounting/budget.rb +25 -1
  25. data/lib/xero-ruby/models/accounting/budget_balance.rb +4 -39
  26. data/lib/xero-ruby/models/bankfeeds_v2/account_type.rb +36 -0
  27. data/lib/xero-ruby/models/bankfeeds_v2/bulk_feed_connection_response.rb +225 -0
  28. data/lib/xero-ruby/models/bankfeeds_v2/bulk_feed_connection_result.rb +300 -0
  29. data/lib/xero-ruby/models/bankfeeds_v2/delete_feed_connections_request.rb +229 -0
  30. data/lib/xero-ruby/models/bankfeeds_v2/existing_account_feed_connection.rb +373 -0
  31. data/lib/xero-ruby/models/bankfeeds_v2/existing_account_feed_connections_request.rb +229 -0
  32. data/lib/xero-ruby/models/bankfeeds_v2/feed_connection.rb +293 -0
  33. data/lib/xero-ruby/models/bankfeeds_v2/feed_connection_to_delete.rb +227 -0
  34. data/lib/xero-ruby/models/bankfeeds_v2/item_error.rb +358 -0
  35. data/lib/xero-ruby/models/bankfeeds_v2/new_account_feed_connection.rb +406 -0
  36. data/lib/xero-ruby/models/bankfeeds_v2/new_account_feed_connections_request.rb +229 -0
  37. data/lib/xero-ruby/models/bankfeeds_v2/paged_feed_connections.rb +234 -0
  38. data/lib/xero-ruby/models/bankfeeds_v2/pagination.rb +252 -0
  39. data/lib/xero-ruby/models/bankfeeds_v2/problem.rb +368 -0
  40. data/lib/xero-ruby/version.rb +2 -2
  41. data/lib/xero-ruby.rb +34 -0
  42. metadata +385 -351
@@ -0,0 +1,293 @@
1
+ =begin
2
+ #Xero Bank Feeds API v2
3
+
4
+ #The Bank Feeds API is available to financial institutions with a Xero partnership and approved app partners. For non-bank apps, it automates statement imports into Xero bank and credit card accounts; it does not create a direct bank feed. Feed Connections 2.0 is intended to replace 1.0. The customer chooses whether to connect an existing Xero account or create a new one. Use ExistingAccount with the chosen accountId, or NewAccount to create an account; Xero does not guess which account to connect or silently change an account name. The GET and delete operations also use 2.0. Statements continue to use 1.0. Partial failures are rare, and nearly all are recoverable by your app with no need to contact Xero support. If an item in a write response has `status` `PARTIAL_FAILURE`, handle only that item and read its `error.type`. For `partial-failure-new-account-creation`, do not resend the NewAccount item: connect `error.accountId` with `POST /FeedConnections/ExistingAccount`. For `partial-failure-new-account-existence-not-confirmed`, the account named in `error.accountName` may or may not exist. Use the Accounting API to check whether an account with that name exists. If it does, connect it with `POST /FeedConnections/ExistingAccount`. If it does not, resend the NewAccount item. If your app has a user, you can show them this message instead: \"Something went wrong. Please check whether your chosen account name now exists. If it does, connect it. If not, try creating the new one again.\" For any other `partial-failure-*` type, resend the same item. If the recovery request for `partial-failure-new-account-creation`, `partial-failure-previous-connection-deletion` or `partial-failure-connection-creation` returns 409 `feed-already-connected-in-current-organisation`, the earlier attempt succeeded: treat the item as created and use `GET /FeedConnections` to find its `id`. `error.subtype` is optional diagnostics; do not branch on it, and never parse `title` or `detail`. Full detail: https://developer.xero.com/documentation/api/bankfeeds/feedconnections-2-0-errors/#partial-failures
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::BankfeedsV2
16
+ # A Feed Connection as Xero records it.
17
+ require 'bigdecimal'
18
+
19
+ class FeedConnection
20
+ # Xero's identifier for the Feed Connection.
21
+ attr_accessor :id
22
+
23
+ # The financial institute's identifier for the account.
24
+ attr_accessor :account_token
25
+
26
+
27
+ attr_accessor :account_type
28
+
29
+ # The account number the feed is connected to.
30
+ attr_accessor :account_number
31
+
32
+ # The name of the Xero Bank Account.
33
+ attr_accessor :account_name
34
+
35
+ # Xero's identifier for the Xero Bank Account.
36
+ attr_accessor :account_id
37
+
38
+ # ISO-4217 currency code.
39
+ attr_accessor :currency
40
+
41
+ # ISO-3166 alpha-2 country code.
42
+ attr_accessor :country
43
+
44
+ # Attribute mapping from ruby-style variable name to JSON key.
45
+ def self.attribute_map
46
+ {
47
+ :'id' => :'id',
48
+ :'account_token' => :'accountToken',
49
+ :'account_type' => :'accountType',
50
+ :'account_number' => :'accountNumber',
51
+ :'account_name' => :'accountName',
52
+ :'account_id' => :'accountId',
53
+ :'currency' => :'currency',
54
+ :'country' => :'country'
55
+ }
56
+ end
57
+
58
+ # Attribute type mapping.
59
+ def self.openapi_types
60
+ {
61
+ :'id' => :'String',
62
+ :'account_token' => :'String',
63
+ :'account_type' => :'AccountType',
64
+ :'account_number' => :'String',
65
+ :'account_name' => :'String',
66
+ :'account_id' => :'String',
67
+ :'currency' => :'String',
68
+ :'country' => :'String'
69
+ }
70
+ end
71
+
72
+ # Initializes the object
73
+ # @param [Hash] attributes Model attributes in the form of hash
74
+ def initialize(attributes = {})
75
+ if (!attributes.is_a?(Hash))
76
+ fail ArgumentError, "The input argument (attributes) must be a hash in `XeroRuby::BankfeedsV2::FeedConnection` initialize method"
77
+ end
78
+
79
+ # check to see if the attribute exists and convert string to symbol for hash key
80
+ attributes = attributes.each_with_object({}) { |(k, v), h|
81
+ if (!self.class.attribute_map.key?(k.to_sym))
82
+ fail ArgumentError, "`#{k}` is not a valid attribute in `XeroRuby::BankfeedsV2::FeedConnection`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
83
+ end
84
+ h[k.to_sym] = v
85
+ }
86
+
87
+ if attributes.key?(:'id')
88
+ self.id = attributes[:'id']
89
+ end
90
+
91
+ if attributes.key?(:'account_token')
92
+ self.account_token = attributes[:'account_token']
93
+ end
94
+
95
+ if attributes.key?(:'account_type')
96
+ self.account_type = attributes[:'account_type']
97
+ end
98
+
99
+ if attributes.key?(:'account_number')
100
+ self.account_number = attributes[:'account_number']
101
+ end
102
+
103
+ if attributes.key?(:'account_name')
104
+ self.account_name = attributes[:'account_name']
105
+ end
106
+
107
+ if attributes.key?(:'account_id')
108
+ self.account_id = attributes[:'account_id']
109
+ end
110
+
111
+ if attributes.key?(:'currency')
112
+ self.currency = attributes[:'currency']
113
+ end
114
+
115
+ if attributes.key?(:'country')
116
+ self.country = attributes[:'country']
117
+ end
118
+ end
119
+
120
+ # Show invalid properties with the reasons. Usually used together with valid?
121
+ # @return Array for valid properties with the reasons
122
+ def list_invalid_properties
123
+ invalid_properties = Array.new
124
+ invalid_properties
125
+ end
126
+
127
+ # Check to see if the all the properties in the model are valid
128
+ # @return true if the model is valid
129
+ def valid?
130
+ true
131
+ end
132
+
133
+ # Checks equality by comparing each attribute.
134
+ # @param [Object] Object to be compared
135
+ def ==(o)
136
+ return true if self.equal?(o)
137
+ self.class == o.class &&
138
+ id == o.id &&
139
+ account_token == o.account_token &&
140
+ account_type == o.account_type &&
141
+ account_number == o.account_number &&
142
+ account_name == o.account_name &&
143
+ account_id == o.account_id &&
144
+ currency == o.currency &&
145
+ country == o.country
146
+ end
147
+
148
+ # @see the `==` method
149
+ # @param [Object] Object to be compared
150
+ def eql?(o)
151
+ self == o
152
+ end
153
+
154
+ # Calculates hash code according to all attributes.
155
+ # @return [Integer] Hash code
156
+ def hash
157
+ [id, account_token, account_type, account_number, account_name, account_id, currency, country].hash
158
+ end
159
+
160
+ # Builds the object from hash
161
+ # @param [Hash] attributes Model attributes in the form of hash
162
+ # @return [Object] Returns the model itself
163
+ def self.build_from_hash(attributes)
164
+ new.build_from_hash(attributes)
165
+ end
166
+
167
+ # Builds the object from hash
168
+ # @param [Hash] attributes Model attributes in the form of hash
169
+ # @return [Object] Returns the model itself
170
+ def build_from_hash(attributes)
171
+ return nil unless attributes.is_a?(Hash)
172
+ self.class.openapi_types.each_pair do |key, type|
173
+ if type =~ /\AArray<(.*)>/i
174
+ # check to ensure the input is an array given that the attribute
175
+ # is documented as an array but the input is not
176
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
177
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
178
+ end
179
+ elsif !attributes[self.class.attribute_map[key]].nil?
180
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
181
+ end # or else data not found in attributes(hash), not an issue as the data can be optional
182
+ end
183
+
184
+ self
185
+ end
186
+
187
+ # Deserializes the data based on type
188
+ # @param string type Data type
189
+ # @param string value Value to be deserialized
190
+ # @return [Object] Deserialized data
191
+ def _deserialize(type, value)
192
+ case type.to_sym
193
+ when :DateTime
194
+ DateTime.parse(parse_date(value))
195
+ when :Date
196
+ Date.parse(parse_date(value))
197
+ when :String
198
+ value.to_s
199
+ when :Integer
200
+ value.to_i
201
+ when :Float
202
+ value.to_f
203
+ when :BigDecimal
204
+ BigDecimal(value.to_s)
205
+ when :Boolean
206
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
207
+ true
208
+ else
209
+ false
210
+ end
211
+ when :Object
212
+ # generic object (usually a Hash), return directly
213
+ value
214
+ when /\AArray<(?<inner_type>.+)>\z/
215
+ inner_type = Regexp.last_match[:inner_type]
216
+ value.map { |v| _deserialize(inner_type, v) }
217
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
218
+ k_type = Regexp.last_match[:k_type]
219
+ v_type = Regexp.last_match[:v_type]
220
+ {}.tap do |hash|
221
+ value.each do |k, v|
222
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
223
+ end
224
+ end
225
+ else # model
226
+ XeroRuby::BankfeedsV2.const_get(type).build_from_hash(value)
227
+ end
228
+ end
229
+
230
+ # Returns the string representation of the object
231
+ # @return [String] String presentation of the object
232
+ def to_s
233
+ to_hash.to_s
234
+ end
235
+
236
+ # to_body is an alias to to_hash (backward compatibility)
237
+ # @return [Hash] Returns the object in the form of hash
238
+ def to_body
239
+ to_hash
240
+ end
241
+
242
+ # Returns the object in the form of hash
243
+ # @return [Hash] Returns the object in the form of hash
244
+ def to_hash(downcase: false)
245
+ hash = {}
246
+ self.class.attribute_map.each_pair do |attr, param|
247
+ value = self.send(attr)
248
+ next if value.nil?
249
+ key = downcase ? attr : param
250
+ hash[key] = _to_hash(value, downcase: downcase)
251
+ end
252
+ hash
253
+ end
254
+
255
+ # Returns the object in the form of hash with snake_case
256
+ def to_attributes
257
+ to_hash(downcase: true)
258
+ end
259
+
260
+ # Outputs non-array value in the form of hash
261
+ # For object, use to_hash. Otherwise, just return the value
262
+ # @param [Object] value Any valid value
263
+ # @return [Hash] Returns the value in the form of hash
264
+ def _to_hash(value, downcase: false)
265
+ if value.is_a?(Array)
266
+ value.map do |v|
267
+ v.to_hash(downcase: downcase)
268
+ end
269
+ elsif value.is_a?(Hash)
270
+ {}.tap do |hash|
271
+ value.map { |k, v| hash[k] = _to_hash(v, downcase: downcase) }
272
+ end
273
+ elsif value.respond_to? :to_hash
274
+ value.to_hash(downcase: downcase)
275
+ else
276
+ value
277
+ end
278
+ end
279
+
280
+ def parse_date(datestring)
281
+ if datestring.include?('Date')
282
+ date_pattern = /\/Date\((-?\d+)(\+\d+)?\)\//
283
+ original, date, timezone = *date_pattern.match(datestring)
284
+ date = (date.to_i / 1000)
285
+ Time.at(date).utc.strftime('%Y-%m-%dT%H:%M:%S%z').to_s
286
+ elsif /(\d\d\d\d)-(\d\d)/.match(datestring) # handles dates w/out Days: YYYY-MM*-DD
287
+ Time.parse(datestring + '-01').strftime('%Y-%m-%dT%H:%M:%S').to_s
288
+ else # handle date 'types' for small subset of payroll API's
289
+ Time.parse(datestring).strftime('%Y-%m-%dT%H:%M:%S').to_s
290
+ end
291
+ end
292
+ end
293
+ end
@@ -0,0 +1,227 @@
1
+ =begin
2
+ #Xero Bank Feeds API v2
3
+
4
+ #The Bank Feeds API is available to financial institutions with a Xero partnership and approved app partners. For non-bank apps, it automates statement imports into Xero bank and credit card accounts; it does not create a direct bank feed. Feed Connections 2.0 is intended to replace 1.0. The customer chooses whether to connect an existing Xero account or create a new one. Use ExistingAccount with the chosen accountId, or NewAccount to create an account; Xero does not guess which account to connect or silently change an account name. The GET and delete operations also use 2.0. Statements continue to use 1.0. Partial failures are rare, and nearly all are recoverable by your app with no need to contact Xero support. If an item in a write response has `status` `PARTIAL_FAILURE`, handle only that item and read its `error.type`. For `partial-failure-new-account-creation`, do not resend the NewAccount item: connect `error.accountId` with `POST /FeedConnections/ExistingAccount`. For `partial-failure-new-account-existence-not-confirmed`, the account named in `error.accountName` may or may not exist. Use the Accounting API to check whether an account with that name exists. If it does, connect it with `POST /FeedConnections/ExistingAccount`. If it does not, resend the NewAccount item. If your app has a user, you can show them this message instead: \"Something went wrong. Please check whether your chosen account name now exists. If it does, connect it. If not, try creating the new one again.\" For any other `partial-failure-*` type, resend the same item. If the recovery request for `partial-failure-new-account-creation`, `partial-failure-previous-connection-deletion` or `partial-failure-connection-creation` returns 409 `feed-already-connected-in-current-organisation`, the earlier attempt succeeded: treat the item as created and use `GET /FeedConnections` to find its `id`. `error.subtype` is optional diagnostics; do not branch on it, and never parse `title` or `detail`. Full detail: https://developer.xero.com/documentation/api/bankfeeds/feedconnections-2-0-errors/#partial-failures
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::BankfeedsV2
16
+ require 'bigdecimal'
17
+
18
+ class FeedConnectionToDelete
19
+ # The Feed Connection to terminate. Required; an all-zeros GUID is treated as though the field were absent. `accountToken`, `accountType` and `country`, which V1 accepted here, are not supported.
20
+ attr_accessor :id
21
+
22
+ # Attribute mapping from ruby-style variable name to JSON key.
23
+ def self.attribute_map
24
+ {
25
+ :'id' => :'id'
26
+ }
27
+ end
28
+
29
+ # Attribute type mapping.
30
+ def self.openapi_types
31
+ {
32
+ :'id' => :'String'
33
+ }
34
+ end
35
+
36
+ # Initializes the object
37
+ # @param [Hash] attributes Model attributes in the form of hash
38
+ def initialize(attributes = {})
39
+ if (!attributes.is_a?(Hash))
40
+ fail ArgumentError, "The input argument (attributes) must be a hash in `XeroRuby::BankfeedsV2::FeedConnectionToDelete` initialize method"
41
+ end
42
+
43
+ # check to see if the attribute exists and convert string to symbol for hash key
44
+ attributes = attributes.each_with_object({}) { |(k, v), h|
45
+ if (!self.class.attribute_map.key?(k.to_sym))
46
+ fail ArgumentError, "`#{k}` is not a valid attribute in `XeroRuby::BankfeedsV2::FeedConnectionToDelete`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
47
+ end
48
+ h[k.to_sym] = v
49
+ }
50
+
51
+ if attributes.key?(:'id')
52
+ self.id = attributes[:'id']
53
+ end
54
+ end
55
+
56
+ # Show invalid properties with the reasons. Usually used together with valid?
57
+ # @return Array for valid properties with the reasons
58
+ def list_invalid_properties
59
+ invalid_properties = Array.new
60
+ if @id.nil?
61
+ invalid_properties.push('invalid value for "id", id cannot be nil.')
62
+ end
63
+
64
+ invalid_properties
65
+ end
66
+
67
+ # Check to see if the all the properties in the model are valid
68
+ # @return true if the model is valid
69
+ def valid?
70
+ return false if @id.nil?
71
+ true
72
+ end
73
+
74
+ # Checks equality by comparing each attribute.
75
+ # @param [Object] Object to be compared
76
+ def ==(o)
77
+ return true if self.equal?(o)
78
+ self.class == o.class &&
79
+ id == o.id
80
+ end
81
+
82
+ # @see the `==` method
83
+ # @param [Object] Object to be compared
84
+ def eql?(o)
85
+ self == o
86
+ end
87
+
88
+ # Calculates hash code according to all attributes.
89
+ # @return [Integer] Hash code
90
+ def hash
91
+ [id].hash
92
+ end
93
+
94
+ # Builds the object from hash
95
+ # @param [Hash] attributes Model attributes in the form of hash
96
+ # @return [Object] Returns the model itself
97
+ def self.build_from_hash(attributes)
98
+ new.build_from_hash(attributes)
99
+ end
100
+
101
+ # Builds the object from hash
102
+ # @param [Hash] attributes Model attributes in the form of hash
103
+ # @return [Object] Returns the model itself
104
+ def build_from_hash(attributes)
105
+ return nil unless attributes.is_a?(Hash)
106
+ self.class.openapi_types.each_pair do |key, type|
107
+ if type =~ /\AArray<(.*)>/i
108
+ # check to ensure the input is an array given that the attribute
109
+ # is documented as an array but the input is not
110
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
111
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
112
+ end
113
+ elsif !attributes[self.class.attribute_map[key]].nil?
114
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
115
+ end # or else data not found in attributes(hash), not an issue as the data can be optional
116
+ end
117
+
118
+ self
119
+ end
120
+
121
+ # Deserializes the data based on type
122
+ # @param string type Data type
123
+ # @param string value Value to be deserialized
124
+ # @return [Object] Deserialized data
125
+ def _deserialize(type, value)
126
+ case type.to_sym
127
+ when :DateTime
128
+ DateTime.parse(parse_date(value))
129
+ when :Date
130
+ Date.parse(parse_date(value))
131
+ when :String
132
+ value.to_s
133
+ when :Integer
134
+ value.to_i
135
+ when :Float
136
+ value.to_f
137
+ when :BigDecimal
138
+ BigDecimal(value.to_s)
139
+ when :Boolean
140
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
141
+ true
142
+ else
143
+ false
144
+ end
145
+ when :Object
146
+ # generic object (usually a Hash), return directly
147
+ value
148
+ when /\AArray<(?<inner_type>.+)>\z/
149
+ inner_type = Regexp.last_match[:inner_type]
150
+ value.map { |v| _deserialize(inner_type, v) }
151
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
152
+ k_type = Regexp.last_match[:k_type]
153
+ v_type = Regexp.last_match[:v_type]
154
+ {}.tap do |hash|
155
+ value.each do |k, v|
156
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
157
+ end
158
+ end
159
+ else # model
160
+ XeroRuby::BankfeedsV2.const_get(type).build_from_hash(value)
161
+ end
162
+ end
163
+
164
+ # Returns the string representation of the object
165
+ # @return [String] String presentation of the object
166
+ def to_s
167
+ to_hash.to_s
168
+ end
169
+
170
+ # to_body is an alias to to_hash (backward compatibility)
171
+ # @return [Hash] Returns the object in the form of hash
172
+ def to_body
173
+ to_hash
174
+ end
175
+
176
+ # Returns the object in the form of hash
177
+ # @return [Hash] Returns the object in the form of hash
178
+ def to_hash(downcase: false)
179
+ hash = {}
180
+ self.class.attribute_map.each_pair do |attr, param|
181
+ value = self.send(attr)
182
+ next if value.nil?
183
+ key = downcase ? attr : param
184
+ hash[key] = _to_hash(value, downcase: downcase)
185
+ end
186
+ hash
187
+ end
188
+
189
+ # Returns the object in the form of hash with snake_case
190
+ def to_attributes
191
+ to_hash(downcase: true)
192
+ end
193
+
194
+ # Outputs non-array value in the form of hash
195
+ # For object, use to_hash. Otherwise, just return the value
196
+ # @param [Object] value Any valid value
197
+ # @return [Hash] Returns the value in the form of hash
198
+ def _to_hash(value, downcase: false)
199
+ if value.is_a?(Array)
200
+ value.map do |v|
201
+ v.to_hash(downcase: downcase)
202
+ end
203
+ elsif value.is_a?(Hash)
204
+ {}.tap do |hash|
205
+ value.map { |k, v| hash[k] = _to_hash(v, downcase: downcase) }
206
+ end
207
+ elsif value.respond_to? :to_hash
208
+ value.to_hash(downcase: downcase)
209
+ else
210
+ value
211
+ end
212
+ end
213
+
214
+ def parse_date(datestring)
215
+ if datestring.include?('Date')
216
+ date_pattern = /\/Date\((-?\d+)(\+\d+)?\)\//
217
+ original, date, timezone = *date_pattern.match(datestring)
218
+ date = (date.to_i / 1000)
219
+ Time.at(date).utc.strftime('%Y-%m-%dT%H:%M:%S%z').to_s
220
+ elsif /(\d\d\d\d)-(\d\d)/.match(datestring) # handles dates w/out Days: YYYY-MM*-DD
221
+ Time.parse(datestring + '-01').strftime('%Y-%m-%dT%H:%M:%S').to_s
222
+ else # handle date 'types' for small subset of payroll API's
223
+ Time.parse(datestring).strftime('%Y-%m-%dT%H:%M:%S').to_s
224
+ end
225
+ end
226
+ end
227
+ end