epages-rest 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- 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
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 6676eb9661237a4c3595dbd3a4bfc5a6829be2df
|
4
|
+
data.tar.gz: daa58bb9a83513b666ca159396241621326fe257
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6f36af9de4320fa9d55a5f8f5989de42ae7c94bf36b16ab16e66115883a3ada633eac7d60da6f8ab2e864c1198c4ceed035c23c3ba9ba74459ef174fc0facecc
|
7
|
+
data.tar.gz: 2679ccd11eea7de87ed145f9e0b92749b02aed185c1ce752846ec906ccb995ad1a6914f241d6013a0488ce3e6f1f8e31a1dcfbae7c8ac13fb99065f2dd0c1934
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Domingo Cividanes
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
# The Epages REST Ruby Gem
|
2
|
+
|
3
|
+
A Ruby interface to the Epages REST API
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
```
|
8
|
+
gem install epages-rest
|
9
|
+
```
|
10
|
+
|
11
|
+
You can require it in the Ruby Interpreter using:
|
12
|
+
```
|
13
|
+
require 'epages-rest'
|
14
|
+
```
|
15
|
+
or add it to your Rails application adding the gem to your Gemfile.
|
16
|
+
|
17
|
+
## Usage
|
18
|
+
|
19
|
+
This gem is used to connect any Ruby application with any [Epages](http://www.epages.com/en/) Shop.
|
20
|
+
You can get any public information of any shop indicating only the name of the shop, but for security reasons, to modify content from your shop you need the token you will get in your online shop space.
|
21
|
+
|
22
|
+
# Usage examples
|
23
|
+
|
24
|
+
The first thing is create your REST shop.
|
25
|
+
`shop = Epages::REST::Shop.new('shop_name')` or `shop = Epages::REST::Shop.new('shop_name', 'token')`
|
26
|
+
|
27
|
+
Once this is done, you can use the API calls.
|
28
|
+
|
29
|
+
#### [Get products](https://developer.epages.com/apps/api-reference/get-shops-shopid-products.html)
|
30
|
+
`products = shop.products`
|
31
|
+
`sorted_products = shop.products(sort: name)`
|
32
|
+
|
33
|
+
#### [Get Categories](https://developer.epages.com/apps/api-reference/get-shops-shopid-categories.html)
|
34
|
+
`categories = shop.categories`
|
35
|
+
|
36
|
+
### Full collection of examples [here](https://github.com/mingoscd/epages/tree/master/examples)
|
37
|
+
|
38
|
+
## Contributing
|
39
|
+
|
40
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/mingoscd/epages.
|
41
|
+
|
42
|
+
## License
|
43
|
+
|
44
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
45
|
+
|
data/epages-rest.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'epages/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.version = Epages::VERSION
|
8
|
+
spec.name = 'epages-rest'
|
9
|
+
spec.authors = ['Domingo Cividanes']
|
10
|
+
spec.email = ['dcividanes91@gmail.com', 'dcividanes@epages.com']
|
11
|
+
spec.description = 'A Ruby interface that allows to integrate any Epages Shop with any ruby framework via Epages Rest API.'
|
12
|
+
spec.summary = 'A Ruby interface to the Epages Rest API.'
|
13
|
+
spec.homepage = 'https://github.com/ePages-de/epages-rest-ruby'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.require_paths = %w(lib)
|
17
|
+
spec.files = %w(LICENSE.txt README.md epages-rest.gemspec) + Dir['lib/**/*.rb']
|
18
|
+
|
19
|
+
spec.add_development_dependency 'bundler', '~> 1.10'
|
20
|
+
spec.add_dependency 'http', '~> 0.9.4'
|
21
|
+
spec.add_dependency 'activesupport', '~> 4.2'
|
22
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'epages/utils'
|
2
|
+
|
3
|
+
module Epages
|
4
|
+
class Address
|
5
|
+
include Epages::Utils
|
6
|
+
|
7
|
+
KEYS = %w(company salutation title first_name last_name street street_details zip_code
|
8
|
+
city state country vat_id birthday email_address).collect(&:to_sym).freeze
|
9
|
+
|
10
|
+
attr_accessor *KEYS
|
11
|
+
|
12
|
+
def initialize(data)
|
13
|
+
parse_attributes(data)
|
14
|
+
end
|
15
|
+
|
16
|
+
def to_json
|
17
|
+
{
|
18
|
+
firstName: first_name,
|
19
|
+
lastName: last_name,
|
20
|
+
street: street,
|
21
|
+
zipCode: zip_code,
|
22
|
+
city: city,
|
23
|
+
country: country,
|
24
|
+
birthday: birthday,
|
25
|
+
emailAddress: email_address,
|
26
|
+
}
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'epages/utils'
|
2
|
+
|
3
|
+
module Epages
|
4
|
+
class BasePrice
|
5
|
+
include Epages::Utils
|
6
|
+
|
7
|
+
KEYS = %w(ref_quantity ref_price formatted quantity).collect(&:to_sym).freeze
|
8
|
+
|
9
|
+
attr_reader *KEYS
|
10
|
+
|
11
|
+
def initialize(data)
|
12
|
+
parse_attribute_as(:ref_price, data.delete(:refPrice), Epages::Price)
|
13
|
+
parse_attributes(data)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/lib/epages/cart.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'epages/utils'
|
2
|
+
|
3
|
+
module Epages
|
4
|
+
class Cart
|
5
|
+
include Epages::Utils
|
6
|
+
|
7
|
+
KEYS = %w(cart_id billing_address shipping_address line_item_container min_cart_value checkout_url).collect(&:to_sym).freeze
|
8
|
+
|
9
|
+
attr_reader *KEYS
|
10
|
+
|
11
|
+
def initialize(data)
|
12
|
+
parse_attribute_as(:billing_address, data.delete(:billingAddress), Epages::Address)
|
13
|
+
parse_attribute_as(:shipping_address, data.delete(:shippingAddress), Epages::Address)
|
14
|
+
parse_attribute_as(:line_item_container, data.delete(:lineItemContainer), Epages::LineItemContainer)
|
15
|
+
parse_attributes(data)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'epages/utils'
|
2
|
+
require 'epages/error'
|
3
|
+
|
4
|
+
module Epages
|
5
|
+
class Category
|
6
|
+
include Epages::Utils
|
7
|
+
|
8
|
+
KEYS = %w(category_id name page_title description special_offer images parent sub_categories sf_url links).collect(&:to_sym).freeze
|
9
|
+
|
10
|
+
attr_reader *KEYS
|
11
|
+
|
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) }
|
16
|
+
@parent = Epages::Link.new(data.delete(:parent)) if data[:parent]
|
17
|
+
parse_attributes(data)
|
18
|
+
end
|
19
|
+
|
20
|
+
def ==(other)
|
21
|
+
return false if other.class != Epages::Category
|
22
|
+
category_id == other.category_id && name == other.name
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'epages/utils'
|
2
|
+
|
3
|
+
module Epages
|
4
|
+
class CustomAttribute
|
5
|
+
include Epages::Utils
|
6
|
+
|
7
|
+
KEYS = %w(key display_key single_value type values).collect(&:to_sym).freeze
|
8
|
+
|
9
|
+
attr_reader *KEYS
|
10
|
+
|
11
|
+
def initialize(data)
|
12
|
+
parse_attributes(data)
|
13
|
+
end
|
14
|
+
|
15
|
+
# return a Hash with the display value as key and an array with all the displayValue as value
|
16
|
+
def formatted_attributes
|
17
|
+
Hash[display_key.downcase.to_sym, values.collect { |el| el[:displayValue] }]
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/lib/epages/error.rb
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
module Epages
|
2
|
+
class Error < StandardError
|
3
|
+
attr_reader :code
|
4
|
+
|
5
|
+
# Raised when a 4xx HTTP status code is returned
|
6
|
+
ClientError = Class.new(self)
|
7
|
+
|
8
|
+
# HTTP status code 400, 401, 403, 404, 406, 422, 429 respectively
|
9
|
+
BadRequest = Class.new(ClientError)
|
10
|
+
Unauthorized = Class.new(ClientError)
|
11
|
+
Forbidden = Class.new(ClientError)
|
12
|
+
NotFound = Class.new(ClientError)
|
13
|
+
NotAcceptable = Class.new(ClientError)
|
14
|
+
UnprocessableEntity = Class.new(ClientError)
|
15
|
+
TooManyRequests = Class.new(ClientError)
|
16
|
+
|
17
|
+
# Raised when a 5xx HTTP status code is returned
|
18
|
+
ServerError = Class.new(self)
|
19
|
+
|
20
|
+
# HTTP status code 500, 502, 503, 504 respectively
|
21
|
+
InternalServerError = Class.new(ServerError)
|
22
|
+
BadGateway = Class.new(ServerError)
|
23
|
+
ServiceUnavailable = Class.new(ServerError)
|
24
|
+
GatewayTimeout = Class.new(ServerError)
|
25
|
+
|
26
|
+
ERRORS = {
|
27
|
+
400 => Epages::Error::BadRequest,
|
28
|
+
401 => Epages::Error::Unauthorized,
|
29
|
+
403 => Epages::Error::Forbidden,
|
30
|
+
404 => Epages::Error::NotFound,
|
31
|
+
406 => Epages::Error::NotAcceptable,
|
32
|
+
422 => Epages::Error::UnprocessableEntity,
|
33
|
+
429 => Epages::Error::TooManyRequests,
|
34
|
+
500 => Epages::Error::InternalServerError,
|
35
|
+
502 => Epages::Error::BadGateway,
|
36
|
+
503 => Epages::Error::ServiceUnavailable,
|
37
|
+
504 => Epages::Error::GatewayTimeout,
|
38
|
+
}
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def parse_error(body)
|
43
|
+
if body.nil? || body.empty?
|
44
|
+
['', nil]
|
45
|
+
elsif body[:error]
|
46
|
+
[body[:error], nil]
|
47
|
+
elsif body[:errors]
|
48
|
+
extract_message_from_errors(body)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def extract_message_from_errors(body)
|
53
|
+
first = Array(body[:errors]).first
|
54
|
+
if first.is_a?(Hash)
|
55
|
+
[first[:message].chomp, first[:code]]
|
56
|
+
else
|
57
|
+
[first.chomp, nil]
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
data/lib/epages/image.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'epages/utils'
|
2
|
+
|
3
|
+
module Epages
|
4
|
+
class ImageSize
|
5
|
+
include Epages::Utils
|
6
|
+
|
7
|
+
attr_accessor :images
|
8
|
+
|
9
|
+
def initialize(data)
|
10
|
+
parse_attribute_as_array_of(:images, data[:sizes], Epages::Image)
|
11
|
+
end
|
12
|
+
|
13
|
+
# return a sorted array with the name of all available sizes
|
14
|
+
def sizes
|
15
|
+
images.collect(&:classifier).sort
|
16
|
+
end
|
17
|
+
|
18
|
+
# return the link of image with the indicated size
|
19
|
+
#
|
20
|
+
# @param size [String]. The name of the image classifier
|
21
|
+
def size_link(size)
|
22
|
+
link = images.find { |i| i.classifier == size }
|
23
|
+
link ? link.url : nil
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'epages/utils'
|
2
|
+
|
3
|
+
module Epages
|
4
|
+
class LineItemContainer
|
5
|
+
include Epages::Utils
|
6
|
+
|
7
|
+
KEYS = %w(grand_total total_before_tax total_tax line_items_sub_total product_line_items shipping_price).collect(&:to_sym).freeze
|
8
|
+
|
9
|
+
attr_reader *KEYS
|
10
|
+
|
11
|
+
def initialize(data)
|
12
|
+
parse_attribute_as(:grand_total, data[:grandTotal], Epages::Price)
|
13
|
+
parse_attribute_as(:total_before_tax, data[:totalBeforeTax], Epages::Price)
|
14
|
+
parse_attribute_as(:total_tax, data[:totalTax], Epages::Price)
|
15
|
+
parse_attribute_as(:line_items_sub_total, data[:lineItemsSubTotal], Epages::Price)
|
16
|
+
parse_attribute_as_array_of(:product_line_items, data[:productLineItems], Epages::ProductLineItem)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/epages/link.rb
ADDED
data/lib/epages/order.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'epages/utils'
|
2
|
+
require 'epages/error'
|
3
|
+
|
4
|
+
module Epages
|
5
|
+
class Order
|
6
|
+
include Epages::Utils
|
7
|
+
|
8
|
+
DATE_ATTRS = %w(creation_date invoiced_on shipped_on pending_on archived_on dispatched_on viewed_on
|
9
|
+
cancelled_on closed_on paid_on returned_on)
|
10
|
+
|
11
|
+
ATTRS = %w(order_id order_number billing_address shipping_address customer_id locale currency_id tax_model
|
12
|
+
grand_total total_before_tax comment line_item_container product_line_items shipping_price links)
|
13
|
+
|
14
|
+
KEYS = (ATTRS + DATE_ATTRS).collect(&:to_sym).freeze
|
15
|
+
|
16
|
+
attr_reader *KEYS
|
17
|
+
|
18
|
+
def initialize(data)
|
19
|
+
parse_attribute_as_array_of(:links, data.delete(:links), Epages::Link)
|
20
|
+
parse_attribute_as_array_of(:product_line_items, data.delete(:productLineItems), Epages::ProductLineItem)
|
21
|
+
parse_attribute_as(:shipping_price, data.delete(:shippingPrice), Epages::Price)
|
22
|
+
parse_attribute_as(:billing_address, data.delete(:billingAddress), Epages::Address)
|
23
|
+
parse_attribute_as(:shipping_address, data.delete(:shippingAddress), Epages::Address)
|
24
|
+
parse_attribute_as(:line_item_container, data.delete(:lineItemContainer), Epages::LineItemContainer)
|
25
|
+
parse_attributes(data)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/epages/price.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'epages/utils'
|
2
|
+
require 'epages/price'
|
3
|
+
|
4
|
+
module Epages
|
5
|
+
class PriceInfo
|
6
|
+
include Epages::Utils
|
7
|
+
|
8
|
+
KEYS = %w(quantity price deposit_price eco_participation_price price_with_deposits manufacturer_price base_price).collect(&:to_sym).freeze
|
9
|
+
|
10
|
+
attr_reader *KEYS
|
11
|
+
|
12
|
+
def initialize(data)
|
13
|
+
parse_attribute_as(:quantity, data.delete(:quantity))
|
14
|
+
parse_attribute_as(:base_price, data.delete(:basePrice), Epages::BasePrice)
|
15
|
+
parse_attributes(data, Epages::Price)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
require 'epages/utils'
|
2
|
+
require 'epages/rest/products'
|
3
|
+
|
4
|
+
module Epages
|
5
|
+
class Product
|
6
|
+
include Epages::Utils
|
7
|
+
include Epages::REST::Products
|
8
|
+
|
9
|
+
KEYS = %w(product_id name short_description description images price_info for_sale special_offer delivery_weight
|
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
|
12
|
+
|
13
|
+
attr_reader *KEYS
|
14
|
+
|
15
|
+
def initialize(data)
|
16
|
+
parse_attribute_as_array_of(:images, data.delete(:images), Epages::Image)
|
17
|
+
parse_attribute_as_array_of(:links, data.delete(:links), Epages::Link)
|
18
|
+
parse_attribute_as(:priceInfo, data.delete(:priceInfo), Epages::PriceInfo)
|
19
|
+
parse_attributes(data)
|
20
|
+
end
|
21
|
+
|
22
|
+
# compare the product with another product. 2 products are considered equals if both has
|
23
|
+
# the same id, the same name and the same product_number
|
24
|
+
def ==(other)
|
25
|
+
return false unless other.is_a? Epages::Product
|
26
|
+
product_id == other.product_id && name == other.name && product_number == other.product_number
|
27
|
+
end
|
28
|
+
|
29
|
+
# returns the name of the shop that belongs the product
|
30
|
+
def shop_name
|
31
|
+
sf_url[%r{epages\/(\w+)}, 1]
|
32
|
+
end
|
33
|
+
|
34
|
+
# returns the list of links
|
35
|
+
def links_title
|
36
|
+
links.collect(&:rel)
|
37
|
+
end
|
38
|
+
|
39
|
+
# returns true if [name] is included in the list of links
|
40
|
+
def link?(name)
|
41
|
+
links_title.include? name
|
42
|
+
end
|
43
|
+
|
44
|
+
# returns the list of slides of the product
|
45
|
+
def slideshow
|
46
|
+
product_slideshow(self) if link?('slideshow')
|
47
|
+
end
|
48
|
+
|
49
|
+
# returns the list of variations of the product
|
50
|
+
def variations
|
51
|
+
product_variations(self) if link?('variations')
|
52
|
+
end
|
53
|
+
|
54
|
+
# returns the list of custom_attributes of the product
|
55
|
+
def custom_attributes
|
56
|
+
product_custom_attributes(self) if link?('custom-attributes')
|
57
|
+
end
|
58
|
+
|
59
|
+
# returns the categories of the product
|
60
|
+
def categories
|
61
|
+
product_categories(self) if link?('categories')
|
62
|
+
end
|
63
|
+
|
64
|
+
# returns the lowest price of all the variations of the product
|
65
|
+
def lowest_price
|
66
|
+
product_lowest_price(self) if link?('lowest-price')
|
67
|
+
end
|
68
|
+
|
69
|
+
# returns the stock level of the product
|
70
|
+
def stock_level
|
71
|
+
product_stock_level(self)[:stocklevel]
|
72
|
+
end
|
73
|
+
|
74
|
+
# modify the current stock level in [units]
|
75
|
+
#
|
76
|
+
# @param units [Fixnum]. Number of units to change. Can be negative
|
77
|
+
# @param shop [Epages::Shop]. The shop that contains the authorization to do the call
|
78
|
+
def change_stock_level(units, shop)
|
79
|
+
shop.product_change_stock_level(self, units)[:stocklevel]
|
80
|
+
end
|
81
|
+
|
82
|
+
# return a hash with productId and quantity. This format is used for the line_items of Cart
|
83
|
+
def to_line_item(quantity = 1)
|
84
|
+
{productId: product_id, quantity: quantity}
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'epages/utils'
|
2
|
+
|
3
|
+
module Epages
|
4
|
+
class ProductLineItem
|
5
|
+
include Epages::Utils
|
6
|
+
|
7
|
+
KEYS = %w(line_item_id sku name product_id quantity line_item_price single_item_price images links).collect(&:to_sym).freeze
|
8
|
+
|
9
|
+
attr_reader *KEYS
|
10
|
+
|
11
|
+
def initialize(data)
|
12
|
+
parse_attribute_as_array_of(:images, data.delete(:images), Epages::Image)
|
13
|
+
parse_attribute_as_array_of(:links, data.delete(:links), Epages::Link)
|
14
|
+
parse_attribute_as(:quantity, data.delete(:quantity))
|
15
|
+
parse_attribute_as(:line_item_price, data.delete(:lineItemPrice), Epages::Price)
|
16
|
+
parse_attribute_as(:single_item_price, data.delete(:singleItemPrice), Epages::Price)
|
17
|
+
parse_attributes(data)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'epages/rest/carts'
|
2
|
+
require 'epages/rest/categories'
|
3
|
+
require 'epages/rest/legal'
|
4
|
+
require 'epages/rest/miscellaneous'
|
5
|
+
require 'epages/rest/orders'
|
6
|
+
require 'epages/rest/products'
|
7
|
+
require 'epages/rest/shipping_methods'
|
8
|
+
|
9
|
+
module Epages
|
10
|
+
module REST
|
11
|
+
module API
|
12
|
+
include REST::Carts
|
13
|
+
include REST::Categories
|
14
|
+
include REST::Legal
|
15
|
+
include REST::Miscellaneous
|
16
|
+
include REST::Orders
|
17
|
+
include REST::Products
|
18
|
+
include REST::ShippingMethods
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,71 @@
|
|
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-carts.html
|
7
|
+
module Carts
|
8
|
+
include REST::Utils
|
9
|
+
|
10
|
+
# implements the call https://developer.epages.com/apps/api-reference/post-shops-shopid-carts.html
|
11
|
+
def create_cart(data = {})
|
12
|
+
default = {currency: 'EUR', taxType: 'GROSS', locale: 'en_GB', lineItems: []}
|
13
|
+
perform_post_with_object('/carts', default.merge(camelize_keys(data)), Epages::Cart)
|
14
|
+
end
|
15
|
+
|
16
|
+
# implements the call https://developer.epages.com/apps/api-reference/get-shops-shopid-carts-cartid.html
|
17
|
+
def cart(cart)
|
18
|
+
id = epages_id(cart)
|
19
|
+
perform_get_with_object("/carts/#{id}", {}, Epages::Cart)
|
20
|
+
end
|
21
|
+
|
22
|
+
# implements the call https://developer.epages.com/apps/api-reference/post-shops-shopid-carts-cartid-line-items.html
|
23
|
+
def cart_line_item(cart, product, quantity = 1)
|
24
|
+
id = epages_id(cart)
|
25
|
+
lineitem = product.is_a?(Epages::Product) ? product.to_line_item(quantity) : product
|
26
|
+
perform_post_with_object("/carts/#{id}/line-items", lineitem, Epages::Cart)
|
27
|
+
end
|
28
|
+
alias_method :add_product_to_cart, :cart_line_item
|
29
|
+
|
30
|
+
# implements the call https://developer.epages.com/apps/api-reference/put-shops-shopid-carts-cartid-line-items-lineitemid.html
|
31
|
+
def update_cart_line_item(cart, lineitem, options)
|
32
|
+
id = epages_id(cart)
|
33
|
+
lineitem = lineitem.line_item_id if lineitem.is_a?(Epages::ProductLineItem)
|
34
|
+
perform_put_with_object("/carts/#{id}/line-items/#{lineitem}", options, Epages::Cart)
|
35
|
+
end
|
36
|
+
|
37
|
+
# implements the call https://developer.epages.com/apps/api-reference/delete-shops-shopid-carts-cartid-line-items-lineitemid.html
|
38
|
+
def delete_cart_line_item(cart, lineitem)
|
39
|
+
id = epages_id(cart)
|
40
|
+
lineitem = lineitem.line_item_id if lineitem.is_a?(Epages::ProductLineItem)
|
41
|
+
perform_delete_with_object("/carts/#{id}/line-items/#{lineitem}", {}, Epages::Cart)
|
42
|
+
end
|
43
|
+
|
44
|
+
# implements the call https://developer.epages.com/apps/api-reference/put-shops-shopid-carts-cartid-billing-address.html
|
45
|
+
def update_cart_billing_address(cart, address)
|
46
|
+
id = epages_id(cart)
|
47
|
+
address = address.to_json if address.is_a?(Epages::Address)
|
48
|
+
perform_put_with_object("/carts/#{id}/billing-address", address, Epages::Cart)
|
49
|
+
end
|
50
|
+
|
51
|
+
# implements the call https://developer.epages.com/apps/api-reference/delete-shops-shopid-carts-cartid-billing-address.html
|
52
|
+
def delete_billing_address(cart)
|
53
|
+
id = epages_id(cart)
|
54
|
+
perform_delete_with_object("/carts/#{id}/billing-address", {}, Epages::Cart)
|
55
|
+
end
|
56
|
+
|
57
|
+
# implements the call https://developer.epages.com/apps/api-reference/put-shops-shopid-carts-cartid-shipping-address.html
|
58
|
+
def update_cart_shipping_address(cart, address)
|
59
|
+
id = epages_id(cart)
|
60
|
+
address = address.to_json if address.is_a?(Epages::Address)
|
61
|
+
perform_put_with_object("/carts/#{id}/shipping-address", address, Epages::Cart)
|
62
|
+
end
|
63
|
+
|
64
|
+
# implements the call https://developer.epages.com/apps/api-reference/delete-shops-shopid-carts-cartid-shipping-address.html
|
65
|
+
def delete_shipping_address(cart)
|
66
|
+
id = epages_id(cart)
|
67
|
+
perform_delete_with_object("/carts/#{id}/shipping-address", {}, Epages::Cart)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'epages/rest/utils'
|
2
|
+
|
3
|
+
module Epages
|
4
|
+
module REST
|
5
|
+
module Categories
|
6
|
+
# implements the calls in https://developer.epages.com/apps/api-reference/resource-category.html
|
7
|
+
include REST::Utils
|
8
|
+
|
9
|
+
# implements the calls in https://developer.epages.com/apps/api-reference/get-shops-shopid-categories.html
|
10
|
+
def categories(options = {})
|
11
|
+
perform_get_with_objects('/categories', options, Epages::Category)
|
12
|
+
end
|
13
|
+
|
14
|
+
# implements the calls in https://developer.epages.com/apps/api-reference/get-shops-shopid-categories-categoryid.html
|
15
|
+
def category(object, options = {})
|
16
|
+
id = epages_id(object)
|
17
|
+
perform_get_with_object("/categories/#{id}", options, Epages::Category)
|
18
|
+
end
|
19
|
+
|
20
|
+
# implements the calls in https://developer.epages.com/apps/api-reference/put-shops-shopid-categories-categoryid.html
|
21
|
+
def update_category(object, options)
|
22
|
+
id = epages_id(object)
|
23
|
+
options[:categoryId] = id
|
24
|
+
perform_put_with_object("/categories/#{id}", options, Epages::Category)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|