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,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
+ # The originating document/event for this transaction line. Always present; its fields are null when the source is unknown.
17
+ require 'bigdecimal'
18
+
19
+ class LineSource
20
+
21
+ attr_accessor :document_id
22
+
23
+
24
+ attr_accessor :document_type
25
+
26
+
27
+ attr_accessor :event_type
28
+
29
+
30
+ attr_accessor :contact_id
31
+
32
+
33
+ attr_accessor :contact_name
34
+
35
+
36
+ attr_accessor :reference
37
+
38
+ # Attribute mapping from ruby-style variable name to JSON key.
39
+ def self.attribute_map
40
+ {
41
+ :'document_id' => :'documentId',
42
+ :'document_type' => :'documentType',
43
+ :'event_type' => :'eventType',
44
+ :'contact_id' => :'contactId',
45
+ :'contact_name' => :'contactName',
46
+ :'reference' => :'reference'
47
+ }
48
+ end
49
+
50
+ # Attribute type mapping.
51
+ def self.openapi_types
52
+ {
53
+ :'document_id' => :'String',
54
+ :'document_type' => :'String',
55
+ :'event_type' => :'String',
56
+ :'contact_id' => :'String',
57
+ :'contact_name' => :'String',
58
+ :'reference' => :'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::LineSource` 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::LineSource`. 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?(:'document_id')
78
+ self.document_id = attributes[:'document_id']
79
+ end
80
+
81
+ if attributes.key?(:'document_type')
82
+ self.document_type = attributes[:'document_type']
83
+ end
84
+
85
+ if attributes.key?(:'event_type')
86
+ self.event_type = attributes[:'event_type']
87
+ end
88
+
89
+ if attributes.key?(:'contact_id')
90
+ self.contact_id = attributes[:'contact_id']
91
+ end
92
+
93
+ if attributes.key?(:'contact_name')
94
+ self.contact_name = attributes[:'contact_name']
95
+ end
96
+
97
+ if attributes.key?(:'reference')
98
+ self.reference = attributes[:'reference']
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
+ document_id == o.document_id &&
121
+ document_type == o.document_type &&
122
+ event_type == o.event_type &&
123
+ contact_id == o.contact_id &&
124
+ contact_name == o.contact_name &&
125
+ reference == o.reference
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
+ [document_id, document_type, event_type, contact_id, contact_name, reference].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
@@ -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
+ # The tax rate applied to this transaction line. Always present; its fields are null when no tax rate applies.
17
+ require 'bigdecimal'
18
+
19
+ class LineTaxRate
20
+
21
+ attr_accessor :code
22
+
23
+
24
+ attr_accessor :name
25
+
26
+
27
+ attr_accessor :percentage
28
+
29
+ # Attribute mapping from ruby-style variable name to JSON key.
30
+ def self.attribute_map
31
+ {
32
+ :'code' => :'code',
33
+ :'name' => :'name',
34
+ :'percentage' => :'percentage'
35
+ }
36
+ end
37
+
38
+ # Attribute type mapping.
39
+ def self.openapi_types
40
+ {
41
+ :'code' => :'String',
42
+ :'name' => :'String',
43
+ :'percentage' => :'Float'
44
+ }
45
+ end
46
+
47
+ # Initializes the object
48
+ # @param [Hash] attributes Model attributes in the form of hash
49
+ def initialize(attributes = {})
50
+ if (!attributes.is_a?(Hash))
51
+ fail ArgumentError, "The input argument (attributes) must be a hash in `XeroRuby::AccountData::LineTaxRate` initialize method"
52
+ end
53
+
54
+ # check to see if the attribute exists and convert string to symbol for hash key
55
+ attributes = attributes.each_with_object({}) { |(k, v), h|
56
+ if (!self.class.attribute_map.key?(k.to_sym))
57
+ fail ArgumentError, "`#{k}` is not a valid attribute in `XeroRuby::AccountData::LineTaxRate`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
58
+ end
59
+ h[k.to_sym] = v
60
+ }
61
+
62
+ if attributes.key?(:'code')
63
+ self.code = attributes[:'code']
64
+ end
65
+
66
+ if attributes.key?(:'name')
67
+ self.name = attributes[:'name']
68
+ end
69
+
70
+ if attributes.key?(:'percentage')
71
+ self.percentage = attributes[:'percentage']
72
+ end
73
+ end
74
+
75
+ # Show invalid properties with the reasons. Usually used together with valid?
76
+ # @return Array for valid properties with the reasons
77
+ def list_invalid_properties
78
+ invalid_properties = Array.new
79
+ invalid_properties
80
+ end
81
+
82
+ # Check to see if the all the properties in the model are valid
83
+ # @return true if the model is valid
84
+ def valid?
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
+ code == o.code &&
94
+ name == o.name &&
95
+ percentage == o.percentage
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
+ [code, name, percentage].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