xero-ruby 3.1.4 → 3.4.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.
Files changed (35) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +257 -222
  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/payroll_au_api.rb +14 -14
  6. data/lib/xero-ruby/api/payroll_nz_api.rb +18 -12
  7. data/lib/xero-ruby/api/payroll_uk_api.rb +14 -2
  8. data/lib/xero-ruby/api_client.rb +35 -6
  9. data/lib/xero-ruby/configuration.rb +2 -0
  10. data/lib/xero-ruby/models/accounting/bank_transfer.rb +35 -1
  11. data/lib/xero-ruby/models/accounting/budget_balance.rb +2 -2
  12. data/lib/xero-ruby/models/accounting/payment.rb +11 -1
  13. data/lib/xero-ruby/models/accounting/time_zone.rb +1 -0
  14. data/lib/xero-ruby/models/app_store/plan.rb +310 -0
  15. data/lib/xero-ruby/models/app_store/price.rb +257 -0
  16. data/lib/xero-ruby/models/app_store/problem_details.rb +272 -0
  17. data/lib/xero-ruby/models/app_store/product.rb +288 -0
  18. data/lib/xero-ruby/models/app_store/subscription.rb +324 -0
  19. data/lib/xero-ruby/models/app_store/subscription_item.rb +292 -0
  20. data/lib/xero-ruby/models/payroll_au/earnings_type.rb +2 -0
  21. data/lib/xero-ruby/models/payroll_au/employee.rb +30 -1
  22. data/lib/xero-ruby/models/payroll_au/manual_tax_type.rb +1 -0
  23. data/lib/xero-ruby/models/payroll_au/payroll_calendar.rb +11 -1
  24. data/lib/xero-ruby/models/payroll_uk/earnings_rate.rb +4 -4
  25. data/lib/xero-ruby/version.rb +2 -2
  26. data/lib/xero-ruby.rb +7 -0
  27. data/spec/api_client_spec.rb +25 -2
  28. data/spec/app_store/api/app_store_api_spec.rb +45 -0
  29. data/spec/app_store/models/plan_spec.rb +62 -0
  30. data/spec/app_store/models/price_spec.rb +52 -0
  31. data/spec/app_store/models/problem_details_spec.rb +70 -0
  32. data/spec/app_store/models/product_spec.rb +56 -0
  33. data/spec/app_store/models/subscription_item_spec.rb +70 -0
  34. data/spec/app_store/models/subscription_spec.rb +82 -0
  35. metadata +24 -3
@@ -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