xero-ruby 3.2.0 → 3.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (118) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +71 -2
  3. data/lib/xero-ruby/api/accounting_api.rb +11 -2
  4. data/lib/xero-ruby/api/app_store_api.rb +87 -0
  5. data/lib/xero-ruby/api/finance_api.rb +866 -0
  6. data/lib/xero-ruby/api/payroll_au_api.rb +14 -14
  7. data/lib/xero-ruby/api/payroll_nz_api.rb +18 -12
  8. data/lib/xero-ruby/api/payroll_uk_api.rb +14 -2
  9. data/lib/xero-ruby/api_client.rb +30 -4
  10. data/lib/xero-ruby/configuration.rb +4 -0
  11. data/lib/xero-ruby/models/accounting/bank_transfer.rb +35 -1
  12. data/lib/xero-ruby/models/accounting/budget_balance.rb +2 -2
  13. data/lib/xero-ruby/models/accounting/contact.rb +86 -1
  14. data/lib/xero-ruby/models/accounting/payment.rb +11 -1
  15. data/lib/xero-ruby/models/accounting/time_zone.rb +1 -0
  16. data/lib/xero-ruby/models/app_store/plan.rb +310 -0
  17. data/lib/xero-ruby/models/app_store/price.rb +257 -0
  18. data/lib/xero-ruby/models/app_store/problem_details.rb +272 -0
  19. data/lib/xero-ruby/models/app_store/product.rb +288 -0
  20. data/lib/xero-ruby/models/app_store/subscription.rb +324 -0
  21. data/lib/xero-ruby/models/app_store/subscription_item.rb +292 -0
  22. data/lib/xero-ruby/models/finance/account_usage.rb +342 -0
  23. data/lib/xero-ruby/models/finance/account_usage_response.rb +254 -0
  24. data/lib/xero-ruby/models/finance/balance_sheet_account_detail.rb +262 -0
  25. data/lib/xero-ruby/models/finance/balance_sheet_account_group.rb +234 -0
  26. data/lib/xero-ruby/models/finance/balance_sheet_account_type.rb +244 -0
  27. data/lib/xero-ruby/models/finance/balance_sheet_response.rb +252 -0
  28. data/lib/xero-ruby/models/finance/bank_statement_response.rb +232 -0
  29. data/lib/xero-ruby/models/finance/cash_account_response.rb +262 -0
  30. data/lib/xero-ruby/models/finance/cash_balance.rb +242 -0
  31. data/lib/xero-ruby/models/finance/cash_validation_response.rb +262 -0
  32. data/lib/xero-ruby/models/finance/cashflow_account.rb +282 -0
  33. data/lib/xero-ruby/models/finance/cashflow_activity.rb +244 -0
  34. data/lib/xero-ruby/models/finance/cashflow_response.rb +254 -0
  35. data/lib/xero-ruby/models/finance/cashflow_type.rb +244 -0
  36. data/lib/xero-ruby/models/finance/contact_detail.rb +274 -0
  37. data/lib/xero-ruby/models/finance/contact_total_detail.rb +242 -0
  38. data/lib/xero-ruby/models/finance/contact_total_other.rb +252 -0
  39. data/lib/xero-ruby/models/finance/current_statement_response.rb +272 -0
  40. data/lib/xero-ruby/models/finance/data_source_response.rb +362 -0
  41. data/lib/xero-ruby/models/finance/history_record_response.rb +262 -0
  42. data/lib/xero-ruby/models/finance/income_by_contact_response.rb +284 -0
  43. data/lib/xero-ruby/models/finance/lock_history_model.rb +242 -0
  44. data/lib/xero-ruby/models/finance/lock_history_response.rb +244 -0
  45. data/lib/xero-ruby/models/finance/manual_journal_total.rb +222 -0
  46. data/lib/xero-ruby/models/finance/pnl_account.rb +272 -0
  47. data/lib/xero-ruby/models/finance/pnl_account_class.rb +234 -0
  48. data/lib/xero-ruby/models/finance/pnl_account_type.rb +244 -0
  49. data/lib/xero-ruby/models/finance/practice_response.rb +262 -0
  50. data/lib/xero-ruby/models/finance/problem.rb +252 -0
  51. data/lib/xero-ruby/models/finance/problem_type.rb +39 -0
  52. data/lib/xero-ruby/models/finance/profit_and_loss_response.rb +262 -0
  53. data/lib/xero-ruby/models/finance/report_history_model.rb +242 -0
  54. data/lib/xero-ruby/models/finance/report_history_response.rb +244 -0
  55. data/lib/xero-ruby/models/finance/statement_balance_response.rb +232 -0
  56. data/lib/xero-ruby/models/finance/statement_lines_response.rb +382 -0
  57. data/lib/xero-ruby/models/finance/total_detail.rb +242 -0
  58. data/lib/xero-ruby/models/finance/total_other.rb +242 -0
  59. data/lib/xero-ruby/models/finance/trial_balance_account.rb +312 -0
  60. data/lib/xero-ruby/models/finance/trial_balance_entry.rb +232 -0
  61. data/lib/xero-ruby/models/finance/trial_balance_movement.rb +252 -0
  62. data/lib/xero-ruby/models/finance/trial_balance_response.rb +244 -0
  63. data/lib/xero-ruby/models/finance/user_activities_response.rb +244 -0
  64. data/lib/xero-ruby/models/finance/user_response.rb +336 -0
  65. data/lib/xero-ruby/models/payroll_au/earnings_type.rb +2 -0
  66. data/lib/xero-ruby/models/payroll_au/employee.rb +30 -1
  67. data/lib/xero-ruby/models/payroll_au/manual_tax_type.rb +1 -0
  68. data/lib/xero-ruby/models/payroll_au/payroll_calendar.rb +11 -1
  69. data/lib/xero-ruby/models/payroll_uk/earnings_rate.rb +4 -4
  70. data/lib/xero-ruby/version.rb +6 -6
  71. data/lib/xero-ruby.rb +51 -0
  72. data/spec/api_client_spec.rb +5 -2
  73. data/spec/app_store/api/app_store_api_spec.rb +45 -0
  74. data/spec/app_store/models/plan_spec.rb +62 -0
  75. data/spec/app_store/models/price_spec.rb +52 -0
  76. data/spec/app_store/models/problem_details_spec.rb +70 -0
  77. data/spec/app_store/models/product_spec.rb +56 -0
  78. data/spec/app_store/models/subscription_item_spec.rb +70 -0
  79. data/spec/app_store/models/subscription_spec.rb +82 -0
  80. data/spec/configuration_spec.rb +1 -0
  81. data/spec/finance/api/finance_api_spec.rb +156 -0
  82. data/spec/finance/models/account_usage_response_spec.rb +58 -0
  83. data/spec/finance/models/account_usage_spec.rb +112 -0
  84. data/spec/finance/models/balance_sheet_account_detail_spec.rb +64 -0
  85. data/spec/finance/models/balance_sheet_account_group_spec.rb +46 -0
  86. data/spec/finance/models/balance_sheet_account_type_spec.rb +52 -0
  87. data/spec/finance/models/balance_sheet_response_spec.rb +58 -0
  88. data/spec/finance/models/bank_statement_response_spec.rb +46 -0
  89. data/spec/finance/models/cash_account_response_spec.rb +64 -0
  90. data/spec/finance/models/cash_balance_spec.rb +52 -0
  91. data/spec/finance/models/cash_validation_response_spec.rb +64 -0
  92. data/spec/finance/models/cashflow_account_spec.rb +76 -0
  93. data/spec/finance/models/cashflow_activity_spec.rb +52 -0
  94. data/spec/finance/models/cashflow_response_spec.rb +58 -0
  95. data/spec/finance/models/cashflow_type_spec.rb +52 -0
  96. data/spec/finance/models/current_statement_response_spec.rb +70 -0
  97. data/spec/finance/models/data_source_response_spec.rb +124 -0
  98. data/spec/finance/models/history_record_response_spec.rb +64 -0
  99. data/spec/finance/models/lock_history_model_spec.rb +52 -0
  100. data/spec/finance/models/lock_history_response_spec.rb +52 -0
  101. data/spec/finance/models/pnl_account_class_spec.rb +46 -0
  102. data/spec/finance/models/pnl_account_spec.rb +70 -0
  103. data/spec/finance/models/pnl_account_type_spec.rb +52 -0
  104. data/spec/finance/models/practice_response_spec.rb +64 -0
  105. data/spec/finance/models/problem_spec.rb +58 -0
  106. data/spec/finance/models/problem_type_spec.rb +34 -0
  107. data/spec/finance/models/profit_and_loss_response_spec.rb +64 -0
  108. data/spec/finance/models/report_history_model_spec.rb +52 -0
  109. data/spec/finance/models/report_history_response_spec.rb +52 -0
  110. data/spec/finance/models/statement_balance_response_spec.rb +46 -0
  111. data/spec/finance/models/statement_lines_response_spec.rb +136 -0
  112. data/spec/finance/models/trial_balance_account_spec.rb +94 -0
  113. data/spec/finance/models/trial_balance_entry_spec.rb +46 -0
  114. data/spec/finance/models/trial_balance_movement_spec.rb +58 -0
  115. data/spec/finance/models/trial_balance_response_spec.rb +52 -0
  116. data/spec/finance/models/user_activities_response_spec.rb +52 -0
  117. data/spec/finance/models/user_response_spec.rb +106 -0
  118. metadata +142 -3
