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,272 @@
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 ProblemDetails
19
+
20
+ attr_accessor :detail
21
+
22
+
23
+ attr_accessor :extensions
24
+
25
+
26
+ attr_accessor :instance
27
+
28
+
29
+ attr_accessor :status
30
+
31
+
32
+ attr_accessor :title
33
+
34
+
35
+ attr_accessor :type
36
+
37
+ # Attribute mapping from ruby-style variable name to JSON key.
38
+ def self.attribute_map
39
+ {
40
+ :'detail' => :'detail',
41
+ :'extensions' => :'extensions',
42
+ :'instance' => :'instance',
43
+ :'status' => :'status',
44
+ :'title' => :'title',
45
+ :'type' => :'type'
46
+ }
47
+ end
48
+
49
+ # Attribute type mapping.
50
+ def self.openapi_types
51
+ {
52
+ :'detail' => :'String',
53
+ :'extensions' => :'Object',
54
+ :'instance' => :'String',
55
+ :'status' => :'Integer',
56
+ :'title' => :'String',
57
+ :'type' => :'String'
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::ProblemDetails` 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::ProblemDetails`. 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?(:'detail')
77
+ self.detail = attributes[:'detail']
78
+ end
79
+
80
+ if attributes.key?(:'extensions')
81
+ self.extensions = attributes[:'extensions']
82
+ end
83
+
84
+ if attributes.key?(:'instance')
85
+ self.instance = attributes[:'instance']
86
+ end
87
+
88
+ if attributes.key?(:'status')
89
+ self.status = attributes[:'status']
90
+ end
91
+
92
+ if attributes.key?(:'title')
93
+ self.title = attributes[:'title']
94
+ end
95
+
96
+ if attributes.key?(:'type')
97
+ self.type = attributes[:'type']
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
+ invalid_properties
106
+ end
107
+
108
+ # Check to see if the all the properties in the model are valid
109
+ # @return true if the model is valid
110
+ def valid?
111
+ true
112
+ end
113
+
114
+ # Checks equality by comparing each attribute.
115
+ # @param [Object] Object to be compared
116
+ def ==(o)
117
+ return true if self.equal?(o)
118
+ self.class == o.class &&
119
+ detail == o.detail &&
120
+ extensions == o.extensions &&
121
+ instance == o.instance &&
122
+ status == o.status &&
123
+ title == o.title &&
124
+ type == o.type
125
+ end
126
+
127
+ # @see the `==` method
128
+ # @param [Object] Object to be compared
129
+ def eql?(o)
130
+ self == o
131
+ end
132
+
133
+ # Calculates hash code according to all attributes.
134
+ # @return [Integer] Hash code
135
+ def hash
136
+ [detail, extensions, instance, status, title, type].hash
137
+ end
138
+
139
+ # Builds the object from hash
140
+ # @param [Hash] attributes Model attributes in the form of hash
141
+ # @return [Object] Returns the model itself
142
+ def self.build_from_hash(attributes)
143
+ new.build_from_hash(attributes)
144
+ end
145
+
146
+ # Builds the object from hash
147
+ # @param [Hash] attributes Model attributes in the form of hash
148
+ # @return [Object] Returns the model itself
149
+ def build_from_hash(attributes)
150
+ return nil unless attributes.is_a?(Hash)
151
+ self.class.openapi_types.each_pair do |key, type|
152
+ if type =~ /\AArray<(.*)>/i
153
+ # check to ensure the input is an array given that the attribute
154
+ # is documented as an array but the input is not
155
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
156
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
157
+ end
158
+ elsif !attributes[self.class.attribute_map[key]].nil?
159
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
160
+ end # or else data not found in attributes(hash), not an issue as the data can be optional
161
+ end
162
+
163
+ self
164
+ end
165
+
166
+ # Deserializes the data based on type
167
+ # @param string type Data type
168
+ # @param string value Value to be deserialized
169
+ # @return [Object] Deserialized data
170
+ def _deserialize(type, value)
171
+ case type.to_sym
172
+ when :DateTime
173
+ DateTime.parse(parse_date(value))
174
+ when :Date
175
+ Date.parse(parse_date(value))
176
+ when :String
177
+ value.to_s
178
+ when :Integer
179
+ value.to_i
180
+ when :Float
181
+ value.to_f
182
+ when :BigDecimal
183
+ BigDecimal(value.to_s)
184
+ when :Boolean
185
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
186
+ true
187
+ else
188
+ false
189
+ end
190
+ when :Object
191
+ # generic object (usually a Hash), return directly
192
+ value
193
+ when /\AArray<(?<inner_type>.+)>\z/
194
+ inner_type = Regexp.last_match[:inner_type]
195
+ value.map { |v| _deserialize(inner_type, v) }
196
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
197
+ k_type = Regexp.last_match[:k_type]
198
+ v_type = Regexp.last_match[:v_type]
199
+ {}.tap do |hash|
200
+ value.each do |k, v|
201
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
202
+ end
203
+ end
204
+ else # model
205
+ XeroRuby::AppStore.const_get(type).build_from_hash(value)
206
+ end
207
+ end
208
+
209
+ # Returns the string representation of the object
210
+ # @return [String] String presentation of the object
211
+ def to_s
212
+ to_hash.to_s
213
+ end
214
+
215
+ # to_body is an alias to to_hash (backward compatibility)
216
+ # @return [Hash] Returns the object in the form of hash
217
+ def to_body
218
+ to_hash
219
+ end
220
+
221
+ # Returns the object in the form of hash
222
+ # @return [Hash] Returns the object in the form of hash
223
+ def to_hash(downcase: false)
224
+ hash = {}
225
+ self.class.attribute_map.each_pair do |attr, param|
226
+ value = self.send(attr)
227
+ next if value.nil?
228
+ key = downcase ? attr : param
229
+ hash[key] = _to_hash(value, downcase: downcase)
230
+ end
231
+ hash
232
+ end
233
+
234
+ # Returns the object in the form of hash with snake_case
235
+ def to_attributes
236
+ to_hash(downcase: true)
237
+ end
238
+
239
+ # Outputs non-array value in the form of hash
240
+ # For object, use to_hash. Otherwise, just return the value
241
+ # @param [Object] value Any valid value
242
+ # @return [Hash] Returns the value in the form of hash
243
+ def _to_hash(value, downcase: false)
244
+ if value.is_a?(Array)
245
+ value.map do |v|
246
+ v.to_hash(downcase: downcase)
247
+ end
248
+ elsif value.is_a?(Hash)
249
+ {}.tap do |hash|
250
+ value.map { |k, v| hash[k] = _to_hash(v, downcase: downcase) }
251
+ end
252
+ elsif value.respond_to? :to_hash
253
+ value.to_hash(downcase: downcase)
254
+ else
255
+ value
256
+ end
257
+ end
258
+
259
+ def parse_date(datestring)
260
+ if datestring.include?('Date')
261
+ date_pattern = /\/Date\((-?\d+)(\+\d+)?\)\//
262
+ original, date, timezone = *date_pattern.match(datestring)
263
+ date = (date.to_i / 1000)
264
+ Time.at(date).utc.strftime('%Y-%m-%dT%H:%M:%S%z').to_s
265
+ elsif /(\d\d\d\d)-(\d\d)/.match(datestring) # handles dates w/out Days: YYYY-MM*-DD
266
+ Time.parse(datestring + '-01').strftime('%Y-%m-%dT%H:%M:%S').to_s
267
+ else # handle date 'types' for small subset of payroll API's
268
+ Time.parse(datestring).strftime('%Y-%m-%dT%H:%M:%S').to_s
269
+ end
270
+ end
271
+ end
272
+ end
@@ -0,0 +1,288 @@
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 Product
19
+ # The unique identifier for the product
20
+ attr_accessor :id
21
+
22
+ # The name of the product
23
+ attr_accessor :name
24
+
25
+ # The pricing model of the product: * FIXED: Customers are charged a fixed amount for each billing period * PER_SEAT: Customers are charged based on the number of units they purchase
26
+ attr_accessor :type
27
+ FIXED = "FIXED".freeze
28
+ PER_SEAT = "PER_SEAT".freeze
29
+
30
+ # The unit of the per seat product. e.g. \"user\", \"organisation\", \"SMS\", etc
31
+ attr_accessor :seat_unit
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
+ :'type' => :'type',
61
+ :'seat_unit' => :'seatUnit'
62
+ }
63
+ end
64
+
65
+ # Attribute type mapping.
66
+ def self.openapi_types
67
+ {
68
+ :'id' => :'String',
69
+ :'name' => :'String',
70
+ :'type' => :'String',
71
+ :'seat_unit' => :'String'
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::Product` 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::Product`. 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?(:'type')
99
+ self.type = attributes[:'type']
100
+ end
101
+
102
+ if attributes.key?(:'seat_unit')
103
+ self.seat_unit = attributes[:'seat_unit']
104
+ end
105
+ end
106
+
107
+ # Show invalid properties with the reasons. Usually used together with valid?
108
+ # @return Array for valid properties with the reasons
109
+ def list_invalid_properties
110
+ invalid_properties = Array.new
111
+ invalid_properties
112
+ end
113
+
114
+ # Check to see if the all the properties in the model are valid
115
+ # @return true if the model is valid
116
+ def valid?
117
+ type_validator = EnumAttributeValidator.new('String', ["FIXED", "PER_SEAT"])
118
+ return false unless type_validator.valid?(@type)
119
+ true
120
+ end
121
+
122
+ # Custom attribute writer method checking allowed values (enum).
123
+ # @param [Object] type Object to be assigned
124
+ def type=(type)
125
+ validator = EnumAttributeValidator.new('String', ["FIXED", "PER_SEAT"])
126
+ unless validator.valid?(type)
127
+ fail ArgumentError, "invalid value for \"type\", must be one of #{validator.allowable_values}."
128
+ end
129
+ @type = type
130
+ end
131
+
132
+ # Checks equality by comparing each attribute.
133
+ # @param [Object] Object to be compared
134
+ def ==(o)
135
+ return true if self.equal?(o)
136
+ self.class == o.class &&
137
+ id == o.id &&
138
+ name == o.name &&
139
+ type == o.type &&
140
+ seat_unit == o.seat_unit
141
+ end
142
+
143
+ # @see the `==` method
144
+ # @param [Object] Object to be compared
145
+ def eql?(o)
146
+ self == o
147
+ end
148
+
149
+ # Calculates hash code according to all attributes.
150
+ # @return [Integer] Hash code
151
+ def hash
152
+ [id, name, type, seat_unit].hash
153
+ end
154
+
155
+ # Builds the object from hash
156
+ # @param [Hash] attributes Model attributes in the form of hash
157
+ # @return [Object] Returns the model itself
158
+ def self.build_from_hash(attributes)
159
+ new.build_from_hash(attributes)
160
+ end
161
+
162
+ # Builds the object from hash
163
+ # @param [Hash] attributes Model attributes in the form of hash
164
+ # @return [Object] Returns the model itself
165
+ def build_from_hash(attributes)
166
+ return nil unless attributes.is_a?(Hash)
167
+ self.class.openapi_types.each_pair do |key, type|
168
+ if type =~ /\AArray<(.*)>/i
169
+ # check to ensure the input is an array given that the attribute
170
+ # is documented as an array but the input is not
171
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
172
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
173
+ end
174
+ elsif !attributes[self.class.attribute_map[key]].nil?
175
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
176
+ end # or else data not found in attributes(hash), not an issue as the data can be optional
177
+ end
178
+
179
+ self
180
+ end
181
+
182
+ # Deserializes the data based on type
183
+ # @param string type Data type
184
+ # @param string value Value to be deserialized
185
+ # @return [Object] Deserialized data
186
+ def _deserialize(type, value)
187
+ case type.to_sym
188
+ when :DateTime
189
+ DateTime.parse(parse_date(value))
190
+ when :Date
191
+ Date.parse(parse_date(value))
192
+ when :String
193
+ value.to_s
194
+ when :Integer
195
+ value.to_i
196
+ when :Float
197
+ value.to_f
198
+ when :BigDecimal
199
+ BigDecimal(value.to_s)
200
+ when :Boolean
201
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
202
+ true
203
+ else
204
+ false
205
+ end
206
+ when :Object
207
+ # generic object (usually a Hash), return directly
208
+ value
209
+ when /\AArray<(?<inner_type>.+)>\z/
210
+ inner_type = Regexp.last_match[:inner_type]
211
+ value.map { |v| _deserialize(inner_type, v) }
212
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
213
+ k_type = Regexp.last_match[:k_type]
214
+ v_type = Regexp.last_match[:v_type]
215
+ {}.tap do |hash|
216
+ value.each do |k, v|
217
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
218
+ end
219
+ end
220
+ else # model
221
+ XeroRuby::AppStore.const_get(type).build_from_hash(value)
222
+ end
223
+ end
224
+
225
+ # Returns the string representation of the object
226
+ # @return [String] String presentation of the object
227
+ def to_s
228
+ to_hash.to_s
229
+ end
230
+
231
+ # to_body is an alias to to_hash (backward compatibility)
232
+ # @return [Hash] Returns the object in the form of hash
233
+ def to_body
234
+ to_hash
235
+ end
236
+
237
+ # Returns the object in the form of hash
238
+ # @return [Hash] Returns the object in the form of hash
239
+ def to_hash(downcase: false)
240
+ hash = {}
241
+ self.class.attribute_map.each_pair do |attr, param|
242
+ value = self.send(attr)
243
+ next if value.nil?
244
+ key = downcase ? attr : param
245
+ hash[key] = _to_hash(value, downcase: downcase)
246
+ end
247
+ hash
248
+ end
249
+
250
+ # Returns the object in the form of hash with snake_case
251
+ def to_attributes
252
+ to_hash(downcase: true)
253
+ end
254
+
255
+ # Outputs non-array value in the form of hash
256
+ # For object, use to_hash. Otherwise, just return the value
257
+ # @param [Object] value Any valid value
258
+ # @return [Hash] Returns the value in the form of hash
259
+ def _to_hash(value, downcase: false)
260
+ if value.is_a?(Array)
261
+ value.map do |v|
262
+ v.to_hash(downcase: downcase)
263
+ end
264
+ elsif value.is_a?(Hash)
265
+ {}.tap do |hash|
266
+ value.map { |k, v| hash[k] = _to_hash(v, downcase: downcase) }
267
+ end
268
+ elsif value.respond_to? :to_hash
269
+ value.to_hash(downcase: downcase)
270
+ else
271
+ value
272
+ end
273
+ end
274
+
275
+ def parse_date(datestring)
276
+ if datestring.include?('Date')
277
+ date_pattern = /\/Date\((-?\d+)(\+\d+)?\)\//
278
+ original, date, timezone = *date_pattern.match(datestring)
279
+ date = (date.to_i / 1000)
280
+ Time.at(date).utc.strftime('%Y-%m-%dT%H:%M:%S%z').to_s
281
+ elsif /(\d\d\d\d)-(\d\d)/.match(datestring) # handles dates w/out Days: YYYY-MM*-DD
282
+ Time.parse(datestring + '-01').strftime('%Y-%m-%dT%H:%M:%S').to_s
283
+ else # handle date 'types' for small subset of payroll API's
284
+ Time.parse(datestring).strftime('%Y-%m-%dT%H:%M:%S').to_s
285
+ end
286
+ end
287
+ end
288
+ end