epages-rest 1.0.6 → 1.0.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE.txt +22 -0
  3. data/epages-rest.gemspec +5 -5
  4. data/lib/epages/cart.rb +2 -1
  5. data/lib/epages/category.rb +4 -4
  6. data/lib/epages/customers_response.rb +19 -0
  7. data/lib/epages/delivery_weight_quantity.rb +15 -0
  8. data/lib/epages/error.rb +7 -1
  9. data/lib/epages/line_item_container.rb +2 -1
  10. data/lib/epages/minimum_cart.rb +16 -0
  11. data/lib/epages/order.rb +2 -1
  12. data/lib/epages/orders_response.rb +19 -0
  13. data/lib/epages/payment_data.rb +1 -1
  14. data/lib/epages/product.rb +2 -1
  15. data/lib/epages/product_line_item.rb +1 -1
  16. data/lib/epages/products_response.rb +19 -0
  17. data/lib/epages/quantity.rb +15 -0
  18. data/lib/epages/rest/api.rb +4 -0
  19. data/lib/epages/rest/carts.rb +19 -6
  20. data/lib/epages/rest/categories.rb +37 -0
  21. data/lib/epages/rest/customers.rb +1 -1
  22. data/lib/epages/rest/miscellaneous.rb +11 -6
  23. data/lib/epages/rest/orders.rb +1 -1
  24. data/lib/epages/rest/products.rb +13 -11
  25. data/lib/epages/rest/request.rb +20 -2
  26. data/lib/epages/rest/sales.rb +2 -2
  27. data/lib/epages/rest/tax_classes.rb +21 -0
  28. data/lib/epages/rest/utils.rb +11 -5
  29. data/lib/epages/rest/webhooks.rb +35 -0
  30. data/lib/epages/{sale.rb → sales.rb} +2 -2
  31. data/lib/epages/sales_summary.rb +19 -0
  32. data/lib/epages/tax_class.rb +16 -0
  33. data/lib/epages/tax_class_info.rb +15 -0
  34. data/lib/epages/variation_identifier.rb +15 -0
  35. data/lib/epages/version.rb +1 -1
  36. data/lib/epages/webhook.rb +18 -0
  37. data/lib/epages/webhook_response.rb +19 -0
  38. data/lib/epages/webhook_response_pagination.rb +15 -0
  39. data/lib/epages-rest.rb +16 -1
  40. metadata +27 -13
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 90f0916b52d7493d5a4e551e896a5087f691880e
4
- data.tar.gz: 24c8d720fda0a80806c383455cd2025b05627504
3
+ metadata.gz: 3f20938ab374f8dde725505ea8e7f3c0f3e11c04
4
+ data.tar.gz: a3de9053ace6cbd2e5727fbafd86b340278e5e65
5
5
  SHA512:
6
- metadata.gz: 1e101a31f432ef803fc953c9ef0d12bfd35f046b1cf7771bf04cc61ac4cd941046c99c556b4f272aaa100d00817a1321c057ffb6f0f2a613bd2ff29ccb5743b9
7
- data.tar.gz: ae871cbb63b7e786782616f1e8270d17b98e5d4d17d1e77935eda3d94307831f19642ee6e70f4f2c7ccf94821290ada1dd4dfd69052fe97425ee9e17fa006d95
6
+ metadata.gz: 2e31b161df9e2e93ebc7f4c81e6d633962457024ed243354e2acd87f96eeeca77164c526254e4ae6c11891210cd8598fd9c7e05b60c6e9c4a7bff755bd5fc68f
7
+ data.tar.gz: b06515dd6208c6605df38a47f33891c76360b9d71ca67ba65388022c16d14ac089673e9e7186784c454a01736ca23643d5d54fd5afc75a249fa7ffb1f1f0cffa
data/LICENSE.txt CHANGED
@@ -19,3 +19,25 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
19
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
20
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
21
  THE SOFTWARE.
22
+
23
+ The MIT License (MIT)
24
+
25
+ Copyright (c) 2017 Unai Martinez
26
+
27
+ Permission is hereby granted, free of charge, to any person obtaining a copy
28
+ of this software and associated documentation files (the "Software"), to deal
29
+ in the Software without restriction, including without limitation the rights
30
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
31
+ copies of the Software, and to permit persons to whom the Software is
32
+ furnished to do so, subject to the following conditions:
33
+
34
+ The above copyright notice and this permission notice shall be included in
35
+ all copies or substantial portions of the Software.
36
+
37
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
38
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
39
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
40
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
41
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
42
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
43
+ THE SOFTWARE.
data/epages-rest.gemspec CHANGED
@@ -6,8 +6,8 @@ require 'epages/version'
6
6
  Gem::Specification.new do |spec|
7
7
  spec.version = Epages::VERSION
8
8
  spec.name = 'epages-rest'
9
- spec.authors = ['Domingo Cividanes']
10
- spec.email = ['dcividanes91@gmail.com', 'dcividanes@epages.com']
9
+ spec.authors = ['Domingo Cividanes', 'Unai Martinez']
10
+ spec.email = ['u.martinez@epages.com']
11
11
  spec.description = 'A Ruby interface that allows to integrate any Epages Shop with any ruby framework via Epages Rest API.'
12
12
  spec.summary = 'A Ruby interface to the Epages Rest API.'
13
13
  spec.homepage = 'https://github.com/ePages-de/epages-rest-ruby'
@@ -16,7 +16,7 @@ Gem::Specification.new do |spec|
16
16
  spec.require_paths = %w(lib)
17
17
  spec.files = %w(LICENSE.txt README.md epages-rest.gemspec) + Dir['lib/**/*.rb']
18
18
 