@@ -49,6 +49,9 @@ module XeroRuby::Accounting
49
49
  # The amount of the payment. Must be less than or equal to the outstanding amount owing on the invoice e.g. 200.00
50
50
  attr_accessor :amount
51
51
 
52
+ # The amount of the payment in the currency of the bank account.
53
+ attr_accessor :bank_amount
54
+
52
55
  # An optional description for the payment e.g. Direct Debit
53
56
  attr_accessor :reference
54
57
 
@@ -137,6 +140,7 @@ module XeroRuby::Accounting
137
140
  :'date' => :'Date',
138
141
  :'currency_rate' => :'CurrencyRate',
139
142
  :'amount' => :'Amount',
143
+ :'bank_amount' => :'BankAmount',
140
144
  :'reference' => :'Reference',
141
145
  :'is_reconciled' => :'IsReconciled',
142
146
  :'status' => :'Status',
@@ -168,6 +172,7 @@ module XeroRuby::Accounting
168
172
  :'date' => :'Date',
169
173
  :'currency_rate' => :'BigDecimal',
170
174
  :'amount' => :'BigDecimal',
175
+ :'bank_amount' => :'BigDecimal',
171
176
  :'reference' => :'String',
172
177
  :'is_reconciled' => :'Boolean',
173
178
  :'status' => :'String',
