xero-ruby 18.4.0 → 18.5.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.
@@ -0,0 +1,368 @@
1
+ =begin
2
+ #Xero Bank Feeds API v2
3
+
4
+ #The Bank Feeds API is available to financial institutions with a Xero partnership and approved app partners. For non-bank apps, it automates statement imports into Xero bank and credit card accounts; it does not create a direct bank feed. Feed Connections 2.0 is intended to replace 1.0. The customer chooses whether to connect an existing Xero account or create a new one. Use ExistingAccount with the chosen accountId, or NewAccount to create an account; Xero does not guess which account to connect or silently change an account name. The GET and delete operations also use 2.0. Statements continue to use 1.0. Partial failures are rare, and nearly all are recoverable by your app with no need to contact Xero support. If an item in a write response has `status` `PARTIAL_FAILURE`, handle only that item and read its `error.type`. For `partial-failure-new-account-creation`, do not resend the NewAccount item: connect `error.accountId` with `POST /FeedConnections/ExistingAccount`. For `partial-failure-new-account-existence-not-confirmed`, the account named in `error.accountName` may or may not exist. Use the Accounting API to check whether an account with that name exists. If it does, connect it with `POST /FeedConnections/ExistingAccount`. If it does not, resend the NewAccount item. If your app has a user, you can show them this message instead: \"Something went wrong. Please check whether your chosen account name now exists. If it does, connect it. If not, try creating the new one again.\" For any other `partial-failure-*` type, resend the same item. If the recovery request for `partial-failure-new-account-creation`, `partial-failure-previous-connection-deletion` or `partial-failure-connection-creation` returns 409 `feed-already-connected-in-current-organisation`, the earlier attempt succeeded: treat the item as created and use `GET /FeedConnections` to find its `id`. `error.subtype` is optional diagnostics; do not branch on it, and never parse `title` or `detail`. Full detail: https://developer.xero.com/documentation/api/bankfeeds/feedconnections-2-0-errors/#partial-failures
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::BankfeedsV2
16
+ # An error. Served as `application/problem+json` when it describes the request as a whole. The `error` of an item result is an `ItemError`, which has the same fields except `status`.
17
+ require 'bigdecimal'
18
+
19
+ class Problem
20
+ # Identifies the error.
21
+ attr_accessor :type
22
+ INVALID_REQUEST ||= "invalid-request".freeze
23
+ INVALID_APPLICATION ||= "invalid-application".freeze
24
+ SUSPENDED_OR_TERMINATED_APPLICATION ||= "suspended-or-terminated-application".freeze
25
+ INVALID_ORGANISATION_BANK_FEEDS ||= "invalid-organisation-bank-feeds".freeze
26
+ INVALID_ORGANISATION_MULTI_CURRENCY ||= "invalid-organisation-multi-currency".freeze
27
+ INVALID_FEED_CONNECTION_FOR_ORGANISATION ||= "invalid-feed-connection-for-organisation".freeze
28
+ INVALID_USER_ROLE ||= "invalid-user-role".freeze
29
+ INVALID_ACCOUNT_TOKEN ||= "invalid-account-token".freeze
30
+ MISSING_IDENTIFYING_FIELDS ||= "missing-identifying-fields".freeze
31
+ INVALID_COUNTRY_SPECIFIED ||= "invalid-country-specified".freeze
32
+ ACCOUNT_NOT_VALID ||= "account-not-valid".freeze
33
+ FEED_ALREADY_CONNECTED_IN_CURRENT_ORGANISATION ||= "feed-already-connected-in-current-organisation".freeze
34
+ ACCOUNT_NAME_ALREADY_EXISTS ||= "account-name-already-exists".freeze
35
+ BANK_FEED_NOT_FOUND ||= "bank-feed-not-found".freeze
36
+ FEED_NOT_FOUND_OR_ALREADY_DELETED ||= "feed-not-found-or-already-deleted".freeze
37
+ PARTIAL_FAILURE_NEW_ACCOUNT_CREATION ||= "partial-failure-new-account-creation".freeze
38
+ PARTIAL_FAILURE_PREVIOUS_CONNECTION_DELETION ||= "partial-failure-previous-connection-deletion".freeze
39
+ PARTIAL_FAILURE_CONNECTION_CREATION ||= "partial-failure-connection-creation".freeze
40
+ PARTIAL_FAILURE_CONNECTION_DELETION ||= "partial-failure-connection-deletion".freeze
41
+ PARTIAL_FAILURE_NEW_ACCOUNT_EXISTENCE_NOT_CONFIRMED ||= "partial-failure-new-account-existence-not-confirmed".freeze
42
+ TOO_MANY_REQUESTS ||= "too-many-requests".freeze
43
+ INTERNAL_ERROR ||= "internal-error".freeze
44
+
45
+ # Present only on a partial failure (a `partial-failure-*` `type`). Names the exact cause within the `type`. Reading it is optional: the `type` alone fixes the recovery action and which identifier fields are present, so branch on `type` and use `subtype` for diagnostics.
46
+ attr_accessor :subtype
47
+ CONNECTION_PHASE_FAILED ||= "connection-phase-failed".freeze
48
+ DELETION_PHASE_FAILED ||= "deletion-phase-failed".freeze
49
+ DELETION_PHASE_NOT_CONFIRMED ||= "deletion-phase-not-confirmed".freeze
50
+ CONNECTION_EXISTENCE_NOT_CONFIRMED ||= "connection-existence-not-confirmed".freeze
51
+ CONNECTION_EXISTS_WITHOUT_FEED_CONNECTION ||= "connection-exists-without-feed-connection".freeze
52
+ FEED_CONNECTION_EXISTENCE_NOT_CONFIRMED_CAN_CHECK_OR_RETRY ||= "feed-connection-existence-not-confirmed-can-check-or-retry".freeze
53
+ CHECK_ACCOUNTS_OR_PROMPT_USER_RETRY ||= "check-accounts-or-prompt-user-retry".freeze
54
+
55
+ # A short human-readable summary of the error.
56
+ attr_accessor :title
57
+
58
+ # The HTTP status this error corresponds to. It is the status of the response. An item result does not repeat it in its `error`: read the item's `statusCode` instead.
59
+ attr_accessor :status
60
+
61
+ # A human-readable explanation specific to this occurrence.
62
+ attr_accessor :detail
63
+
64
+ # Present only on a partial failure. The Xero Bank Account the item concerns. On `partial-failure-new-account-creation`, the account that was created: connect it through `POST /FeedConnections/ExistingAccount`. On `partial-failure-previous-connection-deletion` and `partial-failure-connection-creation`, the account being connected. Absent on `partial-failure-connection-deletion` and `partial-failure-new-account-existence-not-confirmed`, where the account may not exist.
65
+ attr_accessor :account_id
66
+
67
+ # Present only on a partial failure of type `partial-failure-new-account-creation` or `partial-failure-new-account-existence-not-confirmed`. The name of the account that was created, which is now taken; on `partial-failure-new-account-existence-not-confirmed`, the name of the account that may have been created.
68
+ attr_accessor :account_name
69
+
70
+ # Present only on a partial failure. On `partial-failure-previous-connection-deletion`, the previous connection on the account (removed, or being removed). On `partial-failure-connection-creation`, the connection this request created or was creating: the id it was given before the create (the Feed Connection `id` if it was recorded). When the subtype is `connection-existence-not-confirmed`, the create's outcome is unknown and the connection may not exist in Xero. On `partial-failure-connection-deletion`, the connection being deleted (the item `id` also echoes it). Absent on `partial-failure-new-account-creation` and `partial-failure-new-account-existence-not-confirmed`.
71
+ attr_accessor :connection_id
72
+
73
+ class EnumAttributeValidator
74
+ attr_reader :datatype
75
+ attr_reader :allowable_values
76
+
77
+ def initialize(datatype, allowable_values)
78
+ @allowable_values = allowable_values.map do |value|
79
+ case datatype.to_s
80
+ when /Integer/i
81
+ value.to_i
82
+ when /Float/i
83
+ value.to_f
84
+ else
85
+ value
86
+ end
87
+ end
88
+ end
89
+
90
+ def valid?(value)
91
+ !value || allowable_values.include?(value)
92
+ end
93
+ end
94
+
95
+ # Attribute mapping from ruby-style variable name to JSON key.
96
+ def self.attribute_map
97
+ {
98
+ :'type' => :'type',
99
+ :'subtype' => :'subtype',
100
+ :'title' => :'title',
101
+ :'status' => :'status',
102
+ :'detail' => :'detail',
103
+ :'account_id' => :'accountId',
104
+ :'account_name' => :'accountName',
105
+ :'connection_id' => :'connectionId'
106
+ }
107
+ end
108
+
109
+ # Attribute type mapping.
110
+ def self.openapi_types
111
+ {
112
+ :'type' => :'String',
113
+ :'subtype' => :'String',
114
+ :'title' => :'String',
115
+ :'status' => :'Integer',
116
+ :'detail' => :'String',
117
+ :'account_id' => :'String',
118
+ :'account_name' => :'String',
119
+ :'connection_id' => :'String'
120
+ }
121
+ end
122
+
123
+ # Initializes the object
124
+ # @param [Hash] attributes Model attributes in the form of hash
125
+ def initialize(attributes = {})
126
+ if (!attributes.is_a?(Hash))
127
+ fail ArgumentError, "The input argument (attributes) must be a hash in `XeroRuby::BankfeedsV2::Problem` initialize method"
128
+ end
129
+
130
+ # check to see if the attribute exists and convert string to symbol for hash key
131
+ attributes = attributes.each_with_object({}) { |(k, v), h|
132
+ if (!self.class.attribute_map.key?(k.to_sym))
133
+ fail ArgumentError, "`#{k}` is not a valid attribute in `XeroRuby::BankfeedsV2::Problem`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
134
+ end
135
+ h[k.to_sym] = v
136
+ }
137
+
138
+ if attributes.key?(:'type')
139
+ self.type = attributes[:'type']
140
+ end
141
+
142
+ if attributes.key?(:'subtype')
143
+ self.subtype = attributes[:'subtype']
144
+ end
145
+
146
+ if attributes.key?(:'title')
147
+ self.title = attributes[:'title']
148
+ end
149
+
150
+ if attributes.key?(:'status')
151
+ self.status = attributes[:'status']
152
+ end
153
+
154
+ if attributes.key?(:'detail')
155
+ self.detail = attributes[:'detail']
156
+ end
157
+
158
+ if attributes.key?(:'account_id')
159
+ self.account_id = attributes[:'account_id']
160
+ end
161
+
162
+ if attributes.key?(:'account_name')
163
+ self.account_name = attributes[:'account_name']
164
+ end
165
+
166
+ if attributes.key?(:'connection_id')
167
+ self.connection_id = attributes[:'connection_id']
168
+ end
169
+ end
170
+
171
+ # Show invalid properties with the reasons. Usually used together with valid?
172
+ # @return Array for valid properties with the reasons
173
+ def list_invalid_properties
174
+ invalid_properties = Array.new
175
+ invalid_properties
176
+ end
177
+
178
+ # Check to see if the all the properties in the model are valid
179
+ # @return true if the model is valid
180
+ def valid?
181
+ type_validator = EnumAttributeValidator.new('String', ["invalid-request", "invalid-application", "suspended-or-terminated-application", "invalid-organisation-bank-feeds", "invalid-organisation-multi-currency", "invalid-feed-connection-for-organisation", "invalid-user-role", "invalid-account-token", "missing-identifying-fields", "invalid-country-specified", "account-not-valid", "feed-already-connected-in-current-organisation", "account-name-already-exists", "bank-feed-not-found", "feed-not-found-or-already-deleted", "partial-failure-new-account-creation", "partial-failure-previous-connection-deletion", "partial-failure-connection-creation", "partial-failure-connection-deletion", "partial-failure-new-account-existence-not-confirmed", "too-many-requests", "internal-error"])
182
+ return false unless type_validator.valid?(@type)
183
+ subtype_validator = EnumAttributeValidator.new('String', ["connection-phase-failed", "deletion-phase-failed", "deletion-phase-not-confirmed", "connection-existence-not-confirmed", "connection-exists-without-feed-connection", "feed-connection-existence-not-confirmed-can-check-or-retry", "check-accounts-or-prompt-user-retry"])
184
+ return false unless subtype_validator.valid?(@subtype)
185
+ true
186
+ end
187
+
188
+ # Custom attribute writer method checking allowed values (enum).
189
+ # @param [Object] type Object to be assigned
190
+ def type=(type)
191
+ validator = EnumAttributeValidator.new('String', ["invalid-request", "invalid-application", "suspended-or-terminated-application", "invalid-organisation-bank-feeds", "invalid-organisation-multi-currency", "invalid-feed-connection-for-organisation", "invalid-user-role", "invalid-account-token", "missing-identifying-fields", "invalid-country-specified", "account-not-valid", "feed-already-connected-in-current-organisation", "account-name-already-exists", "bank-feed-not-found", "feed-not-found-or-already-deleted", "partial-failure-new-account-creation", "partial-failure-previous-connection-deletion", "partial-failure-connection-creation", "partial-failure-connection-deletion", "partial-failure-new-account-existence-not-confirmed", "too-many-requests", "internal-error"])
192
+ unless validator.valid?(type)
193
+ fail ArgumentError, "invalid value for \"type\", must be one of #{validator.allowable_values}."
194
+ end
195
+ @type = type
196
+ end
197
+
198
+ # Custom attribute writer method checking allowed values (enum).
199
+ # @param [Object] subtype Object to be assigned
200
+ def subtype=(subtype)
201
+ validator = EnumAttributeValidator.new('String', ["connection-phase-failed", "deletion-phase-failed", "deletion-phase-not-confirmed", "connection-existence-not-confirmed", "connection-exists-without-feed-connection", "feed-connection-existence-not-confirmed-can-check-or-retry", "check-accounts-or-prompt-user-retry"])
202
+ unless validator.valid?(subtype)
203
+ fail ArgumentError, "invalid value for \"subtype\", must be one of #{validator.allowable_values}."
204
+ end
205
+ @subtype = subtype
206
+ end
207
+
208
+ # Checks equality by comparing each attribute.
209
+ # @param [Object] Object to be compared
210
+ def ==(o)
211
+ return true if self.equal?(o)
212
+ self.class == o.class &&
213
+ type == o.type &&
214
+ subtype == o.subtype &&
215
+ title == o.title &&
216
+ status == o.status &&
217
+ detail == o.detail &&
218
+ account_id == o.account_id &&
219
+ account_name == o.account_name &&
220
+ connection_id == o.connection_id
221
+ end
222
+
223
+ # @see the `==` method
224
+ # @param [Object] Object to be compared
225
+ def eql?(o)
226
+ self == o
227
+ end
228
+
229
+ # Calculates hash code according to all attributes.
230
+ # @return [Integer] Hash code
231
+ def hash
232
+ [type, subtype, title, status, detail, account_id, account_name, connection_id].hash
233
+ end
234
+
235
+ # Builds the object from hash
236
+ # @param [Hash] attributes Model attributes in the form of hash
237
+ # @return [Object] Returns the model itself
238
+ def self.build_from_hash(attributes)
239
+ new.build_from_hash(attributes)
240
+ end
241
+
242
+ # Builds the object from hash
243
+ # @param [Hash] attributes Model attributes in the form of hash
244
+ # @return [Object] Returns the model itself
245
+ def build_from_hash(attributes)
246
+ return nil unless attributes.is_a?(Hash)
247
+ self.class.openapi_types.each_pair do |key, type|
248
+ if type =~ /\AArray<(.*)>/i
249
+ # check to ensure the input is an array given that the attribute
250
+ # is documented as an array but the input is not
251
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
252
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
253
+ end
254
+ elsif !attributes[self.class.attribute_map[key]].nil?
255
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
256
+ end # or else data not found in attributes(hash), not an issue as the data can be optional
257
+ end
258
+
259
+ self
260
+ end
261
+
262
+ # Deserializes the data based on type
263
+ # @param string type Data type
264
+ # @param string value Value to be deserialized
265
+ # @return [Object] Deserialized data
266
+ def _deserialize(type, value)
267
+ case type.to_sym
268
+ when :DateTime
269
+ DateTime.parse(parse_date(value))
270
+ when :Date
271
+ Date.parse(parse_date(value))
272
+ when :String
273
+ value.to_s
274
+ when :Integer
275
+ value.to_i
276
+ when :Float
277
+ value.to_f
278
+ when :BigDecimal
279
+ BigDecimal(value.to_s)
280
+ when :Boolean
281
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
282
+ true
283
+ else
284
+ false
285
+ end
286
+ when :Object
287
+ # generic object (usually a Hash), return directly
288
+ value
289
+ when /\AArray<(?<inner_type>.+)>\z/
290
+ inner_type = Regexp.last_match[:inner_type]
291
+ value.map { |v| _deserialize(inner_type, v) }
292
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
293
+ k_type = Regexp.last_match[:k_type]
294
+ v_type = Regexp.last_match[:v_type]
295
+ {}.tap do |hash|
296
+ value.each do |k, v|
297
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
298
+ end
299
+ end
300
+ else # model
301
+ XeroRuby::BankfeedsV2.const_get(type).build_from_hash(value)
302
+ end
303
+ end
304
+
305
+ # Returns the string representation of the object
306
+ # @return [String] String presentation of the object
307
+ def to_s
308
+ to_hash.to_s
309
+ end
310
+
311
+ # to_body is an alias to to_hash (backward compatibility)
312
+ # @return [Hash] Returns the object in the form of hash
313
+ def to_body
314
+ to_hash
315
+ end
316
+
317
+ # Returns the object in the form of hash
318
+ # @return [Hash] Returns the object in the form of hash
319
+ def to_hash(downcase: false)
320
+ hash = {}
321
+ self.class.attribute_map.each_pair do |attr, param|
322
+ value = self.send(attr)
323
+ next if value.nil?
324
+ key = downcase ? attr : param
325
+ hash[key] = _to_hash(value, downcase: downcase)
326
+ end
327
+ hash
328
+ end
329
+
330
+ # Returns the object in the form of hash with snake_case
331
+ def to_attributes
332
+ to_hash(downcase: true)
333
+ end
334
+
335
+ # Outputs non-array value in the form of hash
336
+ # For object, use to_hash. Otherwise, just return the value
337
+ # @param [Object] value Any valid value
338
+ # @return [Hash] Returns the value in the form of hash
339
+ def _to_hash(value, downcase: false)
340
+ if value.is_a?(Array)
341
+ value.map do |v|
342
+ v.to_hash(downcase: downcase)
343
+ end
344
+ elsif value.is_a?(Hash)
345
+ {}.tap do |hash|
346
+ value.map { |k, v| hash[k] = _to_hash(v, downcase: downcase) }
347
+ end
348
+ elsif value.respond_to? :to_hash
349
+ value.to_hash(downcase: downcase)
350
+ else
351
+ value
352
+ end
353
+ end
354
+
355
+ def parse_date(datestring)
356
+ if datestring.include?('Date')
357
+ date_pattern = /\/Date\((-?\d+)(\+\d+)?\)\//
358
+ original, date, timezone = *date_pattern.match(datestring)
359
+ date = (date.to_i / 1000)
360
+ Time.at(date).utc.strftime('%Y-%m-%dT%H:%M:%S%z').to_s
361
+ elsif /(\d\d\d\d)-(\d\d)/.match(datestring) # handles dates w/out Days: YYYY-MM*-DD
362
+ Time.parse(datestring + '-01').strftime('%Y-%m-%dT%H:%M:%S').to_s
363
+ else # handle date 'types' for small subset of payroll API's
364
+ Time.parse(datestring).strftime('%Y-%m-%dT%H:%M:%S').to_s
365
+ end
366
+ end
367
+ end
368
+ end
@@ -7,9 +7,9 @@ Contact: api@xero.com
7
7
  Generated by: https://openapi-generator.tech
