epages-rest 1.0.3 → 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/epages/cart.rb +2 -0
- data/lib/epages/category.rb +5 -3
- data/lib/epages/image_size.rb +8 -2
- data/lib/epages/order.rb +7 -1
- data/lib/epages/payment_data.rb +16 -0
- data/lib/epages/payment_method_info.rb +15 -0
- data/lib/epages/product.rb +29 -1
- data/lib/epages/rest/api.rb +2 -0
- data/lib/epages/rest/products.rb +49 -0
- data/lib/epages/rest/request.rb +37 -7
- data/lib/epages/rest/sales.rb +19 -0
- data/lib/epages/rest/shop.rb +15 -0
- data/lib/epages/rest/utils.rb +42 -6
- data/lib/epages/sale.rb +16 -0
- data/lib/epages/shipping_data.rb +16 -0
- data/lib/epages/shipping_method.rb +2 -0
- data/lib/epages/shipping_method_info.rb +15 -0
- data/lib/epages/utils.rb +39 -4
- data/lib/epages/variation.rb +1 -0
- data/lib/epages/version.rb +1 -1
- data/lib/epages-rest.rb +6 -0
- metadata +8 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fafdb220142f238edcc64a66dc7dd8b45c175ad4
|
4
|
+
data.tar.gz: db9b309d88f49ce649abc04c7776a6d914a05e26
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d6c7bc46d20543e1bc2e303062a8f1ac8aef70673e95cf035aaa1172419d8871064204f6b18611e3479870f95f848dd398469fb29e86306ae7fa8b5432b091c0
|
7
|
+
data.tar.gz: 3f93d80851535b4d880a0d29e34708047cdfaf48177d418c869a36aa769d3339f6e96cc23cde9325cd1a478cc699597dba309e2967984b2f3d0aebcb3a085041
|
data/lib/epages/cart.rb
CHANGED
data/lib/epages/category.rb
CHANGED
@@ -10,9 +10,9 @@ module Epages
|
|
10
10
|
attr_reader *KEYS
|
11
11
|
|
12
12
|
def initialize(data)
|
13
|
-
@images = data.delete(:images).collect { |i| Epages::Image.new(i) }
|
14
|
-
@links = data.delete(:links).collect { |i| Epages::Link.new(i) }
|
15
|
-
@sub_categories = data.delete(:subCategories).collect { |i| Epages::Link.new(i) }
|
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]
|
16
16
|
@parent = Epages::Link.new(data.delete(:parent)) if data[:parent]
|
17
17
|
parse_attributes(data)
|
18
18
|
end
|
@@ -21,5 +21,7 @@ module Epages
|
|
21
21
|
return false if other.class != Epages::Category
|
22
22
|
category_id == other.category_id && name == other.name
|
23
23
|
end
|
24
|
+
|
25
|
+
alias_method :id, :category_id
|
24
26
|
end
|
25
27
|
end
|
data/lib/epages/image_size.rb
CHANGED
@@ -4,10 +4,11 @@ module Epages
|
|
4
4
|
class ImageSize
|
5
5
|
include Epages::Utils
|
6
6
|
|
7
|
-
attr_accessor :images
|
7
|
+
attr_accessor :images, :name
|
8
8
|
|
9
9
|
def initialize(data)
|
10
|
-
parse_attribute_as_array_of(:images, data
|
10
|
+
parse_attribute_as_array_of(:images, data.delete(:sizes), Epages::Image)
|
11
|
+
parse_attributes(data)
|
11
12
|
end
|
12
13
|
|
13
14
|
# return a sorted array with the name of all available sizes
|
@@ -22,5 +23,10 @@ module Epages
|
|
22
23
|
link = images.find { |i| i.classifier == size }
|
23
24
|
link ? link.url : nil
|
24
25
|
end
|
26
|
+
|
27
|
+
# return the length of the slideshow
|
28
|
+
def length
|
29
|
+
images.size
|
30
|
+
end
|
25
31
|
end
|
26
32
|
end
|
data/lib/epages/order.rb
CHANGED
@@ -9,20 +9,26 @@ module Epages
|
|
9
9
|
cancelled_on closed_on paid_on returned_on)
|
10
10
|
|
11
11
|
ATTRS = %w(order_id order_number billing_address shipping_address customer_id locale currency_id tax_model
|
12
|
-
grand_total total_before_tax
|
12
|
+
grand_total total_before_tax line_item_container product_line_items shipping_price links internal_note
|
13
|
+
customer_comment shipping_data payment_data)
|
13
14
|
|
14
15
|
KEYS = (ATTRS + DATE_ATTRS).collect(&:to_sym).freeze
|
15
16
|
|
16
17
|
attr_reader *KEYS
|
17
18
|
|
18
19
|
def initialize(data)
|
20
|
+
DATE_ATTRS.each { |i| parse_attribute_as(i.to_sym, data.delete(i.camelize(:lower).to_sym), DateTime) }
|
19
21
|
parse_attribute_as_array_of(:links, data.delete(:links), Epages::Link)
|
20
22
|
parse_attribute_as_array_of(:product_line_items, data.delete(:productLineItems), Epages::ProductLineItem)
|
21
23
|
parse_attribute_as(:shipping_price, data.delete(:shippingPrice), Epages::Price)
|
22
24
|
parse_attribute_as(:billing_address, data.delete(:billingAddress), Epages::Address)
|
23
25
|
parse_attribute_as(:shipping_address, data.delete(:shippingAddress), Epages::Address)
|
24
26
|
parse_attribute_as(:line_item_container, data.delete(:lineItemContainer), Epages::LineItemContainer)
|
27
|
+
parse_attribute_as(:shipping_data, data.delete(:shippingData), Epages::ShippingData)
|
28
|
+
parse_attribute_as(:payment_data, data.delete(:paymentData), Epages::PaymentData)
|
25
29
|
parse_attributes(data)
|
26
30
|
end
|
31
|
+
|
32
|
+
alias_method :id, :order_id
|
27
33
|
end
|
28
34
|
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'epages/utils'
|
2
|
+
|
3
|
+
module Epages
|
4
|
+
class PaymentData
|
5
|
+
include Epages::Utils
|
6
|
+
|
7
|
+
KEYS = %w(payment_method price).collect(&:to_sym).freeze
|
8
|
+
|
9
|
+
attr_reader *KEYS
|
10
|
+
|
11
|
+
def initialize(data)
|
12
|
+
parse_attribute_as(:payment_method, data.delete(:paymentMethod), Epages::PaymentMethodInfo)
|
13
|
+
parse_attribute_as(:price, data.delete(:price), Epages::Price)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/lib/epages/product.rb
CHANGED
@@ -8,7 +8,7 @@ module Epages
|
|
8
8
|
|
9
9
|
KEYS = %w(product_id name short_description description 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
|
-
product_data_sheet sf_url product_number manufacturer upc ean links).collect(&:to_sym).freeze
|
11
|
+
product_data_sheet sf_url product_number manufacturer upc ean links product_image).collect(&:to_sym).freeze
|
12
12
|
|
13
13
|
attr_reader *KEYS
|
14
14
|
|
@@ -51,6 +51,32 @@ module Epages
|
|
51
51
|
product_slideshow(self) if link?('slideshow')
|
52
52
|
end
|
53
53
|
|
54
|
+
# add an image to the slideshow
|
55
|
+
#
|
56
|
+
# @param image [String]
|
57
|
+
def add_slideshow_image(image)
|
58
|
+
product_add_slideshow_image(self, image)
|
59
|
+
end
|
60
|
+
|
61
|
+
# remove the image passed from the slideshow and return the new slideshow
|
62
|
+
#
|
63
|
+
# @param image [String]
|
64
|
+
def delete_slideshow_image(image)
|
65
|
+
product_delete_slideshow_image(self, image)
|
66
|
+
end
|
67
|
+
|
68
|
+
# returns an array containing the slideshow sequence
|
69
|
+
def slideshow_sequence
|
70
|
+
product_slideshow_sequence(self)
|
71
|
+
end
|
72
|
+
|
73
|
+
# updates the order of the sequence with the data passed as parameter
|
74
|
+
#
|
75
|
+
# @param data [Array]
|
76
|
+
def update_slideshow_sequence(data)
|
77
|
+
product_update_slideshow_sequence(self, data)
|
78
|
+
end
|
79
|
+
|
54
80
|
# returns the list of variations of the product
|
55
81
|
def variations
|
56
82
|
product_variations(self) if link?('variations')
|
@@ -88,5 +114,7 @@ module Epages
|
|
88
114
|
def to_line_item(quantity = 1)
|
89
115
|
{productId: product_id, quantity: quantity}
|
90
116
|
end
|
117
|
+
|
118
|
+
alias_method :id, :product_id
|
91
119
|
end
|
92
120
|
end
|
data/lib/epages/rest/api.rb
CHANGED
@@ -4,6 +4,7 @@ require 'epages/rest/legal'
|
|
4
4
|
require 'epages/rest/miscellaneous'
|
5
5
|
require 'epages/rest/orders'
|
6
6
|
require 'epages/rest/products'
|
7
|
+
require 'epages/rest/sales'
|
7
8
|
require 'epages/rest/shipping_methods'
|
8
9
|
|
9
10
|
module Epages
|
@@ -15,6 +16,7 @@ module Epages
|
|
15
16
|
include REST::Miscellaneous
|
16
17
|
include REST::Orders
|
17
18
|
include REST::Products
|
19
|
+
include REST::Sales
|
18
20
|
include REST::ShippingMethods
|
19
21
|
end
|
20
22
|
end
|
data/lib/epages/rest/products.rb
CHANGED
@@ -24,6 +24,16 @@ module Epages
|
|
24
24
|
perform_get_with_object("/products/#{id}", options, Epages::Product)
|
25
25
|
end
|
26
26
|
|
27
|
+
# call the API and return a Epages::Product
|
28
|
+
# implements the call https://developer.epages.com/apps/api-reference/patch-shops-shopid-products-productid.html
|
29
|
+
#
|
30
|
+
# @param product [String], [Epages::Product]
|
31
|
+
# @param options [Hash]
|
32
|
+
def update_product(product, options = {})
|
33
|
+
id = epages_id(product)
|
34
|
+
perform_patch_with_object("/products/#{id}", options, Epages::Product)
|
35
|
+
end
|
36
|
+
|
27
37
|
# call the API and return a Hash with the respective variation_attributes and the variation products
|
28
38
|
# implements the call https://developer.epages.com/apps/api-reference/get-shops-shopid-products-productid-variations.html
|
29
39
|
#
|
@@ -44,6 +54,45 @@ module Epages
|
|
44
54
|
perform_get_with_key_and_objects("/products/#{id}/slideshow", {}, :items, Epages::ImageSize)
|
45
55
|
end
|
46
56
|
|
57
|
+
# call the API to post a new image to the slideshow of a product and return an array of Epages::ImageSize (slides) of the product
|
58
|
+
# implements the call https://developer.epages.com/apps/api-reference/post-shops-shopid-products-productid-slideshow.html
|
59
|
+
#
|
60
|
+
# @param product [String], [Epages::Product]
|
61
|
+
# @param image [String]
|
62
|
+
def product_add_slideshow_image(product, image)
|
63
|
+
id = epages_id(product)
|
64
|
+
perform_multipart_post_with_objects("/products/#{id}/slideshow", image, Epages::ImageSize)
|
65
|
+
end
|
66
|
+
|
67
|
+
# call the API to delete an image from the slideshow of a product
|
68
|
+
# implements the call https://developer.epages.com/apps/api-reference/delete-shops-shopid-products-productid-slideshow-imagename.html
|
69
|
+
#
|
70
|
+
# @param product [String], [Epages::Product]
|
71
|
+
# @param image [String]
|
72
|
+
def product_delete_slideshow_image(product, image)
|
73
|
+
id = epages_id(product)
|
74
|
+
perform_delete_request("/products/#{id}/slideshow/#{image}")
|
75
|
+
end
|
76
|
+
|
77
|
+
# call the API to get the slideshow sequence of a product
|
78
|
+
# implements the call https://developer.epages.com/apps/api-reference/get-shops-shopid-products-productid-slideshow-sequence.html
|
79
|
+
#
|
80
|
+
# @param product [String], [Epages::Product]
|
81
|
+
def product_slideshow_sequence(product)
|
82
|
+
id = epages_id(product)
|
83
|
+
perform_get_request("/products/#{id}/slideshow/sequence", {})
|
84
|
+
end
|
85
|
+
|
86
|
+
# call the API to update the slideshow sequence of a product
|
87
|
+
# implements the call https://developer.epages.com/apps/api-reference/put-shops-shopid-products-productid-slideshow-sequence.html
|
88
|
+
#
|
89
|
+
# @param product [String], [Epages::Product]
|
90
|
+
# @param data [Array]
|
91
|
+
def product_update_slideshow_sequence(product, data)
|
92
|
+
id = epages_id(product)
|
93
|
+
perform_put_request("/products/#{id}/slideshow/sequence", data)
|
94
|
+
end
|
95
|
+
|
47
96
|
# call the API and return an array of Epages::CustomAttribute of the product
|
48
97
|
# implements the call https://developer.epages.com/apps/api-reference/get-shops-shopid-products-productid-custom-attributes.html
|
49
98
|
#
|
data/lib/epages/rest/request.rb
CHANGED
@@ -12,13 +12,13 @@ module Epages
|
|
12
12
|
@shop = build_shop_from(object)
|
13
13
|
@uri = URI.parse("https://#{@shop.host}/rs/shops/#{@shop.name.to_s + path}")
|
14
14
|
@path = uri.path
|
15
|
-
|
15
|
+
set_request_options(request_method, options)
|
16
16
|
end
|
17
17
|
|
18
|
-
def
|
19
|
-
@options = camelize_keys(options)
|
18
|
+
def set_request_options(method, options)
|
20
19
|
@request_method = method
|
21
20
|
@headers = request_headers
|
21
|
+
@options = format_options(options)
|
22
22
|
end
|
23
23
|
|
24
24
|
def auth_token
|
@@ -27,24 +27,54 @@ module Epages
|
|
27
27
|
|
28
28
|
# @return [Array, Hash]
|
29
29
|
def perform
|
30
|
-
|
31
|
-
response = HTTP.with(@headers).public_send(@request_method, @uri.to_s, options_key => @options)
|
30
|
+
response = HTTP.with(@headers).public_send(@request_method, @uri.to_s, options_passed_by => @options)
|
32
31
|
fail_or_return_response_body(response)
|
33
32
|
end
|
34
33
|
|
35
34
|
def request_headers
|
36
35
|
headers = {}
|
37
|
-
headers['Content-Type'] =
|
36
|
+
headers['Content-Type'] = content_type_options unless @request_method == :multipart_post
|
38
37
|
headers['Accept'] = '*/*'
|
39
38
|
headers['Authorization'] = auth_token if @shop.token?
|
40
39
|
headers
|
41
40
|
end
|
42
41
|
|
42
|
+
def options_passed_by
|
43
|
+
return :form if @request_method == :post && @options.key?(:image)
|
44
|
+
case @request_method
|
45
|
+
when :get then :params
|
46
|
+
when :patch then :body
|
47
|
+
else :json
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def content_type_options
|
52
|
+
@request_method == :patch ? 'application/json-patch+json' : 'application/json'
|
53
|
+
end
|
54
|
+
|
55
|
+
def format_options(options)
|
56
|
+
case @request_method
|
57
|
+
when :multipart_post then options_to_multipart_request(options)
|
58
|
+
when :patch then options_to_patch_request(options).to_json
|
59
|
+
else options.is_a?(Hash) ? camelize_keys(options) : options
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def mime_type(basename)
|
64
|
+
case basename
|
65
|
+
when /.gif/ then 'image/gif'
|
66
|
+
when /.jpe?g/ then 'image/jpeg'
|
67
|
+
when /.png/ then 'image/png'
|
68
|
+
else 'application/octet-stream'
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
43
72
|
def fail_or_return_response_body(response)
|
73
|
+
return if response.code == 204
|
44
74
|
if response.code.between?(200, 206)
|
45
75
|
symbolize_keys!(response.parse)
|
46
76
|
else
|
47
|
-
fail Epages::Error::ERRORS[response.code],
|
77
|
+
fail Epages::Error::ERRORS[response.code], response.body.to_s
|
48
78
|
end
|
49
79
|
end
|
50
80
|
end
|
@@ -0,0 +1,19 @@
|
|
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-sales.html
|
6
|
+
module Sales
|
7
|
+
include REST::Utils
|
8
|
+
|
9
|
+
# call the API and return an array of Epages::Sale
|
10
|
+
# implements the call https://developer.epages.com/apps/api-reference/get-shops-shopid-sales.html
|
11
|
+
#
|
12
|
+
# @param options [Hash]
|
13
|
+
def sales(options = {})
|
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)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/epages/rest/shop.rb
CHANGED
@@ -7,6 +7,21 @@ module Epages
|
|
7
7
|
module REST
|
8
8
|
class Shop < Epages::Shop
|
9
9
|
include Epages::REST::API
|
10
|
+
|
11
|
+
def parallel_calls(requests)
|
12
|
+
threads = []
|
13
|
+
result = requests
|
14
|
+
requests.each do |key, values|
|
15
|
+
values.each_with_index do |call, i|
|
16
|
+
threads << (values.is_a?(Array) ? process_thread(key, call, i) : process_thread(key, values))
|
17
|
+
end
|
18
|
+
end
|
19
|
+
threads.each do |t|
|
20
|
+
t.join
|
21
|
+
t[:index].nil? ? result[t[:name]] = t[:result] : result[t[:name]][t[:index]] = t[:result]
|
22
|
+
end
|
23
|
+
result
|
24
|
+
end
|
10
25
|
end
|
11
26
|
end
|
12
27
|
end
|
data/lib/epages/rest/utils.rb
CHANGED
@@ -29,6 +29,13 @@ module Epages
|
|
29
29
|
perform_request_with_object(:put, path, options, klass)
|
30
30
|
end
|
31
31
|
|
32
|
+
# @param path [String]
|
33
|
+
# @param options [Hash]
|
34
|
+
# @param klass [Class]
|
35
|
+
def perform_patch_with_object(path, options, klass)
|
36
|
+
perform_request_with_object(:patch, path, options, klass)
|
37
|
+
end
|
38
|
+
|
32
39
|
# @param path [String]
|
33
40
|
# @param options [Hash]
|
34
41
|
# @param klass [Class]
|
@@ -59,6 +66,14 @@ module Epages
|
|
59
66
|
perform_request_with_objects(:post, path, options, klass)
|
60
67
|
end
|
61
68
|
|
69
|
+
# @param path [String]
|
70
|
+
# @param options [Hash]
|
71
|
+
# @param klass [Class]
|
72
|
+
def perform_multipart_post_with_objects(path, image, klass)
|
73
|
+
response = perform_request(:multipart_post, path, file: image)
|
74
|
+
response.key?('items') ? response[:items].collect { |data| klass.new(data) } : klass.new(response)
|
75
|
+
end
|
76
|
+
|
62
77
|
# @param request_method [Symbol]
|
63
78
|
# @param path [String]
|
64
79
|
# @param options [Hash]
|
@@ -85,7 +100,6 @@ module Epages
|
|
85
100
|
perform_request_with_key_and_objects(:post, path, options, key, klass)
|
86
101
|
end
|
87
102
|
|
88
|
-
# TODO: refactor code bellow
|
89
103
|
# @param path [String]
|
90
104
|
# @param options [Hash]
|
91
105
|
# @param key [Symbol]
|
@@ -98,16 +112,22 @@ module Epages
|
|
98
112
|
|
99
113
|
# @param path [String]
|
100
114
|
# @param options [Hash]
|
101
|
-
def perform_get_request(path, options)
|
115
|
+
def perform_get_request(path, options = {})
|
102
116
|
perform_request(:get, path, options)
|
103
117
|
end
|
104
118
|
|
105
119
|
# @param path [String]
|
106
120
|
# @param options [Hash]
|
107
|
-
def perform_put_request(path, options)
|
121
|
+
def perform_put_request(path, options = {})
|
108
122
|
perform_request(:put, path, options)
|
109
123
|
end
|
110
124
|
|
125
|
+
# @param path [String]
|
126
|
+
# @param options [Hash]
|
127
|
+
def perform_delete_request(path, options = {})
|
128
|
+
perform_request(:delete, path, options)
|
129
|
+
end
|
130
|
+
|
111
131
|
def epages_id(object)
|
112
132
|
return object if object.class == String
|
113
133
|
return if object.class.name.deconstantize != 'Epages'
|
@@ -156,11 +176,27 @@ module Epages
|
|
156
176
|
end
|
157
177
|
|
158
178
|
def parse_suggestions_to_products(data)
|
159
|
-
data[:products].collect
|
160
|
-
|
161
|
-
|
179
|
+
ids = data[:products].collect { |p| p[:link][:href].split('/').last }
|
180
|
+
parallel_calls(product: ids)[:product]
|
181
|
+
end
|
182
|
+
|
183
|
+
def process_thread(key, value, index = nil)
|
184
|
+
Thread.new do
|
185
|
+
Thread.current[:name] = key
|
186
|
+
Thread.current[:index] = index if index
|
187
|
+
Thread.current[:result] = send(key, value)
|
162
188
|
end
|
163
189
|
end
|
190
|
+
|
191
|
+
def format_date(date)
|
192
|
+
(date.is_a?(Date) ? date : DateTime.parse(date)).strftime
|
193
|
+
end
|
194
|
+
|
195
|
+
def format_dates_options(options)
|
196
|
+
options[:created_before] = format_date(options[:created_before]) if options[:created_before]
|
197
|
+
options[:created_after] = format_date(options[:created_after]) if options[:created_after]
|
198
|
+
options
|
199
|
+
end
|
164
200
|
end
|
165
201
|
end
|
166
202
|
end
|
data/lib/epages/sale.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'epages/utils'
|
2
|
+
require 'epages/rest/sales'
|
3
|
+
|
4
|
+
module Epages
|
5
|
+
class Sale
|
6
|
+
include Epages::Utils
|
7
|
+
|
8
|
+
KEYS = %w(currency total_gross_revenue total_net_revenue inits_sold total_orders).collect(&:to_sym).freeze
|
9
|
+
|
10
|
+
attr_reader *KEYS
|
11
|
+
|
12
|
+
def initialize(data)
|
13
|
+
parse_attributes(data)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'epages/utils'
|
2
|
+
|
3
|
+
module Epages
|
4
|
+
class ShippingData
|
5
|
+
include Epages::Utils
|
6
|
+
|
7
|
+
KEYS = %w(shipping_method price).collect(&:to_sym).freeze
|
8
|
+
|
9
|
+
attr_reader *KEYS
|
10
|
+
|
11
|
+
def initialize(data)
|
12
|
+
parse_attribute_as(:shipping_method, data.delete(:shippingMethod), Epages::ShippingMethodInfo)
|
13
|
+
parse_attribute_as(:price, data.delete(:price), Epages::Price)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/lib/epages/utils.rb
CHANGED
@@ -13,9 +13,14 @@ module Epages
|
|
13
13
|
# @param name [Symbol] [String]
|
14
14
|
# @param data [Hash]
|
15
15
|
# @param klass [Class]
|
16
|
-
def parse_attribute_as(name, data, klass =
|
16
|
+
def parse_attribute_as(name, data, klass = NilClass)
|
17
17
|
return if data.nil?
|
18
|
-
value =
|
18
|
+
value =
|
19
|
+
case klass.name
|
20
|
+
when 'NilClass' then data
|
21
|
+
when 'DateTime' then klass.parse(data)
|
22
|
+
else klass.new(data)
|
23
|
+
end
|
19
24
|
instance_variable_set("@#{name.to_s.underscore}", value)
|
20
25
|
end
|
21
26
|
|
@@ -44,8 +49,9 @@ module Epages
|
|
44
49
|
|
45
50
|
# return the hash with the keys converted to lower camelcase
|
46
51
|
#
|
47
|
-
# @param
|
52
|
+
# @param hash [Hash]
|
48
53
|
def camelize_keys(hash)
|
54
|
+
return unless hash.is_a?(Hash)
|
49
55
|
hash.keys.each do |k|
|
50
56
|
key = k.to_s.camelize(:lower).to_sym
|
51
57
|
hash[key] = hash[k]
|
@@ -56,8 +62,9 @@ module Epages
|
|
56
62
|
|
57
63
|
# return the hash with the keys converted to underscore
|
58
64
|
#
|
59
|
-
# @param
|
65
|
+
# @param hash [Hash]
|
60
66
|
def underscorize_keys(hash)
|
67
|
+
return unless hash.is_a?(Hash)
|
61
68
|
hash.keys.each do |k|
|
62
69
|
key = k.to_s.underscore.to_sym
|
63
70
|
hash[key] = hash[k]
|
@@ -73,6 +80,8 @@ module Epages
|
|
73
80
|
end
|
74
81
|
|
75
82
|
# returns the object replacing all the keys as symbols
|
83
|
+
#
|
84
|
+
# @param object [Hash], [Array]
|
76
85
|
def symbolize_keys!(object)
|
77
86
|
if object.is_a?(Array)
|
78
87
|
object.each_with_index { |val, index| object[index] = symbolize_keys!(val) }
|
@@ -81,5 +90,31 @@ module Epages
|
|
81
90
|
end
|
82
91
|
object
|
83
92
|
end
|
93
|
+
|
94
|
+
# returns the json body for the patch calls
|
95
|
+
#
|
96
|
+
# @param options [Hash]
|
97
|
+
def options_to_patch_request(options)
|
98
|
+
json = []
|
99
|
+
Array[options.delete(:remove)].flatten.compact.each { |i| json << {'op' => 'remove', 'path' => "/#{camelize_words(i)}"} }
|
100
|
+
options.each { |k, v| json << {'op' => 'add', 'path' => "/#{camelize_words(k)}", 'value' => v} }
|
101
|
+
json.collect { |i| Hash[i.each_pair.to_a] }
|
102
|
+
end
|
103
|
+
|
104
|
+
# returns the json body for the patch calls
|
105
|
+
#
|
106
|
+
# @param options [Hash]
|
107
|
+
def options_to_multipart_request(options)
|
108
|
+
file = options[:file]
|
109
|
+
@request_method = :post
|
110
|
+
{image: HTTP::FormData::File.new(file, filename: File.basename(file), mime_type: mime_type(File.basename(file)))}
|
111
|
+
end
|
112
|
+
|
113
|
+
# return the string passed as a parameter with all the words camelized
|
114
|
+
#
|
115
|
+
# @param string [Strimg], [Symbol]
|
116
|
+
def camelize_words(string)
|
117
|
+
string.to_s.gsub(/(\w+)/) { |s| s.camelize(:lower) }
|
118
|
+
end
|
84
119
|
end
|
85
120
|
end
|
data/lib/epages/variation.rb
CHANGED
data/lib/epages/version.rb
CHANGED
data/lib/epages-rest.rb
CHANGED
@@ -10,11 +10,16 @@ require 'epages/image_size'
|
|
10
10
|
require 'epages/line_item_container'
|
11
11
|
require 'epages/link'
|
12
12
|
require 'epages/order'
|
13
|
+
require 'epages/payment_data'
|
14
|
+
require 'epages/payment_method_info'
|
13
15
|
require 'epages/price'
|
14
16
|
require 'epages/price_info'
|
15
17
|
require 'epages/product'
|
16
18
|
require 'epages/product_line_item'
|
19
|
+
require 'epages/sale'
|
20
|
+
require 'epages/shipping_data'
|
17
21
|
require 'epages/shipping_method'
|
22
|
+
require 'epages/shipping_method_info'
|
18
23
|
require 'epages/shop'
|
19
24
|
require 'epages/utils'
|
20
25
|
require 'epages/variation'
|
@@ -28,6 +33,7 @@ require 'epages/rest/legal'
|
|
28
33
|
require 'epages/rest/orders'
|
29
34
|
require 'epages/rest/products'
|
30
35
|
require 'epages/rest/request'
|
36
|
+
require 'epages/rest/sales'
|
31
37
|
require 'epages/rest/shipping_methods'
|
32
38
|
require 'epages/rest/shop'
|
33
39
|
require 'epages/rest/utils'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: epages-rest
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Domingo Cividanes
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-02-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -77,6 +77,8 @@ files:
|
|
77
77
|
- lib/epages/line_item_container.rb
|
78
78
|
- lib/epages/link.rb
|
79
79
|
- lib/epages/order.rb
|
80
|
+
- lib/epages/payment_data.rb
|
81
|
+
- lib/epages/payment_method_info.rb
|
80
82
|
- lib/epages/price.rb
|
81
83
|
- lib/epages/price_info.rb
|
82
84
|
- lib/epages/product.rb
|
@@ -89,10 +91,14 @@ files:
|
|
89
91
|
- lib/epages/rest/orders.rb
|
90
92
|
- lib/epages/rest/products.rb
|
91
93
|
- lib/epages/rest/request.rb
|
94
|
+
- lib/epages/rest/sales.rb
|
92
95
|
- lib/epages/rest/shipping_methods.rb
|
93
96
|
- lib/epages/rest/shop.rb
|
94
97
|
- lib/epages/rest/utils.rb
|
98
|
+
- lib/epages/sale.rb
|
99
|
+
- lib/epages/shipping_data.rb
|
95
100
|
- lib/epages/shipping_method.rb
|
101
|
+
- lib/epages/shipping_method_info.rb
|
96
102
|
- lib/epages/shop.rb
|
97
103
|
- lib/epages/utils.rb
|
98
104
|
- lib/epages/variation.rb
|