@@ -244,6 +249,10 @@ module XeroRuby::Accounting
244
249
  self.amount = attributes[:'amount']
245
250
  end
246
251
 
252
+ if attributes.key?(:'bank_amount')
253
+ self.bank_amount = attributes[:'bank_amount']
254
+ end
255
+
247
256
  if attributes.key?(:'reference')
248
257
  self.reference = attributes[:'reference']
249
258
  end
@@ -360,6 +369,7 @@ module XeroRuby::Accounting
360
369
  date == o.date &&
361
370
  currency_rate == o.currency_rate &&
362
371
  amount == o.amount &&
372
+ bank_amount == o.bank_amount &&
363
373
  reference == o.reference &&
364
374
  is_reconciled == o.is_reconciled &&
365
375
  status == o.status &&
@@ -385,7 +395,7 @@ module XeroRuby::Accounting
385
395
  # Calculates hash code according to all attributes.
386
396
  # @return [Integer] Hash code
387
397
  def hash
388
- [invoice, credit_note, prepayment, overpayment, invoice_number, credit_note_number, account, code, date, currency_rate, amount, reference, is_reconciled, status, payment_type, updated_date_utc, payment_id, batch_payment_id, bank_account_number, particulars, details, has_account, has_validation_errors, status_attribute_string, validation_errors].hash
398
+ [invoice, credit_note, prepayment, overpayment, invoice_number, credit_note_number, account, code, date, currency_rate, amount, bank_amount, reference, is_reconciled, status, payment_type, updated_date_utc, payment_id, batch_payment_id, bank_account_number, particulars, details, has_account, has_validation_errors, status_attribute_string, validation_errors].hash
389
399
  end