19
- spec.add_development_dependency 'bundler', '~> 1.10'
20
- spec.add_dependency 'http', '~> 0.9.4'
21
- spec.add_dependency 'activesupport', '~> 4.2'
19
+ spec.add_development_dependency 'bundler', '~> 1.13'
20
+ spec.add_dependency 'http', '~> 2.1'
21
+ spec.add_dependency 'activesupport', '~> 5.0'
22
22
  end
data/lib/epages/cart.rb CHANGED
@@ -4,7 +4,7 @@ module Epages
4
4
  class Cart
5
5
  include Epages::Utils
6
6
 
7
- KEYS = %w(cart_id billing_address shipping_address line_item_container min_cart_value checkout_url).collect(&:to_sym).freeze
7
+ KEYS = %w(cart_id billing_address shipping_address line_item_container minimum_cart checkout_url tax_class_id).collect(&:to_sym).freeze
8
8
 
9
9
  attr_reader *KEYS
10
10
 
@@ -12,6 +12,7 @@ module Epages
12
12
  parse_attribute_as(:billing_address, data.delete(:billingAddress), Epages::Address)
13
13
  parse_attribute_as(:shipping_address, data.delete(:shippingAddress), Epages::Address)
14
14
  parse_attribute_as(:line_item_container, data.delete(:lineItemContainer), Epages::LineItemContainer)
15
+ parse_attribute_as(:minimum_cart, data.delete(:minimumCart), Epages::MinimumCart)
15
16
  parse_attributes(data)
16
17
  end
17
18
 
@@ -5,14 +5,14 @@ module Epages
5
5
  class Category
6
6
  include Epages::Utils
7
7
 
8
- KEYS = %w(category_id name page_title description special_offer images parent sub_categories sf_url links).collect(&:to_sym).freeze
8
+ KEYS = %w(category_id name page_title description special_offer images parent sub_categories sf_url links visible).collect(&:to_sym).freeze
9
9
 
10
10
  attr_reader *KEYS
11
11
 
12
12
  def initialize(data)
13
- @images = data.delete(:images).collect { |i| Epages::Image.new(i) } if data[:images]
14
- @links = data.delete(:links).collect { |i| Epages::Link.new(i) } if data[:links]
15
- @sub_categories = data.delete(:subCategories).collect { |i| Epages::Link.new(i) } if data[:subCategories]
13
+ parse_attribute_as_array_of('images', data.delete(:images), Epages::Image)
14
+ parse_attribute_as_array_of('links', data.delete(:links), Epages::Link)
15
+ parse_attribute_as_array_of('sub_categories', data.delete(:subCategories), Epages::Link)
16
16
  @parent = Epages::Link.new(data.delete(:parent)) if data[:parent]
17
17
  parse_attributes(data)
18
18
  end
@@ -0,0 +1,19 @@
1
+ require 'epages/utils'
2
+ require 'epages/error'
3
+
4
+ module Epages
5
+ class CustomersResponse
6
+ include Epages::Utils
7
+
8
+ KEYS = %w(results page results_per_page items).collect(&:to_sym).freeze
9
+
10
+ attr_reader *KEYS
11
+
12
+ def initialize(data)
13
+ parse_attribute_as_array_of(:items, data.delete(:items), Epages::Customer)
14
+ parse_attributes(data)
15
+ end
16
+
17
+ alias_method :customers, :items
18
+ end
19
+ end
@@ -0,0 +1,15 @@
1
+ require 'epages/utils'
2
+
3
+ module Epages
4
+ class DeliveryWeightQuantity
5
+ include Epages::Utils
6
+
7
+ KEYS = %w(amount unit).collect(&:to_sym).freeze
8
+
9
+ attr_reader *KEYS
10
+
11
+ def initialize(data)
12
+ parse_attributes(data)
13
+ end
14
+ end
15
+ end
data/lib/epages/error.rb CHANGED
@@ -5,12 +5,15 @@ module Epages
5
5
  # Raised when a 4xx HTTP status code is returned
6
6
  ClientError = Class.new(self)
7
7
 
8
- # HTTP status code 400, 401, 403, 404, 406, 422, 429 respectively
8
+ # HTTP status code 400, 401, 403, 404, 405, 406, 409, 410, 422, 429 respectively
9
9
  BadRequest = Class.new(ClientError)
10
10
  Unauthorized = Class.new(ClientError)
11
11
  Forbidden = Class.new(ClientError)
12
12
  NotFound = Class.new(ClientError)
13
+ MethodNotAllowed = Class.new(ClientError)
13
14
  NotAcceptable = Class.new(ClientError)
15
+ Conflict = Class.new(ClientError)
16
+ Gone = Class.new(ClientError)
14
17
  UnprocessableEntity = Class.new(ClientError)
15
18
  TooManyRequests = Class.new(ClientError)
16
19
 
@@ -28,7 +31,10 @@ module Epages
28
31
  401 => Epages::Error::Unauthorized,
29
32
  403 => Epages::Error::Forbidden,
30
33
  404 => Epages::Error::NotFound,
34
+ 405 => Epages::Error::MethodNotAllowed,
31
35
  406 => Epages::Error::NotAcceptable,
36
+ 409 => Epages::Error::Conflict,
37
+ 410 => Epages::Error::Gone,
32
38
  422 => Epages::Error::UnprocessableEntity,
33
39
  429 => Epages::Error::TooManyRequests,
34
40
  500 => Epages::Error::InternalServerError,
@@ -4,7 +4,8 @@ module Epages
4
4
  class LineItemContainer
5
5
  include Epages::Utils
6
6
 
7
- KEYS = %w(grand_total total_before_tax total_tax line_items_sub_total product_line_items shipping_price).collect(&:to_sym).freeze
7
+ KEYS = %w(grand_total total_before_tax total_tax line_items_sub_total product_line_items shipping_price
8
+ coupon_line_item deposits eco_participations shipping_options basket_discount).collect(&:to_sym).freeze
8
9
 
