ecwid_api 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +0 -0
- data/.rspec +0 -0
- data/.travis.yml +0 -0
- data/Gemfile +0 -2
- data/LICENSE.txt +0 -0
- data/README.md +228 -228
- data/Rakefile +0 -0
- data/ecwid_api.gemspec +4 -4
- data/lib/ecwid_api.rb +25 -25
- data/lib/ecwid_api/api.rb +8 -30
- data/lib/ecwid_api/api/base.rb +17 -16
- data/lib/ecwid_api/api/categories.rb +55 -56
- data/lib/ecwid_api/api/orders.rb +36 -36
- data/lib/ecwid_api/api/product_combinations.rb +2 -5
- data/lib/ecwid_api/api/products.rb +61 -63
- data/lib/ecwid_api/category.rb +1 -7
- data/lib/ecwid_api/client.rb +99 -65
- data/lib/ecwid_api/entity.rb +4 -6
- data/lib/ecwid_api/error.rb +12 -12
- data/lib/ecwid_api/o_auth.rb +105 -105
- data/lib/ecwid_api/order.rb +0 -0
- data/lib/ecwid_api/order_item.rb +0 -0
- data/lib/ecwid_api/paged_ecwid_response.rb +0 -0
- data/lib/ecwid_api/paged_enumerator.rb +0 -0
- data/lib/ecwid_api/person.rb +0 -0
- data/lib/ecwid_api/product.rb +3 -15
- data/lib/ecwid_api/product_combination.rb +1 -5
- data/lib/ecwid_api/version.rb +1 -1
- data/lib/ext/string.rb +12 -12
- data/spec/api/categories_spec.rb +30 -30
- data/spec/api/orders_spec.rb +29 -29
- data/spec/api/products_spec.rb +0 -0
- data/spec/category_spec.rb +33 -33
- data/spec/client_spec.rb +20 -20
- data/spec/entity_spec.rb +0 -0
- data/spec/fixtures/categories.json +0 -0
- data/spec/fixtures/category.json +0 -0
- data/spec/fixtures/order.json +0 -0
- data/spec/fixtures/orders.json +0 -0
- data/spec/fixtures/products.json +0 -0
- data/spec/helpers/client.rb +31 -31
- data/spec/oauth_spec.rb +39 -39
- data/spec/order_item_spec.rb +11 -11
- data/spec/order_spec.rb +0 -0
- data/spec/paged_enumerator_spec.rb +0 -0
- data/spec/spec_helper.rb +24 -24
- metadata +26 -34
data/Rakefile
CHANGED
File without changes
|
data/ecwid_api.gemspec
CHANGED
@@ -9,7 +9,8 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.authors = ["David Biehl"]
|
10
10
|
spec.email = ["me@davidbiehl.com"]
|
11
11
|
spec.summary = %q{A client for the Ecwid REST API}
|
12
|
-
spec.
|
12
|
+
spec.description = %q{A client for the Ecwid REST API in Ruby}
|
13
|
+
spec.homepage = "https://github.com/davidbiehl/ecwid_api"
|
13
14
|
spec.license = "MIT"
|
14
15
|
|
15
16
|
spec.files = `git ls-files -z`.split("\x0")
|
@@ -18,9 +19,8 @@ Gem::Specification.new do |spec|
|
|
18
19
|
spec.require_paths = ["lib"]
|
19
20
|
|
20
21
|
spec.add_development_dependency "bundler", "~> 1.5"
|
21
|
-
spec.add_development_dependency "rake"
|
22
|
-
spec.add_development_dependency "rspec", "~> 2.14.1"
|
23
|
-
spec.add_development_dependency "pry"
|
22
|
+
spec.add_development_dependency "rake", "~> 0"
|
23
|
+
spec.add_development_dependency "rspec", "~> 2.14", ">= 2.14.1"
|
24
24
|
|
25
25
|
spec.add_dependency "faraday", "~> 0.9.0"
|
26
26
|
spec.add_dependency "faraday_middleware", "~> 0.9.1"
|
data/lib/ecwid_api.rb
CHANGED
@@ -1,25 +1,25 @@
|
|
1
|
-
require "ecwid_api/version"
|
2
|
-
require "ext/string"
|
3
|
-
require 'faraday'
|
4
|
-
require 'faraday_middleware'
|
5
|
-
|
6
|
-
require_relative "ecwid_api/error"
|
7
|
-
|
8
|
-
# Public: This is the main namespace for the EcwidApi. It can be used to store
|
9
|
-
# the default client.
|
10
|
-
#
|
11
|
-
module EcwidApi
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
end
|
1
|
+
require "ecwid_api/version"
|
2
|
+
require "ext/string"
|
3
|
+
require 'faraday'
|
4
|
+
require 'faraday_middleware'
|
5
|
+
|
6
|
+
require_relative "ecwid_api/error"
|
7
|
+
|
8
|
+
# Public: This is the main namespace for the EcwidApi. It can be used to store
|
9
|
+
# the default client.
|
10
|
+
#
|
11
|
+
module EcwidApi
|
12
|
+
require_relative "ecwid_api/o_auth"
|
13
|
+
require_relative "ecwid_api/client"
|
14
|
+
require_relative "ecwid_api/error"
|
15
|
+
require_relative "ecwid_api/api"
|
16
|
+
require_relative "ecwid_api/entity"
|
17
|
+
|
18
|
+
require_relative "ecwid_api/category"
|
19
|
+
require_relative "ecwid_api/order"
|
20
|
+
require_relative "ecwid_api/order_item"
|
21
|
+
require_relative "ecwid_api/person"
|
22
|
+
require_relative "ecwid_api/product_combination"
|
23
|
+
|
24
|
+
require_relative "ecwid_api/product"
|
25
|
+
end
|
data/lib/ecwid_api/api.rb
CHANGED
@@ -1,31 +1,9 @@
|
|
1
|
-
module EcwidApi
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
# Private: Gets the Client
|
11
|
-
attr_reader :client
|
12
|
-
private :client
|
13
|
-
|
14
|
-
# Private: Raises an Error if a request failed, otherwise it will
|
15
|
-
# yield the block
|
16
|
-
#
|
17
|
-
# response - a Faraday::Response object
|
18
|
-
#
|
19
|
-
# Yield if the response was successful
|
20
|
-
#
|
21
|
-
# Raises an error with the status code and reason if the response failed
|
22
|
-
#
|
23
|
-
def raise_on_failure(response)
|
24
|
-
if response.success?
|
25
|
-
yield(response) if block_given?
|
26
|
-
else
|
27
|
-
raise ResponseError.new(response)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
1
|
+
module EcwidApi
|
2
|
+
module Api
|
3
|
+
require_relative "api/base"
|
4
|
+
require_relative "api/orders"
|
5
|
+
require_relative "api/products"
|
6
|
+
require_relative "api/categories"
|
7
|
+
require_relative "api/product_combinations"
|
8
|
+
end
|
31
9
|
end
|
data/lib/ecwid_api/api/base.rb
CHANGED
@@ -1,17 +1,18 @@
|
|
1
|
-
module EcwidApi
|
2
|
-
module Api
|
3
|
-
# Internal: A base class for common API functionality
|
4
|
-
class Base
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
#
|
9
|
-
#
|
10
|
-
#
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
1
|
+
module EcwidApi
|
2
|
+
module Api
|
3
|
+
# Internal: A base class for common API functionality
|
4
|
+
class Base
|
5
|
+
attr_reader :client
|
6
|
+
private :client
|
7
|
+
|
8
|
+
# Public: Initializes a new EcwidApi::CategoryApi
|
9
|
+
#
|
10
|
+
# client - The EcwidApi::Client to use with the API
|
11
|
+
#
|
12
|
+
def initialize(client)
|
13
|
+
@client = client
|
14
|
+
raise Error.new("The client cannot be nil") unless client
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
17
18
|
end
|
@@ -1,57 +1,56 @@
|
|
1
|
-
require_relative "../paged_ecwid_response"
|
2
|
-
|
3
|
-
module EcwidApi
|
4
|
-
module Api
|
5
|
-
class Categories < Base
|
6
|
-
# Public: Returns all of the sub-categories for a given category
|
7
|
-
#
|
8
|
-
# See: http://kb.ecwid.com/w/page/25285101/Product%20API#RESTAPIMethodcategories
|
9
|
-
#
|
10
|
-
# parent - The Category ID of the parent category. If the parent is 0 then
|
11
|
-
# a list of the root categories will be returned. If the parent is
|
12
|
-
# nil, then all of the categories will be returned
|
13
|
-
#
|
14
|
-
# Returns an array of EcwidApi::Category objects
|
15
|
-
def all(params = {})
|
16
|
-
PagedEcwidResponse.new(client, "categories", params) do |category_hash|
|
17
|
-
Category.new(category_hash, client: client)
|
18
|
-
end.sort_by(&:order_by)
|
19
|
-
end
|
20
|
-
|
21
|
-
# Public: Returns an Array of the root level EcwidApi::Category objects
|
22
|
-
def root(params = {})
|
23
|
-
all(params.merge(parent: 0))
|
24
|
-
end
|
25
|
-
|
26
|
-
# Public: Returns a single EcwidApi::Category
|
27
|
-
#
|
28
|
-
# See: http://kb.ecwid.com/w/page/25285101/Product%20API#RESTAPIMethodcategory
|
29
|
-
#
|
30
|
-
# category_id - A Category ID to get
|
31
|
-
#
|
32
|
-
# Returns an EcwidApi::Category, or nil if it can't be found
|
33
|
-
def find(id)
|
34
|
-
response = client.get("categories/#{id}")
|
35
|
-
|
36
|
-
if response.success?
|
37
|
-
Category.new(response.body, client: client)
|
38
|
-
else
|
39
|
-
nil
|
40
|
-
end
|
41
|
-
rescue Zlib::BufError
|
42
|
-
nil
|
43
|
-
end
|
44
|
-
|
45
|
-
# Public: Creates a new Category
|
46
|
-
#
|
47
|
-
# params - a Hash of API keys and their corresponding values
|
48
|
-
#
|
49
|
-
# Returns a new Category entity
|
50
|
-
def create(params)
|
51
|
-
response = client.post("categories", params)
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
end
|
1
|
+
require_relative "../paged_ecwid_response"
|
2
|
+
|
3
|
+
module EcwidApi
|
4
|
+
module Api
|
5
|
+
class Categories < Base
|
6
|
+
# Public: Returns all of the sub-categories for a given category
|
7
|
+
#
|
8
|
+
# See: http://kb.ecwid.com/w/page/25285101/Product%20API#RESTAPIMethodcategories
|
9
|
+
#
|
10
|
+
# parent - The Category ID of the parent category. If the parent is 0 then
|
11
|
+
# a list of the root categories will be returned. If the parent is
|
12
|
+
# nil, then all of the categories will be returned
|
13
|
+
#
|
14
|
+
# Returns an array of EcwidApi::Category objects
|
15
|
+
def all(params = {})
|
16
|
+
PagedEcwidResponse.new(client, "categories", params) do |category_hash|
|
17
|
+
Category.new(category_hash, client: client)
|
18
|
+
end.sort_by(&:order_by)
|
19
|
+
end
|
20
|
+
|
21
|
+
# Public: Returns an Array of the root level EcwidApi::Category objects
|
22
|
+
def root(params = {})
|
23
|
+
all(params.merge(parent: 0))
|
24
|
+
end
|
25
|
+
|
26
|
+
# Public: Returns a single EcwidApi::Category
|
27
|
+
#
|
28
|
+
# See: http://kb.ecwid.com/w/page/25285101/Product%20API#RESTAPIMethodcategory
|
29
|
+
#
|
30
|
+
# category_id - A Category ID to get
|
31
|
+
#
|
32
|
+
# Returns an EcwidApi::Category, or nil if it can't be found
|
33
|
+
def find(id)
|
34
|
+
response = client.get("categories/#{id}")
|
35
|
+
|
36
|
+
if response.success?
|
37
|
+
Category.new(response.body, client: client)
|
38
|
+
else
|
39
|
+
nil
|
40
|
+
end
|
41
|
+
rescue Zlib::BufError
|
42
|
+
nil
|
43
|
+
end
|
44
|
+
|
45
|
+
# Public: Creates a new Category
|
46
|
+
#
|
47
|
+
# params - a Hash of API keys and their corresponding values
|
48
|
+
#
|
49
|
+
# Returns a new Category entity
|
50
|
+
def create(params)
|
51
|
+
response = client.post("categories", params)
|
52
|
+
find(response.body["id"])
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
57
56
|
end
|
data/lib/ecwid_api/api/orders.rb
CHANGED
@@ -1,36 +1,36 @@
|
|
1
|
-
require_relative "../paged_ecwid_response"
|
2
|
-
|
3
|
-
module EcwidApi
|
4
|
-
module Api
|
5
|
-
# Public: This is the Ecwid API for Orders. It abstracts the end-points
|
6
|
-
# of the Ecwid API that deal with orders.
|
7
|
-
class Orders < Base
|
8
|
-
# Public: Gets Orders from the Ecwid API
|
9
|
-
#
|
10
|
-
# params - optional parameters that can be used to filter the request.
|
11
|
-
# For a list of params, please refer to the API documentation:
|
12
|
-
# http://kb.ecwid.com/w/page/43697230/Order%20API
|
13
|
-
# Note that the limit and offset parameters will be overridden
|
14
|
-
# since all orders will be returned and enumerated
|
15
|
-
#
|
16
|
-
# Returns a PagedEnumerator of `EcwidApi::Order` objects
|
17
|
-
def all(params = {})
|
18
|
-
PagedEcwidResponse.new(client, "orders", params) do |order_hash|
|
19
|
-
Order.new(order_hash, client: client)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
# Public: Finds a an Order given an Ecwid order_number
|
24
|
-
#
|
25
|
-
# order_number - an Integer that is the Ecwid Order number
|
26
|
-
#
|
27
|
-
# Returns an EcwidApi::Order if found, nil if not
|
28
|
-
def find(order_number)
|
29
|
-
response = client.get("orders/#{order_number}")
|
30
|
-
if response.success?
|
31
|
-
Order.new(response.body, client: client)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
1
|
+
require_relative "../paged_ecwid_response"
|
2
|
+
|
3
|
+
module EcwidApi
|
4
|
+
module Api
|
5
|
+
# Public: This is the Ecwid API for Orders. It abstracts the end-points
|
6
|
+
# of the Ecwid API that deal with orders.
|
7
|
+
class Orders < Base
|
8
|
+
# Public: Gets Orders from the Ecwid API
|
9
|
+
#
|
10
|
+
# params - optional parameters that can be used to filter the request.
|
11
|
+
# For a list of params, please refer to the API documentation:
|
12
|
+
# http://kb.ecwid.com/w/page/43697230/Order%20API
|
13
|
+
# Note that the limit and offset parameters will be overridden
|
14
|
+
# since all orders will be returned and enumerated
|
15
|
+
#
|
16
|
+
# Returns a PagedEnumerator of `EcwidApi::Order` objects
|
17
|
+
def all(params = {})
|
18
|
+
PagedEcwidResponse.new(client, "orders", params) do |order_hash|
|
19
|
+
Order.new(order_hash, client: client)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
# Public: Finds a an Order given an Ecwid order_number
|
24
|
+
#
|
25
|
+
# order_number - an Integer that is the Ecwid Order number
|
26
|
+
#
|
27
|
+
# Returns an EcwidApi::Order if found, nil if not
|
28
|
+
def find(order_number)
|
29
|
+
response = client.get("orders/#{order_number}")
|
30
|
+
if response.success?
|
31
|
+
Order.new(response.body, client: client)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -37,14 +37,11 @@ module EcwidApi
|
|
37
37
|
|
38
38
|
def create(params)
|
39
39
|
response = client.post("products/#{product.id}/combinations", params)
|
40
|
-
|
41
|
-
raise_on_failure(response) { find(response.body["id"]) }
|
40
|
+
find(response.body["id"])
|
42
41
|
end
|
43
42
|
|
44
43
|
def delete_all!
|
45
|
-
client.delete("products/#{product.id}/combinations")
|
46
|
-
raise_on_failure(response)
|
47
|
-
end
|
44
|
+
client.delete("products/#{product.id}/combinations")
|
48
45
|
end
|
49
46
|
end
|
50
47
|
end
|
@@ -1,64 +1,62 @@
|
|
1
|
-
require_relative "../paged_ecwid_response"
|
2
|
-
|
3
|
-
module EcwidApi
|
4
|
-
module Api
|
5
|
-
class Products < Base
|
6
|
-
# Public: Get all of the Product objects for the Ecwid store
|
7
|
-
#
|
8
|
-
# Returns an Array of Product objects
|
9
|
-
def all(params = {})
|
10
|
-
PagedEcwidResponse.new(client, "products", params) do |product_hash|
|
11
|
-
Product.new(product_hash, client: client)
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
# Public: Finds a single product by product ID
|
16
|
-
#
|
17
|
-
# id - an Ecwid product ID
|
18
|
-
#
|
19
|
-
# Returns a Product object, or nil if one can't be found
|
20
|
-
def find(id)
|
21
|
-
response = client.get("products/#{id}")
|
22
|
-
if response.success?
|
23
|
-
Product.new(response.body, client: client)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
# Public: Finds a single Product by SKU
|
28
|
-
#
|
29
|
-
# sku - a SKU of a product
|
30
|
-
#
|
31
|
-
# Returns a Product object, or nil if one can't be found
|
32
|
-
def find_by_sku(sku)
|
33
|
-
all(keyword: sku).find { |product| product[:sku] == sku }
|
34
|
-
end
|
35
|
-
|
36
|
-
# Public: Creates a new Product
|
37
|
-
#
|
38
|
-
# params - a Hash
|
39
|
-
#
|
40
|
-
# Raises an Error if there is a problem
|
41
|
-
#
|
42
|
-
# Returns a Product object
|
43
|
-
def create(params)
|
44
|
-
response = client.post("products", params)
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
#
|
50
|
-
#
|
51
|
-
#
|
52
|
-
#
|
53
|
-
#
|
54
|
-
#
|
55
|
-
#
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
end
|
63
|
-
end
|
1
|
+
require_relative "../paged_ecwid_response"
|
2
|
+
|
3
|
+
module EcwidApi
|
4
|
+
module Api
|
5
|
+
class Products < Base
|
6
|
+
# Public: Get all of the Product objects for the Ecwid store
|
7
|
+
#
|
8
|
+
# Returns an Array of Product objects
|
9
|
+
def all(params = {})
|
10
|
+
PagedEcwidResponse.new(client, "products", params) do |product_hash|
|
11
|
+
Product.new(product_hash, client: client)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
# Public: Finds a single product by product ID
|
16
|
+
#
|
17
|
+
# id - an Ecwid product ID
|
18
|
+
#
|
19
|
+
# Returns a Product object, or nil if one can't be found
|
20
|
+
def find(id)
|
21
|
+
response = client.get("products/#{id}")
|
22
|
+
if response.success?
|
23
|
+
Product.new(response.body, client: client)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
# Public: Finds a single Product by SKU
|
28
|
+
#
|
29
|
+
# sku - a SKU of a product
|
30
|
+
#
|
31
|
+
# Returns a Product object, or nil if one can't be found
|
32
|
+
def find_by_sku(sku)
|
33
|
+
all(keyword: sku).find { |product| product[:sku] == sku }
|
34
|
+
end
|
35
|
+
|
36
|
+
# Public: Creates a new Product
|
37
|
+
#
|
38
|
+
# params - a Hash
|
39
|
+
#
|
40
|
+
# Raises an Error if there is a problem
|
41
|
+
#
|
42
|
+
# Returns a Product object
|
43
|
+
def create(params)
|
44
|
+
response = client.post("products", params)
|
45
|
+
find(response.body["id"])
|
46
|
+
end
|
47
|
+
|
48
|
+
# Public: Updates an existing Product
|
49
|
+
#
|
50
|
+
# id - the Ecwid product ID
|
51
|
+
# params - a Hash
|
52
|
+
#
|
53
|
+
# Raises an Error if there is a problem
|
54
|
+
#
|
55
|
+
# Returns a Product object
|
56
|
+
def update(id, params)
|
57
|
+
client.put("products/#{id}", params)
|
58
|
+
find(id)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
64
62
|
end
|