tradenity 0.1.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (95) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +7 -0
  3. data/README.md +89 -77
  4. data/lib/tradenity/api_client.rb +408 -0
  5. data/lib/tradenity/api_error.rb +36 -0
  6. data/lib/tradenity/configuration.rb +205 -0
  7. data/lib/tradenity/exceptions.rb +5 -0
  8. data/lib/tradenity/rails/railtie.rb +20 -20
  9. data/lib/tradenity/resources/address.rb +729 -0
  10. data/lib/tradenity/resources/braintree_gateway.rb +804 -0
  11. data/lib/tradenity/resources/brand.rb +732 -0
  12. data/lib/tradenity/resources/cancel_operation.rb +675 -0
  13. data/lib/tradenity/resources/cart_settings.rb +219 -0
  14. data/lib/tradenity/resources/cash_on_delivery_payment.rb +746 -0
  15. data/lib/tradenity/resources/category.rb +763 -0
  16. data/lib/tradenity/resources/collection.rb +734 -0
  17. data/lib/tradenity/resources/contact_info.rb +306 -0
  18. data/lib/tradenity/resources/countries_geo_zone.rb +739 -0
  19. data/lib/tradenity/resources/country.rb +803 -0
  20. data/lib/tradenity/resources/coupon.rb +454 -0
  21. data/lib/tradenity/resources/credit_card_payment.rb +803 -0
  22. data/lib/tradenity/resources/currency.rb +762 -0
  23. data/lib/tradenity/resources/customer.rb +816 -0
  24. data/lib/tradenity/resources/customer_group.rb +723 -0
  25. data/lib/tradenity/resources/dimensions.rb +263 -0
  26. data/lib/tradenity/resources/discount_coupon.rb +811 -0
  27. data/lib/tradenity/resources/discount_promotion.rb +784 -0
  28. data/lib/tradenity/resources/fixed_rate_shipping.rb +837 -0
  29. data/lib/tradenity/resources/free_item_coupon.rb +793 -0
  30. data/lib/tradenity/resources/free_shipping.rb +806 -0
  31. data/lib/tradenity/resources/free_shipping_coupon.rb +788 -0
  32. data/lib/tradenity/resources/free_shipping_promotion.rb +744 -0
  33. data/lib/tradenity/resources/gateway.rb +435 -0
  34. data/lib/tradenity/resources/general_settings.rb +206 -0
  35. data/lib/tradenity/resources/geo_zone.rb +406 -0
  36. data/lib/tradenity/resources/instance_meta.rb +182 -0
  37. data/lib/tradenity/resources/inventory_settings.rb +197 -0
  38. data/lib/tradenity/resources/items_selector.rb +270 -0
  39. data/lib/tradenity/resources/line_item.rb +347 -0
  40. data/lib/tradenity/resources/mail_server_settings.rb +221 -0
  41. data/lib/tradenity/resources/measurement_settings.rb +253 -0
  42. data/lib/tradenity/resources/option.rb +787 -0
  43. data/lib/tradenity/resources/option_set.rb +734 -0
  44. data/lib/tradenity/resources/option_value.rb +680 -0
  45. data/lib/tradenity/resources/order.rb +929 -0
  46. data/lib/tradenity/resources/order_line_item.rb +777 -0
  47. data/lib/tradenity/resources/paging.rb +38 -0
  48. data/lib/tradenity/resources/payment.rb +429 -0
  49. data/lib/tradenity/resources/payment_card.rb +847 -0
  50. data/lib/tradenity/resources/payment_settings.rb +201 -0
  51. data/lib/tradenity/resources/payment_source.rb +392 -0
  52. data/lib/tradenity/resources/payment_token.rb +723 -0
  53. data/lib/tradenity/resources/payment_transaction.rb +740 -0
  54. data/lib/tradenity/resources/photo.rb +341 -0
  55. data/lib/tradenity/resources/product.rb +1156 -0
  56. data/lib/tradenity/resources/promotion.rb +427 -0
  57. data/lib/tradenity/resources/refund_operation.rb +358 -0
  58. data/lib/tradenity/resources/refund_transaction.rb +730 -0
  59. data/lib/tradenity/resources/return_line_item.rb +781 -0
  60. data/lib/tradenity/resources/return_operation.rb +686 -0
  61. data/lib/tradenity/resources/return_settings.rb +255 -0
  62. data/lib/tradenity/resources/shipping_method.rb +530 -0
  63. data/lib/tradenity/resources/shopping_cart.rb +647 -0
  64. data/lib/tradenity/resources/state.rb +675 -0
  65. data/lib/tradenity/resources/states_geo_zone.rb +748 -0
  66. data/lib/tradenity/resources/store_credit.rb +686 -0
  67. data/lib/tradenity/resources/store_credit_payment.rb +764 -0
  68. data/lib/tradenity/resources/store_credit_transaction.rb +730 -0
  69. data/lib/tradenity/resources/store_profile.rb +532 -0
  70. data/lib/tradenity/resources/stripe_gateway.rb +804 -0
  71. data/lib/tradenity/resources/table_rate_rule.rb +712 -0
  72. data/lib/tradenity/resources/table_rate_shipping.rb +834 -0
  73. data/lib/tradenity/resources/tax_class.rb +723 -0
  74. data/lib/tradenity/resources/tax_rate.rb +845 -0
  75. data/lib/tradenity/resources/tax_settings.rb +231 -0
  76. data/lib/tradenity/resources/test_gateway.rb +804 -0
  77. data/lib/tradenity/resources/transaction.rb +523 -0
  78. data/lib/tradenity/resources/utils.rb +7 -0
  79. data/lib/tradenity/resources/variant.rb +877 -0
  80. data/lib/tradenity/resources/web_hooks.rb +262 -0
  81. data/lib/tradenity/resources/weight.rb +235 -0
  82. data/lib/tradenity/resources/wish_list.rb +686 -0
  83. data/lib/tradenity/resources/zip_codes_geo_zone.rb +755 -0
  84. data/lib/tradenity/token_holder.rb +22 -0
  85. data/lib/tradenity/version.rb +13 -3
  86. data/lib/tradenity.rb +117 -7
  87. data/tradenity.gemspec +35 -30
  88. metadata +200 -34
  89. data/lib/tradenity/api.rb +0 -17
  90. data/lib/tradenity/error/exceptions.rb +0 -52
  91. data/lib/tradenity/error/message.rb +0 -38
  92. data/lib/tradenity/http/client.rb +0 -130
  93. data/lib/tradenity/model/base.rb +0 -100
  94. data/lib/tradenity/model/entities.rb +0 -390
  95. data/lib/tradenity/model/paging.rb +0 -23