9
10
  attr_reader *KEYS
10
11
 
@@ -0,0 +1,16 @@
1
+ require 'epages/utils'
2
+
3
+ module Epages
4
+ class MinimumCart
5
+ include Epages::Utils
6
+
7
+ KEYS = %w(status code amount).collect(&:to_sym).freeze
8
+
9
+ attr_reader *KEYS
10
+
11
+ def initialize(data)
12
+ parse_attribute_as(:amount, data.delete(:amount), Epages::Price)
13
+ parse_attributes(data)
14
+ end
15
+ end
16
+ end
data/lib/epages/order.rb CHANGED
@@ -6,7 +6,8 @@ module Epages
6
6
  include Epages::Utils
7
7
 
8
8
  DATE_ATTRS = %w(creation_date invoiced_on delivered_on pending_on archived_on dispatched_on viewed_on
9
- rejected_on closed_on paid_on returned_on)
9
+ rejected_on closed_on paid_on returned_on partially_dispatched_on partially_paid_on
10
+ partially_invoiced_on)
10
11
 
11
12
  ATTRS = %w(order_id order_number billing_address shipping_address customer_id locale currency_id tax_model
12
13
  grand_total total_before_tax line_item_container product_line_items shipping_price links internal_note
@@ -0,0 +1,19 @@
1
+ require 'epages/utils'
2
+ require 'epages/error'
3
+
4
+ module Epages
5
+ class OrdersResponse
6
+ include Epages::Utils
7
+
8
+ KEYS = %w(results page results_per_page items).collect(&:to_sym).freeze
9
+
10
+ attr_reader *KEYS
11
+
12
+ def initialize(data)
13
+ parse_attribute_as_array_of(:items, data.delete(:items), Epages::Order)
14
+ parse_attributes(data)
15
+ end
16
+
17
+ alias_method :orders, :items
18
+ end
19
+ end
@@ -4,7 +4,7 @@ module Epages
4
4
  class PaymentData
5
5
  include Epages::Utils
6
6
 
7
- KEYS = %w(payment_method price).collect(&:to_sym).freeze
7
+ KEYS = %w(payment_method price status).collect(&:to_sym).freeze
8
8
 
9
9
  attr_reader *KEYS
10
10
 
@@ -9,7 +9,8 @@ module Epages
9
9
  KEYS = %w(product_id name short_description description product_image images price_info for_sale special_offer delivery_weight
10
10
  shipping_methods_restricted_to availability_text availability energy_labels_string energy_label_source_file
11
11
  product_data_sheet sf_url product_number manufacturer upc ean essential_features search_keywords links tax_class
12
- stocklevel watchers).collect(&:to_sym).freeze
12
+ stocklevel watchers delivery_period visible manufacturer_product_number min_stock_level product_length
13
+ product_height product_width product_variation_type product_variation_selection).collect(&:to_sym).freeze
13
14
 
14
15
  attr_reader *KEYS
15
16
 
@@ -4,7 +4,7 @@ module Epages
4
4
  class ProductLineItem
5
5
  include Epages::Utils
6
6
 
7
- KEYS = %w(line_item_id sku name product_id quantity line_item_price single_item_price images links).collect(&:to_sym).freeze
7
+ KEYS = %w(line_item_id sku name product_id quantity line_item_price single_item_price images links delivery_weight).collect(&:to_sym).freeze
8
8
 
9
9
  attr_reader *KEYS
10
10
 
@@ -0,0 +1,19 @@
1
+ require 'epages/utils'
2
+ require 'epages/error'
3
+
4
+ module Epages
5
+ class ProductsResponse
6
+ include Epages::Utils
7
+
8
+ KEYS = %w(results page results_per_page items).collect(&:to_sym).freeze
9
+
10
+ attr_reader *KEYS
11
+
12
+ def initialize(data)
13
+ parse_attribute_as_array_of(:items, data.delete(:items), Epages::Product)
14
+ parse_attributes(data)
15
+ end
16
+
17
+ alias_method :products, :items
18
+ end
19
+ end
@@ -0,0 +1,15 @@
1
+ require 'epages/utils'
2
+
3
+ module Epages
4
+ class Quantity
5
+ include Epages::Utils
6
+
7
+ KEYS = %w(amount unit).collect(&:to_sym).freeze
8
+
9
+ attr_reader *KEYS
10
+
11
+ def initialize(data)
12
+ parse_attributes(data)
13
+ end
14
+ end
15
+ end
@@ -8,6 +8,8 @@ require 'epages/rest/orders'
8
8
  require 'epages/rest/products'
9
9
  require 'epages/rest/sales'
10
10
  require 'epages/rest/shipping_methods'
11
+ require 'epages/rest/tax_classes'
12
+ require 'epages/rest/webhooks'
11
13
 
12
14
  module Epages
13
15
  module REST
@@ -22,6 +24,8 @@ module Epages
22
24
  include REST::Products
23
25
  include REST::Sales
24
26
  include REST::ShippingMethods
27
+ include REST::TaxClasses
28
+ include REST::Webhooks
25
29
  end
26
30
  end
27
31
  end
@@ -19,6 +19,25 @@ module Epages
19
19
  perform_get_with_object("/carts/#{id}", {}, Epages::Cart)
20
20
  end
21
21
 
