dear-inventory-ruby 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +28 -9
  3. data/docs/Account.md +43 -0
  4. data/docs/Accounts.md +21 -0
  5. data/docs/Address.md +2 -2
  6. data/docs/Contact.md +1 -1
  7. data/docs/Customer.md +7 -7
  8. data/docs/InventoryApi.md +731 -25
  9. data/docs/PaymentTerm.md +27 -0
  10. data/docs/PaymentTerms.md +21 -0
  11. data/docs/Success.md +17 -0
  12. data/docs/Tax.md +33 -0
  13. data/docs/TaxComponent.md +23 -0
  14. data/docs/Taxes.md +21 -0
  15. data/lib/dear-inventory-ruby.rb +8 -0
  16. data/lib/dear-inventory-ruby/api/inventory_api.rb +740 -14
  17. data/lib/dear-inventory-ruby/models/account.rb +477 -0
  18. data/lib/dear-inventory-ruby/models/accounts.rb +229 -0
  19. data/lib/dear-inventory-ruby/models/address.rb +10 -0
  20. data/lib/dear-inventory-ruby/models/contact.rb +12 -3
  21. data/lib/dear-inventory-ruby/models/customer.rb +42 -3
  22. data/lib/dear-inventory-ruby/models/payment_term.rb +319 -0
  23. data/lib/dear-inventory-ruby/models/payment_terms.rb +229 -0
  24. data/lib/dear-inventory-ruby/models/success.rb +207 -0
  25. data/lib/dear-inventory-ruby/models/tax.rb +360 -0
  26. data/lib/dear-inventory-ruby/models/tax_component.rb +306 -0
  27. data/lib/dear-inventory-ruby/models/taxes.rb +229 -0
  28. data/lib/dear-inventory-ruby/version.rb +1 -1
  29. data/spec/api/inventory_api_spec.rb +148 -4
  30. data/spec/models/account_spec.rb +131 -0
  31. data/spec/models/accounts_spec.rb +53 -0
  32. data/spec/models/payment_term_spec.rb +75 -0
  33. data/spec/models/payment_terms_spec.rb +53 -0
  34. data/spec/models/success_spec.rb +41 -0
  35. data/spec/models/tax_component_spec.rb +59 -0
  36. data/spec/models/tax_spec.rb +89 -0
  37. data/spec/models/taxes_spec.rb +53 -0
  38. metadata +34 -2
