xero-ruby 3.1.3 → 3.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,292 @@
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 SubscriptionItem
19
+ # Date when the subscription to this product will end
20
+ attr_accessor :end_date
21
+
22
+ # The unique identifier of the subscription item.
23
+ attr_accessor :id
24
+
25
+
26
+ attr_accessor :price
27
+
28
+
29
+ attr_accessor :product
30
+
31
+ # Date the subscription started, or will start. Note: this could be in the future for downgrades or reduced number of seats that haven't taken effect yet.
32
+ attr_accessor :start_date
33
+
34
+ # If the subscription is a test subscription
35
+ attr_accessor :test_mode
36
+
37
+ # Attribute mapping from ruby-style variable name to JSON key.
38
+ def self.attribute_map
39
+ {
40
+ :'end_date' => :'endDate',
41
+ :'id' => :'id',
42
+ :'price' => :'price',
43
+ :'product' => :'product',
44
+ :'start_date' => :'startDate',
45
+ :'test_mode' => :'testMode'
46
+ }
47
+ end
48
+
49
+ # Attribute type mapping.
50
+ def self.openapi_types
51
+ {
52
+ :'end_date' => :'DateTime',
53
+ :'id' => :'String',
54
+ :'price' => :'Price',
55
+ :'product' => :'Product',
56
+ :'start_date' => :'DateTime',
57
+ :'test_mode' => :'Boolean'
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::AppStore::SubscriptionItem` 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::AppStore::SubscriptionItem`. 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?(:'end_date')
77
+ self.end_date = attributes[:'end_date']
78
+ end
79
+
80
+ if attributes.key?(:'id')
81
+ self.id = attributes[:'id']
82
+ end
83
+
84
+ if attributes.key?(:'price')
85
+ self.price = attributes[:'price']
86
+ end
87
+
88
+ if attributes.key?(:'product')
89
+ self.product = attributes[:'product']
90
+ end
91
+
92
+ if attributes.key?(:'start_date')
93
+ self.start_date = attributes[:'start_date']
94
+ end
95
+
96
+ if attributes.key?(:'test_mode')
97
+ self.test_mode = attributes[:'test_mode']
98
+ end
99
+ end
100
+
101
+ # Show invalid properties with the reasons. Usually used together with valid?
102
+ # @return Array for valid properties with the reasons
103
+ def list_invalid_properties
104
+ invalid_properties = Array.new
105
+ if @id.nil?
106
+ invalid_properties.push('invalid value for "id", id cannot be nil.')
107
+ end
108
+
109
+ if @price.nil?
110
+ invalid_properties.push('invalid value for "price", price cannot be nil.')
111
+ end
112
+
113
+ if @product.nil?
114
+ invalid_properties.push('invalid value for "product", product cannot be nil.')
115
+ end
116
+
117
+ if @start_date.nil?
118
+ invalid_properties.push('invalid value for "start_date", start_date cannot be nil.')
119
+ end
120
+
121
+ invalid_properties
122
+ end
123
+
124
+ # Check to see if the all the properties in the model are valid
125
+ # @return true if the model is valid
126
+ def valid?
127
+ return false if @id.nil?
128
+ return false if @price.nil?
129
+ return false if @product.nil?
130
+ return false if @start_date.nil?
131
+ true
132
+ end
133
+
134
+ # Checks equality by comparing each attribute.
135
+ # @param [Object] Object to be compared
136
+ def ==(o)
137
+ return true if self.equal?(o)
138
+ self.class == o.class &&
139
+ end_date == o.end_date &&
140
+ id == o.id &&
141
+ price == o.price &&
142
+ product == o.product &&
143
+ start_date == o.start_date &&
144
+ test_mode == o.test_mode
145
+ end
146
+
147
+ # @see the `==` method
148
+ # @param [Object] Object to be compared
149
+ def eql?(o)
150
+ self == o
151
+ end
152
+
153
+ # Calculates hash code according to all attributes.
154
+ # @return [Integer] Hash code
155
+ def hash
156
+ [end_date, id, price, product, start_date, test_mode].hash
157
+ end
158
+
159
+ # Builds the object from hash
160
+ # @param [Hash] attributes Model attributes in the form of hash
161
+ # @return [Object] Returns the model itself
162
+ def self.build_from_hash(attributes)
163
+ new.build_from_hash(attributes)
164
+ end
165
+
166
+ # Builds the object from hash
167
+ # @param [Hash] attributes Model attributes in the form of hash
168
+ # @return [Object] Returns the model itself
169
+ def build_from_hash(attributes)
170
+ return nil unless attributes.is_a?(Hash)
171
+ self.class.openapi_types.each_pair do |key, type|
172
+ if type =~ /\AArray<(.*)>/i
173
+ # check to ensure the input is an array given that the attribute
174
+ # is documented as an array but the input is not
175
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
176
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
177
+ end
178
+ elsif !attributes[self.class.attribute_map[key]].nil?
179
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
180
+ end # or else data not found in attributes(hash), not an issue as the data can be optional
181
+ end
182
+
183
+ self
184
+ end
185
+
186
+ # Deserializes the data based on type
187
+ # @param string type Data type
188
+ # @param string value Value to be deserialized
189
+ # @return [Object] Deserialized data
190
+ def _deserialize(type, value)
191
+ case type.to_sym
192
+ when :DateTime
193
+ DateTime.parse(parse_date(value))
194
+ when :Date
195
+ Date.parse(parse_date(value))
196
+ when :String
197
+ value.to_s
198
+ when :Integer
199
+ value.to_i
200
+ when :Float
201
+ value.to_f
202
+ when :BigDecimal
203
+ BigDecimal(value.to_s)
204
+ when :Boolean
205
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
206
+ true
207
+ else
208
+ false
209
+ end
210
+ when :Object
211
+ # generic object (usually a Hash), return directly
212
+ value
213
+ when /\AArray<(?<inner_type>.+)>\z/
214
+ inner_type = Regexp.last_match[:inner_type]
215
+ value.map { |v| _deserialize(inner_type, v) }
216
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
217
+ k_type = Regexp.last_match[:k_type]
218
+ v_type = Regexp.last_match[:v_type]
219
+ {}.tap do |hash|
220
+ value.each do |k, v|
221
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
222
+ end
223
+ end
224
+ else # model
225
+ XeroRuby::AppStore.const_get(type).build_from_hash(value)
226
+ end
227
+ end
228
+
229
+ # Returns the string representation of the object
230
+ # @return [String] String presentation of the object
231
+ def to_s
232
+ to_hash.to_s
233
+ end
234
+
235
+ # to_body is an alias to to_hash (backward compatibility)
236
+ # @return [Hash] Returns the object in the form of hash
237
+ def to_body
238
+ to_hash
239
+ end
240
+
241
+ # Returns the object in the form of hash
242
+ # @return [Hash] Returns the object in the form of hash
243
+ def to_hash(downcase: false)
244
+ hash = {}
245
+ self.class.attribute_map.each_pair do |attr, param|
246
+ value = self.send(attr)
247
+ next if value.nil?
248
+ key = downcase ? attr : param
249
+ hash[key] = _to_hash(value, downcase: downcase)
250
+ end
251
+ hash
252
+ end
253
+
254
+ # Returns the object in the form of hash with snake_case
255
+ def to_attributes
256
+ to_hash(downcase: true)
257
+ end
258
+
259
+ # Outputs non-array value in the form of hash
260
+ # For object, use to_hash. Otherwise, just return the value
261
+ # @param [Object] value Any valid value
262
+ # @return [Hash] Returns the value in the form of hash
263
+ def _to_hash(value, downcase: false)
264
+ if value.is_a?(Array)
265
+ value.map do |v|
266
+ v.to_hash(downcase: downcase)
267
+ end
268
+ elsif value.is_a?(Hash)
269
+ {}.tap do |hash|
270
+ value.map { |k, v| hash[k] = _to_hash(v, downcase: downcase) }
271
+ end
272
+ elsif value.respond_to? :to_hash
273
+ value.to_hash(downcase: downcase)
274
+ else
275
+ value
276
+ end
277
+ end
278
+
279
+ def parse_date(datestring)
280
+ if datestring.include?('Date')
281
+ date_pattern = /\/Date\((-?\d+)(\+\d+)?\)\//
282
+ original, date, timezone = *date_pattern.match(datestring)
283
+ date = (date.to_i / 1000)
284
+ Time.at(date).utc.strftime('%Y-%m-%dT%H:%M:%S%z').to_s
285
+ elsif /(\d\d\d\d)-(\d\d)/.match(datestring) # handles dates w/out Days: YYYY-MM*-DD
286
+ Time.parse(datestring + '-01').strftime('%Y-%m-%dT%H:%M:%S').to_s
287
+ else # handle date 'types' for small subset of payroll API's
288
+ Time.parse(datestring).strftime('%Y-%m-%dT%H:%M:%S').to_s
289
+ end
290
+ end
291
+ end
292
+ end
@@ -83,6 +83,16 @@ module XeroRuby::PayrollAu
83
83
  # Employee Termination Date (YYYY-MM-DD)
84
84
  attr_accessor :termination_date
85
85
 
86
+ # * `V` Voluntary cessation - An employee resignation, retirement, domestic or pressing necessity or abandonment of employment * `I` Ill health - An employee resignation due to medical condition that prevents the continuation of employment, such as for illness, ill-health, medical unfitness or total permanent disability * `D` Deceased - The death of an employee * `R` Redundancy - An employer-initiated termination of employment due to a genuine redundancy or approved early retirement scheme * `F` Dismissal - An employer-initiated termination of employment due to dismissal, inability to perform the required work, misconduct or inefficiency * `C` Contract cessation - The natural conclusion of a limited employment relationship due to contract/engagement duration or task completion, seasonal work completion, or to cease casuals that are no longer required * `T` Transfer - The administrative arrangements performed to transfer employees across payroll systems, move them temporarily to another employer (machinery of government for public servants), transfer of business, move them to outsourcing arrangements or other such technical activities.
87
+ attr_accessor :termination_reason
88
+ V = "V".freeze
89
+ # I = "I".freeze
90
+ D = "D".freeze
91
+ R = "R".freeze
92
+ # F = "F".freeze
93
+ C = "C".freeze
94
+ T = "T".freeze
95
+
86
96
 
87
97
  attr_accessor :bank_accounts
88
98
 
@@ -159,6 +169,7 @@ module XeroRuby::PayrollAu
159
169
  :'employee_group_name' => :'EmployeeGroupName',
160
170
  :'employee_id' => :'EmployeeID',
161
171
  :'termination_date' => :'TerminationDate',
172
+ :'termination_reason' => :'TerminationReason',
162
173
  :'bank_accounts' => :'BankAccounts',
163
174
  :'pay_template' => :'PayTemplate',
164
175
  :'opening_balances' => :'OpeningBalances',
@@ -196,6 +207,7 @@ module XeroRuby::PayrollAu
196
207
  :'employee_group_name' => :'String',
197
208
  :'employee_id' => :'String',
198
209
  :'termination_date' => :'Date',
210
+ :'termination_reason' => :'String',
199
211
  :'bank_accounts' => :'Array<BankAccount>',
200
212
  :'pay_template' => :'PayTemplate',
201
213
  :'opening_balances' => :'OpeningBalances',
@@ -308,6 +320,10 @@ module XeroRuby::PayrollAu
308
320
  self.termination_date = attributes[:'termination_date']
309
321
  end
310
322
 
323
+ if attributes.key?(:'termination_reason')
324
+ self.termination_reason = attributes[:'termination_reason']
325
+ end
326
+
311
327
  if attributes.key?(:'bank_accounts')
312
328
  if (value = attributes[:'bank_accounts']).is_a?(Array)
313
329
  self.bank_accounts = value
@@ -386,6 +402,8 @@ module XeroRuby::PayrollAu
386
402
  return false if @date_of_birth.nil?
387
403
  gender_validator = EnumAttributeValidator.new('String', ["N", "M", "F", "I"])
388
404
  return false unless gender_validator.valid?(@gender)
405
+ termination_reason_validator = EnumAttributeValidator.new('String', ["V", "I", "D", "R", "F", "C", "T"])
406
+ return false unless termination_reason_validator.valid?(@termination_reason)
389
407
  true
390
408
  end
391
409
 
@@ -399,6 +417,16 @@ module XeroRuby::PayrollAu
399
417
  @gender = gender
400
418
  end
401
419
 
420
+ # Custom attribute writer method checking allowed values (enum).
421
+ # @param [Object] termination_reason Object to be assigned
422
+ def termination_reason=(termination_reason)
423
+ validator = EnumAttributeValidator.new('String', ["V", "I", "D", "R", "F", "C", "T"])
424
+ unless validator.valid?(termination_reason)
425
+ fail ArgumentError, "invalid value for \"termination_reason\", must be one of #{validator.allowable_values}."
426
+ end
427
+ @termination_reason = termination_reason
428
+ end
429
+
402
430
  # Checks equality by comparing each attribute.
403
431
  # @param [Object] Object to be compared
404
432
  def ==(o)
@@ -425,6 +453,7 @@ module XeroRuby::PayrollAu
425
453
  employee_group_name == o.employee_group_name &&
426
454
  employee_id == o.employee_id &&
427
455
  termination_date == o.termination_date &&
456
+ termination_reason == o.termination_reason &&
428
457
  bank_accounts == o.bank_accounts &&
429
458
  pay_template == o.pay_template &&
430
459
  opening_balances == o.opening_balances &&
@@ -446,7 +475,7 @@ module XeroRuby::PayrollAu
446
475
  # Calculates hash code according to all attributes.
447
476
  # @return [Integer] Hash code
448
477
  def hash
449
- [first_name, last_name, date_of_birth, home_address, start_date, title, middle_names, email, gender, phone, mobile, twitter_user_name, is_authorised_to_approve_leave, is_authorised_to_approve_timesheets, job_title, classification, ordinary_earnings_rate_id, payroll_calendar_id, employee_group_name, employee_id, termination_date, bank_accounts, pay_template, opening_balances, tax_declaration, leave_balances, leave_lines, super_memberships, status, updated_date_utc, validation_errors].hash
478
+ [first_name, last_name, date_of_birth, home_address, start_date, title, middle_names, email, gender, phone, mobile, twitter_user_name, is_authorised_to_approve_leave, is_authorised_to_approve_timesheets, job_title, classification, ordinary_earnings_rate_id, payroll_calendar_id, employee_group_name, employee_id, termination_date, termination_reason, bank_accounts, pay_template, opening_balances, tax_declaration, leave_balances, leave_lines, super_memberships, status, updated_date_utc, validation_errors].hash
450
479
  end
451
480
 
452
481
  # Builds the object from hash
@@ -34,6 +34,9 @@ module XeroRuby::PayrollAu
34
34
  # Last modified timestamp
35
35
  attr_accessor :updated_date_utc
36
36
 
37
+ # Reference Date (YYYY-MM-DD)
38
+ attr_accessor :reference_date
39
+
37
40
  # Displays array of validation error messages from the API
38
41
  attr_accessor :validation_errors
39
42
 
@@ -46,6 +49,7 @@ module XeroRuby::PayrollAu
46
49
  :'payment_date' => :'PaymentDate',
47
50
  :'payroll_calendar_id' => :'PayrollCalendarID',
48
51
  :'updated_date_utc' => :'UpdatedDateUTC',
52
+ :'reference_date' => :'ReferenceDate',
49
53
  :'validation_errors' => :'ValidationErrors'
50
54
  }
