xero-ruby 9.3.0 → 18.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. checksums.yaml +4 -4
  2. data/lib/xero-ruby/api/accounting_api.rb +178 -319
  3. data/lib/xero-ruby/api/files_api.rb +9 -2
  4. data/lib/xero-ruby/api/finance_api.rb +0 -299
  5. data/lib/xero-ruby/api/payroll_au_v2_api.rb +751 -0
  6. data/lib/xero-ruby/api/payroll_nz_api.rb +0 -86
  7. data/lib/xero-ruby/api/payroll_uk_api.rb +0 -86
  8. data/lib/xero-ruby/models/accounting/bank_transfer.rb +71 -1
  9. data/lib/xero-ruby/models/accounting/bank_transfer_delete.rb +244 -0
  10. data/lib/xero-ruby/models/accounting/bank_transfer_delete_by_url_param.rb +229 -0
  11. data/lib/xero-ruby/models/accounting/bank_transfers_delete.rb +224 -0
  12. data/lib/xero-ruby/models/accounting/contact.rb +27 -1
  13. data/lib/xero-ruby/models/accounting/credit_note.rb +11 -1
  14. data/lib/xero-ruby/models/accounting/invoice.rb +12 -2
  15. data/lib/xero-ruby/models/accounting/organisation.rb +25 -6
  16. data/lib/xero-ruby/models/accounting/overpayment.rb +21 -1
  17. data/lib/xero-ruby/models/accounting/payment.rb +11 -1
  18. data/lib/xero-ruby/models/accounting/prepayment.rb +31 -1
  19. data/lib/xero-ruby/models/accounting/tracking_reference.rb +277 -0
  20. data/lib/xero-ruby/models/accounting/user.rb +3 -2
  21. data/lib/xero-ruby/models/app_store/product.rb +4 -3
  22. data/lib/xero-ruby/models/assets/book_depreciation_detail.rb +54 -4
  23. data/lib/xero-ruby/models/files/association.rb +21 -1
  24. data/lib/xero-ruby/models/finance/current_statement_response.rb +1 -1
  25. data/lib/xero-ruby/models/finance/data_source_response.rb +1 -31
  26. data/lib/xero-ruby/models/payroll_au/earnings_rate.rb +16 -1
  27. data/lib/xero-ruby/models/payroll_au/employee.rb +1 -13
  28. data/lib/xero-ruby/models/payroll_au/leave_line.rb +16 -1
  29. data/lib/xero-ruby/models/payroll_au/leave_type.rb +19 -4
  30. data/lib/xero-ruby/models/payroll_au/opening_balance_leave_line.rb +232 -0
  31. data/lib/xero-ruby/models/payroll_au/opening_balances.rb +1 -1
  32. data/lib/xero-ruby/models/payroll_au/tax_declaration.rb +14 -4
  33. data/lib/xero-ruby/models/payroll_au_v2/invalid_field.rb +232 -0
  34. data/lib/xero-ruby/models/payroll_au_v2/pagination.rb +252 -0
  35. data/lib/xero-ruby/models/payroll_au_v2/problem.rb +275 -0
  36. data/lib/xero-ruby/models/payroll_au_v2/timesheet.rb +361 -0
  37. data/lib/xero-ruby/models/payroll_au_v2/timesheet_line.rb +277 -0
  38. data/lib/xero-ruby/models/payroll_au_v2/timesheet_line_object.rb +242 -0
  39. data/lib/xero-ruby/models/payroll_au_v2/timesheet_object.rb +242 -0
  40. data/lib/xero-ruby/models/payroll_au_v2/timesheets.rb +244 -0
  41. data/lib/xero-ruby/models/payroll_nz/employee.rb +20 -0
  42. data/lib/xero-ruby/models/payroll_nz/employee_leave_setup.rb +29 -19
  43. data/lib/xero-ruby/models/payroll_nz/employee_leave_type.rb +31 -11
  44. data/lib/xero-ruby/models/payroll_nz/employee_pay_template.rb +5 -0
  45. data/lib/xero-ruby/models/payroll_nz/employment.rb +15 -0
  46. data/lib/xero-ruby/models/payroll_nz/leave_period.rb +35 -4
  47. data/lib/xero-ruby/models/payroll_nz/leave_type.rb +24 -4
  48. data/lib/xero-ruby/models/payroll_uk/contract_type.rb +38 -0
  49. data/lib/xero-ruby/models/payroll_uk/contracts.rb +297 -0
  50. data/lib/xero-ruby/models/payroll_uk/developmental_role_details.rb +267 -0
  51. data/lib/xero-ruby/models/payroll_uk/earnings_rate.rb +5 -2
  52. data/lib/xero-ruby/models/payroll_uk/employee.rb +68 -4
  53. data/lib/xero-ruby/models/payroll_uk/employee_pay_template.rb +5 -0
  54. data/lib/xero-ruby/models/payroll_uk/employee_statutory_leave_balance.rb +4 -2
  55. data/lib/xero-ruby/models/payroll_uk/employee_statutory_leave_summary.rb +5 -2
  56. data/lib/xero-ruby/models/payroll_uk/employment.rb +49 -52
  57. data/lib/xero-ruby/models/payroll_uk/employment_status.rb +37 -0
  58. data/lib/xero-ruby/models/payroll_uk/ni_category.rb +318 -0
  59. data/lib/xero-ruby/models/payroll_uk/ni_category_letter.rb +51 -0
  60. data/lib/xero-ruby/models/payroll_uk/ni_category_one_of.rb +264 -0
  61. data/lib/xero-ruby/models/payroll_uk/ni_category_one_of1.rb +257 -0
  62. data/lib/xero-ruby/version.rb +2 -2
  63. data/lib/xero-ruby.rb +22 -10
  64. data/spec/finance/api/finance_api_spec.rb +0 -53
  65. metadata +393 -391
  66. data/spec/finance/models/account_usage_response_spec.rb +0 -58
  67. data/spec/finance/models/account_usage_spec.rb +0 -112
  68. data/spec/finance/models/history_record_response_spec.rb +0 -64
  69. data/spec/finance/models/lock_history_model_spec.rb +0 -52
  70. data/spec/finance/models/lock_history_response_spec.rb +0 -52
  71. data/spec/finance/models/practice_response_spec.rb +0 -64
  72. data/spec/finance/models/report_history_model_spec.rb +0 -52
  73. data/spec/finance/models/report_history_response_spec.rb +0 -52
  74. data/spec/finance/models/user_activities_response_spec.rb +0 -52
  75. data/spec/finance/models/user_response_spec.rb +0 -106
