xero-ruby 18.3.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 (25) 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_client.rb +10 -0
  4. data/lib/xero-ruby/configuration.rb +2 -0
  5. data/lib/xero-ruby/models/account_data/account.rb +351 -0
  6. data/lib/xero-ruby/models/account_data/account_balance.rb +287 -0
  7. data/lib/xero-ruby/models/account_data/account_balances_response.rb +229 -0
  8. data/lib/xero-ruby/models/account_data/account_movement.rb +347 -0
  9. data/lib/xero-ruby/models/account_data/account_movements_response.rb +229 -0
  10. data/lib/xero-ruby/models/account_data/account_transaction_line.rb +359 -0
  11. data/lib/xero-ruby/models/account_data/account_transactions_response.rb +269 -0
  12. data/lib/xero-ruby/models/account_data/account_transactions_response_pagination.rb +243 -0
  13. data/lib/xero-ruby/models/account_data/accounting_date_range.rb +242 -0
  14. data/lib/xero-ruby/models/account_data/field_problem.rb +273 -0
  15. data/lib/xero-ruby/models/account_data/gateway_problem.rb +285 -0
  16. data/lib/xero-ruby/models/account_data/ledger_decimal.rb +278 -0
  17. data/lib/xero-ruby/models/account_data/line_source.rb +273 -0
  18. data/lib/xero-ruby/models/account_data/line_tax_rate.rb +243 -0
  19. data/lib/xero-ruby/models/account_data/problem_details.rb +273 -0
  20. data/lib/xero-ruby/models/account_data/tracking_item_details.rb +257 -0
  21. data/lib/xero-ruby/models/account_data/transaction_account.rb +366 -0
  22. data/lib/xero-ruby/models/account_data/validation_problem.rb +275 -0
  23. data/lib/xero-ruby/version.rb +2 -2
  24. data/lib/xero-ruby.rb +19 -0
  25. metadata +21 -2
