xero-ruby 18.4.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.
@@ -0,0 +1,229 @@
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 DeleteFeedConnectionsRequest
19
+ # Between 1 and 50 Feed Connections to terminate. No element may be null, and no identifier may appear twice.
20
+ attr_accessor :items
21
+
22
+ # Attribute mapping from ruby-style variable name to JSON key.
23
+ def self.attribute_map
24
+ {
25
+ :'items' => :'items'
26
+ }
27
+ end
28
+
29
+ # Attribute type mapping.
30
+ def self.openapi_types
31
+ {
32
+ :'items' => :'Array<FeedConnectionToDelete>'
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::DeleteFeedConnectionsRequest` 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::DeleteFeedConnectionsRequest`. 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?(:'items')
52
+ if (value = attributes[:'items']).is_a?(Array)
53
+ self.items = value
54
+ end
55
+ end
56
+ end
57
+
58
+ # Show invalid properties with the reasons. Usually used together with valid?
59
+ # @return Array for valid properties with the reasons
60
+ def list_invalid_properties
61
+ invalid_properties = Array.new
62
+ if @items.nil?
63
+ invalid_properties.push('invalid value for "items", items cannot be nil.')
64
+ end
65
+
66
+ invalid_properties
67
+ end
68
+
69
+ # Check to see if the all the properties in the model are valid
70
+ # @return true if the model is valid
71
+ def valid?
72
+ return false if @items.nil?
73
+ true
74
+ end
75
+
76
+ # Checks equality by comparing each attribute.
77
+ # @param [Object] Object to be compared
78
+ def ==(o)
79
+ return true if self.equal?(o)
80
+ self.class == o.class &&
81
+ items == o.items
82
+ end
83
+
84
+ # @see the `==` method
85
+ # @param [Object] Object to be compared
86
+ def eql?(o)
87
+ self == o
88
+ end
89
+
90
+ # Calculates hash code according to all attributes.
91
+ # @return [Integer] Hash code
92
+ def hash
93
+ [items].hash
94
+ end
95
+
96
+ # Builds the object from hash
97
+ # @param [Hash] attributes Model attributes in the form of hash
98
+ # @return [Object] Returns the model itself
99
+ def self.build_from_hash(attributes)
100
+ new.build_from_hash(attributes)
101
+ end
102
+
103
+ # Builds the object from hash
104
+ # @param [Hash] attributes Model attributes in the form of hash
105
+ # @return [Object] Returns the model itself
106
+ def build_from_hash(attributes)
107
+ return nil unless attributes.is_a?(Hash)
108
+ self.class.openapi_types.each_pair do |key, type|
109
+ if type =~ /\AArray<(.*)>/i
110
+ # check to ensure the input is an array given that the attribute
111
+ # is documented as an array but the input is not
112
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
113
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
114
+ end
115
+ elsif !attributes[self.class.attribute_map[key]].nil?
116
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
117
+ end # or else data not found in attributes(hash), not an issue as the data can be optional
118
+ end
119
+
120
+ self
121
+ end
122
+
123
+ # Deserializes the data based on type
124
+ # @param string type Data type
125
+ # @param string value Value to be deserialized
126
+ # @return [Object] Deserialized data
127
+ def _deserialize(type, value)
128
+ case type.to_sym
129
+ when :DateTime
130
+ DateTime.parse(parse_date(value))
131
+ when :Date
132
+ Date.parse(parse_date(value))
133
+ when :String
134
+ value.to_s
135
+ when :Integer
136
+ value.to_i
137
+ when :Float
138
+ value.to_f
139
+ when :BigDecimal
140
+ BigDecimal(value.to_s)
141
+ when :Boolean
142
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
143
+ true
144
+ else
145
+ false
146
+ end
147
+ when :Object
148
+ # generic object (usually a Hash), return directly
149
+ value
150
+ when /\AArray<(?<inner_type>.+)>\z/
151
+ inner_type = Regexp.last_match[:inner_type]
152
+ value.map { |v| _deserialize(inner_type, v) }
153
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
154
+ k_type = Regexp.last_match[:k_type]
155
+ v_type = Regexp.last_match[:v_type]
156
+ {}.tap do |hash|
157
+ value.each do |k, v|
158
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
159
+ end
160
+ end
161
+ else # model
162
+ XeroRuby::BankfeedsV2.const_get(type).build_from_hash(value)
163
+ end
164
+ end
165
+
166
+ # Returns the string representation of the object
167
+ # @return [String] String presentation of the object
168
+ def to_s
169
+ to_hash.to_s
170
+ end
171
+
172
+ # to_body is an alias to to_hash (backward compatibility)
173
+ # @return [Hash] Returns the object in the form of hash
174
+ def to_body
175
+ to_hash
176
+ end
177
+
178
+ # Returns the object in the form of hash
179
+ # @return [Hash] Returns the object in the form of hash
180
+ def to_hash(downcase: false)
181
+ hash = {}
182
+ self.class.attribute_map.each_pair do |attr, param|
183
+ value = self.send(attr)
184
+ next if value.nil?
185
+ key = downcase ? attr : param
186
+ hash[key] = _to_hash(value, downcase: downcase)
187
+ end
188
+ hash
189
+ end
190
+
191
+ # Returns the object in the form of hash with snake_case
192
+ def to_attributes
193
+ to_hash(downcase: true)
194
+ end
195
+
196
+ # Outputs non-array value in the form of hash
197
+ # For object, use to_hash. Otherwise, just return the value
198
+ # @param [Object] value Any valid value
199
+ # @return [Hash] Returns the value in the form of hash
200
+ def _to_hash(value, downcase: false)
201
+ if value.is_a?(Array)
202
+ value.map do |v|
203
+ v.to_hash(downcase: downcase)
204
+ end
205
+ elsif value.is_a?(Hash)
206
+ {}.tap do |hash|
207
+ value.map { |k, v| hash[k] = _to_hash(v, downcase: downcase) }
208
+ end
209
+ elsif value.respond_to? :to_hash
210
+ value.to_hash(downcase: downcase)
211
+ else
212
+ value
213
+ end
214
+ end
215
+
216
+ def parse_date(datestring)
217
+ if datestring.include?('Date')
218
+ date_pattern = /\/Date\((-?\d+)(\+\d+)?\)\//
219
+ original, date, timezone = *date_pattern.match(datestring)
220
+ date = (date.to_i / 1000)
221
+ Time.at(date).utc.strftime('%Y-%m-%dT%H:%M:%S%z').to_s
222
+ elsif /(\d\d\d\d)-(\d\d)/.match(datestring) # handles dates w/out Days: YYYY-MM*-DD
223
+ Time.parse(datestring + '-01').strftime('%Y-%m-%dT%H:%M:%S').to_s
224
+ else # handle date 'types' for small subset of payroll API's
225
+ Time.parse(datestring).strftime('%Y-%m-%dT%H:%M:%S').to_s
226
+ end
227
+ end
228
+ end
229
+ end
@@ -0,0 +1,373 @@
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 ExistingAccountFeedConnection
19
+ # The Xero Bank Account to connect the feed to. Required. An all-zeros GUID is treated as though the field were absent.
20
+ attr_accessor :account_id
21
+
22
+ # The financial institute's identifier for the account. Must be unique within your financial institute. Some financial institutes additionally constrain its format.
23
+ attr_accessor :account_token
24
+
25
+
26
+ attr_accessor :account_type
27
+
28
+ # ISO-4217 currency code. Must match the currency of the Xero Bank Account named by `accountId`, and must be a currency the Organisation has.
29
+ attr_accessor :currency
30
+
31
+ # ISO-3166 alpha-2 country code. Required only when the Application supports multiple regions. Talk to your Partner Manager to confirm whether this applies to you.
32
+ attr_accessor :country
33
+
34
+ # Ignored. Taken from the Xero Bank Account named by `accountId`.
35
+ attr_accessor :account_number
36
+
37
+ # Ignored. Taken from the Xero Bank Account named by `accountId`.
38
+ attr_accessor :account_name
39
+
40
+ # Attribute mapping from ruby-style variable name to JSON key.
41
+ def self.attribute_map
42
+ {
43
+ :'account_id' => :'accountId',
44
+ :'account_token' => :'accountToken',
45
+ :'account_type' => :'accountType',
46
+ :'currency' => :'currency',
47
+ :'country' => :'country',
48
+ :'account_number' => :'accountNumber',
49
+ :'account_name' => :'accountName'
50
+ }
51
+ end
52
+
53
+ # Attribute type mapping.
54
+ def self.openapi_types
55
+ {
56
+ :'account_id' => :'String',
57
+ :'account_token' => :'String',
58
+ :'account_type' => :'AccountType',
59
+ :'currency' => :'String',
60
+ :'country' => :'String',
61
+ :'account_number' => :'String',
62
+ :'account_name' => :'String'
63
+ }
64
+ end
65
+
66
+ # Initializes the object
67
+ # @param [Hash] attributes Model attributes in the form of hash
68
+ def initialize(attributes = {})
69
+ if (!attributes.is_a?(Hash))
70
+ fail ArgumentError, "The input argument (attributes) must be a hash in `XeroRuby::BankfeedsV2::ExistingAccountFeedConnection` initialize method"
71
+ end
72
+
73
+ # check to see if the attribute exists and convert string to symbol for hash key
74
+ attributes = attributes.each_with_object({}) { |(k, v), h|
75
+ if (!self.class.attribute_map.key?(k.to_sym))
76
+ fail ArgumentError, "`#{k}` is not a valid attribute in `XeroRuby::BankfeedsV2::ExistingAccountFeedConnection`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
77
+ end
78
+ h[k.to_sym] = v
79
+ }
80
+
81
+ if attributes.key?(:'account_id')
82
+ self.account_id = attributes[:'account_id']
83
+ end
84
+
85
+ if attributes.key?(:'account_token')
86
+ self.account_token = attributes[:'account_token']
87
+ end
88
+
89
+ if attributes.key?(:'account_type')
90
+ self.account_type = attributes[:'account_type']
91
+ end
92
+
93
+ if attributes.key?(:'currency')
94
+ self.currency = attributes[:'currency']
95
+ end
96
+
97
+ if attributes.key?(:'country')
98
+ self.country = attributes[:'country']
99
+ end
100
+
101
+ if attributes.key?(:'account_number')
102
+ self.account_number = attributes[:'account_number']
103
+ end
104
+
105
+ if attributes.key?(:'account_name')
106
+ self.account_name = attributes[:'account_name']
107
+ end
108
+ end
109
+
110
+ # Show invalid properties with the reasons. Usually used together with valid?
111
+ # @return Array for valid properties with the reasons
112
+ def list_invalid_properties
113
+ invalid_properties = Array.new
114
+ if @account_id.nil?
115
+ invalid_properties.push('invalid value for "account_id", account_id cannot be nil.')
116
+ end
117
+
118
+ if @account_token.nil?
119
+ invalid_properties.push('invalid value for "account_token", account_token cannot be nil.')
120
+ end
121
+
122
+ if @account_token.to_s.length > 50
123
+ invalid_properties.push('invalid value for "account_token", the character length must be smaller than or equal to 50.')
124
+ end
125
+
126
+ if @account_type.nil?
127
+ invalid_properties.push('invalid value for "account_type", account_type cannot be nil.')
128
+ end
129
+
130
+ if @currency.nil?
131
+ invalid_properties.push('invalid value for "currency", currency cannot be nil.')
132
+ end
133
+
134
+ if @currency.to_s.length > 3
135
+ invalid_properties.push('invalid value for "currency", the character length must be smaller than or equal to 3.')
136
+ end
137
+
138
+ if @currency.to_s.length < 3
139
+ invalid_properties.push('invalid value for "currency", the character length must be great than or equal to 3.')
140
+ end
141
+
142
+ if !@country.nil? && @country.to_s.length > 2
143
+ invalid_properties.push('invalid value for "country", the character length must be smaller than or equal to 2.')
144
+ end
145
+
146
+ if !@country.nil? && @country.to_s.length < 2
147
+ invalid_properties.push('invalid value for "country", the character length must be great than or equal to 2.')
148
+ end
149
+
150
+ invalid_properties
151
+ end
152
+
153
+ # Check to see if the all the properties in the model are valid
154
+ # @return true if the model is valid
155
+ def valid?
156
+ return false if @account_id.nil?
157
+ return false if @account_token.nil?
158
+ return false if @account_token.to_s.length > 50
159
+ return false if @account_type.nil?
160
+ return false if @currency.nil?
161
+ return false if @currency.to_s.length > 3
162
+ return false if @currency.to_s.length < 3
163
+ return false if !@country.nil? && @country.to_s.length > 2
164
+ return false if !@country.nil? && @country.to_s.length < 2
165
+ true
166
+ end
167
+
168
+ # Custom attribute writer method with validation
169
+ # @param [Object] account_token Value to be assigned
170
+ def account_token=(account_token)
171
+ if account_token.nil?
172
+ fail ArgumentError, 'account_token cannot be nil'
173
+ end
174
+
175
+ if account_token.to_s.length > 50
176
+ fail ArgumentError, 'invalid value for "account_token", the character length must be smaller than or equal to 50.'
177
+ end
178
+
179
+ @account_token = account_token
180
+ end
181
+
182
+ # Custom attribute writer method with validation
183
+ # @param [Object] currency Value to be assigned
184
+ def currency=(currency)
185
+ if currency.nil?
186
+ fail ArgumentError, 'currency cannot be nil'
187
+ end
188
+
189
+ if currency.to_s.length > 3
190
+ fail ArgumentError, 'invalid value for "currency", the character length must be smaller than or equal to 3.'
191
+ end
192
+
193
+ if currency.to_s.length < 3
194
+ fail ArgumentError, 'invalid value for "currency", the character length must be great than or equal to 3.'
195
+ end
196
+
197
+ @currency = currency
198
+ end
199
+
200
+ # Custom attribute writer method with validation
201
+ # @param [Object] country Value to be assigned
202
+ def country=(country)
203
+ if !country.nil? && country.to_s.length > 2
204
+ fail ArgumentError, 'invalid value for "country", the character length must be smaller than or equal to 2.'
205
+ end
206
+
207
+ if !country.nil? && country.to_s.length < 2
208
+ fail ArgumentError, 'invalid value for "country", the character length must be great than or equal to 2.'
209
+ end
210
+
211
+ @country = country
212
+ end
213
+
214
+ # Checks equality by comparing each attribute.
215
+ # @param [Object] Object to be compared
216
+ def ==(o)
217
+ return true if self.equal?(o)
218
+ self.class == o.class &&
219
+ account_id == o.account_id &&
220
+ account_token == o.account_token &&
221
+ account_type == o.account_type &&
222
+ currency == o.currency &&
223
+ country == o.country &&
224
+ account_number == o.account_number &&
225
+ account_name == o.account_name
226
+ end
227
+
228
+ # @see the `==` method
229
+ # @param [Object] Object to be compared
230
+ def eql?(o)
231
+ self == o
232
+ end
233
+
234
+ # Calculates hash code according to all attributes.
235
+ # @return [Integer] Hash code
236
+ def hash
237
+ [account_id, account_token, account_type, currency, country, account_number, account_name].hash
238
+ end
239
+
240
+ # Builds the object from hash
241
+ # @param [Hash] attributes Model attributes in the form of hash
242
+ # @return [Object] Returns the model itself
243
+ def self.build_from_hash(attributes)
244
+ new.build_from_hash(attributes)
245
+ end
246
+
247
+ # Builds the object from hash
248
+ # @param [Hash] attributes Model attributes in the form of hash
249
+ # @return [Object] Returns the model itself
250
+ def build_from_hash(attributes)
251
+ return nil unless attributes.is_a?(Hash)
252
+ self.class.openapi_types.each_pair do |key, type|
253
+ if type =~ /\AArray<(.*)>/i
254
+ # check to ensure the input is an array given that the attribute
255
+ # is documented as an array but the input is not
256
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
257
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
258
+ end
259
+ elsif !attributes[self.class.attribute_map[key]].nil?
260
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
261
+ end # or else data not found in attributes(hash), not an issue as the data can be optional
262
+ end
263
+
264
+ self
265
+ end
266
+
267
+ # Deserializes the data based on type
268
+ # @param string type Data type
269
+ # @param string value Value to be deserialized
270
+ # @return [Object] Deserialized data
271
+ def _deserialize(type, value)
272
+ case type.to_sym
273
+ when :DateTime
274
+ DateTime.parse(parse_date(value))
275
+ when :Date
276
+ Date.parse(parse_date(value))
277
+ when :String
278
+ value.to_s
279
+ when :Integer
280
+ value.to_i
281
+ when :Float
282
+ value.to_f
283
+ when :BigDecimal
284
+ BigDecimal(value.to_s)
285
+ when :Boolean
286
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
287
+ true
288
+ else
289
+ false
290
+ end
291
+ when :Object
292
+ # generic object (usually a Hash), return directly
293
+ value
294
+ when /\AArray<(?<inner_type>.+)>\z/
295
+ inner_type = Regexp.last_match[:inner_type]
296
+ value.map { |v| _deserialize(inner_type, v) }
297
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
298
+ k_type = Regexp.last_match[:k_type]
299
+ v_type = Regexp.last_match[:v_type]
300
+ {}.tap do |hash|
301
+ value.each do |k, v|
302
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
303
+ end
304
+ end
305
+ else # model
306
+ XeroRuby::BankfeedsV2.const_get(type).build_from_hash(value)
307
+ end
308
+ end
309
+
310
+ # Returns the string representation of the object
311
+ # @return [String] String presentation of the object
312
+ def to_s
313
+ to_hash.to_s
314
+ end
315
+
316
+ # to_body is an alias to to_hash (backward compatibility)
317
+ # @return [Hash] Returns the object in the form of hash
318
+ def to_body
319
+ to_hash
320
+ end
321
+
322
+ # Returns the object in the form of hash
323
+ # @return [Hash] Returns the object in the form of hash
324
+ def to_hash(downcase: false)
325
+ hash = {}
326
+ self.class.attribute_map.each_pair do |attr, param|
327
+ value = self.send(attr)
328
+ next if value.nil?
329
+ key = downcase ? attr : param
330
+ hash[key] = _to_hash(value, downcase: downcase)
331
+ end
332
+ hash
333
+ end
334
+
335
+ # Returns the object in the form of hash with snake_case
336
+ def to_attributes
337
+ to_hash(downcase: true)
338
+ end
339
+
340
+ # Outputs non-array value in the form of hash
341
+ # For object, use to_hash. Otherwise, just return the value
342
+ # @param [Object] value Any valid value
343
+ # @return [Hash] Returns the value in the form of hash
344
+ def _to_hash(value, downcase: false)
345
+ if value.is_a?(Array)
346
+ value.map do |v|
347
+ v.to_hash(downcase: downcase)
348
+ end
349
+ elsif value.is_a?(Hash)
350
+ {}.tap do |hash|
351
+ value.map { |k, v| hash[k] = _to_hash(v, downcase: downcase) }
352
+ end
353
+ elsif value.respond_to? :to_hash
354
+ value.to_hash(downcase: downcase)
355
+ else
356
+ value
357
+ end
358
+ end
359
+
360
+ def parse_date(datestring)
361
+ if datestring.include?('Date')
362
+ date_pattern = /\/Date\((-?\d+)(\+\d+)?\)\//
363
+ original, date, timezone = *date_pattern.match(datestring)
364
+ date = (date.to_i / 1000)
365
+ Time.at(date).utc.strftime('%Y-%m-%dT%H:%M:%S%z').to_s
366
+ elsif /(\d\d\d\d)-(\d\d)/.match(datestring) # handles dates w/out Days: YYYY-MM*-DD
367
+ Time.parse(datestring + '-01').strftime('%Y-%m-%dT%H:%M:%S').to_s
368
+ else # handle date 'types' for small subset of payroll API's
369
+ Time.parse(datestring).strftime('%Y-%m-%dT%H:%M:%S').to_s
370
+ end
371
+ end
372
+ end
373
+ end