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