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