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,227 @@
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
+ require 'bigdecimal'
17
+
18
+ class FeedConnectionToDelete
19
+ # The Feed Connection to terminate. Required; an all-zeros GUID is treated as though the field were absent. `accountToken`, `accountType` and `country`, which V1 accepted here, are not supported.
20
+ attr_accessor :id
21
+
22
+ # Attribute mapping from ruby-style variable name to JSON key.
23
+ def self.attribute_map
24
+ {
25
+ :'id' => :'id'
26
+ }
27
+ end
28
+
29
+ # Attribute type mapping.
30
+ def self.openapi_types
31
+ {
32
+ :'id' => :'String'
33
+ }
34
+ end
35
+
36
+ # Initializes the object
37
+ # @param [Hash] attributes Model attributes in the form of hash
38
+ def initialize(attributes = {})
39
+ if (!attributes.is_a?(Hash))
40
+ fail ArgumentError, "The input argument (attributes) must be a hash in `XeroRuby::BankfeedsV2::FeedConnectionToDelete` initialize method"
41
+ end
42
+
43
+ # check to see if the attribute exists and convert string to symbol for hash key
44
+ attributes = attributes.each_with_object({}) { |(k, v), h|
45
+ if (!self.class.attribute_map.key?(k.to_sym))
46
+ fail ArgumentError, "`#{k}` is not a valid attribute in `XeroRuby::BankfeedsV2::FeedConnectionToDelete`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
47
+ end
48
+ h[k.to_sym] = v
49
+ }
50
+
51
+ if attributes.key?(:'id')
52
+ self.id = attributes[:'id']
53
+ end
54
+ end
55
+
56
+ # Show invalid properties with the reasons. Usually used together with valid?
57
+ # @return Array for valid properties with the reasons
58
+ def list_invalid_properties
59
+ invalid_properties = Array.new
60
+ if @id.nil?
61
+ invalid_properties.push('invalid value for "id", id cannot be nil.')
62
+ end
63
+
64
+ invalid_properties
65
+ end
66
+
67
+ # Check to see if the all the properties in the model are valid
68
+ # @return true if the model is valid
69
+ def valid?
70
+ return false if @id.nil?
71
+ true
72
+ end
73
+
74
+ # Checks equality by comparing each attribute.
75
+ # @param [Object] Object to be compared
76
+ def ==(o)
77
+ return true if self.equal?(o)
78
+ self.class == o.class &&
79
+ id == o.id
80
+ end
81
+
82
+ # @see the `==` method
83
+ # @param [Object] Object to be compared
84
+ def eql?(o)
85
+ self == o
86
+ end
87
+
88
+ # Calculates hash code according to all attributes.
89
+ # @return [Integer] Hash code
90
+ def hash
91
+ [id].hash
92
+ end
93
+
94
+ # Builds the object from hash
95
+ # @param [Hash] attributes Model attributes in the form of hash
96
+ # @return [Object] Returns the model itself
97
+ def self.build_from_hash(attributes)
98
+ new.build_from_hash(attributes)
99
+ end
100
+
101
+ # Builds the object from hash
102
+ # @param [Hash] attributes Model attributes in the form of hash
103
+ # @return [Object] Returns the model itself
104
+ def build_from_hash(attributes)
105
+ return nil unless attributes.is_a?(Hash)
106
+ self.class.openapi_types.each_pair do |key, type|
107
+ if type =~ /\AArray<(.*)>/i
108
+ # check to ensure the input is an array given that the attribute
109
+ # is documented as an array but the input is not
110
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
111
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
112
+ end
113
+ elsif !attributes[self.class.attribute_map[key]].nil?
114
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
115
+ end # or else data not found in attributes(hash), not an issue as the data can be optional
116
+ end
117
+
118
+ self
119
+ end
120
+
121
+ # Deserializes the data based on type
122
+ # @param string type Data type
123
+ # @param string value Value to be deserialized
124
+ # @return [Object] Deserialized data
125
+ def _deserialize(type, value)
126
+ case type.to_sym
127
+ when :DateTime
128
+ DateTime.parse(parse_date(value))
129
+ when :Date
130
+ Date.parse(parse_date(value))
131
+ when :String
132
+ value.to_s
133
+ when :Integer
134
+ value.to_i
135
+ when :Float
136
+ value.to_f
137
+ when :BigDecimal
138
+ BigDecimal(value.to_s)
139
+ when :Boolean
140
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
141
+ true
142
+ else
143
+ false
144
+ end
145
+ when :Object
146
+ # generic object (usually a Hash), return directly
147
+ value
148
+ when /\AArray<(?<inner_type>.+)>\z/
149
+ inner_type = Regexp.last_match[:inner_type]
150
+ value.map { |v| _deserialize(inner_type, v) }
151
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
152
+ k_type = Regexp.last_match[:k_type]
153
+ v_type = Regexp.last_match[:v_type]
154
+ {}.tap do |hash|
155
+ value.each do |k, v|
156
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
157
+ end
158
+ end
159
+ else # model
160
+ XeroRuby::BankfeedsV2.const_get(type).build_from_hash(value)
161
+ end
162
+ end
163
+
164
+ # Returns the string representation of the object
165
+ # @return [String] String presentation of the object
166
+ def to_s
167
+ to_hash.to_s
168
+ end
169
+
170
+ # to_body is an alias to to_hash (backward compatibility)
171
+ # @return [Hash] Returns the object in the form of hash
172
+ def to_body
173
+ to_hash
174
+ end
175
+
176
+ # Returns the object in the form of hash
177
+ # @return [Hash] Returns the object in the form of hash
178
+ def to_hash(downcase: false)
179
+ hash = {}
180
+ self.class.attribute_map.each_pair do |attr, param|
181
+ value = self.send(attr)
182
+ next if value.nil?
183
+ key = downcase ? attr : param
184
+ hash[key] = _to_hash(value, downcase: downcase)
185
+ end
186
+ hash
187
+ end
188
+
189
+ # Returns the object in the form of hash with snake_case
190
+ def to_attributes
191
+ to_hash(downcase: true)
192
+ end
193
+
194
+ # Outputs non-array value in the form of hash
195
+ # For object, use to_hash. Otherwise, just return the value
196
+ # @param [Object] value Any valid value
197
+ # @return [Hash] Returns the value in the form of hash
198
+ def _to_hash(value, downcase: false)
199
+ if value.is_a?(Array)
200
+ value.map do |v|
201
+ v.to_hash(downcase: downcase)
202
+ end
203
+ elsif value.is_a?(Hash)
204
+ {}.tap do |hash|
205
+ value.map { |k, v| hash[k] = _to_hash(v, downcase: downcase) }
206
+ end
207
+ elsif value.respond_to? :to_hash
208
+ value.to_hash(downcase: downcase)
209
+ else
210
+ value
211
+ end
212
+ end
213
+
214
+ def parse_date(datestring)
215
+ if datestring.include?('Date')
216
+ date_pattern = /\/Date\((-?\d+)(\+\d+)?\)\//
217
+ original, date, timezone = *date_pattern.match(datestring)
218
+ date = (date.to_i / 1000)
219
+ Time.at(date).utc.strftime('%Y-%m-%dT%H:%M:%S%z').to_s
220
+ elsif /(\d\d\d\d)-(\d\d)/.match(datestring) # handles dates w/out Days: YYYY-MM*-DD
221
+ Time.parse(datestring + '-01').strftime('%Y-%m-%dT%H:%M:%S').to_s
222
+ else # handle date 'types' for small subset of payroll API's
223
+ Time.parse(datestring).strftime('%Y-%m-%dT%H:%M:%S').to_s
224
+ end
225
+ end
226
+ end
227
+ end
@@ -0,0 +1,358 @@
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
+ # The `error` of an item result. It has the same fields as `Problem`, except `status`: the item's own `statusCode` is its HTTP status, so it is not repeated here.
17
+ require 'bigdecimal'
18
+
19
+ class ItemError
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
+ # A human-readable explanation specific to this occurrence.
59
+ attr_accessor :detail
60
+
61
+ # 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.
62
+ attr_accessor :account_id
63
+
64
+ # 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.
65
+ attr_accessor :account_name
66
+
67
+ # 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`.
68
+ attr_accessor :connection_id
69
+
70
+ class EnumAttributeValidator
71
+ attr_reader :datatype
72
+ attr_reader :allowable_values
73
+
74
+ def initialize(datatype, allowable_values)
75
+ @allowable_values = allowable_values.map do |value|
76
+ case datatype.to_s
77
+ when /Integer/i
78
+ value.to_i
79
+ when /Float/i
80
+ value.to_f
81
+ else
82
+ value
83
+ end
84
+ end
85
+ end
86
+
87
+ def valid?(value)
88
+ !value || allowable_values.include?(value)
89
+ end
90
+ end
91
+
92
+ # Attribute mapping from ruby-style variable name to JSON key.
93
+ def self.attribute_map
94
+ {
95
+ :'type' => :'type',
96
+ :'subtype' => :'subtype',
97
+ :'title' => :'title',
98
+ :'detail' => :'detail',
99
+ :'account_id' => :'accountId',
100
+ :'account_name' => :'accountName',
101
+ :'connection_id' => :'connectionId'
102
+ }
103
+ end
104
+
105
+ # Attribute type mapping.
106
+ def self.openapi_types
107
+ {
108
+ :'type' => :'String',
109
+ :'subtype' => :'String',
110
+ :'title' => :'String',
111
+ :'detail' => :'String',
112
+ :'account_id' => :'String',
113
+ :'account_name' => :'String',
114
+ :'connection_id' => :'String'
115
+ }
116
+ end
117
+
118
+ # Initializes the object
119
+ # @param [Hash] attributes Model attributes in the form of hash
120
+ def initialize(attributes = {})
121
+ if (!attributes.is_a?(Hash))
122
+ fail ArgumentError, "The input argument (attributes) must be a hash in `XeroRuby::BankfeedsV2::ItemError` initialize method"
123
+ end
124
+
125
+ # check to see if the attribute exists and convert string to symbol for hash key
126
+ attributes = attributes.each_with_object({}) { |(k, v), h|
127
+ if (!self.class.attribute_map.key?(k.to_sym))
128
+ fail ArgumentError, "`#{k}` is not a valid attribute in `XeroRuby::BankfeedsV2::ItemError`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
129
+ end
130
+ h[k.to_sym] = v
131
+ }
132
+
133
+ if attributes.key?(:'type')
134
+ self.type = attributes[:'type']
135
+ end
136
+
137
+ if attributes.key?(:'subtype')
138
+ self.subtype = attributes[:'subtype']
139
+ end
140
+
141
+ if attributes.key?(:'title')
142
+ self.title = attributes[:'title']
143
+ end
144
+
145
+ if attributes.key?(:'detail')
146
+ self.detail = attributes[:'detail']
147
+ end
148
+
149
+ if attributes.key?(:'account_id')
150
+ self.account_id = attributes[:'account_id']
151
+ end
152
+
153
+ if attributes.key?(:'account_name')
154
+ self.account_name = attributes[:'account_name']
155
+ end
156
+
157
+ if attributes.key?(:'connection_id')
158
+ self.connection_id = attributes[:'connection_id']
159
+ end
160
+ end
161
+
162
+ # Show invalid properties with the reasons. Usually used together with valid?
163
+ # @return Array for valid properties with the reasons
164
+ def list_invalid_properties
165
+ invalid_properties = Array.new
166
+ invalid_properties
167
+ end
168
+
169
+ # Check to see if the all the properties in the model are valid
170
+ # @return true if the model is valid
171
+ def valid?
172
+ 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"])
173
+ return false unless type_validator.valid?(@type)
174
+ 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"])
175
+ return false unless subtype_validator.valid?(@subtype)
176
+ true
177
+ end
178
+
179
+ # Custom attribute writer method checking allowed values (enum).
180
+ # @param [Object] type Object to be assigned
181
+ def type=(type)
182
+ 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"])
183
+ unless validator.valid?(type)
184
+ fail ArgumentError, "invalid value for \"type\", must be one of #{validator.allowable_values}."
185
+ end
186
+ @type = type
187
+ end
188
+
189
+ # Custom attribute writer method checking allowed values (enum).
190
+ # @param [Object] subtype Object to be assigned
191
+ def subtype=(subtype)
192
+ 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"])
193
+ unless validator.valid?(subtype)
194
+ fail ArgumentError, "invalid value for \"subtype\", must be one of #{validator.allowable_values}."
195
+ end
196
+ @subtype = subtype
197
+ end
198
+
199
+ # Checks equality by comparing each attribute.
200
+ # @param [Object] Object to be compared
201
+ def ==(o)
202
+ return true if self.equal?(o)
203
+ self.class == o.class &&
204
+ type == o.type &&
205
+ subtype == o.subtype &&
206
+ title == o.title &&
207
+ detail == o.detail &&
208
+ account_id == o.account_id &&
209
+ account_name == o.account_name &&
210
+ connection_id == o.connection_id
211
+ end
212
+
213
+ # @see the `==` method
214
+ # @param [Object] Object to be compared
215
+ def eql?(o)
216
+ self == o
217
+ end
218
+
219
+ # Calculates hash code according to all attributes.
220
+ # @return [Integer] Hash code
221
+ def hash
222
+ [type, subtype, title, detail, account_id, account_name, connection_id].hash
223
+ end
224
+
225
+ # Builds the object from hash
226
+ # @param [Hash] attributes Model attributes in the form of hash
227
+ # @return [Object] Returns the model itself
228
+ def self.build_from_hash(attributes)
229
+ new.build_from_hash(attributes)
230
+ end
231
+
232
+ # Builds the object from hash
233
+ # @param [Hash] attributes Model attributes in the form of hash
234
+ # @return [Object] Returns the model itself
235
+ def build_from_hash(attributes)
236
+ return nil unless attributes.is_a?(Hash)
237
+ self.class.openapi_types.each_pair do |key, type|
238
+ if type =~ /\AArray<(.*)>/i
239
+ # check to ensure the input is an array given that the attribute
240
+ # is documented as an array but the input is not
241
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
242
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
243
+ end
244
+ elsif !attributes[self.class.attribute_map[key]].nil?
245
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
246
+ end # or else data not found in attributes(hash), not an issue as the data can be optional
247
+ end
248
+
249
+ self
250
+ end
251
+
252
+ # Deserializes the data based on type
253
+ # @param string type Data type
254
+ # @param string value Value to be deserialized
255
+ # @return [Object] Deserialized data
256
+ def _deserialize(type, value)
257
+ case type.to_sym
258
+ when :DateTime
259
+ DateTime.parse(parse_date(value))
260
+ when :Date
261
+ Date.parse(parse_date(value))
262
+ when :String
263
+ value.to_s
264
+ when :Integer
265
+ value.to_i
266
+ when :Float
267
+ value.to_f
268
+ when :BigDecimal
269
+ BigDecimal(value.to_s)
270
+ when :Boolean
271
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
272
+ true
273
+ else
274
+ false
275
+ end
276
+ when :Object
277
+ # generic object (usually a Hash), return directly
278
+ value
279
+ when /\AArray<(?<inner_type>.+)>\z/
280
+ inner_type = Regexp.last_match[:inner_type]
281
+ value.map { |v| _deserialize(inner_type, v) }
282
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
283
+ k_type = Regexp.last_match[:k_type]
284
+ v_type = Regexp.last_match[:v_type]
285
+ {}.tap do |hash|
286
+ value.each do |k, v|
287
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
288
+ end
289
+ end
290
+ else # model
291
+ XeroRuby::BankfeedsV2.const_get(type).build_from_hash(value)
292
+ end
293
+ end
294
+
295
+ # Returns the string representation of the object
296
+ # @return [String] String presentation of the object
297
+ def to_s
298
+ to_hash.to_s
299
+ end
300
+
301
+ # to_body is an alias to to_hash (backward compatibility)
302
+ # @return [Hash] Returns the object in the form of hash
303
+ def to_body
304
+ to_hash
305
+ end
306
+
307
+ # Returns the object in the form of hash
308
+ # @return [Hash] Returns the object in the form of hash
309
+ def to_hash(downcase: false)
310
+ hash = {}
311
+ self.class.attribute_map.each_pair do |attr, param|
312
+ value = self.send(attr)
313
+ next if value.nil?
314
+ key = downcase ? attr : param
315
+ hash[key] = _to_hash(value, downcase: downcase)
316
+ end
317
+ hash
318
+ end
319
+
320
+ # Returns the object in the form of hash with snake_case
321
+ def to_attributes
322
+ to_hash(downcase: true)
323
+ end
324
+
325
+ # Outputs non-array value in the form of hash
326
+ # For object, use to_hash. Otherwise, just return the value
327
+ # @param [Object] value Any valid value
328
+ # @return [Hash] Returns the value in the form of hash
329
+ def _to_hash(value, downcase: false)
330
+ if value.is_a?(Array)
331
+ value.map do |v|
332
+ v.to_hash(downcase: downcase)
333
+ end
334
+ elsif value.is_a?(Hash)
335
+ {}.tap do |hash|
336
+ value.map { |k, v| hash[k] = _to_hash(v, downcase: downcase) }
337
+ end
338
+ elsif value.respond_to? :to_hash
339
+ value.to_hash(downcase: downcase)
340
+ else
341
+ value
342
+ end
343
+ end
344
+
345
+ def parse_date(datestring)
346
+ if datestring.include?('Date')
347
+ date_pattern = /\/Date\((-?\d+)(\+\d+)?\)\//
348
+ original, date, timezone = *date_pattern.match(datestring)
349
+ date = (date.to_i / 1000)
350
+ Time.at(date).utc.strftime('%Y-%m-%dT%H:%M:%S%z').to_s
351
+ elsif /(\d\d\d\d)-(\d\d)/.match(datestring) # handles dates w/out Days: YYYY-MM*-DD
352
+ Time.parse(datestring + '-01').strftime('%Y-%m-%dT%H:%M:%S').to_s
353
+ else # handle date 'types' for small subset of payroll API's
354
+ Time.parse(datestring).strftime('%Y-%m-%dT%H:%M:%S').to_s
355
+ end
356
+ end
357
+ end
358
+ end