51
55
  end
@@ -59,6 +63,7 @@ module XeroRuby::PayrollAu
59
63
  :'payment_date' => :'Date',
60
64
  :'payroll_calendar_id' => :'String',
61
65
  :'updated_date_utc' => :'DateTime',
66
+ :'reference_date' => :'Date',
62
67
  :'validation_errors' => :'Array<ValidationError>'
63
68
  }
64
69
  end
@@ -102,6 +107,10 @@ module XeroRuby::PayrollAu
102
107
  self.updated_date_utc = attributes[:'updated_date_utc']
103
108
  end
104
109
 
110
+ if attributes.key?(:'reference_date')
111
+ self.reference_date = attributes[:'reference_date']
112
+ end
113
+
105
114
  if attributes.key?(:'validation_errors')
106
115
  if (value = attributes[:'validation_errors']).is_a?(Array)
107
116
  self.validation_errors = value
@@ -133,6 +142,7 @@ module XeroRuby::PayrollAu
133
142
  payment_date == o.payment_date &&
134
143
  payroll_calendar_id == o.payroll_calendar_id &&
135
144
  updated_date_utc == o.updated_date_utc &&
145
+ reference_date == o.reference_date &&
136
146
  validation_errors == o.validation_errors
137
147
  end
138
148
 
