epages-rest 1.0.4 → 1.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +9 -7
- data/lib/epages/customer.rb +20 -0
- data/lib/epages/order.rb +3 -3
- data/lib/epages/product.rb +3 -3
- data/lib/epages/rest/api.rb +2 -0
- data/lib/epages/rest/customers.rb +37 -0
- data/lib/epages/rest/miscellaneous.rb +6 -0
- data/lib/epages/rest/orders.rb +7 -1
- data/lib/epages/rest/products.rb +10 -0
- data/lib/epages/rest/request.rb +1 -1
- data/lib/epages/rest/utils.rb +1 -1
- data/lib/epages/shop.rb +3 -2
- data/lib/epages/version.rb +1 -1
- data/lib/epages-rest.rb +2 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9e6f19f5ad1f0b8bc0e7663906f8be81128a4535
|
4
|
+
data.tar.gz: f41c9b37e7eb3ecac2ff9de7d6eec000f5f0207a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 747c2442660724bcbffe03750ef9b86294509a8c2c574738f0e6c48b2350535b557d707b2b63bb222952fbfcf481df5bcb7ddcda606e4910e8b2fc210593d3a2
|
7
|
+
data.tar.gz: 590f481c30757145466070a8b6e9624e980c36ea940917fbd565c947363c3e6eeab00d4b00f5b1e132ff7d7be607418034dc902bddef1bbd926b696121ddbe28
|
data/README.md
CHANGED
@@ -2,9 +2,9 @@
|
|
2
2
|
[![Code Climate](https://codeclimate.com/github/ePages-de/epages-rest-ruby/badges/gpa.svg)](https://codeclimate.com/github/ePages-de/epages-rest-ruby)
|
3
3
|
[![Test Coverage](https://codeclimate.com/github/ePages-de/epages-rest-ruby/badges/coverage.svg)](https://codeclimate.com/github/ePages-de/epages-rest-ruby/coverage)
|
4
4
|
|
5
|
-
# The
|
5
|
+
# The ePages REST Ruby Gem
|
6
6
|
|
7
|
-
A Ruby interface to the
|
7
|
+
A Ruby interface to the ePages REST API.
|
8
8
|
|
9
9
|
## Installation
|
10
10
|
|
@@ -20,14 +20,17 @@ or add it to your Rails application adding the gem to your Gemfile.
|
|
20
20
|
|
21
21
|
## Usage
|
22
22
|
|
23
|
-
This gem is used to connect any Ruby application with any [
|
24
|
-
You can get any public information of any shop indicating only the name of the shop
|
23
|
+
This gem is used to connect any Ruby application with any [ePages](http://www.epages.com/en/) shop.
|
24
|
+
You can get any public information of any shop indicating only the name of the shop.
|
25
|
+
But for security reasons, to modify content from your shop, you need the token you will get in the developer environment of your test shop.
|
25
26
|
|
26
27
|
# Usage examples
|
27
28
|
|
28
29
|
The first thing is create your REST shop.
|
29
30
|
`shop = Epages::REST::Shop.new(shop_host, shop_name)` or `shop = Epages::REST::Shop.new(shop_host, shop_name, token)`
|
30
31
|
|
32
|
+
Additionally, you can indicate if your shop uses https or not (default true) `shop = Epages::REST::Shop.new(shop_host, shop_name, token, https: false)`
|
33
|
+
|
31
34
|
Once this is done, you can use the API calls.
|
32
35
|
|
33
36
|
#### [Get products](https://developer.epages.com/apps/api-reference/get-shops-shopid-products.html)
|
@@ -37,13 +40,12 @@ Once this is done, you can use the API calls.
|
|
37
40
|
#### [Get Categories](https://developer.epages.com/apps/api-reference/get-shops-shopid-categories.html)
|
38
41
|
`categories = shop.categories`
|
39
42
|
|
40
|
-
### Full collection of examples [here](https://github.com/
|
43
|
+
### Full collection of examples [here](https://github.com/ePages-de/epages-rest-ruby/tree/master/examples)
|
41
44
|
|
42
45
|
## Contributing
|
43
46
|
|
44
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
47
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/ePages-de/epages-rest-ruby.
|
45
48
|
|
46
49
|
## License
|
47
50
|
|
48
51
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
49
|
-
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'epages/utils'
|
2
|
+
|
3
|
+
module Epages
|
4
|
+
class Customer
|
5
|
+
include Epages::Utils
|
6
|
+
|
7
|
+
KEYS = %w(customer_id customer_number creation_date billing_address internal_note links).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_array_of(:links, data.delete(:links), Epages::Link)
|
14
|
+
parse_attribute_as(:creation_date, data.delete(:creationDate), DateTime)
|
15
|
+
parse_attributes(data)
|
16
|
+
end
|
17
|
+
|
18
|
+
alias_method :id, :customer_id
|
19
|
+
end
|
20
|
+
end
|
data/lib/epages/order.rb
CHANGED
@@ -5,12 +5,12 @@ module Epages
|
|
5
5
|
class Order
|
6
6
|
include Epages::Utils
|
7
7
|
|
8
|
-
DATE_ATTRS = %w(creation_date invoiced_on
|
9
|
-
|
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)
|
10
10
|
|
11
11
|
ATTRS = %w(order_id order_number billing_address shipping_address customer_id locale currency_id tax_model
|
12
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
|
+
customer_comment customer_number shipping_data payment_data)
|
14
14
|
|
15
15
|
KEYS = (ATTRS + DATE_ATTRS).collect(&:to_sym).freeze
|
16
16
|
|
data/lib/epages/product.rb
CHANGED
@@ -6,16 +6,16 @@ module Epages
|
|
6
6
|
include Epages::Utils
|
7
7
|
include Epages::REST::Products
|
8
8
|
|
9
|
-
KEYS = %w(product_id name short_description description images price_info for_sale special_offer delivery_weight
|
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
|
-
product_data_sheet sf_url product_number manufacturer upc ean links
|
11
|
+
product_data_sheet sf_url product_number manufacturer upc ean essential_features search_keywords links).collect(&:to_sym).freeze
|
12
12
|
|
13
13
|
attr_reader *KEYS
|
14
14
|
|
15
15
|
def initialize(data)
|
16
16
|
parse_attribute_as_array_of(:images, data.delete(:images), Epages::Image)
|
17
17
|
parse_attribute_as_array_of(:links, data.delete(:links), Epages::Link)
|
18
|
-
parse_attribute_as(:
|
18
|
+
parse_attribute_as(:price_info, data.delete(:priceInfo), Epages::PriceInfo)
|
19
19
|
parse_attributes(data)
|
20
20
|
end
|
21
21
|
|
data/lib/epages/rest/api.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'epages/rest/carts'
|
2
2
|
require 'epages/rest/categories'
|
3
|
+
require 'epages/rest/customers'
|
3
4
|
require 'epages/rest/legal'
|
4
5
|
require 'epages/rest/miscellaneous'
|
5
6
|
require 'epages/rest/orders'
|
@@ -12,6 +13,7 @@ module Epages
|
|
12
13
|
module API
|
13
14
|
include REST::Carts
|
14
15
|
include REST::Categories
|
16
|
+
include REST::Customers
|
15
17
|
include REST::Legal
|
16
18
|
include REST::Miscellaneous
|
17
19
|
include REST::Orders
|
@@ -0,0 +1,37 @@
|
|
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-customers.html
|
6
|
+
module Customers
|
7
|
+
include REST::Utils
|
8
|
+
|
9
|
+
# call the API to creates a customer. If customer_number is not provided in the request, it will be generated automatically.
|
10
|
+
# implements the call https://developer.epages.com/apps/api-reference/post-shops-shopid-customers.html
|
11
|
+
#
|
12
|
+
# @param options [Hash]
|
13
|
+
def create_customer(options = {})
|
14
|
+
perform_post_with_object('/customers', options, Epages::Customer)
|
15
|
+
end
|
16
|
+
|
17
|
+
# call the API and returns a specified customer
|
18
|
+
# implements the call https://developer.epages.com/apps/api-reference/get-shops-shopid-customers-customerid.html
|
19
|
+
#
|
20
|
+
# @param customer [String], [Epages::Customer]
|
21
|
+
def customer(customer)
|
22
|
+
id = epages_id(customer)
|
23
|
+
perform_get_with_object("/customers/#{id}", {}, Epages::Customer)
|
24
|
+
end
|
25
|
+
|
26
|
+
# call the API to update the information for a single customer
|
27
|
+
# implements the call https://developer.epages.com/apps/api-reference/patch-shops-shopid-customers-customerid.html
|
28
|
+
#
|
29
|
+
# @param customer [String], [Epages::Product]
|
30
|
+
# @param options [Hash]
|
31
|
+
def update_customer(customer, options = {})
|
32
|
+
id = epages_id(customer)
|
33
|
+
perform_patch_with_object("/customers/#{id}", options, Epages::Customer)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -7,6 +7,12 @@ 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
|
11
|
+
def info(options = {})
|
12
|
+
response = perform_get_request('/', options)
|
13
|
+
underscorize_keys(response)
|
14
|
+
end
|
15
|
+
|
10
16
|
# implements the call https://developer.epages.com/apps/api-reference/get-shops-shopid-locales.html
|
11
17
|
def locales
|
12
18
|
perform_get_request('/locales', {})
|
data/lib/epages/rest/orders.rb
CHANGED
@@ -18,12 +18,18 @@ module Epages
|
|
18
18
|
end
|
19
19
|
|
20
20
|
# implements the calls in https://developer.epages.com/apps/api-reference/put-shops-shopid-orders-orderid.html
|
21
|
-
def
|
21
|
+
def modify_order(order, options, locale = 'en_GB')
|
22
22
|
options.each { |k, v| options[k] = v.to_json if v.class.name.deconstantize == 'Epages' }
|
23
23
|
id = epages_id(order)
|
24
24
|
old_order = perform_get_request("/orders/#{id}", locale: locale)
|
25
25
|
perform_put_with_object("/orders/#{id}?locale=#{locale}", old_order.merge(options), Epages::Order)
|
26
26
|
end
|
27
|
+
|
28
|
+
# implements the calls in https://developer.epages.com/apps/api-reference/patch-shops-shopid-orders-orderid.html
|
29
|
+
def update_order(order, options = {}, locale = 'en_GB')
|
30
|
+
id = epages_id(order)
|
31
|
+
perform_patch_with_object("/orders/#{id}?locale=#{locale}", options, Epages::Order)
|
32
|
+
end
|
27
33
|
end
|
28
34
|
end
|
29
35
|
end
|
data/lib/epages/rest/products.rb
CHANGED
@@ -143,6 +143,16 @@ module Epages
|
|
143
143
|
perform_put_request("/products/#{id}/stock-level", changeStocklevel: units)[:stocklevel]
|
144
144
|
end
|
145
145
|
|
146
|
+
# call the API and return an array of Epages::Product with updated attribute
|
147
|
+
# implements the call https://developer.epages.com/apps/api-reference/get-shops-shopid-products-updated-productproperty.html
|
148
|
+
#
|
149
|
+
# @param property [String], [Symbol]
|
150
|
+
# @param options [Hash]
|
151
|
+
def updated_products_by_property(property, options = {})
|
152
|
+
res = perform_get_request("/products/updated/#{property.to_s.camelize(:lower)}", options)
|
153
|
+
res[:items].collect { |i| Epages::Product.new(i[:item]) }
|
154
|
+
end
|
155
|
+
|
146
156
|
# call the API and return a CSV with the proper data of the products
|
147
157
|
# implements the call https://developer.epages.com/apps/api-reference/get-shops-shopid-products-export.html
|
148
158
|
#
|
data/lib/epages/rest/request.rb
CHANGED
@@ -10,7 +10,7 @@ module Epages
|
|
10
10
|
|
11
11
|
def initialize(object, request_method, path, options = {})
|
12
12
|
@shop = build_shop_from(object)
|
13
|
-
@uri = URI.parse("
|
13
|
+
@uri = URI.parse("#{@shop.protocol}://#{@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
|
data/lib/epages/rest/utils.rb
CHANGED
@@ -131,7 +131,7 @@ module Epages
|
|
131
131
|
def epages_id(object)
|
132
132
|
return object if object.class == String
|
133
133
|
return if object.class.name.deconstantize != 'Epages'
|
134
|
-
object.send(
|
134
|
+
object.send(:id)
|
135
135
|
end
|
136
136
|
|
137
137
|
def parse_product_variations(data)
|
data/lib/epages/shop.rb
CHANGED
@@ -2,12 +2,13 @@ require 'epages/error'
|
|
2
2
|
|
3
3
|
module Epages
|
4
4
|
class Shop
|
5
|
-
|
5
|
+
attr_reader :host, :name, :token, :protocol
|
6
6
|
|
7
|
-
def initialize(host, name, token = nil)
|
7
|
+
def initialize(host, name, token = nil, options = { https: true })
|
8
8
|
@host = host
|
9
9
|
@name = name
|
10
10
|
@token = token
|
11
|
+
@protocol = options[:https] ? 'https' : 'http'
|
11
12
|
end
|
12
13
|
|
13
14
|
# return the shop name
|
data/lib/epages/version.rb
CHANGED
data/lib/epages-rest.rb
CHANGED
@@ -3,6 +3,7 @@ require 'epages/base_price'
|
|
3
3
|
require 'epages/cart'
|
4
4
|
require 'epages/category'
|
5
5
|
require 'epages/content_page_summary'
|
6
|
+
require 'epages/customer'
|
6
7
|
require 'epages/custom_attribute'
|
7
8
|
require 'epages/error'
|
8
9
|
require 'epages/image'
|
@@ -29,6 +30,7 @@ require 'epages/version'
|
|
29
30
|
require 'epages/rest/api'
|
30
31
|
require 'epages/rest/carts'
|
31
32
|
require 'epages/rest/categories'
|
33
|
+
require 'epages/rest/customers'
|
32
34
|
require 'epages/rest/legal'
|
33
35
|
require 'epages/rest/orders'
|
34
36
|
require 'epages/rest/products'
|
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.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Domingo Cividanes
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-04-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -71,6 +71,7 @@ files:
|
|
71
71
|
- lib/epages/category.rb
|
72
72
|
- lib/epages/content_page_summary.rb
|
73
73
|
- lib/epages/custom_attribute.rb
|
74
|
+
- lib/epages/customer.rb
|
74
75
|
- lib/epages/error.rb
|
75
76
|
- lib/epages/image.rb
|
76
77
|
- lib/epages/image_size.rb
|
@@ -86,6 +87,7 @@ files:
|
|
86
87
|
- lib/epages/rest/api.rb
|
87
88
|
- lib/epages/rest/carts.rb
|
88
89
|
- lib/epages/rest/categories.rb
|
90
|
+
- lib/epages/rest/customers.rb
|
89
91
|
- lib/epages/rest/legal.rb
|
90
92
|
- lib/epages/rest/miscellaneous.rb
|
91
93
|
- lib/epages/rest/orders.rb
|