22
+ # implements the call https://developer.epages.com/apps/api-reference/post-shops-shopid-carts-cartid-coupon.html
23
+ def apply_coupon(cart, data = {})
24
+ id = epages_id(cart)
25
+ perform_post_with_object("/carts/#{id}/coupon", data, Epages::Cart)
26
+ end
27
+
28
+ # implements the call https://developer.epages.com/apps/api-reference/delete-shops-shopid-carts-cartid-coupon-couponlineitemid.html
29
+ # It needs the couponLineItemId to be able to delete it
30
+ def delete_coupon(cart, coupon_line_item_id)
31
+ id = epages_id(cart)
32
+ perform_delete_with_object("/carts/#{id}/coupon/#{coupon_line_item_id}", {}, Epages::Cart)
33
+ end
34
+
35
+ # implements the call https://developer.epages.com/apps/api-reference/post-shops-shopid-carts-cartid-order.html
36
+ def order_cart(cart)
37
+ id = epages_id(cart)
38
+ perform_post_with_object("/carts/#{id}/order", {}, Epages::Order)
39
+ end
40
+
22
41
  # implements the call https://developer.epages.com/apps/api-reference/post-shops-shopid-carts-cartid-line-items.html
23
42
  def cart_line_item(cart, product, quantity = 1)
24
43
  id = epages_id(cart)
@@ -66,12 +85,6 @@ module Epages
66
85
  id = epages_id(cart)
67
86
  perform_delete_with_object("/carts/#{id}/shipping-address", {}, Epages::Cart)
68
87
  end
69
-
70
- # implements the call https://developer.epages.com/apps/api-reference/post-shops-shopid-carts-cartid-order.html
71
- def order_cart(cart)
72
- id = epages_id(cart)
73
- perform_post_with_object("/carts/#{id}/order", {}, Epages::Order)
74
- end
75
88
  end
76
89
  end
77
90
  end
@@ -17,12 +17,49 @@ module Epages
17
17
  perform_get_with_object("/categories/#{id}", options, Epages::Category)
18
18
  end
19
19
 
20
+ # implements the call https://developer.epages.com/apps/api-reference/post-shops-shopid-categories-categoryid.html
21
+ # The id can be from the root category or to create a subcategory
22
+ def create_category(object, options = {})
23
+ id = epages_id(object)
24
+ perform_post_with_object("/categories/#{id}", options, Epages::Category)
25
+ end
26
+
20
27
  # implements the calls in https://developer.epages.com/apps/api-reference/put-shops-shopid-categories-categoryid.html
21
28
  def update_category(object, options)
22
29
  id = epages_id(object)
23
30
  options[:categoryId] = id
24
31
  perform_put_with_object("/categories/#{id}", options, Epages::Category)
25
32
  end
33
+
34
+ # implements the call https://developer.epages.com/apps/api-reference/delete-shops-shopid-categories-categoryid.html
35
+ def delete_category(category)
36
+ id = epages_id(category)
37
+ perform_delete_request("/categories/#{id}")
38
+ end
39
+
40
+ # implements the call https://developer.epages.com/apps/api-reference/get-shops-shopid-categories-categoryid-sequence.html
41
+ def subcategories(object)
42
+ id = epages_id(object)
43
+ perform_get_request("/categories/#{id}/sequence")
44
+ end
45
+
46
+ # implements the call https://developer.epages.com/apps/api-reference/put-shops-shopid-categories-categoryid-sequence.html
47
+ def reorder_subcategories(object, data)
48
+ id = epages_id(object)
49
+ perform_put_request("/categories/#{id}/sequence", data)
50
+ end
51
+
52
+ # implements the call https://developer.epages.com/apps/api-reference/post-shops-shopid-product-category-assignments.html
53
+ # Same as Epages::REST::Products#`assign_categories`
54
+ def assign_products(options = {})
55
+ perform_post_request('/product-category-assignments', options)
56
+ end
57
+
58
+ # implements the call https://developer.epages.com/apps/api-reference/delete-shops-shopid-product-category-assignments.html
59
+ # Same as Epages::REST::Products#`delete_from_categories`
60
+ def delete_products(options = {})
61
+ perform_delete_request('/product-category-assignments', options)
62
+ end
26
63
  end
27
64
  end
28
65
  end
@@ -11,7 +11,7 @@ module Epages
11
11
  #
12
12
  # @param options [Hash]
13
13
  def customers(options = {})
14
- perform_get_with_key_and_objects('/customers', options, :items, Epages::Customer)
14
+ perform_get_with_object('/customers', options, Epages::CustomersResponse)
15
15
  end
16
16
 
17
17
  # call the API to creates a customer. If customer_number is not provided in the request, it will be generated automatically.
@@ -7,27 +7,32 @@ module Epages
7
7
  module Miscellaneous
8
8
  include Epages::Utils
9
9
 
10
- # implements the cal https://developer.epages.com/apps/api-reference/get-shops-shopid.html
10
+ # implements the call https://developer.epages.com/apps/api-reference/get-shops-shopid.html
11
11
  def info(options = {})
12
12
  response = perform_get_request('/', options)
13
13
  underscorize_keys(response)
14
14
  end
15
15
 
16
- # implements the call https://developer.epages.com/apps/api-reference/get-shops-shopid-locales.html
17
- def locales
18
- perform_get_request('/locales', {})
19
- end
20
-
21
16
  # implements the call https://developer.epages.com/apps/api-reference/get-shops-shopid-currencies.html
22
17
  def currencies
23
18
  perform_get_request('/currencies', {})
24
19
  end
25
20
 
21
+ # implements the call https://developer.epages.com/apps/api-reference/get-shops-shopid-locales.html
22
+ def locales
23
+ perform_get_request('/locales', {})
24
+ end
25
+
26
26
  # implements the call https://developer.epages.com/apps/api-reference/get-shops-shopid-search-product-suggest.html
27
27
  def product_suggestions_for(query, options = {})
28
28
  response = perform_get_request('/search/product-suggest', options.merge(query: query))
29
29
  parse_suggestions_to_products(response)
