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