@@ -145,7 +155,7 @@ module XeroRuby::PayrollAu
145
155
  # Calculates hash code according to all attributes.
146
156
  # @return [Integer] Hash code
147
157
  def hash
148
- [name, calendar_type, start_date, payment_date, payroll_calendar_id, updated_date_utc, validation_errors].hash
158
+ [name, calendar_type, start_date, payment_date, payroll_calendar_id, updated_date_utc, reference_date, validation_errors].hash
149
159
  end
150
160
 
151
161
  # Builds the object from hash
@@ -7,9 +7,9 @@ Contact: api@xero.com
7
7
  Generated by: https://openapi-generator.tech
8
8
  OpenAPI Generator version: 4.3.1
9
9
 
10
- The version of the XeroOpenAPI document: 2.13.2
10
+ The version of the XeroOpenAPI document: 2.15.0
11
11
  =end
12
12
 
13
13
  module XeroRuby
14
- VERSION = '3.1.3'
14
+ VERSION = '3.3.0'
15
15
  end
@@ -47,7 +47,7 @@ describe XeroRuby::ApiClient do
47
47
  state: 'i-am-customer-state'
48
48
  }
49
49
  api_client = XeroRuby::ApiClient.new(credentials: creds)
50
- expect(api_client.authorization_url).to eq('https://login.xero.com/identity/connect/authorize?response_type=code&client_id=abc&redirect_uri=https://mydomain.com/callback&scope=openid+profile+email+accounting.transactions+accounting.settings&state=i-am-customer-state')
50
+ expect(api_client.authorization_url).to eq('https://login.xero.com/identity/connect/authorize?response_type=code&client_id=abc&redirect_uri=https%3A%2F%2Fmydomain.com%2Fcallback&scope=openid+profile+email+accounting.transactions+accounting.settings&state=i-am-customer-state')
51
51
  end