@@ -0,0 +1,435 @@
1
+ =begin
2
+ #Tradenity API
3
+
4
+ #Tradenity eCommerce Rest API
5
+
6
+ Contact: support@tradenity.com
7
+ Generated by: https://github.com/tradenity
8
+
9
+ =end
10
+
11
+ require 'uri'
12
+
13
+ module Tradenity
14
+ class Gateway
15
+
16
+
17
+ def id=(id)
18
+ @id = id
19
+ end
20
+
21
+ def id
22
+ if instance_variable_defined?('@id') && @id != nil
23
+ @id
24
+ elsif __meta && __meta.href != nil
25
+ @id = __meta.href.split('/')[-1]
26
+ @id
27
+ else
28
+ nil
29
+ end
30
+ end
31
+
32
+ attr_accessor :__meta
33
+
34
+ attr_accessor :created_at
35
+
36
+ attr_accessor :updated_at
37
+
38
+ attr_accessor :name
39
+
40
+ attr_accessor :mode
41
+
42
+ attr_accessor :authorize_only
43
+
44
+ attr_accessor :account_id
45
+
46
+ attr_accessor :status
47
+
48
+ class EnumAttributeValidator
49
+ attr_reader :datatype
50
+ attr_reader :allowable_values
51
+
52
+ def initialize(datatype, allowable_values)
53
+ @allowable_values = allowable_values.map do |value|
54
+ case datatype.to_s
55
+ when /Integer/i
56
+ value.to_i
57
+ when /Float/i
58
+ value.to_f
59
+ else
60
+ value
61
+ end
62
+ end
63
+ end
64
+
65
+ def valid?(value)
66
+ !value || allowable_values.include?(value)
67
+ end
68
+ end
69
+
70
+ # Attribute mapping from ruby-style variable name to JSON key.
71
+ def self.attribute_map
72
+ {
73
+ :'id' => :'id',
74
+ :'__meta' => :'__meta',
75
+ :'created_at' => :'createdAt',
76
+ :'updated_at' => :'updatedAt',
77
+ :'name' => :'name',
78
+ :'mode' => :'mode',
79
+ :'authorize_only' => :'authorizeOnly',
80
+ :'account_id' => :'accountId',
81
+ :'status' => :'status'
82
+ }
83
+ end
84
+
85
+ # Attribute type mapping.
86
+ def self.swagger_types
87
+ {
88
+ :'id' => :'String',
89
+ :'__meta' => :'InstanceMeta',
90
+ :'created_at' => :'DateTime',
91
+ :'updated_at' => :'DateTime',
92
+ :'name' => :'String',
93
+ :'mode' => :'String',
94
+ :'authorize_only' => :'BOOLEAN',
95
+ :'account_id' => :'String',
96
+ :'status' => :'String'
97
+ }
98
+ end
99
+
100
+ # Initializes the object
101
+ # @param [Hash] attributes Model attributes in the form of hash
102
+ def initialize(attributes = {})
103
+ return unless attributes.is_a?(Hash)
104
+
105
+ # convert string to symbol for hash key
106
+ attributes = attributes.each_with_object({}) { |(k, v), h| h[k.to_sym] = v }
107
+ if attributes.has_key?(:'id')
108
+ self.id = attributes[:'id']
109
+ end
110
+
111
+ if attributes.has_key?(:'__meta')
112
+ self.__meta = attributes[:'__meta']
113
+ end
114
+
115
+ if attributes.has_key?(:'createdAt')
116
+ self.created_at = attributes[:'createdAt']
117
+ end
118
+
119
+ if attributes.has_key?(:'created_at')
120
+ self.created_at = attributes[:'created_at']
121
+ end
122
+
123
+ if attributes.has_key?(:'updatedAt')
124
+ self.updated_at = attributes[:'updatedAt']
125
+ end
126
+
127
+ if attributes.has_key?(:'updated_at')
128
+ self.updated_at = attributes[:'updated_at']
129
+ end
130
+
131
+ if attributes.has_key?(:'name')
132
+ self.name = attributes[:'name']
133
+ end
134
+
135
+ if attributes.has_key?(:'mode')
136
+ self.mode = attributes[:'mode']
137
+ end
138
+
139
+ if attributes.has_key?(:'authorizeOnly')
140
+ self.authorize_only = attributes[:'authorizeOnly']
141
+ end
142
+
143
+ if attributes.has_key?(:'authorize_only')
144
+ self.authorize_only = attributes[:'authorize_only']
145
+ end
146
+
147
+ if attributes.has_key?(:'accountId')
148
+ self.account_id = attributes[:'accountId']
149
+ end
150
+
151
+ if attributes.has_key?(:'account_id')
152
+ self.account_id = attributes[:'account_id']
153
+ end
154
+
155
+ if attributes.has_key?(:'status')
156
+ self.status = attributes[:'status']
157
+ end
158
+ end
159
+
160
+ # Show invalid properties with the reasons. Usually used together with valid?
161
+ # @return Array for valid properties with the reasons
162
+ def list_invalid_properties
163
+ invalid_properties = Array.new
164
+ if @name.nil?
165
+ invalid_properties.push('invalid value for "name", name cannot be nil.')
166
+ end
167
+
168
+ if @mode.nil?
169
+ invalid_properties.push('invalid value for "mode", mode cannot be nil.')
170
+ end
171
+
172
+ if @status.nil?
173
+ invalid_properties.push('invalid value for "status", status cannot be nil.')
174
+ end
175
+
176
+ invalid_properties
177
+ end
178
+
179
+ # Check to see if the all the properties in the model are valid
180
+ # @return true if the model is valid
181
+ def valid?
182
+ return false if @name.nil?
183
+ return false if @mode.nil?
184
+ mode_validator = EnumAttributeValidator.new('String', ['test', 'live'])
185
+ return false unless mode_validator.valid?(@mode)
186
+ return false if @status.nil?
187
+ status_validator = EnumAttributeValidator.new('String', ['enabled', 'disabled'])
188
+ return false unless status_validator.valid?(@status)
189
+ true
190
+ end
191
+
192
+ # Custom attribute writer method checking allowed values (enum).
193
+ # @param [Object] mode Object to be assigned
194
+ def mode=(mode)
195
+ validator = EnumAttributeValidator.new('String', ['test', 'live'])
196
+ unless validator.valid?(mode)
197
+ fail ArgumentError, 'invalid value for "mode", must be one of #{validator.allowable_values}.'
198
+ end
199
+ @mode = mode
200
+ end
201
+
202
+ # Custom attribute writer method checking allowed values (enum).
203
+ # @param [Object] status Object to be assigned
204
+ def status=(status)
205
+ validator = EnumAttributeValidator.new('String', ['enabled', 'disabled'])
206
+ unless validator.valid?(status)
207
+ fail ArgumentError, 'invalid value for "status", must be one of #{validator.allowable_values}.'
208
+ end
209
+ @status = status
210
+ end
211
+
212
+ # Checks equality by comparing each attribute.
213
+ # @param [Object] Object to be compared
214
+ def ==(o)
215
+ return true if self.equal?(o)
216
+ self.class == o.class &&
217
+ __meta == o.__meta &&
218
+ created_at == o.created_at &&
219
+ updated_at == o.updated_at &&
220
+ name == o.name &&
221
+ mode == o.mode &&
222
+ authorize_only == o.authorize_only &&
223
+ account_id == o.account_id &&
224
+ status == o.status
225
+ end
226
+
227
+ # @see the `==` method
228
+ # @param [Object] Object to be compared
229
+ def eql?(o)
230
+ self == o
231
+ end
232
+
233
+ # Calculates hash code according to all attributes.
234
+ # @return [Fixnum] Hash code
235
+ def hash
236
+ [__meta, created_at, updated_at, name, mode, authorize_only, account_id, status].hash
237
+ end
238
+
239
+ # Builds the object from hash
240
+ # @param [Hash] attributes Model attributes in the form of hash
241
+ # @return [Object] Returns the model itself
242
+ def build_from_hash(attributes)
243
+ return nil unless attributes.is_a?(Hash)
244
+ self.class.swagger_types.each_pair do |key, type|
245
+ if type =~ /\AArray<(.*)>/i
246
+ # check to ensure the input is an array given that the the attribute
247
+ # is documented as an array but the input is not
248
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
249
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
250
+ end
251
+ elsif !attributes[self.class.attribute_map[key]].nil?
252
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
253
+ end # or else data not found in attributes(hash), not an issue as the data can be optional
254
+ end
255
+
256
+ self
257
+ end
258
+
259
+ # Deserializes the data based on type
260
+ # @param string type Data type
261
+ # @param string value Value to be deserialized
262
+ # @return [Object] Deserialized data
263
+ def _deserialize(type, value)
264
+ case type.to_sym
265
+ when :DateTime
266
+ DateTime.parse(value)
267
+ when :Date
268
+ Date.parse(value)
269
+ when :String
270
+ value.to_s
271
+ when :Integer
272
+ value.to_i
273
+ when :Float
274
+ value.to_f
275
+ when :BOOLEAN
276
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
277
+ true
278
+ else
279
+ false
280
+ end
281
+ when :Object
282
+ # generic object (usually a Hash), return directly
283
+ value
284
+ when /\AArray<(?<inner_type>.+)>\z/
285
+ inner_type = Regexp.last_match[:inner_type]
286
+ value.map { |v| _deserialize(inner_type, v) }
287
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
288
+ k_type = Regexp.last_match[:k_type]
289
+ v_type = Regexp.last_match[:v_type]
290
+ {}.tap do |hash|
291
+ value.each do |k, v|
292
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
293
+ end
294
+ end
295
+ else # model
296
+ temp_model = Tradenity.const_get(type).new
297
+ temp_model.build_from_hash(value)
298
+ end
299
+ end
300
+
301
+ # Returns the string representation of the object
302
+ # @return [String] String presentation of the object
303
+ def to_s
304
+ to_hash.to_s
305
+ end
306
+
307
+ # to_body is an alias to to_hash (backward compatibility)
308
+ # @return [Hash] Returns the object in the form of hash
309
+ def to_body
310
+ to_hash
311
+ end
312
+
313
+ # Returns the object in the form of hash
314
+ # @return [Hash] Returns the object in the form of hash
315
+ def to_hash
316
+ hash = {}
317
+ self.class.attribute_map.each_pair do |attr, param|
318
+ value = self.send(attr)
319
+ next if value.nil?
320
+ hash[param] = _to_hash(value)
321
+ end
322
+ hash
323
+ end
324
+
325
+ # Outputs non-array value in the form of hash
326
+ # For object, use to_hash. Otherwise, just return the value
327
+ # @param [Object] value Any valid value
328
+ # @return [Hash] Returns the value in the form of hash
329
+ def _to_hash(value)
330
+ if value.is_a?(Array)
331
+ value.compact.map { |v| _to_hash(v) }
332
+ elsif value.is_a?(Hash)
333
+ {}.tap do |hash|
334
+ value.each { |k, v| hash[k] = _to_hash(v) }
335
+ end
336
+ elsif value.respond_to? :to_hash
337
+ value.to_hash
338
+ else
339
+ value
340
+ end
341
+ end
342
+
343
+
344
+ def self.api_client
345
+ ApiClient.default
346
+ end
347
+
348
+
349
+ class << self
350
+
351
+ # List Gateways
352
+ # Return a list of Gateways
353
+ # @param [Hash] opts the optional parameters
354
+ # @return [Page<Gateway>]
355
+ def find_all
356
+ list_all_gateways
357
+ end
358
+
359
+ # Find List of Gateway
360
+ # Return multiple instances of Gateway by its attributes.
361
+ # @param [Hash] opts the search parameters
362
+ # @return [Page<Collection>]
363
+ def find_all_by(opts = {})
364
+ list_all_gateways(opts)
365
+ end
366
+
367
+ # Find Gateway by its parameters
368
+ # Return single instance of Collection by its attributes.
369
+ # @param [Hash] opts search parameters
370
+ # @return [Gateway]
371
+ def find_one_by(opts = {})
372
+ list_all_gateways(opts)[0]
373
+ end
374
+
375
+
376
+ # List Gateways
377
+ # Return a list of Gateways
378
+ # @param [Hash] opts the optional parameters
379
+ # @option opts [Integer] :page page number
380
+ # @option opts [Integer] :size page size
381
+ # @option opts [String] :sort page order
382
+ # @return [Page<Gateway>]
383
+ def list_all_gateways(opts = {})
384
+ data, _status_code, _headers = list_all_gateways_with_http_info(opts)
385
+ data
386
+ end
387
+
388
+ # List Gateways
389
+ # Return a list of Gateways
390
+ # @param [Hash] opts the optional parameters
391
+ # @option opts [Integer] :page page number
392
+ # @option opts [Integer] :size page size
393
+ # @option opts [String] :sort page order
394
+ # @return [Array<(Page<Gateway>, Fixnum, Hash)>] Page<Gateway> data, response status code and response headers
395
+ def list_all_gateways_with_http_info(opts = {})
396
+ if api_client.config.debugging
397
+ api_client.config.logger.debug 'Calling API: Gateway.list_all_gateways ...'
398
+ end
399
+ # resource path
400
+ local_var_path = '/gateways'
401
+
402
+ # query parameters
403
+ query_params = opts
404
+ # query_params[:'page'] = opts[:'page'] if !opts[:'page'].nil?
405
+ # query_params[:'size'] = opts[:'size'] if !opts[:'size'].nil?
406
+ # query_params[:'sort'] = opts[:'sort'] if !opts[:'sort'].nil?
407
+
408
+ # header parameters
409
+ header_params = {}
410
+ # HTTP header 'Accept' (if needed)
411
+ header_params['Accept'] = api_client.select_header_accept(['application/json'])
412
+ # HTTP header 'Content-Type'
413
+ header_params['Content-Type'] = api_client.select_header_content_type(['application/json'])
414
+
415
+ # form parameters
416
+ form_params = {}
417
+
418
+ # http body (model)
419
+ post_body = nil
420
+ auth_names = []
421
+ data, status_code, headers = api_client.call_api(:GET, local_var_path,
422
+ :header_params => header_params,
423
+ :query_params => query_params,
424
+ :form_params => form_params,
425
+ :body => post_body,
426
+ :auth_names => auth_names,
427
+ :return_type => 'Page<Gateway>')
428
+ if api_client.config.debugging
429
+ api_client.config.logger.debug "API called: Gateway#list_all_gateways\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
430
+ end
431
+ return data, status_code, headers
432
+ end
433
+ end
434
+ end
435
+ end
@@ -0,0 +1,206 @@
1
+ =begin
2
+ #Tradenity API
3
+
4
+ #Tradenity eCommerce Rest API
5
+
6
+ Contact: support@tradenity.com
7
+ Generated by: https://github.com/tradenity
8
+
9
+ =end
10
+
11
+ require 'date'
12
+
13
+ module Tradenity
14
+ class GeneralSettings
15
+
16
+ attr_accessor :local
17
+
18
+ attr_accessor :time_zone
19
+
20
+ attr_accessor :add_new_customers_to
21
+
22
+ # Attribute mapping from ruby-style variable name to JSON key.
23
+ def self.attribute_map
24
+ {
25
+ :'local' => :'local',
26
+ :'time_zone' => :'timeZone',
27
+ :'add_new_customers_to' => :'addNewCustomersTo'
28
+ }
29
+ end
30
+
31
+ # Attribute type mapping.
32
+ def self.swagger_types
33
+ {
34
+ :'local' => :'String',
35
+ :'time_zone' => :'String',
36
+ :'add_new_customers_to' => :'CustomerGroup'
37
+ }
38
+ end
39
+
40
+ # Initializes the object
41
+ # @param [Hash] attributes Model attributes in the form of hash
42
+ def initialize(attributes = {})
43
+ return unless attributes.is_a?(Hash)
44
+
45
+ # convert string to symbol for hash key
46
+ attributes = attributes.each_with_object({}) { |(k, v), h| h[k.to_sym] = v }
47
+
48
+ if attributes.has_key?(:'local')
49
+ self.local = attributes[:'local']
50
+ end
51
+
52
+ if attributes.has_key?(:'timeZone')
53
+ self.time_zone = attributes[:'timeZone']
54
+ end
55
+ if attributes.has_key?(:'time_zone')
56
+ self.time_zone = attributes[:'time_zone']
57
+ end
58
+
59
+ if attributes.has_key?(:'addNewCustomersTo')
60
+ self.add_new_customers_to = attributes[:'addNewCustomersTo']
61
+ end
62
+ if attributes.has_key?(:'add_new_customers_to')
63
+ self.add_new_customers_to = attributes[:'add_new_customers_to']
64
+ end
65
+ end
66
+
67
+ # Show invalid properties with the reasons. Usually used together with valid?
68
+ # @return Array for valid properties with the reasons
69
+ def list_invalid_properties
70
+ invalid_properties = Array.new
71
+ invalid_properties
72
+ end
73
+
74
+ # Check to see if the all the properties in the model are valid
75
+ # @return true if the model is valid
76
+ def valid?
77
+ true
78
+ end
79
+
80
+ # Checks equality by comparing each attribute.
81
+ # @param [Object] Object to be compared
82
+ def ==(o)
83
+ return true if self.equal?(o)
84
+ self.class == o.class &&
85
+ local == o.local &&
86
+ time_zone == o.time_zone &&
87
+ add_new_customers_to == o.add_new_customers_to
88
+ end
89
+
90
+ # @see the `==` method
91
+ # @param [Object] Object to be compared
92
+ def eql?(o)
93
+ self == o
94
+ end
95
+
96
+ # Calculates hash code according to all attributes.
97
+ # @return [Fixnum] Hash code
98
+ def hash
99
+ [local, time_zone, add_new_customers_to].hash
100
+ end
101
+
102
+ # Builds the object from hash
103
+ # @param [Hash] attributes Model attributes in the form of hash
104
+ # @return [Object] Returns the model itself
105
+ def build_from_hash(attributes)
106
+ return nil unless attributes.is_a?(Hash)
107
+ self.class.swagger_types.each_pair do |key, type|
108
+ if type =~ /\AArray<(.*)>/i
109
+ # check to ensure the input is an array given that the the attribute
110
+ # is documented as an array but the input is not
111
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
112
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
113
+ end
114
+ elsif !attributes[self.class.attribute_map[key]].nil?
115
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
116
+ end # or else data not found in attributes(hash), not an issue as the data can be optional
117
+ end
118
+
119
+ self
120
+ end
121
+
122
+ # Deserializes the data based on type
123
+ # @param string type Data type
124
+ # @param string value Value to be deserialized
125
+ # @return [Object] Deserialized data
126
+ def _deserialize(type, value)
127
+ case type.to_sym
128
+ when :DateTime
129
+ DateTime.parse(value)
130
+ when :Date
131
+ Date.parse(value)
132
+ when :String
133
+ value.to_s
134
+ when :Integer
135
+ value.to_i
136
+ when :Float
137
+ value.to_f
138
+ when :BOOLEAN
139
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
140
+ true
141
+ else
142
+ false
143
+ end
144
+ when :Object
145
+ # generic object (usually a Hash), return directly
146
+ value
147
+ when /\AArray<(?<inner_type>.+)>\z/
148
+ inner_type = Regexp.last_match[:inner_type]
149
+ value.map { |v| _deserialize(inner_type, v) }
150
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
151
+ k_type = Regexp.last_match[:k_type]
152
+ v_type = Regexp.last_match[:v_type]
153
+ {}.tap do |hash|
154
+ value.each do |k, v|
155
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
156
+ end
157
+ end
158
+ else # model
159
+ temp_model = Tradenity.const_get(type).new
160
+ temp_model.build_from_hash(value)
161
+ end
162
+ end
163
+
164
+ # Returns the string representation of the object
165
+ # @return [String] String presentation of the object
166
+ def to_s
167
+ to_hash.to_s
168
+ end
169
+
170
+ # to_body is an alias to to_hash (backward compatibility)
171
+ # @return [Hash] Returns the object in the form of hash
172
+ def to_body
173
+ to_hash
174
+ end
175
+
176
+ # Returns the object in the form of hash
177
+ # @return [Hash] Returns the object in the form of hash
178
+ def to_hash
179
+ hash = {}
180
+ self.class.attribute_map.each_pair do |attr, param|
181
+ value = self.send(attr)
182
+ next if value.nil?
183
+ hash[param] = _to_hash(value)
184
+ end
185
+ hash
186
+ end
187
+
188
+ # Outputs non-array value in the form of hash
189
+ # For object, use to_hash. Otherwise, just return the value
190
+ # @param [Object] value Any valid value
191
+ # @return [Hash] Returns the value in the form of hash
192
+ def _to_hash(value)
193
+ if value.is_a?(Array)
194
+ value.compact.map { |v| _to_hash(v) }
195
+ elsif value.is_a?(Hash)
196
+ {}.tap do |hash|
197
+ value.each { |k, v| hash[k] = _to_hash(v) }
198
+ end
199
+ elsif value.respond_to? :to_hash
200
+ value.to_hash
201
+ else
202
+ value
203
+ end
204
+ end
205
+ end
206
+ end