@@ -0,0 +1,229 @@
1
+ =begin
2
+ #DEAR Inventory API
3
+
4
+ #This specifing endpoints for DEAR Inventory API
5
+
6
+ The version of the OpenAPI document: 2.0.0
7
+ Contact: nnhansg@gmail.com
8
+ Generated by: https://openapi-generator.tech
9
+ OpenAPI Generator version: 4.2.3
10
+
11
+ =end
12
+
13
+ require 'date'
14
+
15
+ module DearInventoryRuby
16
+ class Accounts
17
+ # Total
18
+ attr_accessor :total
19
+
20
+ # Page
21
+ attr_accessor :page
22
+
23
+ # Array of Accounts
24
+ attr_accessor :accounts_list
25
+
26
+ # Attribute mapping from ruby-style variable name to JSON key.
27
+ def self.attribute_map
28
+ {
29
+ :'total' => :'Total',
30
+ :'page' => :'Page',
31
+ :'accounts_list' => :'AccountsList'
32
+ }
33
+ end
34
+
35
+ # Attribute type mapping.
36
+ def self.openapi_types
37
+ {
38
+ :'total' => :'String',
39
+ :'page' => :'String',
40
+ :'accounts_list' => :'Array<Account>'
41
+ }
42
+ end
43
+
44
+ # List of attributes with nullable: true
45
+ def self.openapi_nullable
46
+ Set.new([
47
+ ])
48
+ end
49
+
50
+ # Initializes the object
51
+ # @param [Hash] attributes Model attributes in the form of hash
52
+ def initialize(attributes = {})
53
+ if (!attributes.is_a?(Hash))
54
+ fail ArgumentError, "The input argument (attributes) must be a hash in `DearInventoryRuby::Accounts` initialize method"
55
+ end
56
+
57
+ # check to see if the attribute exists and convert string to symbol for hash key
58
+ attributes = attributes.each_with_object({}) { |(k, v), h|
59
+ if (!self.class.attribute_map.key?(k.to_sym))
60
+ fail ArgumentError, "`#{k}` is not a valid attribute in `DearInventoryRuby::Accounts`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
61
+ end
62
+ h[k.to_sym] = v
63
+ }
64
+
65
+ if attributes.key?(:'total')
66
+ self.total = attributes[:'total']
67
+ end
68
+
69
+ if attributes.key?(:'page')
70
+ self.page = attributes[:'page']
71
+ end
72
+
73
+ if attributes.key?(:'accounts_list')
74
+ if (value = attributes[:'accounts_list']).is_a?(Array)
75
+ self.accounts_list = value
76
+ end
77
+ end
78
+ end
79
+
80
+ # Show invalid properties with the reasons. Usually used together with valid?
81
+ # @return Array for valid properties with the reasons
82
+ def list_invalid_properties
83
+ invalid_properties = Array.new
84
+ invalid_properties
85
+ end
86
+
87
+ # Check to see if the all the properties in the model are valid
88
+ # @return true if the model is valid
89
+ def valid?
90
+ true
91
+ end
92
+
93
+ # Checks equality by comparing each attribute.
94
+ # @param [Object] Object to be compared
95
+ def ==(o)
96
+ return true if self.equal?(o)
97
+ self.class == o.class &&
98
+ total == o.total &&
99
+ page == o.page &&
100
+ accounts_list == o.accounts_list
101
+ end
102
+
103
+ # @see the `==` method
104
+ # @param [Object] Object to be compared
105
+ def eql?(o)
106
+ self == o
107
+ end
108
+
109
+ # Calculates hash code according to all attributes.
110
+ # @return [Integer] Hash code
111
+ def hash
112
+ [total, page, accounts_list].hash
113
+ end
114
+
115
+ # Builds the object from hash
116
+ # @param [Hash] attributes Model attributes in the form of hash
117
+ # @return [Object] Returns the model itself
118
+ def self.build_from_hash(attributes)
119
+ new.build_from_hash(attributes)
120
+ end
121
+
122
+ # Builds the object from hash
123
+ # @param [Hash] attributes Model attributes in the form of hash
124
+ # @return [Object] Returns the model itself
125
+ def build_from_hash(attributes)
126
+ return nil unless attributes.is_a?(Hash)
127
+ self.class.openapi_types.each_pair do |key, type|
128
+ if type =~ /\AArray<(.*)>/i
129
+ # check to ensure the input is an array given that the attribute
130
+ # is documented as an array but the input is not
131
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
132
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
133
+ end
134
+ elsif !attributes[self.class.attribute_map[key]].nil?
135
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
136
+ end # or else data not found in attributes(hash), not an issue as the data can be optional
137
+ end
138
+
139
+ self
140
+ end
141
+
142
+ # Deserializes the data based on type
143
+ # @param string type Data type
144
+ # @param string value Value to be deserialized
145
+ # @return [Object] Deserialized data
146
+ def _deserialize(type, value)
147
+ case type.to_sym
148
+ when :DateTime
149
+ DateTime.parse(value)
150
+ when :Date
151
+ Date.parse(value)
152
+ when :String
153
+ value.to_s
154
+ when :Integer
155
+ value.to_i
156
+ when :Float
157
+ value.to_f
158
+ when :Boolean
159
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
160
+ true
161
+ else
162
+ false
163
+ end
164
+ when :Object
165
+ # generic object (usually a Hash), return directly
166
+ value
167
+ when /\AArray<(?<inner_type>.+)>\z/
168
+ inner_type = Regexp.last_match[:inner_type]
169
+ value.map { |v| _deserialize(inner_type, v) }
170
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
171
+ k_type = Regexp.last_match[:k_type]
172
+ v_type = Regexp.last_match[:v_type]
173
+ {}.tap do |hash|
174
+ value.each do |k, v|
175
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
176
+ end
177
+ end
178
+ else # model
179
+ DearInventoryRuby.const_get(type).build_from_hash(value)
180
+ end
181
+ end
182
+
183
+ # Returns the string representation of the object
184
+ # @return [String] String presentation of the object
185
+ def to_s
186
+ to_hash.to_s
187
+ end
188
+
189
+ # to_body is an alias to to_hash (backward compatibility)
190
+ # @return [Hash] Returns the object in the form of hash
191
+ def to_body
192
+ to_hash
193
+ end
194
+
195
+ # Returns the object in the form of hash
196
+ # @return [Hash] Returns the object in the form of hash
197
+ def to_hash
198
+ hash = {}
199
+ self.class.attribute_map.each_pair do |attr, param|
200
+ value = self.send(attr)
201
+ if value.nil?
202
+ is_nullable = self.class.openapi_nullable.include?(attr)
203
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
204
+ end
205
+
206
+ hash[param] = _to_hash(value)
207
+ end
208
+ hash
209
+ end
210
+
211
+ # Outputs non-array value in the form of hash
212
+ # For object, use to_hash. Otherwise, just return the value
213
+ # @param [Object] value Any valid value
214
+ # @return [Hash] Returns the value in the form of hash
215
+ def _to_hash(value)
216
+ if value.is_a?(Array)
217
+ value.compact.map { |v| _to_hash(v) }
218
+ elsif value.is_a?(Hash)
219
+ {}.tap do |hash|
220
+ value.each { |k, v| hash[k] = _to_hash(v) }
221
+ end
222
+ elsif value.respond_to? :to_hash
223
+ value.to_hash
224
+ else
225
+ value
226
+ end
227
+ end
228
+ end
229
+ end
@@ -177,6 +177,14 @@ module DearInventoryRuby
177
177
  invalid_properties.push('invalid value for "post_code", the character length must be smaller than or equal to 20.')