30
30
  end
31
+
32
+ # implements the call https://developer.epages.com/apps/api-reference/get-shops-shopid-watched-products
33
+ def watched_products(options = {})
34
+ perform_get_request('/watched-products', {})
35
+ end
31
36
  end
32
37
  end
33
38
  end
@@ -8,7 +8,7 @@ module Epages
8
8
 
9
9
  # implements the calls in https://developer.epages.com/apps/api-reference/get-shops-shopid-orders.html
10
10
  def orders(options = {})
11
- perform_get_with_key_and_objects('/orders', options, :items, Epages::Order)
11
+ perform_get_with_object('/orders', options, Epages::OrdersResponse)
12
12
  end
13
13
 
14
14
  # implements the calls in https://developer.epages.com/apps/api-reference/get-shops-shopid-orders-orderid.html
@@ -11,7 +11,7 @@ module Epages
11
11
  #
12
12
  # @param options [Hash]
13
13
  def products(options = {})
14
- perform_get_with_key_and_objects('/products', options, :items, Epages::Product)
14
+ perform_get_with_object('/products', options, Epages::ProductsResponse)
15
15
  end
16
16
 
17
17
  # call the API and return a Epages::Product
@@ -123,16 +123,6 @@ module Epages
123
123
  parse_product_lowest_price(response)
124
124
  end
125
125
 
126
- # call the API and return an array of Epages::Link pointing to the categories of the product
127
- # implements the call https://developer.epages.com/apps/api-reference/get-shops-shopid-products-productid-categories.html
128
- #
129
- # @param product [String], [Epages::Product]
130
- # @param options [Hash]
131
- def product_categories(product, options = {})
132
- id = epages_id(product)
133
- perform_get_with_key_and_objects("/products/#{id}/categories", options, :links, Epages::Link)
134
- end
135
-
136
126
  # call the API and return an array of Epages::Product with updated attribute
137
127
  # implements the call https://developer.epages.com/apps/api-reference/get-shops-shopid-products-updated-productproperty.html
138
128
  #
@@ -158,6 +148,18 @@ module Epages
158
148
  def watched_products(options = {})
159
149
  perform_get_with_key_and_objects('/watched-products', options, :items, Epages::Product)
160
150
  end
151
+
152
+ # implements the call https://developer.epages.com/apps/api-reference/post-shops-shopid-product-category-assignments.html
153
+ # Same as Epages::REST::Categories#`assign_products`
154
+ def assign_categories(options = {})
155
+ perform_post_request('/product-category-assignments', options)
156
+ end
157
+
158
+ # implements the call https://developer.epages.com/apps/api-reference/delete-shops-shopid-product-category-assignments.html
159
+ # Same as Epages::REST::Categories#`delete_products`
160
+ def delete_from_categories(options = {})
161
+ perform_delete_request('/product-category-assignments', options)
162
+ end
161
163
  end
162
164
  end
163
165
  end
@@ -17,6 +17,8 @@ module Epages
17
17
 
18
18
  def set_request_options(method, options)
19
19
  @request_method = method
20
+ @is_a_new_webhook = new_webhook?(path)
21
+ @status_webhook = edit_webhook?(path)
20
22
  @headers = request_headers
21
23
  @options = format_options(options)
22
24
  end
@@ -27,7 +29,10 @@ module Epages
27
29
 
28
30
  # @return [Array, Hash]
29
31
  def perform
30
- response = HTTP.with(@headers).public_send(@request_method, @uri.to_s, options_passed_by => @options)
32
+ response = HTTP.headers(accept: @headers['Accept'],
33
+ authorization: @headers['Authorization'],
34
+ content_type: @headers['Content-Type'],
35
+ user_agent: @headers['User-Agent']).public_send(@request_method, @uri.to_s, options_passed_by => @options)
31
36
  fail_or_return_response_body(response)
32
37
  end
33
38
 
@@ -36,11 +41,14 @@ module Epages
36
41
  headers['Content-Type'] = content_type_options unless @request_method == :multipart_post
37
42
  headers['Accept'] = '*/*'
38
43
  headers['Authorization'] = auth_token if @shop.token?
44
+ headers['User-Agent'] = 'ruby gem'
39
45
  headers
40
46
  end
41
47
 
42
48
  def options_passed_by
43
- return :form if @request_method == :post && @options.key?(:image)
49
+ return :body if @is_a_new_webhook
50
+ return :form if @status_webhook
51
+ return :form if (@request_method == :post && @options.key?(:image))
44
52
  case @request_method
45
53
  when :get then :params
46
54
  when :patch then :body
@@ -49,10 +57,12 @@ module Epages
49
57
  end
50
58
 
51
59
  def content_type_options
60
+ return 'application/x-www-form-urlencoded' if @status_webhook
52
61
  @request_method == :patch ? 'application/json-patch+json' : 'application/json'
53
62
  end
54
63
 
55
64
  def format_options(options)
65
+ # return options if @status_webhook
56
66
  case @request_method
57
67
  when :multipart_post then options_to_multipart_request(options)
58
68
  when :patch then options_to_patch_request(options).to_json
@@ -77,6 +87,14 @@ module Epages
77
87
  fail Epages::Error::ERRORS[response.code], response.body.to_s
78
88
  end
79
89
  end
90
+
91
+ def new_webhook?(path)
92
+ (path.to_s == "/webhooks") && (@request_method == :post)
93
+ end
94
+
95
+ def edit_webhook?(path)
96
+ (path.to_s.include? "/webhooks/") && (@request_method == :post)
97
+ end
80
98
  end
81
99
  end
82
100
  end
@@ -6,13 +6,13 @@ module Epages
6
6
  module Sales
7
7
  include REST::Utils
8
8
 