8
8
  OpenAPI Generator version: 4.3.1
9
9
 
10
- The version of the XeroOpenAPI document: 20.0.1
10
+ The version of the XeroOpenAPI document: 20.1.0
11
11
  =end
12
12
 
13
13
  module XeroRuby
14
- VERSION = '18.4.0'
14
+ VERSION = '18.5.0'
15
15
  end
data/lib/xero-ruby.rb CHANGED
@@ -18,6 +18,20 @@ require 'xero-ruby/version'
18
18
  require 'xero-ruby/configuration'
19
19
 
20
20
  # Models
21
+ require 'xero-ruby/models/bankfeeds_v2/account_type'
22
+ require 'xero-ruby/models/bankfeeds_v2/bulk_feed_connection_response'
23
+ require 'xero-ruby/models/bankfeeds_v2/bulk_feed_connection_result'
24
+ require 'xero-ruby/models/bankfeeds_v2/delete_feed_connections_request'
25
+ require 'xero-ruby/models/bankfeeds_v2/existing_account_feed_connection'
26
+ require 'xero-ruby/models/bankfeeds_v2/existing_account_feed_connections_request'
27
+ require 'xero-ruby/models/bankfeeds_v2/feed_connection'
28
+ require 'xero-ruby/models/bankfeeds_v2/feed_connection_to_delete'
29
+ require 'xero-ruby/models/bankfeeds_v2/item_error'
30
+ require 'xero-ruby/models/bankfeeds_v2/new_account_feed_connection'
31
+ require 'xero-ruby/models/bankfeeds_v2/new_account_feed_connections_request'
32
+ require 'xero-ruby/models/bankfeeds_v2/paged_feed_connections'
33
+ require 'xero-ruby/models/bankfeeds_v2/pagination'
34
+ require 'xero-ruby/models/bankfeeds_v2/problem'
21
35
  require 'xero-ruby/models/account_data/account'
22
36
  require 'xero-ruby/models/account_data/account_balance'
23
37
  require 'xero-ruby/models/account_data/account_balances_response'
@@ -571,6 +585,7 @@ require 'xero-ruby/models/accounting/users'
571
585
  require 'xero-ruby/models/accounting/validation_error'
572
586
 
573
587
  # APIs
588
+ require 'xero-ruby/api/feed_connections_api'
574
589
  require 'xero-ruby/api/account_data_api'
575
590
  require 'xero-ruby/api/finance_api'
576
591
  require 'xero-ruby/api/app_store_api'