xero-ruby 3.6.0 → 3.7.0

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