@@ -0,0 +1,318 @@
1
+ =begin
2
+ #Xero Payroll UK
3
+
4
+ #This is the Xero Payroll API for orgs in the UK region.
5
+
6
+ Contact: api@xero.com
7
+ Generated by: https://openapi-generator.tech
8
+ OpenAPI Generator version: 4.3.1
9
+
10
+ =end
11
+
12
+ require 'time'
13
+ require 'date'
14
+
15
+ module XeroRuby::PayrollUk
16
+ require 'bigdecimal'
17
+
18
+ class NICategory
19
+ # The start date of the NI category (YYYY-MM-DD)
20
+ attr_accessor :start_date
21
+
22
+
23
+ attr_accessor :ni_category
24
+
25
+ # Xero unique identifier for the NI category
26
+ attr_accessor :ni_category_id
27
+
28
+ # The date in which the employee was first employed as a civilian (YYYY-MM-DD)
29
+ attr_accessor :date_first_employed_as_civilian
30
+
31
+ # The workplace postcode
32
+ attr_accessor :workplace_postcode
33
+
34
+ class EnumAttributeValidator
35
+ attr_reader :datatype
36
+ attr_reader :allowable_values
37
+
38
+ def initialize(datatype, allowable_values)
39
+ @allowable_values = allowable_values.map do |value|
40
+ case datatype.to_s
41
+ when /Integer/i
42
+ value.to_i
43
+ when /Float/i
44
+ value.to_f
45
+ else
46
+ value
47
+ end
48
+ end
49
+ end
50
+
51
+ def valid?(value)
52
+ !value || allowable_values.include?(value)
53
+ end
54
+ end
55
+
56
+ # Attribute mapping from ruby-style variable name to JSON key.
57
+ def self.attribute_map
58
+ {
59
+ :'start_date' => :'startDate',
60
+ :'ni_category' => :'niCategory',
61
+ :'ni_category_id' => :'niCategoryID',
62
+ :'date_first_employed_as_civilian' => :'dateFirstEmployedAsCivilian',
63
+ :'workplace_postcode' => :'workplacePostcode'
64
+ }
65
+ end
66
+
67
+ # Attribute type mapping.
68
+ def self.openapi_types
69
+ {
70
+ :'start_date' => :'Date',
71
+ :'ni_category' => :'NICategoryLetter',
72
+ :'ni_category_id' => :'Float',
73
+ :'date_first_employed_as_civilian' => :'Date',
74
+ :'workplace_postcode' => :'String'
75
+ }
76
+ end
77
+
78
+ # List of class defined in oneOf (OpenAPI v3)
79
+ def self.openapi_one_of
80
+ [
81
+ :'NICategoryOneOf',
82
+ :'NICategoryOneOf1'
83
+ ]
84
+ end
85
+
86
+ # Initializes the object
87
+ # @param [Hash] attributes Model attributes in the form of hash
88
+ def initialize(attributes = {})
89
+ if (!attributes.is_a?(Hash))
90
+ fail ArgumentError, "The input argument (attributes) must be a hash in `XeroRuby::PayrollUk::NICategory` initialize method"
91
+ end
92
+
93
+ # check to see if the attribute exists and convert string to symbol for hash key
94
+ attributes = attributes.each_with_object({}) { |(k, v), h|
95
+ if (!self.class.attribute_map.key?(k.to_sym))
96
+ fail ArgumentError, "`#{k}` is not a valid attribute in `XeroRuby::PayrollUk::NICategory`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
97
+ end
98
+ h[k.to_sym] = v
99
+ }
100
+
101
+ if attributes.key?(:'start_date')
102
+ self.start_date = attributes[:'start_date']
103
+ end
104
+
105
+ if attributes.key?(:'ni_category')
106
+ self.ni_category = attributes[:'ni_category']
107
+ end
108
+
109
+ if attributes.key?(:'ni_category_id')
110
+ self.ni_category_id = attributes[:'ni_category_id']
111
+ end
112
+
113
+ if attributes.key?(:'date_first_employed_as_civilian')
114
+ self.date_first_employed_as_civilian = attributes[:'date_first_employed_as_civilian']
115
+ end
116
+
117
+ if attributes.key?(:'workplace_postcode')
118
+ self.workplace_postcode = attributes[:'workplace_postcode']
119
+ end
120
+ end
121
+
122
+ # Show invalid properties with the reasons. Usually used together with valid?
123
+ # @return Array for valid properties with the reasons
124
+ def list_invalid_properties
125
+ invalid_properties = Array.new
126
+ if @ni_category.nil?
127
+ invalid_properties.push('invalid value for "ni_category", ni_category cannot be nil.')
128
+ end
129
+
130
+ if @workplace_postcode.nil?
131
+ invalid_properties.push('invalid value for "workplace_postcode", workplace_postcode cannot be nil.')
132
+ end
133
+
134
+ invalid_properties
135
+ end
136
+
137
+ # Check to see if the all the properties in the model are valid
138
+ # @return true if the model is valid
139
+ def valid?
140
+ return false if @ni_category.nil?
141
+ return false if @workplace_postcode.nil?
142
+ _one_of_found = false
143
+ self.class.openapi_one_of.each do |_class|
144
+ _one_of = XeroRuby::PayrollUk.const_get(_class).build_from_hash(self.to_hash)
145
+ if _one_of.valid?
146
+ if _one_of_found
147
+ return false
148
+ else
149
+ _one_of_found = true
150
+ end
151
+ end
152
+ end
153
+
154
+ if !_one_of_found
155
+ return false
156
+ end
157
+
158
+ true
159
+ end
160
+
161
+ # Checks equality by comparing each attribute.
162
+ # @param [Object] Object to be compared
163
+ def ==(o)
164
+ return true if self.equal?(o)
165
+ self.class == o.class &&
166
+ start_date == o.start_date &&
167
+ ni_category == o.ni_category &&
168
+ ni_category_id == o.ni_category_id &&
169
+ date_first_employed_as_civilian == o.date_first_employed_as_civilian &&
170
+ workplace_postcode == o.workplace_postcode
171
+ end
172
+
173
+ # @see the `==` method
174
+ # @param [Object] Object to be compared
175
+ def eql?(o)
176
+ self == o
177
+ end
178
+
179
+ # Calculates hash code according to all attributes.
180
+ # @return [Integer] Hash code
181
+ def hash
182
+ [start_date, ni_category, ni_category_id, date_first_employed_as_civilian, workplace_postcode].hash
183
+ end
184
+
185
+ # Builds the object from hash
186
+ # @param [Hash] attributes Model attributes in the form of hash
187
+ # @return [Object] Returns the model itself
188
+ def self.build_from_hash(attributes)
189
+ new.build_from_hash(attributes)
190
+ end
191
+
192
+ # Builds the object from hash
193
+ # @param [Hash] attributes Model attributes in the form of hash
194
+ # @return [Object] Returns the model itself
195
+ def build_from_hash(attributes)
196
+ return nil unless attributes.is_a?(Hash)
197
+ self.class.openapi_types.each_pair do |key, type|
198
+ if type =~ /\AArray<(.*)>/i
199
+ # check to ensure the input is an array given that the attribute
200
+ # is documented as an array but the input is not
201
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
202
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
203
+ end
204
+ elsif !attributes[self.class.attribute_map[key]].nil?
205
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
206
+ end # or else data not found in attributes(hash), not an issue as the data can be optional
207
+ end
208
+
209
+ self
210
+ end
211
+
212
+ # Deserializes the data based on type
213
+ # @param string type Data type
214
+ # @param string value Value to be deserialized
215
+ # @return [Object] Deserialized data
216
+ def _deserialize(type, value)
217
+ case type.to_sym
218
+ when :DateTime
219
+ DateTime.parse(parse_date(value))
220
+ when :Date
221
+ Date.parse(parse_date(value))
222
+ when :String
223
+ value.to_s
224
+ when :Integer
225
+ value.to_i
226
+ when :Float
227
+ value.to_f
228
+ when :BigDecimal
229
+ BigDecimal(value.to_s)
230
+ when :Boolean
231
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
232
+ true
233
+ else
234
+ false
235
+ end
236
+ when :Object
237
+ # generic object (usually a Hash), return directly
238
+ value
239
+ when /\AArray<(?<inner_type>.+)>\z/
240
+ inner_type = Regexp.last_match[:inner_type]
241
+ value.map { |v| _deserialize(inner_type, v) }
242
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
243
+ k_type = Regexp.last_match[:k_type]
244
+ v_type = Regexp.last_match[:v_type]
245
+ {}.tap do |hash|
246
+ value.each do |k, v|
247
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
248
+ end
249
+ end
250
+ else # model
251
+ XeroRuby::PayrollUk.const_get(type).build_from_hash(value)
252
+ end
253
+ end
254
+
255
+ # Returns the string representation of the object
256
+ # @return [String] String presentation of the object
257
+ def to_s
258
+ to_hash.to_s
259
+ end
260
+
261
+ # to_body is an alias to to_hash (backward compatibility)
262
+ # @return [Hash] Returns the object in the form of hash
263
+ def to_body
264
+ to_hash
265
+ end
266
+
267
+ # Returns the object in the form of hash
268
+ # @return [Hash] Returns the object in the form of hash
269
+ def to_hash(downcase: false)
270
+ hash = {}
271
+ self.class.attribute_map.each_pair do |attr, param|
272
+ value = self.send(attr)
273
+ next if value.nil?
274
+ key = downcase ? attr : param
275
+ hash[key] = _to_hash(value, downcase: downcase)
276
+ end
277
+ hash
278
+ end
279
+
280
+ # Returns the object in the form of hash with snake_case
281
+ def to_attributes
282
+ to_hash(downcase: true)
283
+ end
284
+
285
+ # Outputs non-array value in the form of hash
286
+ # For object, use to_hash. Otherwise, just return the value
287
+ # @param [Object] value Any valid value
288
+ # @return [Hash] Returns the value in the form of hash
289
+ def _to_hash(value, downcase: false)
290
+ if value.is_a?(Array)
291
+ value.map do |v|
292
+ v.to_hash(downcase: downcase)
293
+ end
294
+ elsif value.is_a?(Hash)
295
+ {}.tap do |hash|
296
+ value.map { |k, v| hash[k] = _to_hash(v, downcase: downcase) }
297
+ end
298
+ elsif value.respond_to? :to_hash
299
+ value.to_hash(downcase: downcase)
300
+ else
301
+ value
302
+ end
303
+ end
304
+
305
+ def parse_date(datestring)
306
+ if datestring.include?('Date')
307
+ date_pattern = /\/Date\((-?\d+)(\+\d+)?\)\//
308
+ original, date, timezone = *date_pattern.match(datestring)
309
+ date = (date.to_i / 1000)
310
+ Time.at(date).utc.strftime('%Y-%m-%dT%H:%M:%S%z').to_s
311
+ elsif /(\d\d\d\d)-(\d\d)/.match(datestring) # handles dates w/out Days: YYYY-MM*-DD
312
+ Time.parse(datestring + '-01').strftime('%Y-%m-%dT%H:%M:%S').to_s
313
+ else # handle date 'types' for small subset of payroll API's
314
+ Time.parse(datestring).strftime('%Y-%m-%dT%H:%M:%S').to_s
315
+ end
316
+ end
317
+ end
318
+ end
@@ -0,0 +1,51 @@
1
+ =begin
2
+ #Xero Payroll UK
3
+
4
+ #This is the Xero Payroll API for orgs in the UK region.
5
+
6
+ Contact: api@xero.com
7
+ Generated by: https://openapi-generator.tech
8
+ OpenAPI Generator version: 4.3.1
9
+
10
+ =end
11
+
12
+ require 'time'
13
+ require 'date'
14
+
15
+ module XeroRuby::PayrollUk
16
+ class NICategoryLetter
17
+ A ||= "A".freeze
18
+ B ||= "B".freeze
19
+ C ||= "C".freeze
20
+ F ||= "F".freeze
21
+ H ||= "H".freeze
22
+ I ||= "I".freeze
23
+ J ||= "J".freeze
24
+ L ||= "L".freeze
25
+ M ||= "M".freeze
26
+ S ||= "S".freeze
27
+ V ||= "V".freeze
28
+ X ||= "X".freeze
29
+ Z ||= "Z".freeze
30
+ D ||= "D".freeze
31
+ E ||= "E".freeze
32
+ K ||= "K".freeze
33
+ N ||= "N".freeze
34
+
35
+ # Builds the enum from string
36
+ # @param [String] The enum value in the form of the string
37
+ # @return [String] The enum value
38
+ def self.build_from_hash(value)
39
+ new.build_from_hash(value)
40
+ end
41
+
42
+ # Builds the enum from string
43
+ # @param [String] The enum value in the form of the string
44
+ # @return [String] The enum value
45
+ def build_from_hash(value)
46
+ constantValues = NICategoryLetter.constants.select { |c| NICategoryLetter::const_get(c) == value }
47
+ raise "Invalid ENUM value #{value} for class #NICategoryLetter" if constantValues.empty?
48
+ value
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,264 @@
1
+ =begin
2
+ #Xero Payroll UK
3
+
4
+ #This is the Xero Payroll API for orgs in the UK region.
5
+
6
+ Contact: api@xero.com
7
+ Generated by: https://openapi-generator.tech
8
+ OpenAPI Generator version: 4.3.1
9
+
10
+ =end
11
+
12
+ require 'time'
13
+ require 'date'
14
+
15
+ module XeroRuby::PayrollUk
16
+ require 'bigdecimal'
17
+
18
+ class NICategoryOneOf
19
+
20
+ attr_accessor :ni_category
21
+ F ||= "F".freeze
22
+ I ||= "I".freeze
23
+ L ||= "L".freeze
24
+ S ||= "S".freeze
25
+ N ||= "N".freeze
26
+ E ||= "E".freeze
27
+ D ||= "D".freeze
28
+ K ||= "K".freeze
29
+
30
+ class EnumAttributeValidator
31
+ attr_reader :datatype
32
+ attr_reader :allowable_values
33
+
34
+ def initialize(datatype, allowable_values)
35
+ @allowable_values = allowable_values.map do |value|
36
+ case datatype.to_s
37
+ when /Integer/i
38
+ value.to_i
39
+ when /Float/i
40
+ value.to_f
41
+ else
42
+ value
43
+ end
44
+ end
45
+ end
46
+
47
+ def valid?(value)
48
+ !value || allowable_values.include?(value)
49
+ end
50
+ end
51
+
52
+ # Attribute mapping from ruby-style variable name to JSON key.
53
+ def self.attribute_map
54
+ {
55
+ :'ni_category' => :'niCategory'
56
+ }
57
+ end
58
+
59
+ # Attribute type mapping.
60
+ def self.openapi_types
61
+ {
62
+ :'ni_category' => :'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::PayrollUk::NICategoryOneOf` 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::PayrollUk::NICategoryOneOf`. 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?(:'ni_category')
82
+ self.ni_category = attributes[:'ni_category']
83
+ end
84
+ end
85
+
86
+ # Show invalid properties with the reasons. Usually used together with valid?
87
+ # @return Array for valid properties with the reasons
88
+ def list_invalid_properties
89
+ invalid_properties = Array.new
90
+ invalid_properties
91
+ end
92
+
93
+ # Check to see if the all the properties in the model are valid
94
+ # @return true if the model is valid
95
+ def valid?
96
+ ni_category_validator = EnumAttributeValidator.new('String', ["F", "I", "L", "S", "N", "E", "D", "K"])
97
+ return false unless ni_category_validator.valid?(@ni_category)
98
+ true
99
+ end
100
+
101
+ # Custom attribute writer method checking allowed values (enum).
102
+ # @param [Object] ni_category Object to be assigned
103
+ def ni_category=(ni_category)
104
+ validator = EnumAttributeValidator.new('String', ["F", "I", "L", "S", "N", "E", "D", "K"])
105
+ unless validator.valid?(ni_category)
106
+ fail ArgumentError, "invalid value for \"ni_category\", must be one of #{validator.allowable_values}."
107
+ end
108
+ @ni_category = ni_category
109
+ end
110
+
111
+ # Checks equality by comparing each attribute.
112
+ # @param [Object] Object to be compared
113
+ def ==(o)
114
+ return true if self.equal?(o)
115
+ self.class == o.class &&
116
+ ni_category == o.ni_category
117
+ end
118
+
119
+ # @see the `==` method
120
+ # @param [Object] Object to be compared
121
+ def eql?(o)
122
+ self == o
123
+ end
124
+
125
+ # Calculates hash code according to all attributes.
126
+ # @return [Integer] Hash code
127
+ def hash
128
+ [ni_category].hash
129
+ end
130
+
131
+ # Builds the object from hash
132
+ # @param [Hash] attributes Model attributes in the form of hash
133
+ # @return [Object] Returns the model itself
134
+ def self.build_from_hash(attributes)
135
+ new.build_from_hash(attributes)
136
+ end
137
+
138
+ # Builds the object from hash
139
+ # @param [Hash] attributes Model attributes in the form of hash
140
+ # @return [Object] Returns the model itself
141
+ def build_from_hash(attributes)
142
+ return nil unless attributes.is_a?(Hash)
143
+ self.class.openapi_types.each_pair do |key, type|
144
+ if type =~ /\AArray<(.*)>/i
145
+ # check to ensure the input is an array given that the attribute
146
+ # is documented as an array but the input is not
147
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
148
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
149
+ end
150
+ elsif !attributes[self.class.attribute_map[key]].nil?
151
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
152
+ end # or else data not found in attributes(hash), not an issue as the data can be optional
153
+ end
154
+
155
+ self
156
+ end
157
+
158
+ # Deserializes the data based on type
159
+ # @param string type Data type
160
+ # @param string value Value to be deserialized
161
+ # @return [Object] Deserialized data
162
+ def _deserialize(type, value)
163
+ case type.to_sym
164
+ when :DateTime
165
+ DateTime.parse(parse_date(value))
166
+ when :Date
167
+ Date.parse(parse_date(value))
168
+ when :String
169
+ value.to_s
170
+ when :Integer
171
+ value.to_i
172
+ when :Float
173
+ value.to_f
174
+ when :BigDecimal
175
+ BigDecimal(value.to_s)
176
+ when :Boolean
177
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
178
+ true
179
+ else
180
+ false
181
+ end
182
+ when :Object
183
+ # generic object (usually a Hash), return directly
184
+ value
185
+ when /\AArray<(?<inner_type>.+)>\z/
186
+ inner_type = Regexp.last_match[:inner_type]
187
+ value.map { |v| _deserialize(inner_type, v) }
188
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
189
+ k_type = Regexp.last_match[:k_type]
190
+ v_type = Regexp.last_match[:v_type]
191
+ {}.tap do |hash|
192
+ value.each do |k, v|
193
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
194
+ end
195
+ end
196
+ else # model
197
+ XeroRuby::PayrollUk.const_get(type).build_from_hash(value)
198
+ end
199
+ end
200
+
201
+ # Returns the string representation of the object
202
+ # @return [String] String presentation of the object
203
+ def to_s
204
+ to_hash.to_s
205
+ end
206
+
207
+ # to_body is an alias to to_hash (backward compatibility)
208
+ # @return [Hash] Returns the object in the form of hash
209
+ def to_body
210
+ to_hash
211
+ end
212
+
213
+ # Returns the object in the form of hash
214
+ # @return [Hash] Returns the object in the form of hash
215
+ def to_hash(downcase: false)
216
+ hash = {}
217
+ self.class.attribute_map.each_pair do |attr, param|
218
+ value = self.send(attr)
219
+ next if value.nil?
220
+ key = downcase ? attr : param
221
+ hash[key] = _to_hash(value, downcase: downcase)
222
+ end
223
+ hash
224
+ end
225
+
226
+ # Returns the object in the form of hash with snake_case
227
+ def to_attributes
228
+ to_hash(downcase: true)
229
+ end
230
+
231
+ # Outputs non-array value in the form of hash
232
+ # For object, use to_hash. Otherwise, just return the value
233
+ # @param [Object] value Any valid value
234
+ # @return [Hash] Returns the value in the form of hash
235
+ def _to_hash(value, downcase: false)
236
+ if value.is_a?(Array)
237
+ value.map do |v|
238
+ v.to_hash(downcase: downcase)
239
+ end
240
+ elsif value.is_a?(Hash)
241
+ {}.tap do |hash|
242
+ value.map { |k, v| hash[k] = _to_hash(v, downcase: downcase) }
243
+ end
244
+ elsif value.respond_to? :to_hash
245
+ value.to_hash(downcase: downcase)
246
+ else
247
+ value
248
+ end
249
+ end
250
+
251
+ def parse_date(datestring)
252
+ if datestring.include?('Date')
253
+ date_pattern = /\/Date\((-?\d+)(\+\d+)?\)\//
254
+ original, date, timezone = *date_pattern.match(datestring)
255
+ date = (date.to_i / 1000)
256
+ Time.at(date).utc.strftime('%Y-%m-%dT%H:%M:%S%z').to_s
257
+ elsif /(\d\d\d\d)-(\d\d)/.match(datestring) # handles dates w/out Days: YYYY-MM*-DD
258
+ Time.parse(datestring + '-01').strftime('%Y-%m-%dT%H:%M:%S').to_s
259
+ else # handle date 'types' for small subset of payroll API's
260
+ Time.parse(datestring).strftime('%Y-%m-%dT%H:%M:%S').to_s
261
+ end
262
+ end
263
+ end
264
+ end