xero-ruby 3.13.0 → 3.15.0

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