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,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
@@ -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