52
52
 
53
53
  it "Does not append state if it is not provided" do
@@ -58,7 +58,7 @@ describe XeroRuby::ApiClient do
58
58
  scopes: 'openid profile email accounting.transactions accounting.settings'
59
59
  }
60
60
  api_client = XeroRuby::ApiClient.new(credentials: creds)
61
- expect(api_client.authorization_url).to eq('https://login.xero.com/identity/connect/authorize?response_type=code&client_id=abc&redirect_uri=https://mydomain.com/callback&scope=openid+profile+email+accounting.transactions+accounting.settings')
61
+ expect(api_client.authorization_url).to eq('https://login.xero.com/identity/connect/authorize?response_type=code&client_id=abc&redirect_uri=https%3A%2F%2Fmydomain.com%2Fcallback&scope=openid+profile+email+accounting.transactions+accounting.settings')
62
62
  end
63
63
 
64
64
  it "Validates state on callback matches @config.state" do
@@ -74,6 +74,29 @@ describe XeroRuby::ApiClient do
74
74
  expect{api_client.validate_state(altered_state)}.to raise_error(StandardError, 'WARNING: @config.state: custom-state and OAuth callback state: do not match!')
75
75
  end
76
76
  end
77
+
78
+ context "Creates a valid client_credentials client" do
79
+
80
+ it "But still defaults to grant_type: authorization_code" do
81
+ creds = {
82
+ client_id: 'abc',
83
+ client_secret: '123',
84
+ }
85
+ api_client = XeroRuby::ApiClient.new(credentials: creds)
86
+ expect(api_client.grant_type).to eq('authorization_code')
87
+ end
88
+
89
+ it "Sets grant_type correctly" do
90
+ creds = {
91
+ client_id: 'abc',
92
+ client_secret: '123',
93
+ grant_type: 'client_credentials'
94
+ }
95
+ api_client = XeroRuby::ApiClient.new(credentials: creds)
96
+ expect(api_client.grant_type).to eq('client_credentials')
97
+ end
98
+
99
+ end
77
100
  end
78
101
  end
79
102