178
178
  end
179
179
 
180
+ if @country.nil?
181
+ invalid_properties.push('invalid value for "country", country cannot be nil.')
182
+ end
183
+
184
+ if @type.nil?
185
+ invalid_properties.push('invalid value for "type", type cannot be nil.')
186
+ end
187
+
180
188
  invalid_properties
181
189
  end
182
190
 
@@ -188,6 +196,8 @@ module DearInventoryRuby
188
196
  return false if !@city.nil? && @city.to_s.length > 256
189
197
  return false if !@state.nil? && @state.to_s.length > 256
190
198
  return false if !@post_code.nil? && @post_code.to_s.length > 20
199
+ return false if @country.nil?
200
+ return false if @type.nil?
191
201
  type_validator = EnumAttributeValidator.new('String', ["Billing", "Business", "Shipping"])
192
202
  return false unless type_validator.valid?(@type)
193
203
  true
@@ -137,7 +137,11 @@ module DearInventoryRuby
137
137
  # @return Array for valid properties with the reasons
138
138
  def list_invalid_properties
139
139
  invalid_properties = Array.new
140
- if !@name.nil? && @name.to_s.length > 256
140
+ if @name.nil?
141
+ invalid_properties.push('invalid value for "name", name cannot be nil.')
142
+ end
143
+
144
+ if @name.to_s.length > 256
141
145
  invalid_properties.push('invalid value for "name", the character length must be smaller than or equal to 256.')
142
146
  end
143
147
 
@@ -167,7 +171,8 @@ module DearInventoryRuby
167
171
  # Check to see if the all the properties in the model are valid
168
172
  # @return true if the model is valid
169
173
  def valid?
170
- return false if !@name.nil? && @name.to_s.length > 256
174
+ return false if @name.nil?
175
+ return false if @name.to_s.length > 256
171
176
  return false if !@phone.nil? && @phone.to_s.length > 50
172
177
  return false if !@fax.nil? && @fax.to_s.length > 50
173
178
  return false if !@email.nil? && @email.to_s.length > 256
@@ -179,7 +184,11 @@ module DearInventoryRuby
179
184
  # Custom attribute writer method with validation
180
185
  # @param [Object] name Value to be assigned
181
186
  def name=(name)
182
- if !name.nil? && name.to_s.length > 256
187
+ if name.nil?
188
+ fail ArgumentError, 'name cannot be nil'
189
+ end
190
+
191
+ if name.to_s.length > 256
183
192
  fail ArgumentError, 'invalid value for "name", the character length must be smaller than or equal to 256.'
184
193
  end
185
194
 
@@ -356,10 +356,38 @@ module DearInventoryRuby
356
356
  # @return Array for valid properties with the reasons
357
357
  def list_invalid_properties
358
358
  invalid_properties = Array.new
359
- if !@name.nil? && @name.to_s.length > 256
359
+ if @name.nil?
360
+ invalid_properties.push('invalid value for "name", name cannot be nil.')
361
+ end
362
+
363
+ if @name.to_s.length > 256
360
364
  invalid_properties.push('invalid value for "name", the character length must be smaller than or equal to 256.')
361
365
  end
362
366
 