390
400
 
391
401
  # Builds the object from hash
@@ -122,6 +122,7 @@ module XeroRuby::Accounting
122
122
  HAWAIIANSTANDARDTIME = "HAWAIIANSTANDARDTIME".freeze
123
123
  UTC11 = "UTC11".freeze
124
124
  DATELINESTANDARDTIME = "DATELINESTANDARDTIME".freeze
125
+ EASTERISLANDSTANDARDTIME = "EASTERISLANDSTANDARDTIME".freeze
125
126
 
126
127
  # Builds the enum from string
127
128
  # @param [String] The enum value in the form of the string
@@ -0,0 +1,310 @@
1
+ =begin
2
+ #Xero AppStore API
3
+
4
+ #These endpoints are for Xero Partners to interact with the App Store Billing platform
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::AppStore
16
+ require 'bigdecimal'
17
+
18
+ class Plan
19
+ # The unique identifier of the plan
20
+ attr_accessor :id
21
+
22
+ # The name of the plan. It is used in the invoice line item description.
23
+ attr_accessor :name
24
+
25
+ # Status of the plan. Available statuses are ACTIVE, PENDING_ACTIVATION.
26
+ attr_accessor :status
27
+ ACTIVE = "ACTIVE".freeze
28
+ PENDING_ACTIVATION = "PENDING_ACTIVATION".freeze
29
+
30
+ # List of the subscription items belonging to the plan. It does not include cancelled subscription items.
31
+ attr_accessor :subscription_items
32
+
33
+ class EnumAttributeValidator
34
+ attr_reader :datatype
35
+ attr_reader :allowable_values
36
+
37
+ def initialize(datatype, allowable_values)
38
+ @allowable_values = allowable_values.map do |value|
39
+ case datatype.to_s
40
+ when /Integer/i
41
+ value.to_i
42
+ when /Float/i
43
+ value.to_f
44
+ else
45
+ value
46
+ end
47
+ end
48
+ end
49
+
50
+ def valid?(value)
51
+ !value || allowable_values.include?(value)
52
+ end
53
+ end
54
+
55
+ # Attribute mapping from ruby-style variable name to JSON key.
56
+ def self.attribute_map
57
+ {
58
+ :'id' => :'id',
59
+ :'name' => :'name',
60
+ :'status' => :'status',
61
+ :'subscription_items' => :'subscriptionItems'
62
+ }
63
+ end
64
+
65
+ # Attribute type mapping.
66
+ def self.openapi_types
67
+ {
68
+ :'id' => :'String',
69
+ :'name' => :'String',
70
+ :'status' => :'String',
71
+ :'subscription_items' => :'Array<SubscriptionItem>'
72
+ }
73
+ end
74
+
75
+ # Initializes the object
76
+ # @param [Hash] attributes Model attributes in the form of hash
77
+ def initialize(attributes = {})
78
+ if (!attributes.is_a?(Hash))
79
+ fail ArgumentError, "The input argument (attributes) must be a hash in `XeroRuby::AppStore::Plan` initialize method"
80
+ end
81
+
82
+ # check to see if the attribute exists and convert string to symbol for hash key
83
+ attributes = attributes.each_with_object({}) { |(k, v), h|
84
+ if (!self.class.attribute_map.key?(k.to_sym))
85
+ fail ArgumentError, "`#{k}` is not a valid attribute in `XeroRuby::AppStore::Plan`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
86
+ end
87
+ h[k.to_sym] = v
88
+ }
89
+
90
+ if attributes.key?(:'id')
91
+ self.id = attributes[:'id']
92
+ end
93
+
94
+ if attributes.key?(:'name')
95
+ self.name = attributes[:'name']
96
+ end
97
+
98
+ if attributes.key?(:'status')
99
+ self.status = attributes[:'status']
100
+ end
101
+
102
+ if attributes.key?(:'subscription_items')
103
+ if (value = attributes[:'subscription_items']).is_a?(Array)
104
+ self.subscription_items = value
105
+ end
106
+ end
107
+ end
108
+
109
+ # Show invalid properties with the reasons. Usually used together with valid?
110
+ # @return Array for valid properties with the reasons
111
+ def list_invalid_properties
112
+ invalid_properties = Array.new
113
+ if @id.nil?
114
+ invalid_properties.push('invalid value for "id", id cannot be nil.')
115
+ end
116
+
117
+ if @name.nil?
118
+ invalid_properties.push('invalid value for "name", name cannot be nil.')
119
+ end
120
+
121
+ if @status.nil?
122
+ invalid_properties.push('invalid value for "status", status cannot be nil.')
123
+ end
124
+
125
+ if @subscription_items.nil?
126
+ invalid_properties.push('invalid value for "subscription_items", subscription_items cannot be nil.')
127
+ end
128
+
129
+ invalid_properties
130
+ end
131
+
132
+ # Check to see if the all the properties in the model are valid
133
+ # @return true if the model is valid
134
+ def valid?
135
+ return false if @id.nil?
136
+ return false if @name.nil?
137
+ return false if @status.nil?
138
+ status_validator = EnumAttributeValidator.new('String', ["ACTIVE", "PENDING_ACTIVATION"])
139
+ return false unless status_validator.valid?(@status)
140
+ return false if @subscription_items.nil?
141
+ true
142
+ end
143
+
144
+ # Custom attribute writer method checking allowed values (enum).
145
+ # @param [Object] status Object to be assigned
146
+ def status=(status)
147
+ validator = EnumAttributeValidator.new('String', ["ACTIVE", "PENDING_ACTIVATION"])
148
+ unless validator.valid?(status)
149
+ fail ArgumentError, "invalid value for \"status\", must be one of #{validator.allowable_values}."
150
+ end
151
+ @status = status
152
+ end
153
+
154
+ # Checks equality by comparing each attribute.
155
+ # @param [Object] Object to be compared
156
+ def ==(o)
157
+ return true if self.equal?(o)
158
+ self.class == o.class &&
159
+ id == o.id &&
160
+ name == o.name &&
161
+ status == o.status &&
162
+ subscription_items == o.subscription_items
163
+ end
164
+
165
+ # @see the `==` method
166
+ # @param [Object] Object to be compared
167
+ def eql?(o)
168
+ self == o
169
+ end
170
+
171
+ # Calculates hash code according to all attributes.
172
+ # @return [Integer] Hash code
173
+ def hash
174
+ [id, name, status, subscription_items].hash
175
+ end
176
+
177
+ # Builds the object from hash
178
+ # @param [Hash] attributes Model attributes in the form of hash
179
+ # @return [Object] Returns the model itself
180
+ def self.build_from_hash(attributes)
181
+ new.build_from_hash(attributes)
182
+ end
183
+
184
+ # Builds the object from hash
185
+ # @param [Hash] attributes Model attributes in the form of hash
186
+ # @return [Object] Returns the model itself
187
+ def build_from_hash(attributes)
188
+ return nil unless attributes.is_a?(Hash)
189
+ self.class.openapi_types.each_pair do |key, type|
190
+ if type =~ /\AArray<(.*)>/i
191
+ # check to ensure the input is an array given that the attribute
192
+ # is documented as an array but the input is not
193
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
194
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
195
+ end
196
+ elsif !attributes[self.class.attribute_map[key]].nil?
197
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
198
+ end # or else data not found in attributes(hash), not an issue as the data can be optional
199
+ end
200
+
201
+ self
202
+ end
203
+
204
+ # Deserializes the data based on type
205
+ # @param string type Data type
206
+ # @param string value Value to be deserialized
207
+ # @return [Object] Deserialized data
208
+ def _deserialize(type, value)
209
+ case type.to_sym
210
+ when :DateTime
211
+ DateTime.parse(parse_date(value))
212
+ when :Date
213
+ Date.parse(parse_date(value))
214
+ when :String
215
+ value.to_s
216
+ when :Integer
217
+ value.to_i
218
+ when :Float
219
+ value.to_f
220
+ when :BigDecimal
221
+ BigDecimal(value.to_s)
222
+ when :Boolean
223
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
224
+ true
225
+ else
226
+ false
227
+ end
228
+ when :Object
229
+ # generic object (usually a Hash), return directly
230
+ value
231
+ when /\AArray<(?<inner_type>.+)>\z/
232
+ inner_type = Regexp.last_match[:inner_type]
233
+ value.map { |v| _deserialize(inner_type, v) }
234
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
235
+ k_type = Regexp.last_match[:k_type]
236
+ v_type = Regexp.last_match[:v_type]
237
+ {}.tap do |hash|
238
+ value.each do |k, v|
239
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
240
+ end
241
+ end
242
+ else # model
243
+ XeroRuby::AppStore.const_get(type).build_from_hash(value)
244
+ end
245
+ end
246
+
247
+ # Returns the string representation of the object
248
+ # @return [String] String presentation of the object
249
+ def to_s
250
+ to_hash.to_s
251
+ end
252
+
253
+ # to_body is an alias to to_hash (backward compatibility)
254
+ # @return [Hash] Returns the object in the form of hash
255
+ def to_body
256
+ to_hash
257
+ end
258
+
259
+ # Returns the object in the form of hash
260
+ # @return [Hash] Returns the object in the form of hash
261
+ def to_hash(downcase: false)
262
+ hash = {}
263
+ self.class.attribute_map.each_pair do |attr, param|
264
+ value = self.send(attr)
265
+ next if value.nil?
266
+ key = downcase ? attr : param
267
+ hash[key] = _to_hash(value, downcase: downcase)
268
+ end
269
+ hash
270
+ end
271
+
272
+ # Returns the object in the form of hash with snake_case
273
+ def to_attributes
274
+ to_hash(downcase: true)
275
+ end
276
+
277
+ # Outputs non-array value in the form of hash
278
+ # For object, use to_hash. Otherwise, just return the value
279
+ # @param [Object] value Any valid value
280
+ # @return [Hash] Returns the value in the form of hash
281
+ def _to_hash(value, downcase: false)
282
+ if value.is_a?(Array)
283
+ value.map do |v|
284
+ v.to_hash(downcase: downcase)
285
+ end
286
+ elsif value.is_a?(Hash)
287
+ {}.tap do |hash|
288
+ value.map { |k, v| hash[k] = _to_hash(v, downcase: downcase) }
289
+ end
290
+ elsif value.respond_to? :to_hash
291
+ value.to_hash(downcase: downcase)
292
+ else
293
+ value
294
+ end
295
+ end
296
+
297
+ def parse_date(datestring)
298
+ if datestring.include?('Date')
299
+ date_pattern = /\/Date\((-?\d+)(\+\d+)?\)\//
300
+ original, date, timezone = *date_pattern.match(datestring)
301
+ date = (date.to_i / 1000)
302
+ Time.at(date).utc.strftime('%Y-%m-%dT%H:%M:%S%z').to_s
303
+ elsif /(\d\d\d\d)-(\d\d)/.match(datestring) # handles dates w/out Days: YYYY-MM*-DD
304
+ Time.parse(datestring + '-01').strftime('%Y-%m-%dT%H:%M:%S').to_s
305
+ else # handle date 'types' for small subset of payroll API's
306
+ Time.parse(datestring).strftime('%Y-%m-%dT%H:%M:%S').to_s
307
+ end
308
+ end
309
+ end
310
+ end
@@ -0,0 +1,257 @@
1
+ =begin
2
+ #Xero AppStore API
3
+
4
+ #These endpoints are for Xero Partners to interact with the App Store Billing platform
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::AppStore
16
+ require 'bigdecimal'
17
+
18
+ class Price
19
+ # The net (before tax) amount.
20
+ attr_accessor :amount
21
+
22
+ # The currency of the price.
23
+ attr_accessor :currency
24
+
25
+ # The unique identifier of the price.
26
+ attr_accessor :id
27
+
28
+ # Attribute mapping from ruby-style variable name to JSON key.
29
+ def self.attribute_map
30
+ {
31
+ :'amount' => :'amount',
32
+ :'currency' => :'currency',
33
+ :'id' => :'id'
34
+ }
35
+ end
36
+
37
+ # Attribute type mapping.
38
+ def self.openapi_types
39
+ {
40
+ :'amount' => :'BigDecimal',
41
+ :'currency' => :'String',
42
+ :'id' => :'String'
43
+ }
44
+ end
45
+
46
+ # Initializes the object
47
+ # @param [Hash] attributes Model attributes in the form of hash
48
+ def initialize(attributes = {})
49
+ if (!attributes.is_a?(Hash))
50
+ fail ArgumentError, "The input argument (attributes) must be a hash in `XeroRuby::AppStore::Price` initialize method"
51
+ end
52
+
53
+ # check to see if the attribute exists and convert string to symbol for hash key
54
+ attributes = attributes.each_with_object({}) { |(k, v), h|
55
+ if (!self.class.attribute_map.key?(k.to_sym))
56
+ fail ArgumentError, "`#{k}` is not a valid attribute in `XeroRuby::AppStore::Price`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
57
+ end
58
+ h[k.to_sym] = v
59
+ }
60
+
61
+ if attributes.key?(:'amount')
62
+ self.amount = attributes[:'amount']
63
+ end
64
+
65
+ if attributes.key?(:'currency')
66
+ self.currency = attributes[:'currency']
67
+ end
68
+
69
+ if attributes.key?(:'id')
70
+ self.id = attributes[:'id']
71
+ end
72
+ end
73
+
74
+ # Show invalid properties with the reasons. Usually used together with valid?
75
+ # @return Array for valid properties with the reasons
76
+ def list_invalid_properties
77
+ invalid_properties = Array.new
78
+ if @amount.nil?
79
+ invalid_properties.push('invalid value for "amount", amount cannot be nil.')
80
+ end
81
+
82
+ if @currency.nil?
83
+ invalid_properties.push('invalid value for "currency", currency cannot be nil.')
84
+ end
85
+
86
+ if @id.nil?
87
+ invalid_properties.push('invalid value for "id", id cannot be nil.')
88
+ end
89
+
90
+ invalid_properties
91
+ end
92
+
93
+ # Check to see if the all the properties in the model are valid
94
+ # @return true if the model is valid
95
+ def valid?
96
+ return false if @amount.nil?
97
+ return false if @currency.nil?
98
+ return false if @id.nil?
99
+ true
100
+ end
101
+
102
+ # Checks equality by comparing each attribute.
103
+ # @param [Object] Object to be compared
104
+ def ==(o)
105
+ return true if self.equal?(o)
106
+ self.class == o.class &&
107
+ amount == o.amount &&
108
+ currency == o.currency &&
109
+ id == o.id
110
+ end
111
+
112
+ # @see the `==` method
113
+ # @param [Object] Object to be compared
114
+ def eql?(o)
115
+ self == o
116
+ end
117
+
118
+ # Calculates hash code according to all attributes.
119
+ # @return [Integer] Hash code
120
+ def hash
121
+ [amount, currency, id].hash
122
+ end
123
+
124
+ # Builds the object from hash
125
+ # @param [Hash] attributes Model attributes in the form of hash
126
+ # @return [Object] Returns the model itself
127
+ def self.build_from_hash(attributes)
128
+ new.build_from_hash(attributes)
129
+ end
130
+
131
+ # Builds the object from hash
132
+ # @param [Hash] attributes Model attributes in the form of hash
133
+ # @return [Object] Returns the model itself
134
+ def build_from_hash(attributes)
135
+ return nil unless attributes.is_a?(Hash)
136
+ self.class.openapi_types.each_pair do |key, type|
137
+ if type =~ /\AArray<(.*)>/i
138
+ # check to ensure the input is an array given that the attribute
139
+ # is documented as an array but the input is not
140
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
141
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
142
+ end
143
+ elsif !attributes[self.class.attribute_map[key]].nil?
144
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
145
+ end # or else data not found in attributes(hash), not an issue as the data can be optional
146
+ end
147
+
148
+ self
149
+ end
150
+
151
+ # Deserializes the data based on type
152
+ # @param string type Data type
153
+ # @param string value Value to be deserialized
154
+ # @return [Object] Deserialized data
155
+ def _deserialize(type, value)
156
+ case type.to_sym
157
+ when :DateTime
158
+ DateTime.parse(parse_date(value))
159
+ when :Date
160
+ Date.parse(parse_date(value))
161
+ when :String
162
+ value.to_s
163
+ when :Integer
164
+ value.to_i
165
+ when :Float
166
+ value.to_f
167
+ when :BigDecimal
168
+ BigDecimal(value.to_s)
169
+ when :Boolean
170
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
171
+ true
172
+ else
173
+ false
174
+ end
175
+ when :Object
176
+ # generic object (usually a Hash), return directly
177
+ value
178
+ when /\AArray<(?<inner_type>.+)>\z/
179
+ inner_type = Regexp.last_match[:inner_type]
180
+ value.map { |v| _deserialize(inner_type, v) }
181
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
182
+ k_type = Regexp.last_match[:k_type]
183
+ v_type = Regexp.last_match[:v_type]
184
+ {}.tap do |hash|
185
+ value.each do |k, v|
186
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
187
+ end
188
+ end
189
+ else # model
190
+ XeroRuby::AppStore.const_get(type).build_from_hash(value)
191
+ end
192
+ end
193
+
194
+ # Returns the string representation of the object
195
+ # @return [String] String presentation of the object
196
+ def to_s
197
+ to_hash.to_s
198
+ end
199
+
200
+ # to_body is an alias to to_hash (backward compatibility)
201
+ # @return [Hash] Returns the object in the form of hash
202
+ def to_body
203
+ to_hash
204
+ end
205
+
206
+ # Returns the object in the form of hash
207
+ # @return [Hash] Returns the object in the form of hash
208
+ def to_hash(downcase: false)
209
+ hash = {}
210
+ self.class.attribute_map.each_pair do |attr, param|
211
+ value = self.send(attr)
212
+ next if value.nil?
213
+ key = downcase ? attr : param
214
+ hash[key] = _to_hash(value, downcase: downcase)
215
+ end
216
+ hash
217
+ end
218
+
219
+ # Returns the object in the form of hash with snake_case
220
+ def to_attributes
221
+ to_hash(downcase: true)
222
+ end
223
+
224
+ # Outputs non-array value in the form of hash
225
+ # For object, use to_hash. Otherwise, just return the value
226
+ # @param [Object] value Any valid value
227
+ # @return [Hash] Returns the value in the form of hash
228
+ def _to_hash(value, downcase: false)
229
+ if value.is_a?(Array)
230
+ value.map do |v|
231
+ v.to_hash(downcase: downcase)
232
+ end
233
+ elsif value.is_a?(Hash)
234
+ {}.tap do |hash|
235
+ value.map { |k, v| hash[k] = _to_hash(v, downcase: downcase) }
236
+ end
237
+ elsif value.respond_to? :to_hash
238
+ value.to_hash(downcase: downcase)
239
+ else
240
+ value
241
+ end
242
+ end
243
+
244
+ def parse_date(datestring)
245
+ if datestring.include?('Date')
246
+ date_pattern = /\/Date\((-?\d+)(\+\d+)?\)\//
247
+ original, date, timezone = *date_pattern.match(datestring)
248
+ date = (date.to_i / 1000)
249
+ Time.at(date).utc.strftime('%Y-%m-%dT%H:%M:%S%z').to_s
250
+ elsif /(\d\d\d\d)-(\d\d)/.match(datestring) # handles dates w/out Days: YYYY-MM*-DD
251
+ Time.parse(datestring + '-01').strftime('%Y-%m-%dT%H:%M:%S').to_s
252
+ else # handle date 'types' for small subset of payroll API's
253
+ Time.parse(datestring).strftime('%Y-%m-%dT%H:%M:%S').to_s
254
+ end
255
+ end
256
+ end
257
+ end