epages-rest 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/LICENSE.txt +21 -0
- data/README.md +45 -0
- data/epages-rest.gemspec +22 -0
- data/lib/epages/address.rb +29 -0
- data/lib/epages/base_price.rb +16 -0
- data/lib/epages/cart.rb +18 -0
- data/lib/epages/category.rb +25 -0
- data/lib/epages/content_page_summary.rb +13 -0
- data/lib/epages/custom_attribute.rb +20 -0
- data/lib/epages/error.rb +61 -0
- data/lib/epages/image.rb +13 -0
- data/lib/epages/image_size.rb +26 -0
- data/lib/epages/line_item_container.rb +19 -0
- data/lib/epages/link.rb +13 -0
- data/lib/epages/order.rb +28 -0
- data/lib/epages/price.rb +15 -0
- data/lib/epages/price_info.rb +18 -0
- data/lib/epages/product.rb +87 -0
- data/lib/epages/product_line_item.rb +20 -0
- data/lib/epages/rest/api.rb +21 -0
- data/lib/epages/rest/carts.rb +71 -0
- data/lib/epages/rest/categories.rb +28 -0
- data/lib/epages/rest/legal.rb +81 -0
- data/lib/epages/rest/miscellaneous.rb +27 -0
- data/lib/epages/rest/orders.rb +29 -0
- data/lib/epages/rest/products.rb +106 -0
- data/lib/epages/rest/request.rb +53 -0
- data/lib/epages/rest/shipping_methods.rb +22 -0
- data/lib/epages/rest/shop.rb +12 -0
- data/lib/epages/rest/utils.rb +166 -0
- data/lib/epages/shipping_method.rb +15 -0
- data/lib/epages/shop.rb +22 -0
- data/lib/epages/utils.rb +85 -0
- data/lib/epages/variation.rb +30 -0
- data/lib/epages/variation_attribute.rb +23 -0
- data/lib/epages/version.rb +3 -0
- data/lib/epages-rest.rb +33 -0
- metadata +126 -0
@@ -0,0 +1,81 @@
|
|
1
|
+
require 'epages/utils'
|
2
|
+
require 'epages/rest/utils'
|
3
|
+
|
4
|
+
module Epages
|
5
|
+
module REST
|
6
|
+
# implements the calls in https://developer.epages.com/apps/api-reference/resource-legal.html
|
7
|
+
module Legal
|
8
|
+
include Epages::Utils
|
9
|
+
# implements the call https://developer.epages.com/apps/api-reference/get-shops-shopid-legal.html
|
10
|
+
def legal(options = {})
|
11
|
+
response = perform_get_request('/legal', options)
|
12
|
+
parse_legal_info(response)
|
13
|
+
end
|
14
|
+
|
15
|
+
# implements the call https://developer.epages.com/apps/api-reference/get-shops-shopid-legal-contact-information.html
|
16
|
+
def contact_info(options = {})
|
17
|
+
response = perform_get_request('/legal/contact-information', options)
|
18
|
+
underscorize_keys(response)
|
19
|
+
end
|
20
|
+
|
21
|
+
# implements the call https://developer.epages.com/apps/api-reference/put-shops-shopid-legal-contact-information.html
|
22
|
+
def update_contact_info(options, locale = 'en_GB')
|
23
|
+
old_data = contact_info(locale: locale)
|
24
|
+
response = perform_put_request("/legal/contact-information?locale=#{locale}", old_data.merge(options))
|
25
|
+
underscorize_keys(response)
|
26
|
+
end
|
27
|
+
|
28
|
+
# implements the call https://developer.epages.com/apps/api-reference/get-shops-shopid-legal-privacy-policy.html
|
29
|
+
def privacy_policy(options = {})
|
30
|
+
response = perform_get_request('/legal/privacy-policy', options)
|
31
|
+
underscorize_keys(response)
|
32
|
+
end
|
33
|
+
|
34
|
+
# implements the call https://developer.epages.com/apps/api-reference/put-shops-shopid-legal-privacy-policy.html
|
35
|
+
def update_privacy_policy(options, locale = 'en_GB')
|
36
|
+
old_data = privacy_policy(locale: locale)
|
37
|
+
response = perform_put_request("/legal/privacy-policy?locale=#{locale}", old_data.merge(options))
|
38
|
+
underscorize_keys(response)
|
39
|
+
end
|
40
|
+
|
41
|
+
# implements the call https://developer.epages.com/apps/api-reference/get-shops-shopid-legal-terms-and-conditions.html
|
42
|
+
def terms_and_conditions(options = {})
|
43
|
+
response = perform_get_request('/legal/terms-and-conditions', options)
|
44
|
+
underscorize_keys(response)
|
45
|
+
end
|
46
|
+
|
47
|
+
# implements the call https://developer.epages.com/apps/api-reference/put-shops-shopid-legal-terms-and-conditions.html
|
48
|
+
def update_terms_and_conditions(options, locale = 'en_GB')
|
49
|
+
old_data = terms_and_conditions(locale: locale)
|
50
|
+
response = perform_put_request("/legal/terms-and-conditions?locale=#{locale}", old_data.merge(options))
|
51
|
+
underscorize_keys(response)
|
52
|
+
end
|
53
|
+
|
54
|
+
# implements the call https://developer.epages.com/apps/api-reference/get-shops-shopid-legal-rights-of-withdrawal.html
|
55
|
+
def rights_of_withdrawal(options = {})
|
56
|
+
response = perform_get_request('/legal/rights-of-withdrawal', options)
|
57
|
+
underscorize_keys(response)
|
58
|
+
end
|
59
|
+
|
60
|
+
# implements the call https://developer.epages.com/apps/api-reference/put-shops-shopid-legal-rights-of-withdrawal.html
|
61
|
+
def update_rights_of_withdrawal(options, locale = 'en_GB')
|
62
|
+
old_data = rights_of_withdrawal(locale: locale)
|
63
|
+
response = perform_put_request("/legal/rights-of-withdrawal?locale=#{locale}", old_data.merge(options))
|
64
|
+
underscorize_keys(response)
|
65
|
+
end
|
66
|
+
|
67
|
+
# implements the call https://developer.epages.com/apps/api-reference/get-shops-shopid-legal-shipping-information.html
|
68
|
+
def shipping_info(options = {})
|
69
|
+
response = perform_get_request('/legal/shipping-information', options)
|
70
|
+
underscorize_keys(response)
|
71
|
+
end
|
72
|
+
|
73
|
+
# implements the call https://developer.epages.com/apps/api-reference/put-shops-shopid-legal-shipping-information.html
|
74
|
+
def update_shipping_info(options, locale = 'en_GB')
|
75
|
+
old_data = shipping_info(locale: locale)
|
76
|
+
response = perform_put_request("/legal/shipping-information?locale=#{locale}", old_data.merge(options))
|
77
|
+
underscorize_keys(response)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'epages/utils'
|
2
|
+
require 'epages/rest/utils'
|
3
|
+
|
4
|
+
module Epages
|
5
|
+
module REST
|
6
|
+
# implement the calls in https://developer.epages.com/apps/api-reference/resource-miscellaneous.html
|
7
|
+
module Miscellaneous
|
8
|
+
include Epages::Utils
|
9
|
+
|
10
|
+
# implements the call https://developer.epages.com/apps/api-reference/get-shops-shopid-locales.html
|
11
|
+
def locales
|
12
|
+
perform_get_request('/locales', {})
|
13
|
+
end
|
14
|
+
|
15
|
+
# implements the call https://developer.epages.com/apps/api-reference/get-shops-shopid-currencies.html
|
16
|
+
def currencies
|
17
|
+
perform_get_request('/currencies', {})
|
18
|
+
end
|
19
|
+
|
20
|
+
# implements the call https://developer.epages.com/apps/api-reference/get-shops-shopid-search-product-suggest.html
|
21
|
+
def product_suggestions_for(query, options = {})
|
22
|
+
response = perform_get_request('/search/product-suggest', options.merge(query: query))
|
23
|
+
parse_suggestions_to_products(response)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'epages/rest/utils'
|
2
|
+
|
3
|
+
module Epages
|
4
|
+
module REST
|
5
|
+
module Orders
|
6
|
+
# implements the calls in https://developer.epages.com/apps/api-reference/resource-orders.html
|
7
|
+
include REST::Utils
|
8
|
+
|
9
|
+
# implements the calls in https://developer.epages.com/apps/api-reference/get-shops-shopid-orders.html
|
10
|
+
def orders(options = {})
|
11
|
+
perform_get_with_key_and_objects('/orders', options, :items, Epages::Order)
|
12
|
+
end
|
13
|
+
|
14
|
+
# implements the calls in https://developer.epages.com/apps/api-reference/get-shops-shopid-orders-orderid.html
|
15
|
+
def order(order, options = {})
|
16
|
+
id = epages_id(order)
|
17
|
+
perform_get_with_object("/orders/#{id}", options, Epages::Order)
|
18
|
+
end
|
19
|
+
|
20
|
+
# implements the calls in https://developer.epages.com/apps/api-reference/put-shops-shopid-orders-orderid.html
|
21
|
+
def update_order(order, options, locale = 'en_GB')
|
22
|
+
options.each { |k, v| options[k] = v.to_json if v.class.name.deconstantize == 'Epages' }
|
23
|
+
id = epages_id(order)
|
24
|
+
old_order = perform_get_request("/orders/#{id}", locale: locale)
|
25
|
+
perform_put_with_object("/orders/#{id}?locale=#{locale}", old_order.merge(options), Epages::Order)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,106 @@
|
|
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-product.html
|
6
|
+
module Products
|
7
|
+
include REST::Utils
|
8
|
+
|
9
|
+
# call the API and return an array of Epages::Product
|
10
|
+
# implements the call https://developer.epages.com/apps/api-reference/get-shops-shopid-products.html
|
11
|
+
#
|
12
|
+
# @param options [Hash]
|
13
|
+
def products(options = {})
|
14
|
+
perform_get_with_key_and_objects('/products', options, :items, Epages::Product)
|
15
|
+
end
|
16
|
+
|
17
|
+
# call the API and return a Epages::Product
|
18
|
+
# implements the call https://developer.epages.com/apps/api-reference/get-shops-shopid-products-productid.html
|
19
|
+
#
|
20
|
+
# @param product [String], [Epages::Product]
|
21
|
+
# @param options [Hash]
|
22
|
+
def product(product, options = {})
|
23
|
+
id = epages_id(product)
|
24
|
+
perform_get_with_object("/products/#{id}", options, Epages::Product)
|
25
|
+
end
|
26
|
+
|
27
|
+
# call the API and return a Hash with the respective variation_attributes and the variation products
|
28
|
+
# implements the call https://developer.epages.com/apps/api-reference/get-shops-shopid-products-productid-variations.html
|
29
|
+
#
|
30
|
+
# @param product [String], [Epages::Product]
|
31
|
+
# @param options [Hash]
|
32
|
+
def product_variations(product, options = {})
|
33
|
+
id = epages_id(product)
|
34
|
+
response = perform_get_request("/products/#{id}/variations", options)
|
35
|
+
parse_product_variations(response)
|
36
|
+
end
|
37
|
+
|
38
|
+
# call the API and return an array of Epages::ImageSize (slides) of the product
|
39
|
+
# implements the call https://developer.epages.com/apps/api-reference/get-shops-shopid-products-productid-slideshow.html
|
40
|
+
#
|
41
|
+
# @param product [String], [Epages::Product]
|
42
|
+
def product_slideshow(product)
|
43
|
+
id = epages_id(product)
|
44
|
+
perform_get_with_key_and_objects("/products/#{id}/slideshow", {}, :items, Epages::ImageSize)
|
45
|
+
end
|
46
|
+
|
47
|
+
# call the API and return an array of Epages::CustomAttribute of the product
|
48
|
+
# implements the call https://developer.epages.com/apps/api-reference/get-shops-shopid-products-productid-custom-attributes.html
|
49
|
+
#
|
50
|
+
# @param product [String], [Epages::Product]
|
51
|
+
# @param options [Hash]
|
52
|
+
def product_custom_attributes(product, options = {})
|
53
|
+
id = epages_id(product)
|
54
|
+
perform_get_with_key_and_objects("/products/#{id}/custom-attributes", options, :items, Epages::CustomAttribute)
|
55
|
+
end
|
56
|
+
|
57
|
+
# call the API and return a hash with the lowest price of the product and the respective link
|
58
|
+
# implements the call https://developer.epages.com/apps/api-reference/get-shops-shopid-products-productid-lowest-price.html
|
59
|
+
#
|
60
|
+
# @param product [String], [Epages::Product]
|
61
|
+
# @param options [Hash]
|
62
|
+
def product_lowest_price(product, options = {})
|
63
|
+
id = epages_id(product)
|
64
|
+
response = perform_get_request("/products/#{id}/lowest-price", options)
|
65
|
+
parse_product_lowest_price(response)
|
66
|
+
end
|
67
|
+
|
68
|
+
# call the API and return an array of Epages::Link pointing to the categories of the product
|
69
|
+
# implements the call https://developer.epages.com/apps/api-reference/get-shops-shopid-products-productid-categories.html
|
70
|
+
#
|
71
|
+
# @param product [String], [Epages::Product]
|
72
|
+
# @param options [Hash]
|
73
|
+
def product_categories(product, options = {})
|
74
|
+
id = epages_id(product)
|
75
|
+
perform_get_with_key_and_objects("/products/#{id}/categories", options, :links, Epages::Link)
|
76
|
+
end
|
77
|
+
|
78
|
+
# call the API and return a hash that contains the stock-level
|
79
|
+
# implements the call https://developer.epages.com/apps/api-reference/get-shops-shopid-products-productid-stock-level.html
|
80
|
+
#
|
81
|
+
# @param product [String], [Epages::Product]
|
82
|
+
def product_stock_level(product)
|
83
|
+
id = epages_id(product)
|
84
|
+
perform_get_request("/products/#{id}/stock-level", {})[:stocklevel]
|
85
|
+
end
|
86
|
+
|
87
|
+
# call the API to modify the current stock level of the product
|
88
|
+
# implements the call https://developer.epages.com/apps/api-reference/get-shops-shopid-products-productid-stock-level.html
|
89
|
+
#
|
90
|
+
# @param product [String], [Epages::Product]
|
91
|
+
# @param units [Fixnum]
|
92
|
+
def product_change_stock_level(product, units)
|
93
|
+
id = epages_id(product)
|
94
|
+
perform_put_request("/products/#{id}/stock-level", changeStocklevel: units)[:stocklevel]
|
95
|
+
end
|
96
|
+
|
97
|
+
# call the API and return a CSV with the proper data of the products
|
98
|
+
# implements the call https://developer.epages.com/apps/api-reference/get-shops-shopid-products-export.html
|
99
|
+
#
|
100
|
+
# @param options [Hash]
|
101
|
+
def export_products(options = {})
|
102
|
+
perform_get_request('/products/export', options)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'http'
|
2
|
+
require 'epages/utils'
|
3
|
+
|
4
|
+
module Epages
|
5
|
+
module REST
|
6
|
+
class Request
|
7
|
+
include Epages::Utils
|
8
|
+
|
9
|
+
BASE_URL = 'https://pm.epages.com/rs/shops/'
|
10
|
+
attr_accessor :shop, :uri, :path, :request_method, :options, :headers
|
11
|
+
|
12
|
+
def initialize(object, request_method, path, options = {})
|
13
|
+
@shop = build_shop_from(object)
|
14
|
+
@uri = URI.parse(BASE_URL + @shop.name.to_s + path)
|
15
|
+
@path = uri.path
|
16
|
+
set_options(request_method, options)
|
17
|
+
end
|
18
|
+
|
19
|
+
def set_options(method, options)
|
20
|
+
@options = camelize_keys(options)
|
21
|
+
@request_method = method
|
22
|
+
@headers = request_headers
|
23
|
+
end
|
24
|
+
|
25
|
+
def auth_token
|
26
|
+
"Bearer #{@shop.token}"
|
27
|
+
end
|
28
|
+
|
29
|
+
# @return [Array, Hash]
|
30
|
+
def perform
|
31
|
+
options_key = @request_method == :get ? :params : :json
|
32
|
+
response = HTTP.with(@headers).public_send(@request_method, @uri.to_s, options_key => @options)
|
33
|
+
fail_or_return_response_body(response)
|
34
|
+
end
|
35
|
+
|
36
|
+
def request_headers
|
37
|
+
headers = {}
|
38
|
+
headers['Content-Type'] = 'application/json'
|
39
|
+
headers['Accept'] = '*/*'
|
40
|
+
headers['Authorization'] = auth_token if @shop.token?
|
41
|
+
headers
|
42
|
+
end
|
43
|
+
|
44
|
+
def fail_or_return_response_body(response)
|
45
|
+
if response.code.between?(200, 206)
|
46
|
+
symbolize_keys!(response.parse)
|
47
|
+
else
|
48
|
+
fail Epages::Error::ERRORS[response.code], JSON.parse(response.body.to_s)['message']
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'epages/utils'
|
2
|
+
require 'epages/rest/utils'
|
3
|
+
|
4
|
+
module Epages
|
5
|
+
module REST
|
6
|
+
# implement the calls in https://developer.epages.com/apps/api-reference/resource-shipping-method.html
|
7
|
+
module ShippingMethods
|
8
|
+
include Epages::Utils
|
9
|
+
|
10
|
+
# implements the call https://developer.epages.com/apps/api-reference/get-shops-shopid-shipping-methods.html
|
11
|
+
def shipping_methods(options = {})
|
12
|
+
perform_get_with_objects('/shipping-methods', options, Epages::ShippingMethod)
|
13
|
+
end
|
14
|
+
|
15
|
+
# implements the call https://developer.epages.com/apps/api-reference/get-shops-shopid-shipping-methods-shippingmethodid.html
|
16
|
+
def shipping_method(object, options = {})
|
17
|
+
id = epages_id(object)
|
18
|
+
perform_get_with_object("/shipping-methods/#{id}", options, Epages::ShippingMethod)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,166 @@
|
|
1
|
+
module Epages
|
2
|
+
module REST
|
3
|
+
module Utils
|
4
|
+
# @param request_method [Symbol]
|
5
|
+
# @param path [String]
|
6
|
+
# @param options [Hash]
|
7
|
+
def perform_request(request_method, path, options = {})
|
8
|
+
Epages::REST::Request.new(self, request_method, path, options).perform
|
9
|
+
end
|
10
|
+
|
11
|
+
# @param path [String]
|
12
|
+
# @param options [Hash]
|
13
|
+
# @param klass [Class]
|
14
|
+
def perform_get_with_object(path, options, klass)
|
15
|
+
perform_request_with_object(:get, path, options, klass)
|
16
|
+
end
|
17
|
+
|
18
|
+
# @param path [String]
|
19
|
+
# @param options [Hash]
|
20
|
+
# @param klass [Class]
|
21
|
+
def perform_post_with_object(path, options, klass)
|
22
|
+
perform_request_with_object(:post, path, options, klass)
|
23
|
+
end
|
24
|
+
|
25
|
+
# @param path [String]
|
26
|
+
# @param options [Hash]
|
27
|
+
# @param klass [Class]
|
28
|
+
def perform_put_with_object(path, options, klass)
|
29
|
+
perform_request_with_object(:put, path, options, klass)
|
30
|
+
end
|
31
|
+
|
32
|
+
# @param path [String]
|
33
|
+
# @param options [Hash]
|
34
|
+
# @param klass [Class]
|
35
|
+
def perform_delete_with_object(path, options, klass)
|
36
|
+
perform_request_with_object(:delete, path, options, klass)
|
37
|
+
end
|
38
|
+
|
39
|
+
# @param request_method [Symbol]
|
40
|
+
# @param path [String]
|
41
|
+
# @param options [Hash]
|
42
|
+
# @param klass [Class]
|
43
|
+
def perform_request_with_object(request_method, path, options, klass)
|
44
|
+
response = perform_request(request_method, path, options)
|
45
|
+
klass.new(response)
|
46
|
+
end
|
47
|
+
|
48
|
+
# @param path [String]
|
49
|
+
# @param options [Hash]
|
50
|
+
# @param klass [Class]
|
51
|
+
def perform_get_with_objects(path, options, klass)
|
52
|
+
perform_request_with_objects(:get, path, options, klass)
|
53
|
+
end
|
54
|
+
|
55
|
+
# @param path [String]
|
56
|
+
# @param options [Hash]
|
57
|
+
# @param klass [Class]
|
58
|
+
def perform_post_with_objects(path, options, klass)
|
59
|
+
perform_request_with_objects(:post, path, options, klass)
|
60
|
+
end
|
61
|
+
|
62
|
+
# @param request_method [Symbol]
|
63
|
+
# @param path [String]
|
64
|
+
# @param options [Hash]
|
65
|
+
# @param klass [Class]
|
66
|
+
def perform_request_with_objects(request_method, path, options, klass)
|
67
|
+
perform_request(request_method, path, options).collect do |element|
|
68
|
+
klass.new(element)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
# @param path [String]
|
73
|
+
# @param options [Hash]
|
74
|
+
# @param key [Symbol]
|
75
|
+
# @param klass [Class]
|
76
|
+
def perform_get_with_key_and_objects(path, options, key, klass)
|
77
|
+
perform_request_with_key_and_objects(:get, path, options, key, klass)
|
78
|
+
end
|
79
|
+
|
80
|
+
# @param path [String]
|
81
|
+
# @param options [Hash]
|
82
|
+
# @param key [Symbol]
|
83
|
+
# @param klass [Class]
|
84
|
+
def perform_post_with_key_and_objects(path, options, key, klass)
|
85
|
+
perform_request_with_key_and_objects(:post, path, options, key, klass)
|
86
|
+
end
|
87
|
+
|
88
|
+
# TODO: refactor code bellow
|
89
|
+
# @param path [String]
|
90
|
+
# @param options [Hash]
|
91
|
+
# @param key [Symbol]
|
92
|
+
# @param klass [Class]
|
93
|
+
def perform_request_with_key_and_objects(request_method, path, options, key, klass)
|
94
|
+
perform_request(request_method, path, options)[key].collect do |element|
|
95
|
+
klass.new(element)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
# @param path [String]
|
100
|
+
# @param options [Hash]
|
101
|
+
def perform_get_request(path, options)
|
102
|
+
perform_request(:get, path, options)
|
103
|
+
end
|
104
|
+
|
105
|
+
# @param path [String]
|
106
|
+
# @param options [Hash]
|
107
|
+
def perform_put_request(path, options)
|
108
|
+
perform_request(:put, path, options)
|
109
|
+
end
|
110
|
+
|
111
|
+
def epages_id(object)
|
112
|
+
return object if object.class == String
|
113
|
+
return if object.class.name.deconstantize != 'Epages'
|
114
|
+
object.send("#{object.class.name.demodulize.downcase}_id")
|
115
|
+
end
|
116
|
+
|
117
|
+
def parse_product_variations(data)
|
118
|
+
{
|
119
|
+
variation_attributes: parse_variations(data),
|
120
|
+
items: parse_variation_object(data),
|
121
|
+
}
|
122
|
+
end
|
123
|
+
|
124
|
+
def parse_product_lowest_price(data)
|
125
|
+
{
|
126
|
+
price_info: parse_price_info(data[:priceInfo]),
|
127
|
+
links: parse_links(data[:links]),
|
128
|
+
}
|
129
|
+
end
|
130
|
+
|
131
|
+
def parse_legal_info(data)
|
132
|
+
{
|
133
|
+
contact_info: Epages::ContentPageSummary.new(data[:contactInformation]),
|
134
|
+
privacy_policy: Epages::ContentPageSummary.new(data[:privacyPolicy]),
|
135
|
+
terms_and_conditions: Epages::ContentPageSummary.new(data[:termsAndConditions]),
|
136
|
+
rights_of_withdrawal: Epages::ContentPageSummary.new(data[:rightsOfWithdrawal]),
|
137
|
+
shipping_info: Epages::ContentPageSummary.new(data[:shippingInformation]),
|
138
|
+
links: parse_links(data[:links]),
|
139
|
+
}
|
140
|
+
end
|
141
|
+
|
142
|
+
def parse_variations(data)
|
143
|
+
data[:variationAttributes].collect { |el| Epages::VariationAttribute.new(el) }
|
144
|
+
end
|
145
|
+
|
146
|
+
def parse_variation_object(data)
|
147
|
+
data[:items].collect { |el| Epages::Variation.new(el) }
|
148
|
+
end
|
149
|
+
|
150
|
+
def parse_price_info(data)
|
151
|
+
Epages::PriceInfo.new(data)
|
152
|
+
end
|
153
|
+
|
154
|
+
def parse_links(data)
|
155
|
+
data.collect { |link| Epages::Link.new(link) }
|
156
|
+
end
|
157
|
+
|
158
|
+
def parse_suggestions_to_products(data)
|
159
|
+
data[:products].collect do |p|
|
160
|
+
id = p[:link][:href].split('/').last
|
161
|
+
product(id)
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'epages/utils'
|
2
|
+
|
3
|
+
module Epages
|
4
|
+
class ShippingMethod
|
5
|
+
include Epages::Utils
|
6
|
+
|
7
|
+
KEYS = %w(shipping_method_id name description logo).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/shop.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'epages/error'
|
2
|
+
|
3
|
+
module Epages
|
4
|
+
class Shop
|
5
|
+
attr_accessor :name, :token
|
6
|
+
|
7
|
+
def initialize(name, token = nil)
|
8
|
+
@name = name
|
9
|
+
@token = token
|
10
|
+
end
|
11
|
+
|
12
|
+
# return the shop name
|
13
|
+
def shop_name
|
14
|
+
name
|
15
|
+
end
|
16
|
+
|
17
|
+
# retuns a boolean indicating if the shop has a token set
|
18
|
+
def token?
|
19
|
+
!!token
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/lib/epages/utils.rb
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
require 'active_support/inflector'
|
2
|
+
require 'date'
|
3
|
+
require 'uri'
|
4
|
+
require 'json'
|
5
|
+
|
6
|
+
module Epages
|
7
|
+
module Utils
|
8
|
+
module_function
|
9
|
+
|
10
|
+
# creates a instance variable (underscore) from the [data]
|
11
|
+
# if [klass] is passed, creates a object of [klass] initialized with data
|
12
|
+
#
|
13
|
+
# @param name [Symbol] [String]
|
14
|
+
# @param data [Hash]
|
15
|
+
# @param klass [Class]
|
16
|
+
def parse_attribute_as(name, data, klass = nil)
|
17
|
+
return if data.nil?
|
18
|
+
value = klass.nil? ? data : klass.new(data)
|
19
|
+
instance_variable_set("@#{name.to_s.underscore}", value)
|
20
|
+
end
|
21
|
+
|
22
|
+
# creates a instance variable (underscore). This variable contains an array of <klass> or empty array
|
23
|
+
#
|
24
|
+
# @param name [Symbol] [String]
|
25
|
+
# @param data [Hash]
|
26
|
+
# @param klass [Class]
|
27
|
+
def parse_attribute_as_array_of(name, data, klass)
|
28
|
+
value = data.class != Array || data.empty? ? [] : data.collect { |i| klass.new(i) }
|
29
|
+
instance_variable_set("@#{name.to_s.underscore}", value)
|
30
|
+
end
|
31
|
+
|
32
|
+
# creates instance variables from the data
|
33
|
+
# if klass is passed, create a object initializing with data
|
34
|
+
#
|
35
|
+
# @param data [Hash]
|
36
|
+
# @param klass [Class]
|
37
|
+
def parse_attributes(data, klass = nil)
|
38
|
+
data.keys.each do |key|
|
39
|
+
next if data[key.to_sym].nil?
|
40
|
+
value = klass.nil? ? data[key.to_sym] : klass.new(data[key.to_sym])
|
41
|
+
instance_variable_set("@#{key.to_s.underscore}", value)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
# return the hash with the keys converted to lower camelcase
|
46
|
+
#
|
47
|
+
# @param data [Hash]
|
48
|
+
def camelize_keys(hash)
|
49
|
+
hash.keys.each do |k|
|
50
|
+
key = k.to_s.camelize(:lower).to_sym
|
51
|
+
hash[key] = hash[k]
|
52
|
+
hash.delete(k) if key != k
|
53
|
+
end
|
54
|
+
hash
|
55
|
+
end
|
56
|
+
|
57
|
+
# return the hash with the keys converted to underscore
|
58
|
+
#
|
59
|
+
# @param data [Hash]
|
60
|
+
def underscorize_keys(hash)
|
61
|
+
hash.keys.each do |k|
|
62
|
+
key = k.to_s.underscore.to_sym
|
63
|
+
hash[key] = hash[k]
|
64
|
+
hash.delete(k) if key != k
|
65
|
+
end
|
66
|
+
hash
|
67
|
+
end
|
68
|
+
|
69
|
+
# returns a shop. If [shop] is not a Epages::REST::Shop create one calling the [shop] method shop_mame
|
70
|
+
def build_shop_from(shop)
|
71
|
+
return shop if shop.is_a? Epages::REST::Shop
|
72
|
+
Epages::REST::Shop.new(shop.shop_name)
|
73
|
+
end
|
74
|
+
|
75
|
+
# returns the object replacing all the keys as symbols
|
76
|
+
def symbolize_keys!(object)
|
77
|
+
if object.is_a?(Array)
|
78
|
+
object.each_with_index { |val, index| object[index] = symbolize_keys!(val) }
|
79
|
+
elsif object.is_a?(Hash)
|
80
|
+
object.keys.each { |key| object[key.to_sym] = symbolize_keys!(object.delete(key)) }
|
81
|
+
end
|
82
|
+
object
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'epages/utils'
|
2
|
+
|
3
|
+
module Epages
|
4
|
+
class Variation
|
5
|
+
include Epages::Utils
|
6
|
+
|
7
|
+
attr_reader :link, :attribute_selection
|
8
|
+
|
9
|
+
def initialize(data)
|
10
|
+
parse_attributes(data)
|
11
|
+
end
|
12
|
+
|
13
|
+
# returns the url of the variation
|
14
|
+
def url
|
15
|
+
link.href
|
16
|
+
end
|
17
|
+
|
18
|
+
# returns the product_id of the variation
|
19
|
+
def product_id
|
20
|
+
url.split('/').last
|
21
|
+
end
|
22
|
+
|
23
|
+
# returns a hash formatting the property and the respective value as a pair of the hash
|
24
|
+
def properties
|
25
|
+
Hash[attribute_selection.collect { |el| [el[:name].downcase.to_sym, el[:value]] }]
|
26
|
+
end
|
27
|
+
|
28
|
+
alias_method :attributes, :properties
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'epages/utils'
|
2
|
+
|
3
|
+
module Epages
|
4
|
+
class VariationAttribute
|
5
|
+
include Epages::Utils
|
6
|
+
|
7
|
+
attr_accessor :name, :display_name, :values
|
8
|
+
|
9
|
+
def initialize(data)
|
10
|
+
parse_attributes(data)
|
11
|
+
end
|
12
|
+
|
13
|
+
# returns an array with all the values
|
14
|
+
def formatted_values
|
15
|
+
values.collect { |el| el[:value] }
|
16
|
+
end
|
17
|
+
|
18
|
+
# returns an array with all the display_values
|
19
|
+
def display_values
|
20
|
+
values.collect { |el| el[:displayValue] }
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|