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 PrepaymentResponse
19
+ # Xero Identifier of prepayment
20
+ attr_accessor :prepayment_id
21
+
22
+
23
+ attr_accessor :contact
24
+
25
+ # Total of Invoice tax inclusive (i.e. SubTotal + TotalTax); Not included in summary mode
26
+ attr_accessor :total
27
+
28
+ # Not included in summary mode
29
+ attr_accessor :line_items
30
+
31
+ # Attribute mapping from ruby-style variable name to JSON key.
32
+ def self.attribute_map
33
+ {
34
+ :'prepayment_id' => :'prepaymentId',
35
+ :'contact' => :'contact',
36
+ :'total' => :'total',
37
+ :'line_items' => :'lineItems'
38
+ }
39
+ end
40
+
41
+ # Attribute type mapping.
42
+ def self.openapi_types
43
+ {
44
+ :'prepayment_id' => :'String',
45
+ :'contact' => :'ContactResponse',
46
+ :'total' => :'BigDecimal',
47
+ :'line_items' => :'Array<LineItemResponse>'
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::PrepaymentResponse` 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::PrepaymentResponse`. 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?(:'prepayment_id')
67
+ self.prepayment_id = attributes[:'prepayment_id']
68
+ end
69
+
70
+ if attributes.key?(:'contact')
71
+ self.contact = attributes[:'contact']
72
+ end
73
+
74
+ if attributes.key?(:'total')
75
+ self.total = attributes[:'total']
76
+ end
77
+
78
+ if attributes.key?(:'line_items')
79
+ if (value = attributes[:'line_items']).is_a?(Array)
80
+ self.line_items = 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
+ prepayment_id == o.prepayment_id &&
104
+ contact == o.contact &&
105
+ total == o.total &&
106
+ line_items == o.line_items
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
+ [prepayment_id, contact, total, line_items].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
@@ -15,10 +15,15 @@ require 'date'
15
15
  module XeroRuby::Finance
16
16
  class ProblemType
17
17
  NOT_SET ||= "NotSet".freeze
18
- INVALID_REQUEST ||= "invalid-request".freeze
18
+ BANK_ACCOUNT_NOT_FOUND ||= "bank-account-not-found".freeze
19
+ INTERNAL_ERROR ||= "internal-error".freeze
19
20
  INVALID_APPLICATION ||= "invalid-application".freeze
21
+ INVALID_REQUEST ||= "invalid-request".freeze
22
+ ORGANISATION_NOT_FOUND ||= "organisation-not-found".freeze
23
+ ORGANISATION_OFFLINE ||= "organisation-offline".freeze
24
+ REQUEST_TIMEOUT ||= "request-timeout".freeze
20
25
  SERVICE_UNAVAILABLE ||= "service-unavailable".freeze
21
- INTERNAL_ERROR ||= "internal-error".freeze
26
+ UNAUTHORIZED ||= "unauthorized".freeze
22
27
 
23
28
  # Builds the enum from string
24
29
  # @param [String] The enum value in the form of the string
@@ -0,0 +1,346 @@
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 StatementLineResponse
19
+ # Xero Identifier of statement line
20
+ attr_accessor :statement_line_id
21
+
22
+ # Date of when statement line was posted
23
+ attr_accessor :posted_date
24
+
25
+ # Reference description of statement line
26
+ attr_accessor :reference
27
+
28
+ # Notes description of statement line
29
+ attr_accessor :notes
30
+
31
+ # Cheque number of statement line
32
+ attr_accessor :cheque_no
33
+
34
+ # Amount of statement line
35
+ attr_accessor :amount
36
+
37
+ # Transaction date of statement line
38
+ attr_accessor :transaction_date
39
+
40
+ # Type of statement line
41
+ attr_accessor :type
42
+
43
+ # Boolean to show if statement line is reconciled
44
+ attr_accessor :is_reconciled
45
+
46
+ # Boolean to show if statement line is duplicate
47
+ attr_accessor :is_duplicate
48
+
49
+ # Boolean to show if statement line is deleted
50
+ attr_accessor :is_deleted
51
+
52
+ # List of payments associated with reconciled statement lines
53
+ attr_accessor :payments
54
+
55
+ # List of bank transactions associated with reconciled statement lines
56
+ attr_accessor :bank_transactions
57
+
58
+ # Attribute mapping from ruby-style variable name to JSON key.
59
+ def self.attribute_map
60
+ {
61
+ :'statement_line_id' => :'statementLineId',
62
+ :'posted_date' => :'postedDate',
63
+ :'reference' => :'reference',
64
+ :'notes' => :'notes',
65
+ :'cheque_no' => :'chequeNo',
66
+ :'amount' => :'amount',
67
+ :'transaction_date' => :'transactionDate',
68
+ :'type' => :'type',
69
+ :'is_reconciled' => :'isReconciled',
70
+ :'is_duplicate' => :'isDuplicate',
71
+ :'is_deleted' => :'isDeleted',
72
+ :'payments' => :'payments',
73
+ :'bank_transactions' => :'bankTransactions'
74
+ }
75
+ end
76
+
77
+ # Attribute type mapping.
78
+ def self.openapi_types
79
+ {
80
+ :'statement_line_id' => :'String',
81
+ :'posted_date' => :'DateTime',
82
+ :'reference' => :'String',
83
+ :'notes' => :'String',
84
+ :'cheque_no' => :'String',
85
+ :'amount' => :'BigDecimal',
86
+ :'transaction_date' => :'DateTime',
87
+ :'type' => :'String',
88
+ :'is_reconciled' => :'Boolean',
89
+ :'is_duplicate' => :'Boolean',
90
+ :'is_deleted' => :'Boolean',
91
+ :'payments' => :'Array<PaymentResponse>',
92
+ :'bank_transactions' => :'Array<BankTransactionResponse>'
93
+ }
94
+ end
95
+
96
+ # Initializes the object
97
+ # @param [Hash] attributes Model attributes in the form of hash
98
+ def initialize(attributes = {})
99
+ if (!attributes.is_a?(Hash))
100
+ fail ArgumentError, "The input argument (attributes) must be a hash in `XeroRuby::Finance::StatementLineResponse` initialize method"
101
+ end
102
+
103
+ # check to see if the attribute exists and convert string to symbol for hash key
104
+ attributes = attributes.each_with_object({}) { |(k, v), h|
105
+ if (!self.class.attribute_map.key?(k.to_sym))
106
+ fail ArgumentError, "`#{k}` is not a valid attribute in `XeroRuby::Finance::StatementLineResponse`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
107
+ end
108
+ h[k.to_sym] = v
109
+ }
110
+
111
+ if attributes.key?(:'statement_line_id')
112
+ self.statement_line_id = attributes[:'statement_line_id']
113
+ end
114
+
115
+ if attributes.key?(:'posted_date')
116
+ self.posted_date = attributes[:'posted_date']
117
+ end
118
+
119
+ if attributes.key?(:'reference')
120
+ self.reference = attributes[:'reference']
121
+ end
122
+
123
+ if attributes.key?(:'notes')
124
+ self.notes = attributes[:'notes']
125
+ end
126
+
127
+ if attributes.key?(:'cheque_no')
128
+ self.cheque_no = attributes[:'cheque_no']
129
+ end
130
+
131
+ if attributes.key?(:'amount')
132
+ self.amount = attributes[:'amount']
133
+ end
134
+
135
+ if attributes.key?(:'transaction_date')
136
+ self.transaction_date = attributes[:'transaction_date']
137
+ end
138
+
139
+ if attributes.key?(:'type')
140
+ self.type = attributes[:'type']
141
+ end
142
+
143
+ if attributes.key?(:'is_reconciled')
144
+ self.is_reconciled = attributes[:'is_reconciled']
145
+ end
146
+
147
+ if attributes.key?(:'is_duplicate')
148
+ self.is_duplicate = attributes[:'is_duplicate']
149
+ end
150
+
151
+ if attributes.key?(:'is_deleted')
152
+ self.is_deleted = attributes[:'is_deleted']
153
+ end
154
+
155
+ if attributes.key?(:'payments')
156
+ if (value = attributes[:'payments']).is_a?(Array)
157
+ self.payments = value
158
+ end
159
+ end
160
+
161
+ if attributes.key?(:'bank_transactions')
162
+ if (value = attributes[:'bank_transactions']).is_a?(Array)
163
+ self.bank_transactions = value
164
+ end
165
+ end
166
+ end
167
+
168
+ # Show invalid properties with the reasons. Usually used together with valid?
169
+ # @return Array for valid properties with the reasons
170
+ def list_invalid_properties
171
+ invalid_properties = Array.new
172
+ invalid_properties
173
+ end
174
+
175
+ # Check to see if the all the properties in the model are valid
176
+ # @return true if the model is valid
177
+ def valid?
178
+ true
179
+ end
180
+
181
+ # Checks equality by comparing each attribute.
182
+ # @param [Object] Object to be compared
183
+ def ==(o)
184
+ return true if self.equal?(o)
185
+ self.class == o.class &&
186
+ statement_line_id == o.statement_line_id &&
187
+ posted_date == o.posted_date &&
188
+ reference == o.reference &&
189
+ notes == o.notes &&
190
+ cheque_no == o.cheque_no &&
191
+ amount == o.amount &&
192
+ transaction_date == o.transaction_date &&
193
+ type == o.type &&
194
+ is_reconciled == o.is_reconciled &&
195
+ is_duplicate == o.is_duplicate &&
196
+ is_deleted == o.is_deleted &&
197
+ payments == o.payments &&
198
+ bank_transactions == o.bank_transactions
199
+ end
200
+
201
+ # @see the `==` method
202
+ # @param [Object] Object to be compared
203
+ def eql?(o)
204
+ self == o
205
+ end
206
+
207
+ # Calculates hash code according to all attributes.
208
+ # @return [Integer] Hash code
209
+ def hash
210
+ [statement_line_id, posted_date, reference, notes, cheque_no, amount, transaction_date, type, is_reconciled, is_duplicate, is_deleted, payments, bank_transactions].hash
211
+ end
212
+
213
+ # Builds the object from hash
214
+ # @param [Hash] attributes Model attributes in the form of hash
215
+ # @return [Object] Returns the model itself
216
+ def self.build_from_hash(attributes)
217
+ new.build_from_hash(attributes)
218
+ end
219
+
220
+ # Builds the object from hash
221
+ # @param [Hash] attributes Model attributes in the form of hash
222
+ # @return [Object] Returns the model itself
223
+ def build_from_hash(attributes)
224
+ return nil unless attributes.is_a?(Hash)
225
+ self.class.openapi_types.each_pair do |key, type|
226
+ if type =~ /\AArray<(.*)>/i
227
+ # check to ensure the input is an array given that the attribute
228
+ # is documented as an array but the input is not
229
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
230
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
231
+ end
232
+ elsif !attributes[self.class.attribute_map[key]].nil?
233
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
234
+ end # or else data not found in attributes(hash), not an issue as the data can be optional
235
+ end
236
+
237
+ self
238
+ end
239
+
240
+ # Deserializes the data based on type
241
+ # @param string type Data type
242
+ # @param string value Value to be deserialized
243
+ # @return [Object] Deserialized data
244
+ def _deserialize(type, value)
245
+ case type.to_sym
246
+ when :DateTime
247
+ DateTime.parse(parse_date(value))
248
+ when :Date
249
+ Date.parse(parse_date(value))
250
+ when :String
251
+ value.to_s
252
+ when :Integer
253
+ value.to_i
254
+ when :Float
255
+ value.to_f
256
+ when :BigDecimal
257
+ BigDecimal(value.to_s)
258
+ when :Boolean
259
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
260
+ true
261
+ else
262
+ false
263
+ end
264
+ when :Object
265
+ # generic object (usually a Hash), return directly
266
+ value
267
+ when /\AArray<(?<inner_type>.+)>\z/
268
+ inner_type = Regexp.last_match[:inner_type]
269
+ value.map { |v| _deserialize(inner_type, v) }
270
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
271
+ k_type = Regexp.last_match[:k_type]
272
+ v_type = Regexp.last_match[:v_type]
273
+ {}.tap do |hash|
274
+ value.each do |k, v|
275
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
276
+ end
277
+ end
278
+ else # model
279
+ XeroRuby::Finance.const_get(type).build_from_hash(value)
280
+ end
281
+ end
282
+
283
+ # Returns the string representation of the object
284
+ # @return [String] String presentation of the object
285
+ def to_s
286
+ to_hash.to_s
287
+ end
288
+
289
+ # to_body is an alias to to_hash (backward compatibility)
290
+ # @return [Hash] Returns the object in the form of hash
291
+ def to_body
292
+ to_hash
293
+ end
294
+
295
+ # Returns the object in the form of hash
296
+ # @return [Hash] Returns the object in the form of hash
297
+ def to_hash(downcase: false)
298
+ hash = {}
299
+ self.class.attribute_map.each_pair do |attr, param|
300
+ value = self.send(attr)
301
+ next if value.nil?
302
+ key = downcase ? attr : param
303
+ hash[key] = _to_hash(value, downcase: downcase)
304
+ end
305
+ hash
306
+ end
307
+
308
+ # Returns the object in the form of hash with snake_case
309
+ def to_attributes
310
+ to_hash(downcase: true)
311
+ end
312
+
313
+ # Outputs non-array value in the form of hash
314
+ # For object, use to_hash. Otherwise, just return the value
315
+ # @param [Object] value Any valid value
316
+ # @return [Hash] Returns the value in the form of hash
317
+ def _to_hash(value, downcase: false)
318
+ if value.is_a?(Array)
319
+ value.map do |v|
320
+ v.to_hash(downcase: downcase)
321
+ end
322
+ elsif value.is_a?(Hash)
323
+ {}.tap do |hash|
324
+ value.map { |k, v| hash[k] = _to_hash(v, downcase: downcase) }
325
+ end
326
+ elsif value.respond_to? :to_hash
327
+ value.to_hash(downcase: downcase)
328
+ else
329
+ value
330
+ end
331
+ end
332
+
333
+ def parse_date(datestring)
334
+ if datestring.include?('Date')
335
+ date_pattern = /\/Date\((-?\d+)(\+\d+)?\)\//
336
+ original, date, timezone = *date_pattern.match(datestring)
337
+ date = (date.to_i / 1000)
338
+ Time.at(date).utc.strftime('%Y-%m-%dT%H:%M:%S%z').to_s
339
+ elsif /(\d\d\d\d)-(\d\d)/.match(datestring) # handles dates w/out Days: YYYY-MM*-DD
340
+ Time.parse(datestring + '-01').strftime('%Y-%m-%dT%H:%M:%S').to_s
341
+ else # handle date 'types' for small subset of payroll API's
342
+ Time.parse(datestring).strftime('%Y-%m-%dT%H:%M:%S').to_s
343
+ end
344
+ end
345
+ end
346
+ end