9
- # call the API and return an array of Epages::Sale
9
+ # call the API and return an object of SalesSummary
10
10
  # implements the call https://developer.epages.com/apps/api-reference/get-shops-shopid-sales.html
11
11
  #
12
12
  # @param options [Hash]
13
13
  def sales(options = {})
14
14
  options[:product_id] = epages_id(options[:product_id]) if options[:product_id]
15
- perform_get_with_key_and_objects('/sales', format_dates_options(options), :salesPerCurrency, Epages::Sale)
15
+ perform_get_with_object('/sales', format_dates_options(options), Epages::SalesSummary)
16
16
  end
17
17
  end
18
18
  end
@@ -0,0 +1,21 @@
1
+ require 'epages/rest/utils'
2
+
3
+ module Epages
4
+ module REST
5
+ # implements the calls in https://developer.epages.com/apps/api-reference/resource-tax-classes
6
+ module TaxClasses
7
+ include REST::Utils
8
+
9
+ # implements the call https://developer.epages.com/apps/api-reference/get-shops-shopid-tax-classes-taxclassid.html
10
+ def tax_class(tax, options = {})
11
+ id = epages_id(tax)
12
+ perform_get_with_object("/tax-classes/#{id}", options, Epages::TaxClass)
13
+ end
14
+
15
+ # implements the call https://developer.epages.com/apps/api-reference/get-shops-shopid-tax-classes.html
16
+ def tax_classes(options = {})
17
+ perform_get_with_key_and_objects("/tax-classes/", options, :items, Epages::TaxClass)
18
+ end
19
+ end
20
+ end
21
+ end
@@ -116,6 +116,12 @@ module Epages
116
116
  perform_request(:get, path, options)
117
117
  end
118
118
 
119
+ # @param path [String]
120
+ # @param options [Hash]
121
+ def perform_post_request(path, options = {})
122
+ perform_request(:post, path, options)
123
+ end
124
+
119
125
  # @param path [String]
120
126
  # @param options [Hash]
121
127
  def perform_put_request(path, options = {})
@@ -150,11 +156,11 @@ module Epages
150
156
 
151
157
  def parse_legal_info(data)
152
158
  {
153
- contact_info: Epages::ContentPageSummary.new(data[:contactInformation]),
154
- privacy_policy: Epages::ContentPageSummary.new(data[:privacyPolicy]),
155
- terms_and_conditions: Epages::ContentPageSummary.new(data[:termsAndConditions]),
156
- rights_of_withdrawal: Epages::ContentPageSummary.new(data[:rightsOfWithdrawal]),
157
- shipping_info: Epages::ContentPageSummary.new(data[:shippingInformation]),
159
+ contact_info: Epages::ContentPageSummary.new(data[:contactInformation].nil? ? {'':''} : data[:contactInformation]),
160
+ privacy_policy: Epages::ContentPageSummary.new(data[:privacyPolicy].nil? ? {'':''} : data[:privacyPolicy]),
161
+ terms_and_conditions: Epages::ContentPageSummary.new(data[:termsAndConditions].nil? ? {'':''} : data[:termsAndConditions]),
162
+ rights_of_withdrawal: Epages::ContentPageSummary.new(data[:rightsOfWithdrawal].nil? ? {'':''} : data[:rightsOfWithdrawal]),
163
+ shipping_info: Epages::ContentPageSummary.new(data[:shippingInformation].nil? ? {'':''} : data[:shippingInformation]),
158
164
  links: parse_links(data[:links]),
159
165
  }
160
166
  end
@@ -0,0 +1,35 @@
1
+ require 'epages/utils'
2
+ require 'epages/rest/utils'
3
+
4
+ module Epages
5
+ module REST
6
+ module Webhooks
7
+ include REST::Utils
8
+
9
+ def webhook(webhook_id, options = {})
10
+ perform_get_with_object("/webhooks/#{webhook_id}", options, Epages::Webhook)
11
+ end
12
+
13
+ def create_webhook(callback_url, event_type)
14
+ available_events = ["PRODUCT_CREATE", "PRODUCT_UPDATE", "PRODUCT_DELETE", "ORDER_CREATE", "ORDER_UPDATE", "ORDER_DELETE", "APP_UNINSTALL"]
15
+ # return 'Invalid event' unless (available_events.include? event_type)
16
+ perform_post_with_object("/webhooks",
17
+ { 'callbackUrl': callback_url, 'eventType': event_type },
18
+ Epages::Webhook)
19
+ end
20
+
21
+ def activate_webhook(webhook_id)
22
+ perform_post_with_object("/webhooks/#{webhook_id}", { 'active': 'true' }, Epages::Webhook)
23
+ end
24
+
25
+ def deactivate_webhook(webhook_id)
26
+ perform_post_with_object("/webhooks/#{webhook_id}", { 'active': 'false' }, Epages::Webhook)
27
+ end
28
+
29
+ def delete_webhook(webhook_id, options = {})
30
+ answer = perform_delete_request("/webhooks/#{webhook_id}", options)
31
+ return answer.nil? ? 'Deleted' : 'Error'
32
+ end
33
+ end
34
+ end
35
+ end
@@ -2,10 +2,10 @@ require 'epages/utils'
2
2
  require 'epages/rest/sales'
3
3
 
4
4
  module Epages
5
- class Sale
5
+ class Sales
6
6
  include Epages::Utils
7
7
 
8
- KEYS = %w(currency total_gross_revenue total_net_revenue inits_sold total_orders).collect(&:to_sym).freeze
8
+ KEYS = %w(currency total_gross_revenue total_net_revenue units_sold total_orders).collect(&:to_sym).freeze
9
9
 
10
10
  attr_reader *KEYS
11
11
 
