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,454 @@
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 Coupon
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 :description
41
+
42
+ attr_accessor :status
43
+
44
+ attr_accessor :minimum_order
45
+
46
+ attr_accessor :code
47
+
48
+ attr_accessor :begins_at
49
+
50
+ attr_accessor :ends_at
51
+
52
+ attr_accessor :include
53
+
54
+ class EnumAttributeValidator
55
+ attr_reader :datatype
56
+ attr_reader :allowable_values
57
+
58
+ def initialize(datatype, allowable_values)
59
+ @allowable_values = allowable_values.map do |value|
60
+ case datatype.to_s
61
+ when /Integer/i
62
+ value.to_i
63
+ when /Float/i
64
+ value.to_f
65
+ else
66
+ value
67
+ end
68
+ end
69
+ end
70
+
71
+ def valid?(value)
72
+ !value || allowable_values.include?(value)
73
+ end
74
+ end
75
+
76
+ # Attribute mapping from ruby-style variable name to JSON key.
77
+ def self.attribute_map
78
+ {
79
+ :'id' => :'id',
80
+ :'__meta' => :'__meta',
81
+ :'created_at' => :'createdAt',
82
+ :'updated_at' => :'updatedAt',
83
+ :'name' => :'name',
84
+ :'description' => :'description',
85
+ :'status' => :'status',
86
+ :'minimum_order' => :'minimumOrder',
87
+ :'code' => :'code',
88
+ :'begins_at' => :'beginsAt',
89
+ :'ends_at' => :'endsAt',
90
+ :'include' => :'include'
91
+ }
92
+ end
93
+
94
+ # Attribute type mapping.
95
+ def self.swagger_types
96
+ {
97
+ :'id' => :'String',
98
+ :'__meta' => :'InstanceMeta',
99
+ :'created_at' => :'DateTime',
100
+ :'updated_at' => :'DateTime',
101
+ :'name' => :'String',
102
+ :'description' => :'String',
103
+ :'status' => :'String',
104
+ :'minimum_order' => :'Integer',
105
+ :'code' => :'String',
106
+ :'begins_at' => :'DateTime',
107
+ :'ends_at' => :'DateTime',
108
+ :'include' => :'ItemsSelector'
109
+ }
110
+ end
111
+
112
+ # Initializes the object
113
+ # @param [Hash] attributes Model attributes in the form of hash
114
+ def initialize(attributes = {})
115
+ return unless attributes.is_a?(Hash)
116
+
117
+ # convert string to symbol for hash key
118
+ attributes = attributes.each_with_object({}) { |(k, v), h| h[k.to_sym] = v }
119
+ if attributes.has_key?(:'id')
120
+ self.id = attributes[:'id']
121
+ end
122
+
123
+ if attributes.has_key?(:'__meta')
124
+ self.__meta = attributes[:'__meta']
125
+ end
126
+
127
+ if attributes.has_key?(:'createdAt')
128
+ self.created_at = attributes[:'createdAt']
129
+ end
130
+
131
+ if attributes.has_key?(:'created_at')
132
+ self.created_at = attributes[:'created_at']
133
+ end
134
+
135
+ if attributes.has_key?(:'updatedAt')
136
+ self.updated_at = attributes[:'updatedAt']
137
+ end
138
+
139
+ if attributes.has_key?(:'updated_at')
140
+ self.updated_at = attributes[:'updated_at']
141
+ end
142
+
143
+ if attributes.has_key?(:'name')
144
+ self.name = attributes[:'name']
145
+ end
146
+
147
+ if attributes.has_key?(:'description')
148
+ self.description = attributes[:'description']
149
+ end
150
+
151
+ if attributes.has_key?(:'status')
152
+ self.status = attributes[:'status']
153
+ end
154
+
155
+ if attributes.has_key?(:'minimumOrder')
156
+ self.minimum_order = attributes[:'minimumOrder']
157
+ end
158
+
159
+ if attributes.has_key?(:'minimum_order')
160
+ self.minimum_order = attributes[:'minimum_order']
161
+ end
162
+
163
+ if attributes.has_key?(:'code')
164
+ self.code = attributes[:'code']
165
+ end
166
+
167
+ if attributes.has_key?(:'beginsAt')
168
+ self.begins_at = attributes[:'beginsAt']
169
+ end
170
+
171
+ if attributes.has_key?(:'begins_at')
172
+ self.begins_at = attributes[:'begins_at']
173
+ end
174
+
175
+ if attributes.has_key?(:'endsAt')
176
+ self.ends_at = attributes[:'endsAt']
177
+ end
178
+
179
+ if attributes.has_key?(:'ends_at')
180
+ self.ends_at = attributes[:'ends_at']
181
+ end
182
+
183
+ if attributes.has_key?(:'include')
184
+ self.include = attributes[:'include']
185
+ end
186
+ end
187
+
188
+ # Show invalid properties with the reasons. Usually used together with valid?
189
+ # @return Array for valid properties with the reasons
190
+ def list_invalid_properties
191
+ invalid_properties = Array.new
192
+ if @name.nil?
193
+ invalid_properties.push('invalid value for "name", name cannot be nil.')
194
+ end
195
+
196
+ if @status.nil?
197
+ invalid_properties.push('invalid value for "status", status cannot be nil.')
198
+ end
199
+
200
+ if @code.nil?
201
+ invalid_properties.push('invalid value for "code", code cannot be nil.')
202
+ end
203
+
204
+ invalid_properties
205
+ end
206
+
207
+ # Check to see if the all the properties in the model are valid
208
+ # @return true if the model is valid
209
+ def valid?
210
+ return false if @name.nil?
211
+ return false if @status.nil?
212
+ status_validator = EnumAttributeValidator.new('String', ['enabled', 'disabled'])
213
+ return false unless status_validator.valid?(@status)
214
+ return false if @code.nil?
215
+ true
216
+ end
217
+
218
+ # Custom attribute writer method checking allowed values (enum).
219
+ # @param [Object] status Object to be assigned
220
+ def status=(status)
221
+ validator = EnumAttributeValidator.new('String', ['enabled', 'disabled'])
222
+ unless validator.valid?(status)
223
+ fail ArgumentError, 'invalid value for "status", must be one of #{validator.allowable_values}.'
224
+ end
225
+ @status = status
226
+ end
227
+
228
+ # Checks equality by comparing each attribute.
229
+ # @param [Object] Object to be compared
230
+ def ==(o)
231
+ return true if self.equal?(o)
232
+ self.class == o.class &&
233
+ __meta == o.__meta &&
234
+ created_at == o.created_at &&
235
+ updated_at == o.updated_at &&
236
+ name == o.name &&
237
+ description == o.description &&
238
+ status == o.status &&
239
+ minimum_order == o.minimum_order &&
240
+ code == o.code &&
241
+ begins_at == o.begins_at &&
242
+ ends_at == o.ends_at &&
243
+ include == o.include
244
+ end
245
+
246
+ # @see the `==` method
247
+ # @param [Object] Object to be compared
248
+ def eql?(o)
249
+ self == o
250
+ end
251
+
252
+ # Calculates hash code according to all attributes.
253
+ # @return [Fixnum] Hash code
254
+ def hash
255
+ [__meta, created_at, updated_at, name, description, status, minimum_order, code, begins_at, ends_at, include].hash
256
+ end
257
+
258
+ # Builds the object from hash
259
+ # @param [Hash] attributes Model attributes in the form of hash
260
+ # @return [Object] Returns the model itself
261
+ def build_from_hash(attributes)
262
+ return nil unless attributes.is_a?(Hash)
263
+ self.class.swagger_types.each_pair do |key, type|
264
+ if type =~ /\AArray<(.*)>/i
265
+ # check to ensure the input is an array given that the the attribute
266
+ # is documented as an array but the input is not
267
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
268
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
269
+ end
270
+ elsif !attributes[self.class.attribute_map[key]].nil?
271
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
272
+ end # or else data not found in attributes(hash), not an issue as the data can be optional
273
+ end
274
+
275
+ self
276
+ end
277
+
278
+ # Deserializes the data based on type
279
+ # @param string type Data type
280
+ # @param string value Value to be deserialized
281
+ # @return [Object] Deserialized data
282
+ def _deserialize(type, value)
283
+ case type.to_sym
284
+ when :DateTime
285
+ DateTime.parse(value)
286
+ when :Date
287
+ Date.parse(value)
288
+ when :String
289
+ value.to_s
290
+ when :Integer
291
+ value.to_i
292
+ when :Float
293
+ value.to_f
294
+ when :BOOLEAN
295
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
296
+ true
297
+ else
298
+ false
299
+ end
300
+ when :Object
301
+ # generic object (usually a Hash), return directly
302
+ value
303
+ when /\AArray<(?<inner_type>.+)>\z/
304
+ inner_type = Regexp.last_match[:inner_type]
305
+ value.map { |v| _deserialize(inner_type, v) }
306
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
307
+ k_type = Regexp.last_match[:k_type]
308
+ v_type = Regexp.last_match[:v_type]
309
+ {}.tap do |hash|
310
+ value.each do |k, v|
311
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
312
+ end
313
+ end
314
+ else # model
315
+ temp_model = Tradenity.const_get(type).new
316
+ temp_model.build_from_hash(value)
317
+ end
318
+ end
319
+
320
+ # Returns the string representation of the object
321
+ # @return [String] String presentation of the object
322
+ def to_s
323
+ to_hash.to_s
324
+ end
325
+
326
+ # to_body is an alias to to_hash (backward compatibility)
327
+ # @return [Hash] Returns the object in the form of hash
328
+ def to_body
329
+ to_hash
330
+ end
331
+
332
+ # Returns the object in the form of hash
333
+ # @return [Hash] Returns the object in the form of hash
334
+ def to_hash
335
+ hash = {}
336
+ self.class.attribute_map.each_pair do |attr, param|
337
+ value = self.send(attr)
338
+ next if value.nil?
339
+ hash[param] = _to_hash(value)
340
+ end
341
+ hash
342
+ end
343
+
344
+ # Outputs non-array value in the form of hash
345
+ # For object, use to_hash. Otherwise, just return the value
346
+ # @param [Object] value Any valid value
347
+ # @return [Hash] Returns the value in the form of hash
348
+ def _to_hash(value)
349
+ if value.is_a?(Array)
350
+ value.compact.map { |v| _to_hash(v) }
351
+ elsif value.is_a?(Hash)
352
+ {}.tap do |hash|
353
+ value.each { |k, v| hash[k] = _to_hash(v) }
354
+ end
355
+ elsif value.respond_to? :to_hash
356
+ value.to_hash
357
+ else
358
+ value
359
+ end
360
+ end
361
+
362
+
363
+ def self.api_client
364
+ ApiClient.default
365
+ end
366
+
367
+
368
+ class << self
369
+
370
+ # List Coupons
371
+ # Return a list of Coupons
372
+ # @param [Hash] opts the optional parameters
373
+ # @return [Page<Coupon>]
374
+ def find_all
375
+ list_all_coupons
376
+ end
377
+
378
+ # Find List of Coupon
379
+ # Return multiple instances of Coupon by its attributes.
380
+ # @param [Hash] opts the search parameters
381
+ # @return [Page<Collection>]
382
+ def find_all_by(opts = {})
383
+ list_all_coupons(opts)
384
+ end
385
+
386
+ # Find Coupon by its parameters
387
+ # Return single instance of Collection by its attributes.
388
+ # @param [Hash] opts search parameters
389
+ # @return [Coupon]
390
+ def find_one_by(opts = {})
391
+ list_all_coupons(opts)[0]
392
+ end
393
+
394
+
395
+ # List Coupons
396
+ # Return a list of Coupons
397
+ # @param [Hash] opts the optional parameters
398
+ # @option opts [Integer] :page page number
399
+ # @option opts [Integer] :size page size
400
+ # @option opts [String] :sort page order
401
+ # @return [Page<Coupon>]
402
+ def list_all_coupons(opts = {})
403
+ data, _status_code, _headers = list_all_coupons_with_http_info(opts)
404
+ data
405
+ end
406
+
407
+ # List Coupons
408
+ # Return a list of Coupons
409
+ # @param [Hash] opts the optional parameters
410
+ # @option opts [Integer] :page page number
411
+ # @option opts [Integer] :size page size
412
+ # @option opts [String] :sort page order
413
+ # @return [Array<(Page<Coupon>, Fixnum, Hash)>] Page<Coupon> data, response status code and response headers
414
+ def list_all_coupons_with_http_info(opts = {})
415
+ if api_client.config.debugging
416
+ api_client.config.logger.debug 'Calling API: Coupon.list_all_coupons ...'
417
+ end
418
+ # resource path
419
+ local_var_path = '/coupons'
420
+
421
+ # query parameters
422
+ query_params = opts
423
+ # query_params[:'page'] = opts[:'page'] if !opts[:'page'].nil?
424
+ # query_params[:'size'] = opts[:'size'] if !opts[:'size'].nil?
425
+ # query_params[:'sort'] = opts[:'sort'] if !opts[:'sort'].nil?
426
+
427
+ # header parameters
428
+ header_params = {}
429
+ # HTTP header 'Accept' (if needed)
430
+ header_params['Accept'] = api_client.select_header_accept(['application/json'])
431
+ # HTTP header 'Content-Type'
432
+ header_params['Content-Type'] = api_client.select_header_content_type(['application/json'])
433
+
434
+ # form parameters
435
+ form_params = {}
436
+
437
+ # http body (model)
438
+ post_body = nil
439
+ auth_names = []
440
+ data, status_code, headers = api_client.call_api(:GET, local_var_path,
441
+ :header_params => header_params,
442
+ :query_params => query_params,
443
+ :form_params => form_params,
444
+ :body => post_body,
445
+ :auth_names => auth_names,
446
+ :return_type => 'Page<Coupon>')
447
+ if api_client.config.debugging
448
+ api_client.config.logger.debug "API called: Coupon#list_all_coupons\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
449
+ end
450
+ return data, status_code, headers
451
+ end
452
+ end
453
+ end
454
+ end