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