@@ -0,0 +1,19 @@
1
+ require 'epages/utils'
2
+ require 'epages/rest/sales'
3
+
4
+ module Epages
5
+ class SalesSummary
6
+ include Epages::Utils
7
+
8
+ KEYS = %w(created_after created_before sales_per_currency).collect(&:to_sym).freeze
9
+
10
+ attr_reader *KEYS
11
+
12
+ def initialize(data)
13
+ parse_attribute_as_array_of(:salesPerCurrency, data.delete(:salesPerCurrency), Epages::Sales)
14
+ parse_attributes(data)
15
+ end
16
+
17
+ alias_method :sales, :sales_per_currency
18
+ end
19
+ end
@@ -0,0 +1,16 @@
1
+ require 'epages/utils'
2
+
3
+ module Epages
4
+ class TaxClass
5
+ include Epages::Utils
6
+
7
+ KEYS = %w(tax_class_id name links).collect(&:to_sym).freeze
8
+
9
+ attr_reader *KEYS
10
+
11
+ def initialize(data)
12
+ @links = data.delete(:links).collect { |i| Epages::Link.new(i) } if data[:links]
13
+ parse_attributes(data)
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,15 @@
1
+ require 'epages/utils'
2
+
3
+ module Epages
4
+ class TaxClassInfo
5
+ include Epages::Utils
6
+
7
+ KEYS = %w(tax_class_id name percentage).collect(&:to_sym).freeze
8
+
9
+ attr_reader *KEYS
10
+
11
+ def initialize(data)
12
+ parse_attributes(data)
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ require 'epages/utils'
2
+
3
+ module Epages
4
+ class VariationIdentifier
5
+ include Epages::Utils
6
+
7
+ KEYS = %w(name value).collect(&:to_sym).freeze
8
+
9
+ attr_reader *KEYS
10
+
11
+ def initialize(data)
12
+ parse_attributes(data)
13
+ end
14
+ end
15
+ end
@@ -1,3 +1,3 @@
1
1
  module Epages
2
- VERSION = '1.0.6'
2
+ VERSION = '1.0.7'
3
3
  end
@@ -0,0 +1,18 @@
1
+ require 'epages/utils'
2
+
3
+ module Epages
4
+ class Webhook
5
+ include Epages::Utils
6
+
7
+ KEYS = %w(webhook_id active event_type callback_url created_on updated_on links).collect(&:to_sym).freeze
8
+
9
+ attr_reader *KEYS
10
+
11
+ def initialize(data)
12
+ parse_attribute_as_array_of(:links, data.delete(:links), Epages::Link)
13
+ parse_attributes(data)
14
+ end
15
+
16
+ alias_method :id, :webhook_id
17
+ end
18
+ end
@@ -0,0 +1,19 @@
1
+ require 'epages/utils'
2
+
3
+ module Epages
4
+ class WebhookResponse
5
+ include Epages::Utils
6
+
7
+ KEYS = %w(links content page).collect(&:to_sym).freeze
8
+
9
+ attr_reader *KEYS
10
+
11
+ def initialize(data)
12
+ parse_attribute_as_array_of(:links, data.delete(:links), Epages::Link)
13
+ parse_attribute_as_array_of(:content, data.delete(:content), Epages::Webhook)
14
+ parse_attribute_as(:page, data.delete(:page), Epages::WebhookResponsePagination)
15
+ end
16
+
17
+ alias_method :webhooks, :content
18
+ end
19
+ end
@@ -0,0 +1,15 @@
1
+ require 'epages/utils'
2
+
3
+ module Epages
4
+ class WebhookResponsePagination
5
+ include Epages::Utils
6
+
7
+ KEYS = %w(size total_elements total_pages number).collect(&:to_sym).freeze
8
+
9
+ attr_reader *KEYS
10
+
11
+ def initialize(data)
12
+ parse_attributes(data)
13
+ end
14
+ end
15
+ end
data/lib/epages-rest.rb CHANGED
@@ -4,30 +4,43 @@ require 'epages/cart'
4
4
  require 'epages/category'
5
5
  require 'epages/content_page_summary'
6
6
  require 'epages/customer'
7
+ require 'epages/customers_response'
7
8
  require 'epages/custom_attribute'
9
+ require 'epages/delivery_weight_quantity'
8
10
  require 'epages/error'
9
11
  require 'epages/image'
10
12
  require 'epages/image_size'
11
13
  require 'epages/line_item_container'
12
14
  require 'epages/link'
13
15
  require 'epages/newsletter'
16
+ require 'epages/minimum_cart'
14
17
  require 'epages/order'
18
+ require 'epages/orders_response'
15
19
  require 'epages/payment_data'
16
20
  require 'epages/payment_method_info'
17
21
  require 'epages/price'
18
22
  require 'epages/price_info'
19
23
  require 'epages/product'
24
+ require 'epages/products_response'
20
25
  require 'epages/product_line_item'
21
- require 'epages/sale'
26
+ require 'epages/quantity'
27
+ require 'epages/sales'
28
+ require 'epages/sales_summary'
22
29
  require 'epages/shipping_data'
23
30
  require 'epages/shipping_method'
24
31
  require 'epages/shipping_method_info'
25
32
  require 'epages/shop'
26
33
  require 'epages/subscriber'
34
+ require 'epages/tax_class'
35
+ require 'epages/tax_class_info'
27
36
  require 'epages/utils'
28
37
  require 'epages/variation'
29
38
  require 'epages/variation_attribute'
39
+ require 'epages/variation_identifier'
30
40
  require 'epages/version'
41
+ require 'epages/webhook_response_pagination'
42
+ require 'epages/webhook_response'
43
+ require 'epages/webhook'
31
44
 
32
45
  require 'epages/rest/api'
33
46
  require 'epages/rest/carts'