367
+ if @status.nil?
368
+ invalid_properties.push('invalid value for "status", status cannot be nil.')
369
+ end
370
+
371
+ if @currency.nil?
372
+ invalid_properties.push('invalid value for "currency", currency cannot be nil.')
373
+ end
374
+
375
+ if @payment_term.nil?
376
+ invalid_properties.push('invalid value for "payment_term", payment_term cannot be nil.')
377
+ end
378
+
379
+ if @account_receivable.nil?
380
+ invalid_properties.push('invalid value for "account_receivable", account_receivable cannot be nil.')
381
+ end
382
+
383
+ if @revenue_account.nil?
384
+ invalid_properties.push('invalid value for "revenue_account", revenue_account cannot be nil.')
385
+ end
386
+
387
+ if @tax_rule.nil?
388
+ invalid_properties.push('invalid value for "tax_rule", tax_rule cannot be nil.')
389
+ end
390
+
363
391
  if !@comments.nil? && @comments.to_s.length > 256
364
392
  invalid_properties.push('invalid value for "comments", the character length must be smaller than or equal to 256.')
365
393
  end
@@ -370,9 +398,16 @@ module DearInventoryRuby
370
398
  # Check to see if the all the properties in the model are valid
371
399
  # @return true if the model is valid
372
400
  def valid?
373
- return false if !@name.nil? && @name.to_s.length > 256
401
+ return false if @name.nil?
402
+ return false if @name.to_s.length > 256
403
+ return false if @status.nil?
374
404
  status_validator = EnumAttributeValidator.new('String', ["Active", "Deprecated"])
375
405
  return false unless status_validator.valid?(@status)
406
+ return false if @currency.nil?
407
+ return false if @payment_term.nil?
408
+ return false if @account_receivable.nil?
409
+ return false if @revenue_account.nil?
410
+ return false if @tax_rule.nil?
376
411
  return false if !@comments.nil? && @comments.to_s.length > 256
377
412
  true
378
413
  end
@@ -380,7 +415,11 @@ module DearInventoryRuby
380
415
  # Custom attribute writer method with validation
381
416
  # @param [Object] name Value to be assigned
382
417
  def name=(name)
383
- if !name.nil? && name.to_s.length > 256
418
+ if name.nil?
419
+ fail ArgumentError, 'name cannot be nil'
420
+ end
421
+
422
+ if name.to_s.length > 256
384
423
  fail ArgumentError, 'invalid value for "name", the character length must be smaller than or equal to 256.'
385
424
  end
386
425
 
@@ -0,0 +1,319 @@
1
+ =begin
2
+ #DEAR Inventory API
3
+
4
+ #This specifing endpoints for DEAR Inventory API
5
+
6
+ The version of the OpenAPI document: 2.0.0
7
+ Contact: nnhansg@gmail.com
8
+ Generated by: https://openapi-generator.tech
9
+ OpenAPI Generator version: 4.2.3
10
+
11
+ =end
12
+
13
+ require 'date'
14
+
15
+ module DearInventoryRuby
16
+ class PaymentTerm
17
+ # Unique Payment Term ID
18
+ attr_accessor :id
19
+
20
+ # Name of Payment Term
21
+ attr_accessor :name
22
+
23
+ # Minimum Payment Term duration in days
24
+ attr_accessor :duration
25
+
26
+ # Method of Payment Term. Should be one of the following values: `number of days`, `day of next month`, `last day of next month`, `days since the end of the month`
27
+ attr_accessor :method
28
+
29
+ # Points that Payment Term is Active. `True` as default for POST.
30
+ attr_accessor :is_active
31
+
32
+ # Points that Payment Term is Default. `False` as default for POST.
33
+ attr_accessor :is_default
34
+
35
+ class EnumAttributeValidator
36
+ attr_reader :datatype
37
+ attr_reader :allowable_values
38
+
39
+ def initialize(datatype, allowable_values)
40
+ @allowable_values = allowable_values.map do |value|
41
+ case datatype.to_s
42
+ when /Integer/i
43
+ value.to_i
44
+ when /Float/i
45
+ value.to_f
46
+ else
47
+ value
48
+ end
49
+ end
50
+ end
51
+
52
+ def valid?(value)
53
+ !value || allowable_values.include?(value)
54
+ end
55
+ end
56
+
57
+ # Attribute mapping from ruby-style variable name to JSON key.
58
+ def self.attribute_map
59
+ {
60
+ :'id' => :'ID',
61
+ :'name' => :'Name',
62
+ :'duration' => :'Duration',
63
+ :'method' => :'Method',
64
+ :'is_active' => :'IsActive',
65
+ :'is_default' => :'IsDefault'
66
+ }
67
+ end
68
+
69
+ # Attribute type mapping.
70
+ def self.openapi_types
71
+ {
72
+ :'id' => :'String',
73
+ :'name' => :'String',
74
+ :'duration' => :'String',
75
+ :'method' => :'String',
76
+ :'is_active' => :'Boolean',
77
+ :'is_default' => :'Boolean'
78
+ }
79
+ end
80
+
81
+ # List of attributes with nullable: true
82
+ def self.openapi_nullable
83
+ Set.new([
84
+ ])
85
+ end
86
+
87
+ # Initializes the object
88
+ # @param [Hash] attributes Model attributes in the form of hash
89
+ def initialize(attributes = {})
90
+ if (!attributes.is_a?(Hash))
91
+ fail ArgumentError, "The input argument (attributes) must be a hash in `DearInventoryRuby::PaymentTerm` initialize method"
92
+ end
93
+
94
+ # check to see if the attribute exists and convert string to symbol for hash key
95
+ attributes = attributes.each_with_object({}) { |(k, v), h|
96
+ if (!self.class.attribute_map.key?(k.to_sym))
97
+ fail ArgumentError, "`#{k}` is not a valid attribute in `DearInventoryRuby::PaymentTerm`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
98
+ end
99
+ h[k.to_sym] = v
100
+ }
101
+
102
+ if attributes.key?(:'id')
103
+ self.id = attributes[:'id']
104
+ end
105
+
106
+ if attributes.key?(:'name')
107
+ self.name = attributes[:'name']
108
+ end
109
+
110
+ if attributes.key?(:'duration')
111
+ self.duration = attributes[:'duration']
112
+ end
113
+
114
+ if attributes.key?(:'method')
115
+ self.method = attributes[:'method']
116
+ end
117
+
118
+ if attributes.key?(:'is_active')
119
+ self.is_active = attributes[:'is_active']
120
+ else
121
+ self.is_active = true
122
+ end
123
+
124
+ if attributes.key?(:'is_default')
125
+ self.is_default = attributes[:'is_default']
126
+ else
127
+ self.is_default = false
128
+ end
129
+ end
130
+
131
+ # Show invalid properties with the reasons. Usually used together with valid?
132
+ # @return Array for valid properties with the reasons
133
+ def list_invalid_properties
134
+ invalid_properties = Array.new
135
+ if @name.nil?
136
+ invalid_properties.push('invalid value for "name", name cannot be nil.')
137
+ end
138
+
139
+ if @name.to_s.length > 256
140
+ invalid_properties.push('invalid value for "name", the character length must be smaller than or equal to 256.')
141
+ end
142
+
143
+ invalid_properties
144
+ end
145
+
146
+ # Check to see if the all the properties in the model are valid
147
+ # @return true if the model is valid
148
+ def valid?
149
+ return false if @name.nil?
150
+ return false if @name.to_s.length > 256
151
+ method_validator = EnumAttributeValidator.new('String', ["number of days", "day of next month", "last day of next month", "days since the end of the month"])
152
+ return false unless method_validator.valid?(@method)
153
+ true
154
+ end
155
+
156
+ # Custom attribute writer method with validation
157
+ # @param [Object] name Value to be assigned
158
+ def name=(name)
159
+ if name.nil?
160
+ fail ArgumentError, 'name cannot be nil'
161
+ end
162
+
163
+ if name.to_s.length > 256
164
+ fail ArgumentError, 'invalid value for "name", the character length must be smaller than or equal to 256.'
165
+ end
166
+
167
+ @name = name
168
+ end
169
+
170
+ # Custom attribute writer method checking allowed values (enum).
171
+ # @param [Object] method Object to be assigned
172
+ def method=(method)
173
+ validator = EnumAttributeValidator.new('String', ["number of days", "day of next month", "last day of next month", "days since the end of the month"])
174
+ unless validator.valid?(method)
175
+ fail ArgumentError, "invalid value for \"method\", must be one of #{validator.allowable_values}."
176
+ end
177
+ @method = method
178
+ end
179
+
180
+ # Checks equality by comparing each attribute.
181
+ # @param [Object] Object to be compared
182
+ def ==(o)
183
+ return true if self.equal?(o)
184
+ self.class == o.class &&
185
+ id == o.id &&
186
+ name == o.name &&
187
+ duration == o.duration &&
188
+ method == o.method &&
189
+ is_active == o.is_active &&
190
+ is_default == o.is_default
191
+ end
192
+
193
+ # @see the `==` method
194
+ # @param [Object] Object to be compared
195
+ def eql?(o)
196
+ self == o
197
+ end
198
+
199
+ # Calculates hash code according to all attributes.
200
+ # @return [Integer] Hash code
201
+ def hash
202
+ [id, name, duration, method, is_active, is_default].hash
203
+ end
204
+
205
+ # Builds the object from hash
206
+ # @param [Hash] attributes Model attributes in the form of hash
207
+ # @return [Object] Returns the model itself
208
+ def self.build_from_hash(attributes)
209
+ new.build_from_hash(attributes)
210
+ end
211
+
212
+ # Builds the object from hash
213
+ # @param [Hash] attributes Model attributes in the form of hash
214
+ # @return [Object] Returns the model itself
215
+ def build_from_hash(attributes)
216
+ return nil unless attributes.is_a?(Hash)
217
+ self.class.openapi_types.each_pair do |key, type|
218
+ if type =~ /\AArray<(.*)>/i
219
+ # check to ensure the input is an array given that the attribute
220
+ # is documented as an array but the input is not
221
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
222
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
223
+ end
224
+ elsif !attributes[self.class.attribute_map[key]].nil?
225
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
226
+ end # or else data not found in attributes(hash), not an issue as the data can be optional
227
+ end
228
+
229
+ self
230
+ end
231
+
232
+ # Deserializes the data based on type
233
+ # @param string type Data type
234
+ # @param string value Value to be deserialized
235
+ # @return [Object] Deserialized data
236
+ def _deserialize(type, value)
237
+ case type.to_sym
238
+ when :DateTime
239
+ DateTime.parse(value)
240
+ when :Date
241
+ Date.parse(value)
242
+ when :String
243
+ value.to_s
244
+ when :Integer
245
+ value.to_i
246
+ when :Float
247
+ value.to_f
248
+ when :Boolean
249
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
250
+ true
251
+ else
252
+ false
253
+ end
254
+ when :Object
255
+ # generic object (usually a Hash), return directly
256
+ value
257
+ when /\AArray<(?<inner_type>.+)>\z/
258
+ inner_type = Regexp.last_match[:inner_type]
259
+ value.map { |v| _deserialize(inner_type, v) }
260
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
261
+ k_type = Regexp.last_match[:k_type]
262
+ v_type = Regexp.last_match[:v_type]
263
+ {}.tap do |hash|
264
+ value.each do |k, v|
265
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
266
+ end
267
+ end
268
+ else # model
269
+ DearInventoryRuby.const_get(type).build_from_hash(value)
270
+ end
271
+ end
272
+
273
+ # Returns the string representation of the object
274
+ # @return [String] String presentation of the object
275
+ def to_s
276
+ to_hash.to_s
277
+ end
278
+
279
+ # to_body is an alias to to_hash (backward compatibility)
280
+ # @return [Hash] Returns the object in the form of hash
281
+ def to_body
282
+ to_hash
283
+ end
284
+
285
+ # Returns the object in the form of hash
286
+ # @return [Hash] Returns the object in the form of hash
287
+ def to_hash
288
+ hash = {}
289
+ self.class.attribute_map.each_pair do |attr, param|
290
+ value = self.send(attr)
291
+ if value.nil?
292
+ is_nullable = self.class.openapi_nullable.include?(attr)
293
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
294
+ end
295
+
296
+ hash[param] = _to_hash(value)
297
+ end
298
+ hash
299
+ end
300
+
301
+ # Outputs non-array value in the form of hash
302
+ # For object, use to_hash. Otherwise, just return the value
303
+ # @param [Object] value Any valid value
304
+ # @return [Hash] Returns the value in the form of hash
305
+ def _to_hash(value)
306
+ if value.is_a?(Array)
307
+ value.compact.map { |v| _to_hash(v) }
308
+ elsif value.is_a?(Hash)
309
+ {}.tap do |hash|
310
+ value.each { |k, v| hash[k] = _to_hash(v) }
311
+ end
312
+ elsif value.respond_to? :to_hash
313
+ value.to_hash
314
+ else
315
+ value
316
+ end
317
+ end
318
+ end
319
+ end