@@ -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 AccountBalancesResponse
19
+
20
+ attr_accessor :account_balances
21
+
22
+ # Attribute mapping from ruby-style variable name to JSON key.
23
+ def self.attribute_map
24
+ {
25
+ :'account_balances' => :'accountBalances'
26
+ }
27
+ end
28
+
29
+ # Attribute type mapping.
30
+ def self.openapi_types
31
+ {
32
+ :'account_balances' => :'Array<AccountBalance>'
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::AccountBalancesResponse` 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::AccountBalancesResponse`. 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_balances')
52
+ if (value = attributes[:'account_balances']).is_a?(Array)
53
+ self.account_balances = 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_balances.nil?
63
+ invalid_properties.push('invalid value for "account_balances", account_balances 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_balances.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_balances == o.account_balances
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_balances].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,347 @@
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 AccountMovement
19
+ # The account this movement is for.
20
+ attr_accessor :account_id
21
+
22
+
23
+ attr_accessor :date_range
24
+
25
+ # Total debits posted to this account within the date range.
26
+ attr_accessor :debits
27
+
28
+ # Total credits posted to this account within the date range.
29
+ attr_accessor :credits
30
+
31
+
32
+ attr_accessor :movement
33
+
34
+ # Movement as a signed number (positive for debit, negative for credit).
35
+ attr_accessor :signed_movement
36
+
37
+ # Total tax debits within the date range. Omitted from the response when tax values are not available.
38
+ attr_accessor :tax_debits
39
+
40
+ # Total tax credits within the date range. Omitted from the response when tax values are not available.
41
+ attr_accessor :tax_credits
42
+
43
+ # Tax movement as a signed number (positive for debit, negative for credit). Omitted from the response when tax values are not available.
44
+ attr_accessor :signed_tax_movement
45
+
46
+
47
+ attr_accessor :account
48
+
49
+ # Attribute mapping from ruby-style variable name to JSON key.
50
+ def self.attribute_map
51
+ {
52
+ :'account_id' => :'accountId',
53
+ :'date_range' => :'dateRange',
54
+ :'debits' => :'debits',
55
+ :'credits' => :'credits',
56
+ :'movement' => :'movement',
57
+ :'signed_movement' => :'signedMovement',
58
+ :'tax_debits' => :'taxDebits',
59
+ :'tax_credits' => :'taxCredits',
60
+ :'signed_tax_movement' => :'signedTaxMovement',
61
+ :'account' => :'account'
62
+ }
63
+ end
64
+
65
+ # Attribute type mapping.
66
+ def self.openapi_types
67
+ {
68
+ :'account_id' => :'String',
69
+ :'date_range' => :'AccountingDateRange',
70
+ :'debits' => :'Float',
71
+ :'credits' => :'Float',
72
+ :'movement' => :'LedgerDecimal',
73
+ :'signed_movement' => :'Float',
74
+ :'tax_debits' => :'Float',
75
+ :'tax_credits' => :'Float',
76
+ :'signed_tax_movement' => :'Float',
77
+ :'account' => :'Account'
78
+ }
79
+ end
80
+
81
+ # Initializes the object
82
+ # @param [Hash] attributes Model attributes in the form of hash
83
+ def initialize(attributes = {})
84
+ if (!attributes.is_a?(Hash))
85
+ fail ArgumentError, "The input argument (attributes) must be a hash in `XeroRuby::AccountData::AccountMovement` initialize method"
86
+ end
87
+
88
+ # check to see if the attribute exists and convert string to symbol for hash key
89
+ attributes = attributes.each_with_object({}) { |(k, v), h|
90
+ if (!self.class.attribute_map.key?(k.to_sym))
91
+ fail ArgumentError, "`#{k}` is not a valid attribute in `XeroRuby::AccountData::AccountMovement`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
92
+ end
93
+ h[k.to_sym] = v
94
+ }
95
+
96
+ if attributes.key?(:'account_id')
97
+ self.account_id = attributes[:'account_id']
98
+ end
99
+
100
+ if attributes.key?(:'date_range')
101
+ self.date_range = attributes[:'date_range']
102
+ end
103
+
104
+ if attributes.key?(:'debits')
105
+ self.debits = attributes[:'debits']
106
+ end
107
+
108
+ if attributes.key?(:'credits')
109
+ self.credits = attributes[:'credits']
110
+ end
111
+
112
+ if attributes.key?(:'movement')
113
+ self.movement = attributes[:'movement']
114
+ end
115
+
116
+ if attributes.key?(:'signed_movement')
117
+ self.signed_movement = attributes[:'signed_movement']
118
+ end
119
+
120
+ if attributes.key?(:'tax_debits')
121
+ self.tax_debits = attributes[:'tax_debits']
122
+ end
123
+
124
+ if attributes.key?(:'tax_credits')
125
+ self.tax_credits = attributes[:'tax_credits']
126
+ end
127
+
128
+ if attributes.key?(:'signed_tax_movement')
129
+ self.signed_tax_movement = attributes[:'signed_tax_movement']
130
+ end
131
+
132
+ if attributes.key?(:'account')
133
+ self.account = attributes[:'account']
134
+ end
135
+ end
136
+
137
+ # Show invalid properties with the reasons. Usually used together with valid?
138
+ # @return Array for valid properties with the reasons
139
+ def list_invalid_properties
140
+ invalid_properties = Array.new
141
+ if @account_id.nil?
142
+ invalid_properties.push('invalid value for "account_id", account_id cannot be nil.')
143
+ end
144
+
145
+ if @date_range.nil?
146
+ invalid_properties.push('invalid value for "date_range", date_range cannot be nil.')
147
+ end
148
+
149
+ if @debits.nil?
150
+ invalid_properties.push('invalid value for "debits", debits cannot be nil.')
151
+ end
152
+
153
+ if @credits.nil?
154
+ invalid_properties.push('invalid value for "credits", credits cannot be nil.')
155
+ end
156
+
157
+ if @movement.nil?
158
+ invalid_properties.push('invalid value for "movement", movement cannot be nil.')
159
+ end
160
+
161
+ if @signed_movement.nil?
162
+ invalid_properties.push('invalid value for "signed_movement", signed_movement cannot be nil.')
163
+ end
164
+
165
+ if @account.nil?
166
+ invalid_properties.push('invalid value for "account", account cannot be nil.')
167
+ end
168
+
169
+ invalid_properties
170
+ end
171
+
172
+ # Check to see if the all the properties in the model are valid
173
+ # @return true if the model is valid
174
+ def valid?
175
+ return false if @account_id.nil?
176
+ return false if @date_range.nil?
177
+ return false if @debits.nil?
178
+ return false if @credits.nil?
179
+ return false if @movement.nil?
180
+ return false if @signed_movement.nil?
181
+ return false if @account.nil?
182
+ true
183
+ end
184
+
185
+ # Checks equality by comparing each attribute.
186
+ # @param [Object] Object to be compared
187
+ def ==(o)
188
+ return true if self.equal?(o)
189
+ self.class == o.class &&
190
+ account_id == o.account_id &&
191
+ date_range == o.date_range &&
192
+ debits == o.debits &&
193
+ credits == o.credits &&
194
+ movement == o.movement &&
195
+ signed_movement == o.signed_movement &&
196
+ tax_debits == o.tax_debits &&
197
+ tax_credits == o.tax_credits &&
198
+ signed_tax_movement == o.signed_tax_movement &&
199
+ account == o.account
200
+ end
201
+
202
+ # @see the `==` method
203
+ # @param [Object] Object to be compared
204
+ def eql?(o)
205
+ self == o
206
+ end
207
+
208
+ # Calculates hash code according to all attributes.
209
+ # @return [Integer] Hash code
210
+ def hash
211
+ [account_id, date_range, debits, credits, movement, signed_movement, tax_debits, tax_credits, signed_tax_movement, account].hash
212
+ end
213
+
214
+ # Builds the object from hash
215
+ # @param [Hash] attributes Model attributes in the form of hash
216
+ # @return [Object] Returns the model itself
217
+ def self.build_from_hash(attributes)
218
+ new.build_from_hash(attributes)
219
+ end
220
+
221
+ # Builds the object from hash
222
+ # @param [Hash] attributes Model attributes in the form of hash
223
+ # @return [Object] Returns the model itself
224
+ def build_from_hash(attributes)
225
+ return nil unless attributes.is_a?(Hash)
226
+ self.class.openapi_types.each_pair do |key, type|
227
+ if type =~ /\AArray<(.*)>/i
228
+ # check to ensure the input is an array given that the attribute
229
+ # is documented as an array but the input is not
230
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
231
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
232
+ end
233
+ elsif !attributes[self.class.attribute_map[key]].nil?
234
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
235
+ end # or else data not found in attributes(hash), not an issue as the data can be optional
236
+ end
237
+
238
+ self
239
+ end
240
+
241
+ # Deserializes the data based on type
242
+ # @param string type Data type
243
+ # @param string value Value to be deserialized
244
+ # @return [Object] Deserialized data
245
+ def _deserialize(type, value)
246
+ case type.to_sym
247
+ when :DateTime
248
+ DateTime.parse(parse_date(value))
249
+ when :Date
250
+ Date.parse(parse_date(value))
251
+ when :String
252
+ value.to_s
253
+ when :Integer
254
+ value.to_i
255
+ when :Float
256
+ value.to_f
257
+ when :BigDecimal
258
+ BigDecimal(value.to_s)
259
+ when :Boolean
260
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
261
+ true
262
+ else
263
+ false
264
+ end
265
+ when :Object
266
+ # generic object (usually a Hash), return directly
267
+ value
268
+ when /\AArray<(?<inner_type>.+)>\z/
269
+ inner_type = Regexp.last_match[:inner_type]
270
+ value.map { |v| _deserialize(inner_type, v) }
271
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
272
+ k_type = Regexp.last_match[:k_type]
273
+ v_type = Regexp.last_match[:v_type]
274
+ {}.tap do |hash|
275
+ value.each do |k, v|
276
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
277
+ end
278
+ end
279
+ else # model
280
+ XeroRuby::AccountData.const_get(type).build_from_hash(value)
281
+ end
282
+ end
283
+
284
+ # Returns the string representation of the object
285
+ # @return [String] String presentation of the object
286
+ def to_s
287
+ to_hash.to_s
288
+ end
289
+
290
+ # to_body is an alias to to_hash (backward compatibility)
291
+ # @return [Hash] Returns the object in the form of hash
292
+ def to_body
293
+ to_hash
294
+ end
295
+
296
+ # Returns the object in the form of hash
297
+ # @return [Hash] Returns the object in the form of hash
298
+ def to_hash(downcase: false)
299
+ hash = {}
300
+ self.class.attribute_map.each_pair do |attr, param|
301
+ value = self.send(attr)
302
+ next if value.nil?
303
+ key = downcase ? attr : param
304
+ hash[key] = _to_hash(value, downcase: downcase)
305
+ end
306
+ hash
307
+ end
308
+
309
+ # Returns the object in the form of hash with snake_case
310
+ def to_attributes
311
+ to_hash(downcase: true)
312
+ end
313
+
314
+ # Outputs non-array value in the form of hash
315
+ # For object, use to_hash. Otherwise, just return the value
316
+ # @param [Object] value Any valid value
317
+ # @return [Hash] Returns the value in the form of hash
318
+ def _to_hash(value, downcase: false)
319
+ if value.is_a?(Array)
320
+ value.map do |v|
321
+ v.to_hash(downcase: downcase)
322
+ end
323
+ elsif value.is_a?(Hash)
324
+ {}.tap do |hash|
325
+ value.map { |k, v| hash[k] = _to_hash(v, downcase: downcase) }
326
+ end
327
+ elsif value.respond_to? :to_hash
328
+ value.to_hash(downcase: downcase)
329
+ else
330
+ value
331
+ end
332
+ end
333
+
334
+ def parse_date(datestring)
335
+ if datestring.include?('Date')
336
+ date_pattern = /\/Date\((-?\d+)(\+\d+)?\)\//
337
+ original, date, timezone = *date_pattern.match(datestring)
338
+ date = (date.to_i / 1000)
339
+ Time.at(date).utc.strftime('%Y-%m-%dT%H:%M:%S%z').to_s
340
+ elsif /(\d\d\d\d)-(\d\d)/.match(datestring) # handles dates w/out Days: YYYY-MM*-DD
341
+ Time.parse(datestring + '-01').strftime('%Y-%m-%dT%H:%M:%S').to_s
342
+ else # handle date 'types' for small subset of payroll API's
343
+ Time.parse(datestring).strftime('%Y-%m-%dT%H:%M:%S').to_s
344
+ end
345
+ end
346
+ end
347
+ end