xero-ruby 18.2.0 → 18.4.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 (28) 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/payroll_nz_api.rb +2 -0
  4. data/lib/xero-ruby/api_client.rb +10 -0
  5. data/lib/xero-ruby/configuration.rb +2 -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/account.rb +11 -1
  25. data/lib/xero-ruby/models/payroll_nz/employee_tax.rb +44 -6
  26. data/lib/xero-ruby/version.rb +2 -2
  27. data/lib/xero-ruby.rb +19 -0
  28. metadata +385 -366
@@ -0,0 +1,229 @@
1
+ =begin
2
+ #Xero Account Data API (Beta)
3
+
4
+ #**Beta:** this API is in beta. Endpoints, request parameters and response shapes may change before general availability. The Account Data API provides read access to general ledger account data for a Xero organisation: account balances as at a date, account movements over a date range, and the individual account transactions behind them.
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::AccountData
16
+ require 'bigdecimal'
17
+
18
+ class AccountMovementsResponse
19
+
20
+ attr_accessor :account_movements
21
+
22
+ # Attribute mapping from ruby-style variable name to JSON key.
23
+ def self.attribute_map
24
+ {
25
+ :'account_movements' => :'accountMovements'
26
+ }
27
+ end
28
+
29
+ # Attribute type mapping.
30
+ def self.openapi_types
31
+ {
32
+ :'account_movements' => :'Array<AccountMovement>'
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::AccountData::AccountMovementsResponse` 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::AccountData::AccountMovementsResponse`. 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?(:'account_movements')
52
+ if (value = attributes[:'account_movements']).is_a?(Array)
53
+ self.account_movements = 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 @account_movements.nil?
63
+ invalid_properties.push('invalid value for "account_movements", account_movements 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 @account_movements.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
+ account_movements == o.account_movements
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
+ [account_movements].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::AccountData.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,359 @@
1
+ =begin
2
+ #Xero Account Data API (Beta)
3
+
4
+ #**Beta:** this API is in beta. Endpoints, request parameters and response shapes may change before general availability. The Account Data API provides read access to general ledger account data for a Xero organisation: account balances as at a date, account movements over a date range, and the individual account transactions behind them.
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::AccountData
16
+ require 'bigdecimal'
17
+
18
+ class AccountTransactionLine
19
+ # Unique journal number for this transaction.
20
+ attr_accessor :journal_number
21
+
22
+ # Accounting date of the transaction (YYYY-MM-DD).
23
+ attr_accessor :journal_date
24
+
25
+ # Line description, falling back to the journal narration. Empty if neither is set.
26
+ attr_accessor :description
27
+
28
+
29
+ attr_accessor :account
30
+
31
+
32
+ attr_accessor :net_amount
33
+
34
+ # Net amount as a signed number (positive for debit, negative for credit).
35
+ attr_accessor :signed_net_amount
36
+
37
+
38
+ attr_accessor :tax_amount
39
+
40
+ # Tax amount as a signed number (positive for debit, negative for credit).
41
+ attr_accessor :signed_tax_amount
42
+
43
+
44
+ attr_accessor :source
45
+
46
+
47
+ attr_accessor :tax_rate
48
+
49
+ # Present only when `include=trackingCategories` was requested, and omitted otherwise. Keys are tracking category IDs (UUIDs); values describe the selected tracking option. The object is empty when the line has no tracking.
50
+ attr_accessor :tracking_categories
51
+
52
+ # Attribute mapping from ruby-style variable name to JSON key.
53
+ def self.attribute_map
54
+ {
55
+ :'journal_number' => :'journalNumber',
56
+ :'journal_date' => :'journalDate',
57
+ :'description' => :'description',
58
+ :'account' => :'account',
59
+ :'net_amount' => :'netAmount',
60
+ :'signed_net_amount' => :'signedNetAmount',
61
+ :'tax_amount' => :'taxAmount',
62
+ :'signed_tax_amount' => :'signedTaxAmount',
63
+ :'source' => :'source',
64
+ :'tax_rate' => :'taxRate',
65
+ :'tracking_categories' => :'trackingCategories'
66
+ }
67
+ end
68
+
69
+ # Attribute type mapping.
70
+ def self.openapi_types
71
+ {
72
+ :'journal_number' => :'Integer',
73
+ :'journal_date' => :'Date',
74
+ :'description' => :'String',
75
+ :'account' => :'TransactionAccount',
76
+ :'net_amount' => :'LedgerDecimal',
77
+ :'signed_net_amount' => :'Float',
78
+ :'tax_amount' => :'LedgerDecimal',
79
+ :'signed_tax_amount' => :'Float',
80
+ :'source' => :'LineSource',
81
+ :'tax_rate' => :'LineTaxRate',
82
+ :'tracking_categories' => :'Hash<String, TrackingItemDetails>'
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::AccountData::AccountTransactionLine` 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::AccountData::AccountTransactionLine`. 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?(:'journal_number')
102
+ self.journal_number = attributes[:'journal_number']
103
+ end
104
+
105
+ if attributes.key?(:'journal_date')
106
+ self.journal_date = attributes[:'journal_date']
107
+ end
108
+
109
+ if attributes.key?(:'description')
110
+ self.description = attributes[:'description']
111
+ end
112
+
113
+ if attributes.key?(:'account')
114
+ self.account = attributes[:'account']
115
+ end
116
+
117
+ if attributes.key?(:'net_amount')
118
+ self.net_amount = attributes[:'net_amount']
119
+ end
120
+
121
+ if attributes.key?(:'signed_net_amount')
122
+ self.signed_net_amount = attributes[:'signed_net_amount']
123
+ end
124
+
125
+ if attributes.key?(:'tax_amount')
126
+ self.tax_amount = attributes[:'tax_amount']
127
+ end
128
+
129
+ if attributes.key?(:'signed_tax_amount')
130
+ self.signed_tax_amount = attributes[:'signed_tax_amount']
131
+ end
132
+
133
+ if attributes.key?(:'source')
134
+ self.source = attributes[:'source']
135
+ end
136
+
137
+ if attributes.key?(:'tax_rate')
138
+ self.tax_rate = attributes[:'tax_rate']
139
+ end
140
+
141
+ if attributes.key?(:'tracking_categories')
142
+ if (value = attributes[:'tracking_categories']).is_a?(Hash)
143
+ self.tracking_categories = value
144
+ end
145
+ end
146
+ end
147
+
148
+ # Show invalid properties with the reasons. Usually used together with valid?
149
+ # @return Array for valid properties with the reasons
150
+ def list_invalid_properties
151
+ invalid_properties = Array.new
152
+ if @journal_number.nil?
153
+ invalid_properties.push('invalid value for "journal_number", journal_number cannot be nil.')
154
+ end
155
+
156
+ if @journal_date.nil?
157
+ invalid_properties.push('invalid value for "journal_date", journal_date cannot be nil.')
158
+ end
159
+
160
+ if @description.nil?
161
+ invalid_properties.push('invalid value for "description", description cannot be nil.')
162
+ end
163
+
164
+ if @account.nil?
165
+ invalid_properties.push('invalid value for "account", account cannot be nil.')
166
+ end
167
+
168
+ if @net_amount.nil?
169
+ invalid_properties.push('invalid value for "net_amount", net_amount cannot be nil.')
170
+ end
171
+
172
+ if @source.nil?
173
+ invalid_properties.push('invalid value for "source", source cannot be nil.')
174
+ end
175
+
176
+ if @tax_rate.nil?
177
+ invalid_properties.push('invalid value for "tax_rate", tax_rate cannot be nil.')
178
+ end
179
+
180
+ invalid_properties
181
+ end
182
+
183
+ # Check to see if the all the properties in the model are valid
184
+ # @return true if the model is valid
185
+ def valid?
186
+ return false if @journal_number.nil?
187
+ return false if @journal_date.nil?
188
+ return false if @description.nil?
189
+ return false if @account.nil?
190
+ return false if @net_amount.nil?
191
+ return false if @source.nil?
192
+ return false if @tax_rate.nil?
193
+ true
194
+ end
195
+
196
+ # Checks equality by comparing each attribute.
197
+ # @param [Object] Object to be compared
198
+ def ==(o)
199
+ return true if self.equal?(o)
200
+ self.class == o.class &&
201
+ journal_number == o.journal_number &&
202
+ journal_date == o.journal_date &&
203
+ description == o.description &&
204
+ account == o.account &&
205
+ net_amount == o.net_amount &&
206
+ signed_net_amount == o.signed_net_amount &&
207
+ tax_amount == o.tax_amount &&
208
+ signed_tax_amount == o.signed_tax_amount &&
209
+ source == o.source &&
210
+ tax_rate == o.tax_rate &&
211
+ tracking_categories == o.tracking_categories
212
+ end
213
+
214
+ # @see the `==` method
215
+ # @param [Object] Object to be compared
216
+ def eql?(o)
217
+ self == o
218
+ end
219
+
220
+ # Calculates hash code according to all attributes.
221
+ # @return [Integer] Hash code
222
+ def hash
223
+ [journal_number, journal_date, description, account, net_amount, signed_net_amount, tax_amount, signed_tax_amount, source, tax_rate, tracking_categories].hash
224
+ end
225
+
226
+ # Builds the object from hash
227
+ # @param [Hash] attributes Model attributes in the form of hash
228
+ # @return [Object] Returns the model itself
229
+ def self.build_from_hash(attributes)
230
+ new.build_from_hash(attributes)
231
+ end
232
+
233
+ # Builds the object from hash
234
+ # @param [Hash] attributes Model attributes in the form of hash
235
+ # @return [Object] Returns the model itself
236
+ def build_from_hash(attributes)
237
+ return nil unless attributes.is_a?(Hash)
238
+ self.class.openapi_types.each_pair do |key, type|
239
+ if type =~ /\AArray<(.*)>/i
240
+ # check to ensure the input is an array given that the attribute
241
+ # is documented as an array but the input is not
242
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
243
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
244
+ end
245
+ elsif !attributes[self.class.attribute_map[key]].nil?
246
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
247
+ end # or else data not found in attributes(hash), not an issue as the data can be optional
248
+ end
249
+
250
+ self
251
+ end
252
+
253
+ # Deserializes the data based on type
254
+ # @param string type Data type
255
+ # @param string value Value to be deserialized
256
+ # @return [Object] Deserialized data
257
+ def _deserialize(type, value)
258
+ case type.to_sym
259
+ when :DateTime
260
+ DateTime.parse(parse_date(value))
261
+ when :Date
262
+ Date.parse(parse_date(value))
263
+ when :String
264
+ value.to_s
265
+ when :Integer
266
+ value.to_i
267
+ when :Float
268
+ value.to_f
269
+ when :BigDecimal
270
+ BigDecimal(value.to_s)
271
+ when :Boolean
272
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
273
+ true
274
+ else
275
+ false
276
+ end
277
+ when :Object
278
+ # generic object (usually a Hash), return directly
279
+ value
280
+ when /\AArray<(?<inner_type>.+)>\z/
281
+ inner_type = Regexp.last_match[:inner_type]
282
+ value.map { |v| _deserialize(inner_type, v) }
283
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
284
+ k_type = Regexp.last_match[:k_type]
285
+ v_type = Regexp.last_match[:v_type]
286
+ {}.tap do |hash|
287
+ value.each do |k, v|
288
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
289
+ end
290
+ end
291
+ else # model
292
+ XeroRuby::AccountData.const_get(type).build_from_hash(value)
293
+ end
294
+ end
295
+
296
+ # Returns the string representation of the object
297
+ # @return [String] String presentation of the object
298
+ def to_s
299
+ to_hash.to_s
300
+ end
301
+
302
+ # to_body is an alias to to_hash (backward compatibility)
303
+ # @return [Hash] Returns the object in the form of hash
304
+ def to_body
305
+ to_hash
306
+ end
307
+
308
+ # Returns the object in the form of hash
309
+ # @return [Hash] Returns the object in the form of hash
310
+ def to_hash(downcase: false)
311
+ hash = {}
312
+ self.class.attribute_map.each_pair do |attr, param|
313
+ value = self.send(attr)
314
+ next if value.nil?
315
+ key = downcase ? attr : param
316
+ hash[key] = _to_hash(value, downcase: downcase)
317
+ end
318
+ hash
319
+ end
320
+
321
+ # Returns the object in the form of hash with snake_case
322
+ def to_attributes
323
+ to_hash(downcase: true)
324
+ end
325
+
326
+ # Outputs non-array value in the form of hash
327
+ # For object, use to_hash. Otherwise, just return the value
328
+ # @param [Object] value Any valid value
329
+ # @return [Hash] Returns the value in the form of hash
330
+ def _to_hash(value, downcase: false)
331
+ if value.is_a?(Array)
332
+ value.map do |v|
333
+ v.to_hash(downcase: downcase)
334
+ end
335
+ elsif value.is_a?(Hash)
336
+ {}.tap do |hash|
337
+ value.map { |k, v| hash[k] = _to_hash(v, downcase: downcase) }
338
+ end
339
+ elsif value.respond_to? :to_hash
340
+ value.to_hash(downcase: downcase)
341
+ else
342
+ value
343
+ end
344
+ end
345
+
346
+ def parse_date(datestring)
347
+ if datestring.include?('Date')
348
+ date_pattern = /\/Date\((-?\d+)(\+\d+)?\)\//
349
+ original, date, timezone = *date_pattern.match(datestring)
350
+ date = (date.to_i / 1000)
351
+ Time.at(date).utc.strftime('%Y-%m-%dT%H:%M:%S%z').to_s
352
+ elsif /(\d\d\d\d)-(\d\d)/.match(datestring) # handles dates w/out Days: YYYY-MM*-DD
353
+ Time.parse(datestring + '-01').strftime('%Y-%m-%dT%H:%M:%S').to_s
354
+ else # handle date 'types' for small subset of payroll API's
355
+ Time.parse(datestring).strftime('%Y-%m-%dT%H:%M:%S').to_s
356
+ end
357
+ end
358
+ end
359
+ end