@@ -41,4 +54,6 @@ require 'epages/rest/request'
41
54
  require 'epages/rest/sales'
42
55
  require 'epages/rest/shipping_methods'
43
56
  require 'epages/rest/shop'
57
+ require 'epages/rest/tax_classes'
44
58
  require 'epages/rest/utils'
59
+ require 'epages/rest/webhooks'
metadata CHANGED
@@ -1,14 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: epages-rest
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.6
4
+ version: 1.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Domingo Cividanes
8
+ - Unai Martinez
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2016-05-13 00:00:00.000000000 Z
12
+ date: 2017-05-23 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: bundler
@@ -16,47 +17,46 @@ dependencies:
16
17
  requirements:
17
18
  - - "~>"
18
19
  - !ruby/object:Gem::Version
19
- version: '1.10'
20
+ version: '1.13'
20
21
  type: :development
21
22
  prerelease: false
22
23
  version_requirements: !ruby/object:Gem::Requirement
23
24
  requirements:
24
25
  - - "~>"
25
26
  - !ruby/object:Gem::Version
26
- version: '1.10'
27
+ version: '1.13'
27
28
  - !ruby/object:Gem::Dependency
28
29
  name: http
29
30
  requirement: !ruby/object:Gem::Requirement
30
31
  requirements:
31
32
  - - "~>"
32
33
  - !ruby/object:Gem::Version
33
- version: 0.9.4
34
+ version: '2.1'
34
35
  type: :runtime
35
36
  prerelease: false
36
37
  version_requirements: !ruby/object:Gem::Requirement
37
38
  requirements:
38
39
  - - "~>"
39
40
  - !ruby/object:Gem::Version
40
- version: 0.9.4
41
+ version: '2.1'
41
42
  - !ruby/object:Gem::Dependency
42
43
  name: activesupport
43
44
  requirement: !ruby/object:Gem::Requirement
44
45
  requirements:
45
46
  - - "~>"
46
47
  - !ruby/object:Gem::Version
47
- version: '4.2'
48
+ version: '5.0'
48
49
  type: :runtime
49
50
  prerelease: false
50
51
  version_requirements: !ruby/object:Gem::Requirement
51
52
  requirements:
52
53
  - - "~>"
53
54
  - !ruby/object:Gem::Version
54
- version: '4.2'
55
+ version: '5.0'
55
56
  description: A Ruby interface that allows to integrate any Epages Shop with any ruby
56
57
  framework via Epages Rest API.
57
58
  email:
58
- - dcividanes91@gmail.com
59
- - dcividanes@epages.com
59
+ - u.martinez@epages.com
60
60
  executables: []
61
61
  extensions: []
62
62
  extra_rdoc_files: []
@@ -72,19 +72,25 @@ files:
72
72
  - lib/epages/content_page_summary.rb
73
73
  - lib/epages/custom_attribute.rb
74
74
  - lib/epages/customer.rb
75
+ - lib/epages/customers_response.rb
76
+ - lib/epages/delivery_weight_quantity.rb
75
77
  - lib/epages/error.rb
76
78
  - lib/epages/image.rb
77
79
  - lib/epages/image_size.rb
78
80
  - lib/epages/line_item_container.rb
79
81
  - lib/epages/link.rb
82
+ - lib/epages/minimum_cart.rb
80
83
  - lib/epages/newsletter.rb
81
84
  - lib/epages/order.rb
85
+ - lib/epages/orders_response.rb
82
86
  - lib/epages/payment_data.rb
83
87
  - lib/epages/payment_method_info.rb
84
88
  - lib/epages/price.rb
85
89
  - lib/epages/price_info.rb
86
90
  - lib/epages/product.rb
87
91
  - lib/epages/product_line_item.rb
92
+ - lib/epages/products_response.rb
93
+ - lib/epages/quantity.rb
88
94
  - lib/epages/rest/api.rb
89
95
  - lib/epages/rest/carts.rb
90
96
  - lib/epages/rest/categories.rb
@@ -98,17 +104,26 @@ files:
98
104
  - lib/epages/rest/sales.rb
99
105
  - lib/epages/rest/shipping_methods.rb
100
106
  - lib/epages/rest/shop.rb
107
+ - lib/epages/rest/tax_classes.rb
101
108
  - lib/epages/rest/utils.rb
102
- - lib/epages/sale.rb
109
+ - lib/epages/rest/webhooks.rb
110
+ - lib/epages/sales.rb
111
+ - lib/epages/sales_summary.rb
103
112
  - lib/epages/shipping_data.rb
104
113
  - lib/epages/shipping_method.rb
105
114
  - lib/epages/shipping_method_info.rb
106
115
  - lib/epages/shop.rb
107
116
  - lib/epages/subscriber.rb
117
+ - lib/epages/tax_class.rb
118
+ - lib/epages/tax_class_info.rb
108
119
  - lib/epages/utils.rb
109
120
  - lib/epages/variation.rb
110
121
  - lib/epages/variation_attribute.rb
122
+ - lib/epages/variation_identifier.rb
111
123
  - lib/epages/version.rb
124
+ - lib/epages/webhook.rb
125
+ - lib/epages/webhook_response.rb
126
+ - lib/epages/webhook_response_pagination.rb
112
127
  homepage: https://github.com/ePages-de/epages-rest-ruby
113
128
  licenses:
114
129
  - MIT
@@ -129,9 +144,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
129
144
  version: '0'
130
145
  requirements: []
131
146
  rubyforge_project:
132
- rubygems_version: 2.5.1
147
+ rubygems_version: 2.6.11
133
148
  signing_key:
134
149
  specification_version: 4
135
150
  summary: A Ruby interface to the Epages Rest API.
136
151
  test_files: []
137
- has_rdoc: