xero-ruby 3.2.1 → 3.3.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.
@@ -0,0 +1,278 @@
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
+ class EnumAttributeValidator
31
+ attr_reader :datatype
32
+ attr_reader :allowable_values
33
+
34
+ def initialize(datatype, allowable_values)
35
+ @allowable_values = allowable_values.map do |value|
36
+ case datatype.to_s
37
+ when /Integer/i
38
+ value.to_i
39
+ when /Float/i
40
+ value.to_f
41
+ else
42
+ value
43
+ end
44
+ end
45
+ end
46
+
47
+ def valid?(value)
48
+ !value || allowable_values.include?(value)
49
+ end
50
+ end
51
+
52
+ # Attribute mapping from ruby-style variable name to JSON key.
53
+ def self.attribute_map
54
+ {
55
+ :'id' => :'id',
56
+ :'name' => :'name',
57
+ :'type' => :'type'
58
+ }
59
+ end
60
+
61
+ # Attribute type mapping.
62
+ def self.openapi_types
63
+ {
64
+ :'id' => :'String',
65
+ :'name' => :'String',
66
+ :'type' => :'String'
67
+ }
68
+ end
69
+
70
+ # Initializes the object
71
+ # @param [Hash] attributes Model attributes in the form of hash
72
+ def initialize(attributes = {})
73
+ if (!attributes.is_a?(Hash))
74
+ fail ArgumentError, "The input argument (attributes) must be a hash in `XeroRuby::AppStore::Product` initialize method"
75
+ end
76
+
77
+ # check to see if the attribute exists and convert string to symbol for hash key
78
+ attributes = attributes.each_with_object({}) { |(k, v), h|
79
+ if (!self.class.attribute_map.key?(k.to_sym))
80
+ 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
81
+ end
82
+ h[k.to_sym] = v
83
+ }
84
+
85
+ if attributes.key?(:'id')
86
+ self.id = attributes[:'id']
87
+ end
88
+
89
+ if attributes.key?(:'name')
90
+ self.name = attributes[:'name']
91
+ end
92
+
93
+ if attributes.key?(:'type')
94
+ self.type = attributes[:'type']
95
+ end
96
+ end
97
+
98
+ # Show invalid properties with the reasons. Usually used together with valid?
99
+ # @return Array for valid properties with the reasons
100
+ def list_invalid_properties
101
+ invalid_properties = Array.new
102
+ invalid_properties
103
+ end
104
+
105
+ # Check to see if the all the properties in the model are valid
106
+ # @return true if the model is valid
107
+ def valid?
108
+ type_validator = EnumAttributeValidator.new('String', ["FIXED", "PER_SEAT"])
109
+ return false unless type_validator.valid?(@type)
110
+ true
111
+ end
112
+
113
+ # Custom attribute writer method checking allowed values (enum).
114
+ # @param [Object] type Object to be assigned
115
+ def type=(type)
116
+ validator = EnumAttributeValidator.new('String', ["FIXED", "PER_SEAT"])
117
+ unless validator.valid?(type)
118
+ fail ArgumentError, "invalid value for \"type\", must be one of #{validator.allowable_values}."
119
+ end
120
+ @type = type
121
+ end
122
+
123
+ # Checks equality by comparing each attribute.
124
+ # @param [Object] Object to be compared
125
+ def ==(o)
126
+ return true if self.equal?(o)
127
+ self.class == o.class &&
128
+ id == o.id &&
129
+ name == o.name &&
130
+ type == o.type
131
+ end
132
+
133
+ # @see the `==` method
134
+ # @param [Object] Object to be compared
135
+ def eql?(o)
136
+ self == o
137
+ end
138
+
139
+ # Calculates hash code according to all attributes.
140
+ # @return [Integer] Hash code
141
+ def hash
142
+ [id, name, type].hash
143
+ end
144
+
145
+ # Builds the object from hash
146
+ # @param [Hash] attributes Model attributes in the form of hash
147
+ # @return [Object] Returns the model itself
148
+ def self.build_from_hash(attributes)
149
+ new.build_from_hash(attributes)
150
+ end
151
+
152
+ # Builds the object from hash
153
+ # @param [Hash] attributes Model attributes in the form of hash
154
+ # @return [Object] Returns the model itself
155
+ def build_from_hash(attributes)
156
+ return nil unless attributes.is_a?(Hash)
157
+ self.class.openapi_types.each_pair do |key, type|
158
+ if type =~ /\AArray<(.*)>/i
159
+ # check to ensure the input is an array given that the attribute
160
+ # is documented as an array but the input is not
161
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
162
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
163
+ end
164
+ elsif !attributes[self.class.attribute_map[key]].nil?
165
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
166
+ end # or else data not found in attributes(hash), not an issue as the data can be optional
167
+ end
168
+
169
+ self
170
+ end
171
+
172
+ # Deserializes the data based on type
173
+ # @param string type Data type
174
+ # @param string value Value to be deserialized
175
+ # @return [Object] Deserialized data
176
+ def _deserialize(type, value)
177
+ case type.to_sym
178
+ when :DateTime
179
+ DateTime.parse(parse_date(value))
180
+ when :Date
181
+ Date.parse(parse_date(value))
182
+ when :String
183
+ value.to_s
184
+ when :Integer
185
+ value.to_i
186
+ when :Float
187
+ value.to_f
188
+ when :BigDecimal
189
+ BigDecimal(value.to_s)
190
+ when :Boolean
191
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
192
+ true
193
+ else
194
+ false
195
+ end
196
+ when :Object
197
+ # generic object (usually a Hash), return directly
198
+ value
199
+ when /\AArray<(?<inner_type>.+)>\z/
200
+ inner_type = Regexp.last_match[:inner_type]
201
+ value.map { |v| _deserialize(inner_type, v) }
202
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
203
+ k_type = Regexp.last_match[:k_type]
204
+ v_type = Regexp.last_match[:v_type]
205
+ {}.tap do |hash|
206
+ value.each do |k, v|
207
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
208
+ end
209
+ end
210
+ else # model
211
+ XeroRuby::AppStore.const_get(type).build_from_hash(value)
212
+ end
213
+ end
214
+
215
+ # Returns the string representation of the object
216
+ # @return [String] String presentation of the object
217
+ def to_s
218
+ to_hash.to_s
219
+ end
220
+
221
+ # to_body is an alias to to_hash (backward compatibility)
222
+ # @return [Hash] Returns the object in the form of hash
223
+ def to_body
224
+ to_hash
225
+ end
226
+
227
+ # Returns the object in the form of hash
228
+ # @return [Hash] Returns the object in the form of hash
229
+ def to_hash(downcase: false)
230
+ hash = {}
231
+ self.class.attribute_map.each_pair do |attr, param|
232
+ value = self.send(attr)
233
+ next if value.nil?
234
+ key = downcase ? attr : param
235
+ hash[key] = _to_hash(value, downcase: downcase)
236
+ end
237
+ hash
238
+ end
239
+
240
+ # Returns the object in the form of hash with snake_case
241
+ def to_attributes
242
+ to_hash(downcase: true)
243
+ end
244
+
245
+ # Outputs non-array value in the form of hash
246
+ # For object, use to_hash. Otherwise, just return the value
247
+ # @param [Object] value Any valid value
248
+ # @return [Hash] Returns the value in the form of hash
249
+ def _to_hash(value, downcase: false)
250
+ if value.is_a?(Array)
251
+ value.map do |v|
252
+ v.to_hash(downcase: downcase)
253
+ end
254
+ elsif value.is_a?(Hash)
255
+ {}.tap do |hash|
256
+ value.map { |k, v| hash[k] = _to_hash(v, downcase: downcase) }
257
+ end
258
+ elsif value.respond_to? :to_hash
259
+ value.to_hash(downcase: downcase)
260
+ else
261
+ value
262
+ end
263
+ end
264
+
265
+ def parse_date(datestring)
266
+ if datestring.include?('Date')
267
+ date_pattern = /\/Date\((-?\d+)(\+\d+)?\)\//
268
+ original, date, timezone = *date_pattern.match(datestring)
269
+ date = (date.to_i / 1000)
270
+ Time.at(date).utc.strftime('%Y-%m-%dT%H:%M:%S%z').to_s
271
+ elsif /(\d\d\d\d)-(\d\d)/.match(datestring) # handles dates w/out Days: YYYY-MM*-DD
272
+ Time.parse(datestring + '-01').strftime('%Y-%m-%dT%H:%M:%S').to_s
273
+ else # handle date 'types' for small subset of payroll API's
274
+ Time.parse(datestring).strftime('%Y-%m-%dT%H:%M:%S').to_s
275
+ end
276
+ end
277
+ end
278
+ end
@@ -0,0 +1,324 @@
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 Subscription
19
+ # End of the current period that the subscription has been invoiced for.
20
+ attr_accessor :current_period_end
21
+
22
+ # If the subscription has been canceled, this is the date when the subscription ends. If null, the subscription is active and has not been cancelled
23
+ attr_accessor :end_date
24
+
25
+ # The unique identifier of the subscription
26
+ attr_accessor :id
27
+
28
+ # The Xero generated unique identifier for the organisation
29
+ attr_accessor :organisation_id
30
+
31
+ # List of plans for the subscription.
32
+ attr_accessor :plans
33
+
34
+ # Date when the subscription was first created.
35
+ attr_accessor :start_date
36
+
37
+ # Status of the subscription. Available statuses are ACTIVE, CANCELED, and PAST_DUE.
38
+ attr_accessor :status
39
+
40
+ # Boolean used to indicate if the subscription is in test mode
41
+ attr_accessor :test_mode
42
+
43
+ # Attribute mapping from ruby-style variable name to JSON key.
44
+ def self.attribute_map
45
+ {
46
+ :'current_period_end' => :'currentPeriodEnd',
47
+ :'end_date' => :'endDate',
48
+ :'id' => :'id',
49
+ :'organisation_id' => :'organisationId',
50
+ :'plans' => :'plans',
51
+ :'start_date' => :'startDate',
52
+ :'status' => :'status',
53
+ :'test_mode' => :'testMode'
54
+ }
55
+ end
56
+
57
+ # Attribute type mapping.
58
+ def self.openapi_types
59
+ {
60
+ :'current_period_end' => :'DateTime',
61
+ :'end_date' => :'DateTime',
62
+ :'id' => :'String',
63
+ :'organisation_id' => :'String',
64
+ :'plans' => :'Array<Plan>',
65
+ :'start_date' => :'DateTime',
66
+ :'status' => :'String',
67
+ :'test_mode' => :'Boolean'
68
+ }
69
+ end
70
+
71
+ # Initializes the object
72
+ # @param [Hash] attributes Model attributes in the form of hash
73
+ def initialize(attributes = {})
74
+ if (!attributes.is_a?(Hash))
75
+ fail ArgumentError, "The input argument (attributes) must be a hash in `XeroRuby::AppStore::Subscription` initialize method"
76
+ end
77
+
78
+ # check to see if the attribute exists and convert string to symbol for hash key
79
+ attributes = attributes.each_with_object({}) { |(k, v), h|
80
+ if (!self.class.attribute_map.key?(k.to_sym))
81
+ fail ArgumentError, "`#{k}` is not a valid attribute in `XeroRuby::AppStore::Subscription`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
82
+ end
83
+ h[k.to_sym] = v
84
+ }
85
+
86
+ if attributes.key?(:'current_period_end')
87
+ self.current_period_end = attributes[:'current_period_end']
88
+ end
89
+
90
+ if attributes.key?(:'end_date')
91
+ self.end_date = attributes[:'end_date']
92
+ end
93
+
94
+ if attributes.key?(:'id')
95
+ self.id = attributes[:'id']
96
+ end
97
+
98
+ if attributes.key?(:'organisation_id')
99
+ self.organisation_id = attributes[:'organisation_id']
100
+ end
101
+
102
+ if attributes.key?(:'plans')
103
+ if (value = attributes[:'plans']).is_a?(Array)
104
+ self.plans = value
105
+ end
106
+ end
107
+
108
+ if attributes.key?(:'start_date')
109
+ self.start_date = attributes[:'start_date']
110
+ end
111
+
112
+ if attributes.key?(:'status')
113
+ self.status = attributes[:'status']
114
+ end
115
+
116
+ if attributes.key?(:'test_mode')
117
+ self.test_mode = attributes[:'test_mode']
118
+ end
119
+ end
120
+
121
+ # Show invalid properties with the reasons. Usually used together with valid?
122
+ # @return Array for valid properties with the reasons
123
+ def list_invalid_properties
124
+ invalid_properties = Array.new
125
+ if @current_period_end.nil?
126
+ invalid_properties.push('invalid value for "current_period_end", current_period_end cannot be nil.')
127
+ end
128
+
129
+ if @id.nil?
130
+ invalid_properties.push('invalid value for "id", id cannot be nil.')
131
+ end
132
+
133
+ if @organisation_id.nil?
134
+ invalid_properties.push('invalid value for "organisation_id", organisation_id cannot be nil.')
135
+ end
136
+
137
+ if @plans.nil?
138
+ invalid_properties.push('invalid value for "plans", plans cannot be nil.')
139
+ end
140
+
141
+ if @start_date.nil?
142
+ invalid_properties.push('invalid value for "start_date", start_date cannot be nil.')
143
+ end
144
+
145
+ if @status.nil?
146
+ invalid_properties.push('invalid value for "status", status cannot be nil.')
147
+ end
148
+
149
+ invalid_properties
150
+ end
151
+
152
+ # Check to see if the all the properties in the model are valid
153
+ # @return true if the model is valid
154
+ def valid?
155
+ return false if @current_period_end.nil?
156
+ return false if @id.nil?
157
+ return false if @organisation_id.nil?
158
+ return false if @plans.nil?
159
+ return false if @start_date.nil?
160
+ return false if @status.nil?
161
+ true
162
+ end
163
+
164
+ # Checks equality by comparing each attribute.
165
+ # @param [Object] Object to be compared
166
+ def ==(o)
167
+ return true if self.equal?(o)
168
+ self.class == o.class &&
169
+ current_period_end == o.current_period_end &&
170
+ end_date == o.end_date &&
171
+ id == o.id &&
172
+ organisation_id == o.organisation_id &&
173
+ plans == o.plans &&
174
+ start_date == o.start_date &&
175
+ status == o.status &&
176
+ test_mode == o.test_mode
177
+ end
178
+
179
+ # @see the `==` method
180
+ # @param [Object] Object to be compared
181
+ def eql?(o)
182
+ self == o
183
+ end
184
+
185
+ # Calculates hash code according to all attributes.
186
+ # @return [Integer] Hash code
187
+ def hash
188
+ [current_period_end, end_date, id, organisation_id, plans, start_date, status, test_mode].hash
189
+ end
190
+
191
+ # Builds the object from hash
192
+ # @param [Hash] attributes Model attributes in the form of hash
193
+ # @return [Object] Returns the model itself
194
+ def self.build_from_hash(attributes)
195
+ new.build_from_hash(attributes)
196
+ end
197
+
198
+ # Builds the object from hash
199
+ # @param [Hash] attributes Model attributes in the form of hash
200
+ # @return [Object] Returns the model itself
201
+ def build_from_hash(attributes)
202
+ return nil unless attributes.is_a?(Hash)
203
+ self.class.openapi_types.each_pair do |key, type|
204
+ if type =~ /\AArray<(.*)>/i
205
+ # check to ensure the input is an array given that the attribute
206
+ # is documented as an array but the input is not
207
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
208
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
209
+ end
210
+ elsif !attributes[self.class.attribute_map[key]].nil?
211
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
212
+ end # or else data not found in attributes(hash), not an issue as the data can be optional
213
+ end
214
+
215
+ self
216
+ end
217
+
218
+ # Deserializes the data based on type
219
+ # @param string type Data type
220
+ # @param string value Value to be deserialized
221
+ # @return [Object] Deserialized data
222
+ def _deserialize(type, value)
223
+ case type.to_sym
224
+ when :DateTime
225
+ DateTime.parse(parse_date(value))
226
+ when :Date
227
+ Date.parse(parse_date(value))
228
+ when :String
229
+ value.to_s
230
+ when :Integer
231
+ value.to_i
232
+ when :Float
233
+ value.to_f
234
+ when :BigDecimal
235
+ BigDecimal(value.to_s)
236
+ when :Boolean
237
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
238
+ true
239
+ else
240
+ false
241
+ end
242
+ when :Object
243
+ # generic object (usually a Hash), return directly
244
+ value
245
+ when /\AArray<(?<inner_type>.+)>\z/
246
+ inner_type = Regexp.last_match[:inner_type]
247
+ value.map { |v| _deserialize(inner_type, v) }
248
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
249
+ k_type = Regexp.last_match[:k_type]
250
+ v_type = Regexp.last_match[:v_type]
251
+ {}.tap do |hash|
252
+ value.each do |k, v|
253
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
254
+ end
255
+ end
256
+ else # model
257
+ XeroRuby::AppStore.const_get(type).build_from_hash(value)
258
+ end
259
+ end
260
+
261
+ # Returns the string representation of the object
262
+ # @return [String] String presentation of the object
263
+ def to_s
264
+ to_hash.to_s
265
+ end
266
+
267
+ # to_body is an alias to to_hash (backward compatibility)
268
+ # @return [Hash] Returns the object in the form of hash
269
+ def to_body
270
+ to_hash
271
+ end
272
+
273
+ # Returns the object in the form of hash
274
+ # @return [Hash] Returns the object in the form of hash
275
+ def to_hash(downcase: false)
276
+ hash = {}
277
+ self.class.attribute_map.each_pair do |attr, param|
278
+ value = self.send(attr)
279
+ next if value.nil?
280
+ key = downcase ? attr : param
281
+ hash[key] = _to_hash(value, downcase: downcase)
282
+ end
283
+ hash
284
+ end
285
+
286
+ # Returns the object in the form of hash with snake_case
287
+ def to_attributes
288
+ to_hash(downcase: true)
289
+ end
290
+
291
+ # Outputs non-array value in the form of hash
292
+ # For object, use to_hash. Otherwise, just return the value
293
+ # @param [Object] value Any valid value
294
+ # @return [Hash] Returns the value in the form of hash
295
+ def _to_hash(value, downcase: false)
296
+ if value.is_a?(Array)
297
+ value.map do |v|
298
+ v.to_hash(downcase: downcase)
299
+ end
300
+ elsif value.is_a?(Hash)
301
+ {}.tap do |hash|
302
+ value.map { |k, v| hash[k] = _to_hash(v, downcase: downcase) }
303
+ end
304
+ elsif value.respond_to? :to_hash
305
+ value.to_hash(downcase: downcase)
306
+ else
307
+ value
308
+ end
309
+ end
310
+
311
+ def parse_date(datestring)
312
+ if datestring.include?('Date')
313
+ date_pattern = /\/Date\((-?\d+)(\+\d+)?\)\//
314
+ original, date, timezone = *date_pattern.match(datestring)
315
+ date = (date.to_i / 1000)
316
+ Time.at(date).utc.strftime('%Y-%m-%dT%H:%M:%S%z').to_s
317
+ elsif /(\d\d\d\d)-(\d\d)/.match(datestring) # handles dates w/out Days: YYYY-MM*-DD
318
+ Time.parse(datestring + '-01').strftime('%Y-%m-%dT%H:%M:%S').to_s
319
+ else # handle date 'types' for small subset of payroll API's
320
+ Time.parse(datestring).strftime('%Y-%m-%dT%H:%M:%S').to_s
321
+ end
322
+ end
323
+ end
324
+ end