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,269 @@
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 AccountTransactionsResponse
19
+ # Organisation's base currency code (ISO 4217).
20
+ attr_accessor :currency_code
21
+
22
+ # Maximum journal number included in this result set. Captured at the first request and held constant across all pages for consistency.
23
+ attr_accessor :max_journal_number
24
+
25
+ # Transaction lines for this page (max 200).
26
+ attr_accessor :lines
27
+
28
+
29
+ attr_accessor :pagination
30
+
31
+ # Attribute mapping from ruby-style variable name to JSON key.
32
+ def self.attribute_map
33
+ {
34
+ :'currency_code' => :'currencyCode',
35
+ :'max_journal_number' => :'maxJournalNumber',
36
+ :'lines' => :'lines',
37
+ :'pagination' => :'pagination'
38
+ }
39
+ end
40
+
41
+ # Attribute type mapping.
42
+ def self.openapi_types
43
+ {
44
+ :'currency_code' => :'String',
45
+ :'max_journal_number' => :'Integer',
46
+ :'lines' => :'Array<AccountTransactionLine>',
47
+ :'pagination' => :'AccountTransactionsResponsePagination'
48
+ }
49
+ end
50
+
51
+ # Initializes the object
52
+ # @param [Hash] attributes Model attributes in the form of hash
53
+ def initialize(attributes = {})
54
+ if (!attributes.is_a?(Hash))
55
+ fail ArgumentError, "The input argument (attributes) must be a hash in `XeroRuby::AccountData::AccountTransactionsResponse` initialize method"
56
+ end
57
+
58
+ # check to see if the attribute exists and convert string to symbol for hash key
59
+ attributes = attributes.each_with_object({}) { |(k, v), h|
60
+ if (!self.class.attribute_map.key?(k.to_sym))
61
+ fail ArgumentError, "`#{k}` is not a valid attribute in `XeroRuby::AccountData::AccountTransactionsResponse`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
62
+ end
63
+ h[k.to_sym] = v
64
+ }
65
+
66
+ if attributes.key?(:'currency_code')
67
+ self.currency_code = attributes[:'currency_code']
68
+ end
69
+
70
+ if attributes.key?(:'max_journal_number')
71
+ self.max_journal_number = attributes[:'max_journal_number']
72
+ end
73
+
74
+ if attributes.key?(:'lines')
75
+ if (value = attributes[:'lines']).is_a?(Array)
76
+ self.lines = value
77
+ end
78
+ end
79
+
80
+ if attributes.key?(:'pagination')
81
+ self.pagination = attributes[:'pagination']
82
+ end
83
+ end
84
+
85
+ # Show invalid properties with the reasons. Usually used together with valid?
86
+ # @return Array for valid properties with the reasons
87
+ def list_invalid_properties
88
+ invalid_properties = Array.new
89
+ if @currency_code.nil?
90
+ invalid_properties.push('invalid value for "currency_code", currency_code cannot be nil.')
91
+ end
92
+
93
+ if @max_journal_number.nil?
94
+ invalid_properties.push('invalid value for "max_journal_number", max_journal_number cannot be nil.')
95
+ end
96
+
97
+ if @lines.nil?
98
+ invalid_properties.push('invalid value for "lines", lines cannot be nil.')
99
+ end
100
+
101
+ invalid_properties
102
+ end
103
+
104
+ # Check to see if the all the properties in the model are valid
105
+ # @return true if the model is valid
106
+ def valid?
107
+ return false if @currency_code.nil?
108
+ return false if @max_journal_number.nil?
109
+ return false if @lines.nil?
110
+ true
111
+ end
112
+
113
+ # Checks equality by comparing each attribute.
114
+ # @param [Object] Object to be compared
115
+ def ==(o)
116
+ return true if self.equal?(o)
117
+ self.class == o.class &&
118
+ currency_code == o.currency_code &&
119
+ max_journal_number == o.max_journal_number &&
120
+ lines == o.lines &&
121
+ pagination == o.pagination
122
+ end
123
+
124
+ # @see the `==` method
125
+ # @param [Object] Object to be compared
126
+ def eql?(o)
127
+ self == o
128
+ end
129
+
130
+ # Calculates hash code according to all attributes.
131
+ # @return [Integer] Hash code
132
+ def hash
133
+ [currency_code, max_journal_number, lines, pagination].hash
134
+ end
135
+
136
+ # Builds the object from hash
137
+ # @param [Hash] attributes Model attributes in the form of hash
138
+ # @return [Object] Returns the model itself
139
+ def self.build_from_hash(attributes)
140
+ new.build_from_hash(attributes)
141
+ end
142
+
143
+ # Builds the object from hash
144
+ # @param [Hash] attributes Model attributes in the form of hash
145
+ # @return [Object] Returns the model itself
146
+ def build_from_hash(attributes)
147
+ return nil unless attributes.is_a?(Hash)
148
+ self.class.openapi_types.each_pair do |key, type|
149
+ if type =~ /\AArray<(.*)>/i
150
+ # check to ensure the input is an array given that the attribute
151
+ # is documented as an array but the input is not
152
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
153
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
154
+ end
155
+ elsif !attributes[self.class.attribute_map[key]].nil?
156
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
157
+ end # or else data not found in attributes(hash), not an issue as the data can be optional
158
+ end
159
+
160
+ self
161
+ end
162
+
163
+ # Deserializes the data based on type
164
+ # @param string type Data type
165
+ # @param string value Value to be deserialized
166
+ # @return [Object] Deserialized data
167
+ def _deserialize(type, value)
168
+ case type.to_sym
169
+ when :DateTime
170
+ DateTime.parse(parse_date(value))
171
+ when :Date
172
+ Date.parse(parse_date(value))
173
+ when :String
174
+ value.to_s
175
+ when :Integer
176
+ value.to_i
177
+ when :Float
178
+ value.to_f
179
+ when :BigDecimal
180
+ BigDecimal(value.to_s)
181
+ when :Boolean
182
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
183
+ true
184
+ else
185
+ false
186
+ end
187
+ when :Object
188
+ # generic object (usually a Hash), return directly
189
+ value
190
+ when /\AArray<(?<inner_type>.+)>\z/
191
+ inner_type = Regexp.last_match[:inner_type]
192
+ value.map { |v| _deserialize(inner_type, v) }
193
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
194
+ k_type = Regexp.last_match[:k_type]
195
+ v_type = Regexp.last_match[:v_type]
196
+ {}.tap do |hash|
197
+ value.each do |k, v|
198
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
199
+ end
200
+ end
201
+ else # model
202
+ XeroRuby::AccountData.const_get(type).build_from_hash(value)
203
+ end
204
+ end
205
+
206
+ # Returns the string representation of the object
207
+ # @return [String] String presentation of the object
208
+ def to_s
209
+ to_hash.to_s
210
+ end
211
+
212
+ # to_body is an alias to to_hash (backward compatibility)
213
+ # @return [Hash] Returns the object in the form of hash
214
+ def to_body
215
+ to_hash
216
+ end
217
+
218
+ # Returns the object in the form of hash
219
+ # @return [Hash] Returns the object in the form of hash
220
+ def to_hash(downcase: false)
221
+ hash = {}
222
+ self.class.attribute_map.each_pair do |attr, param|
223
+ value = self.send(attr)
224
+ next if value.nil?
225
+ key = downcase ? attr : param
226
+ hash[key] = _to_hash(value, downcase: downcase)
227
+ end
228
+ hash
229
+ end
230
+
231
+ # Returns the object in the form of hash with snake_case
232
+ def to_attributes
233
+ to_hash(downcase: true)
234
+ end
235
+
236
+ # Outputs non-array value in the form of hash
237
+ # For object, use to_hash. Otherwise, just return the value
238
+ # @param [Object] value Any valid value
239
+ # @return [Hash] Returns the value in the form of hash
240
+ def _to_hash(value, downcase: false)
241
+ if value.is_a?(Array)
242
+ value.map do |v|
243
+ v.to_hash(downcase: downcase)
244
+ end
245
+ elsif value.is_a?(Hash)
246
+ {}.tap do |hash|
247
+ value.map { |k, v| hash[k] = _to_hash(v, downcase: downcase) }
248
+ end
249
+ elsif value.respond_to? :to_hash
250
+ value.to_hash(downcase: downcase)
251
+ else
252
+ value
253
+ end
254
+ end
255
+
256
+ def parse_date(datestring)
257
+ if datestring.include?('Date')
258
+ date_pattern = /\/Date\((-?\d+)(\+\d+)?\)\//
259
+ original, date, timezone = *date_pattern.match(datestring)
260
+ date = (date.to_i / 1000)
261
+ Time.at(date).utc.strftime('%Y-%m-%dT%H:%M:%S%z').to_s
262
+ elsif /(\d\d\d\d)-(\d\d)/.match(datestring) # handles dates w/out Days: YYYY-MM*-DD
263
+ Time.parse(datestring + '-01').strftime('%Y-%m-%dT%H:%M:%S').to_s
264
+ else # handle date 'types' for small subset of payroll API's
265
+ Time.parse(datestring).strftime('%Y-%m-%dT%H:%M:%S').to_s
266
+ end
267
+ end
268
+ end
269
+ end
@@ -0,0 +1,243 @@
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
+ # Pagination metadata. `null` on the last page, including when there are no results.
17
+ require 'bigdecimal'
18
+
19
+ class AccountTransactionsResponsePagination
20
+
21
+ attr_accessor :page_size
22
+
23
+ # Opaque continuation token for the next page. Send it as the `token` query parameter to retrieve the next page.
24
+ attr_accessor :next_token
25
+
26
+ # Attribute mapping from ruby-style variable name to JSON key.
27
+ def self.attribute_map
28
+ {
29
+ :'page_size' => :'pageSize',
30
+ :'next_token' => :'nextToken'
31
+ }
32
+ end
33
+
34
+ # Attribute type mapping.
35
+ def self.openapi_types
36
+ {
37
+ :'page_size' => :'Integer',
38
+ :'next_token' => :'String'
39
+ }
40
+ end
41
+
42
+ # Initializes the object
43
+ # @param [Hash] attributes Model attributes in the form of hash
44
+ def initialize(attributes = {})
45
+ if (!attributes.is_a?(Hash))
46
+ fail ArgumentError, "The input argument (attributes) must be a hash in `XeroRuby::AccountData::AccountTransactionsResponsePagination` initialize method"
47
+ end
48
+
49
+ # check to see if the attribute exists and convert string to symbol for hash key
50
+ attributes = attributes.each_with_object({}) { |(k, v), h|
51
+ if (!self.class.attribute_map.key?(k.to_sym))
52
+ fail ArgumentError, "`#{k}` is not a valid attribute in `XeroRuby::AccountData::AccountTransactionsResponsePagination`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
53
+ end
54
+ h[k.to_sym] = v
55
+ }
56
+
57
+ if attributes.key?(:'page_size')
58
+ self.page_size = attributes[:'page_size']
59
+ end
60
+
61
+ if attributes.key?(:'next_token')
62
+ self.next_token = attributes[:'next_token']
63
+ end
64
+ end
65
+
66
+ # Show invalid properties with the reasons. Usually used together with valid?
67
+ # @return Array for valid properties with the reasons
68
+ def list_invalid_properties
69
+ invalid_properties = Array.new
70
+ if @page_size.nil?
71
+ invalid_properties.push('invalid value for "page_size", page_size cannot be nil.')
72
+ end
73
+
74
+ if @next_token.nil?
75
+ invalid_properties.push('invalid value for "next_token", next_token cannot be nil.')
76
+ end
77
+
78
+ invalid_properties
79
+ end
80
+
81
+ # Check to see if the all the properties in the model are valid
82
+ # @return true if the model is valid
83
+ def valid?
84
+ return false if @page_size.nil?
85
+ return false if @next_token.nil?
86
+ true
87
+ end
88
+
89
+ # Checks equality by comparing each attribute.
90
+ # @param [Object] Object to be compared
91
+ def ==(o)
92
+ return true if self.equal?(o)
93
+ self.class == o.class &&
94
+ page_size == o.page_size &&
95
+ next_token == o.next_token
96
+ end
97
+
98
+ # @see the `==` method
99
+ # @param [Object] Object to be compared
100
+ def eql?(o)
101
+ self == o
102
+ end
103
+
104
+ # Calculates hash code according to all attributes.
105
+ # @return [Integer] Hash code
106
+ def hash
107
+ [page_size, next_token].hash
108
+ end
109
+
110
+ # Builds the object from hash
111
+ # @param [Hash] attributes Model attributes in the form of hash
112
+ # @return [Object] Returns the model itself
113
+ def self.build_from_hash(attributes)
114
+ new.build_from_hash(attributes)
115
+ end
116
+
117
+ # Builds the object from hash
118
+ # @param [Hash] attributes Model attributes in the form of hash
119
+ # @return [Object] Returns the model itself
120
+ def build_from_hash(attributes)
121
+ return nil unless attributes.is_a?(Hash)
122
+ self.class.openapi_types.each_pair do |key, type|
123
+ if type =~ /\AArray<(.*)>/i
124
+ # check to ensure the input is an array given that the attribute
125
+ # is documented as an array but the input is not
126
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
127
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
128
+ end
129
+ elsif !attributes[self.class.attribute_map[key]].nil?
130
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
131
+ end # or else data not found in attributes(hash), not an issue as the data can be optional
132
+ end
133
+
134
+ self
135
+ end
136
+
137
+ # Deserializes the data based on type
138
+ # @param string type Data type
139
+ # @param string value Value to be deserialized
140
+ # @return [Object] Deserialized data
141
+ def _deserialize(type, value)
142
+ case type.to_sym
143
+ when :DateTime
144
+ DateTime.parse(parse_date(value))
145
+ when :Date
146
+ Date.parse(parse_date(value))
147
+ when :String
148
+ value.to_s
149
+ when :Integer
150
+ value.to_i
151
+ when :Float
152
+ value.to_f
153
+ when :BigDecimal
154
+ BigDecimal(value.to_s)
155
+ when :Boolean
156
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
157
+ true
158
+ else
159
+ false
160
+ end
161
+ when :Object
162
+ # generic object (usually a Hash), return directly
163
+ value
164
+ when /\AArray<(?<inner_type>.+)>\z/
165
+ inner_type = Regexp.last_match[:inner_type]
166
+ value.map { |v| _deserialize(inner_type, v) }
167
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
168
+ k_type = Regexp.last_match[:k_type]
169
+ v_type = Regexp.last_match[:v_type]
170
+ {}.tap do |hash|
171
+ value.each do |k, v|
172
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
173
+ end
174
+ end
175
+ else # model
176
+ XeroRuby::AccountData.const_get(type).build_from_hash(value)
177
+ end
178
+ end
179
+
180
+ # Returns the string representation of the object
181
+ # @return [String] String presentation of the object
182
+ def to_s
183
+ to_hash.to_s
184
+ end
185
+
186
+ # to_body is an alias to to_hash (backward compatibility)
187
+ # @return [Hash] Returns the object in the form of hash
188
+ def to_body
189
+ to_hash
190
+ end
191
+
192
+ # Returns the object in the form of hash
193
+ # @return [Hash] Returns the object in the form of hash
194
+ def to_hash(downcase: false)
195
+ hash = {}
196
+ self.class.attribute_map.each_pair do |attr, param|
197
+ value = self.send(attr)
198
+ next if value.nil?
199
+ key = downcase ? attr : param
200
+ hash[key] = _to_hash(value, downcase: downcase)
201
+ end
202
+ hash
203
+ end
204
+
205
+ # Returns the object in the form of hash with snake_case
206
+ def to_attributes
207
+ to_hash(downcase: true)
208
+ end
209
+
210
+ # Outputs non-array value in the form of hash
211
+ # For object, use to_hash. Otherwise, just return the value
212
+ # @param [Object] value Any valid value
213
+ # @return [Hash] Returns the value in the form of hash
214
+ def _to_hash(value, downcase: false)
215
+ if value.is_a?(Array)
216
+ value.map do |v|
217
+ v.to_hash(downcase: downcase)
218
+ end
219
+ elsif value.is_a?(Hash)
220
+ {}.tap do |hash|
221
+ value.map { |k, v| hash[k] = _to_hash(v, downcase: downcase) }
222
+ end
223
+ elsif value.respond_to? :to_hash
224
+ value.to_hash(downcase: downcase)
225
+ else
226
+ value
227
+ end
228
+ end
229
+
230
+ def parse_date(datestring)
231
+ if datestring.include?('Date')
232
+ date_pattern = /\/Date\((-?\d+)(\+\d+)?\)\//
233
+ original, date, timezone = *date_pattern.match(datestring)
234
+ date = (date.to_i / 1000)
235
+ Time.at(date).utc.strftime('%Y-%m-%dT%H:%M:%S%z').to_s
236
+ elsif /(\d\d\d\d)-(\d\d)/.match(datestring) # handles dates w/out Days: YYYY-MM*-DD
237
+ Time.parse(datestring + '-01').strftime('%Y-%m-%dT%H:%M:%S').to_s
238
+ else # handle date 'types' for small subset of payroll API's
239
+ Time.parse(datestring).strftime('%Y-%m-%dT%H:%M:%S').to_s
240
+ end
241
+ end
242
+ end
243
+ end