ecwid_api 0.0.2 → 0.2.3
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 +5 -5
- data/.travis.yml +8 -0
- data/README.md +123 -31
- data/ecwid_api.gemspec +10 -8
- data/lib/ecwid_api.rb +18 -29
- data/lib/ecwid_api/api.rb +12 -0
- data/lib/ecwid_api/api/base.rb +18 -0
- data/lib/ecwid_api/api/categories.rb +56 -0
- data/lib/ecwid_api/api/customers.rb +53 -0
- data/lib/ecwid_api/api/orders.rb +36 -0
- data/lib/ecwid_api/api/product_combinations.rb +48 -0
- data/lib/ecwid_api/api/product_types.rb +56 -0
- data/lib/ecwid_api/api/products.rb +148 -0
- data/lib/ecwid_api/category.rb +53 -4
- data/lib/ecwid_api/client.rb +65 -58
- data/lib/ecwid_api/customer.rb +10 -0
- data/lib/ecwid_api/entity.rb +151 -29
- data/lib/ecwid_api/error.rb +10 -0
- data/lib/ecwid_api/o_auth.rb +106 -0
- data/lib/ecwid_api/order.rb +118 -0
- data/lib/ecwid_api/order_item.rb +17 -0
- data/lib/ecwid_api/paged_ecwid_response.rb +57 -0
- data/lib/ecwid_api/paged_enumerator.rb +66 -0
- data/lib/ecwid_api/person.rb +7 -0
- data/lib/ecwid_api/product.rb +65 -0
- data/lib/ecwid_api/product_combination.rb +30 -0
- data/lib/ecwid_api/product_type.rb +18 -0
- data/lib/ecwid_api/product_type_attribute.rb +27 -0
- data/lib/ecwid_api/unpaged_ecwid_response.rb +38 -0
- data/lib/ecwid_api/version.rb +1 -1
- data/lib/ext/string.rb +9 -1
- data/spec/api/categories_spec.rb +31 -0
- data/spec/api/customers_spec.rb +20 -0
- data/spec/api/orders_spec.rb +30 -0
- data/spec/api/product_types_spec.rb +20 -0
- data/spec/api/products_spec.rb +20 -0
- data/spec/category_spec.rb +1 -6
- data/spec/client_spec.rb +4 -32
- data/spec/entity_spec.rb +120 -8
- data/spec/fixtures/categories.json +28 -22
- data/spec/fixtures/classes.json +44 -0
- data/spec/fixtures/customers.json +48 -0
- data/spec/fixtures/order.json +162 -0
- data/spec/fixtures/orders.json +303 -0
- data/spec/fixtures/products.json +141 -0
- data/spec/helpers/client.rb +34 -0
- data/spec/oauth_spec.rb +40 -0
- data/spec/order_item_spec.rb +12 -0
- data/spec/order_spec.rb +71 -0
- data/spec/paged_enumerator_spec.rb +38 -0
- data/spec/spec_helper.rb +3 -3
- metadata +93 -37
- data/lib/ecwid_api/category_api.rb +0 -62
- data/spec/category_api_spec.rb +0 -36
- data/spec/ecwid_api_spec.rb +0 -15
- data/spec/helpers/faraday.rb +0 -30
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: b3586666f15cbba13b4138fd19fba02ac3e1dffccc70803d975215e447b8471b
|
4
|
+
data.tar.gz: 9aadcd7b9217e1e92cebdaba858da43cf359873b7d2be100a63f514313da63fd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0d83a8bf4a7460bdbbf86b878b3383bd29fbb40659a7b3f3e796b058d20e36d6ec4ff8a0af33f50e34d888157eb3d75d28aec4d8a2c9b92870e19928fd0e504c
|
7
|
+
data.tar.gz: ce28316fc8cee04433d47b04ea9c58d79c6b2519aab5cd27735338268601c763c9d4cde6cef4afe463169078d94611febb637f93d0dd77f0861420df34a05159
|
data/.travis.yml
ADDED
data/README.md
CHANGED
@@ -2,7 +2,20 @@
|
|
2
2
|
|
3
3
|
A gem to interface with the Ecwid REST APIs.
|
4
4
|
|
5
|
-
[](https://codeclimate.com/github/vishalzambre/ecwid_api)
|
6
|
+
[](https://travis-ci.org/vishalzambre/ecwid_api)
|
7
|
+
|
8
|
+
## API v3 Warning!
|
9
|
+
|
10
|
+
This is for the latest version of the API, also known as v3, which is currently
|
11
|
+
in closed beta! The (incomplete) v1 API is still available on the
|
12
|
+
[api-v1 branch](https://github.com/vishalzambre/ecwid_api/tree/api-v1).
|
13
|
+
|
14
|
+
To participate in the beta, please contact Ecwid and they will give you the
|
15
|
+
information necessary to configure and authorize your application with OAuth2.
|
16
|
+
|
17
|
+
[Ecwid's API Documentation](http://api.ecwid.com) will be an important reference
|
18
|
+
in order to understand what their API is capable of.
|
6
19
|
|
7
20
|
## Installation
|
8
21
|
|
@@ -20,44 +33,56 @@ Or install it yourself as:
|
|
20
33
|
|
21
34
|
## Usage
|
22
35
|
|
23
|
-
###
|
24
|
-
|
25
|
-
A `Client` will interface with a single Ecwid store. The `store_id` will need
|
26
|
-
to be configured for each new `Client`.
|
36
|
+
### Get Authorized with OAuth2
|
27
37
|
|
28
|
-
|
38
|
+
Ecwid API v3 uses OAuth2 to authorize 3rd party apps to use the API with a
|
39
|
+
store. The `EcwidApi::OAuth` class helps facilitate this process. Once you
|
40
|
+
get setup with a `client_id` and `client_secret` from Ecwid, configure a new
|
41
|
+
instance like so:
|
29
42
|
|
30
|
-
|
31
|
-
config.
|
32
|
-
config.
|
33
|
-
config.
|
34
|
-
config.
|
43
|
+
@auth = EcwidApi::OAuth.new do |config|
|
44
|
+
config.client_id = "the client id"
|
45
|
+
config.client_secret = "the client secret (shh...)"
|
46
|
+
config.redirect_uri = "https://example.com/oauth"
|
47
|
+
config.scope = "the_permissions_i_want"
|
35
48
|
end
|
36
49
|
|
37
|
-
|
50
|
+
The `#oauth_url` method will provide the URL that the user needs to go to
|
51
|
+
to authorize your application with their store. It can be used in Rails like so:
|
38
52
|
|
39
|
-
|
53
|
+
link_to @auth.oauth_url, "Click here to Authorize this Groovy App!"
|
40
54
|
|
41
|
-
|
42
|
-
|
55
|
+
When the user authorizes your app, they will be redirected to the `redirect_uri`
|
56
|
+
with a `code` parameter in the query string.
|
57
|
+
Just send that code to the `#access_token` method to complete the authorization
|
58
|
+
and get your `access_token` and `store_id`.
|
43
59
|
|
44
|
-
|
45
|
-
# => #<EcwidApi::CategoryApi>
|
60
|
+
# https://example.com/oauth?code=super_secret_temporary_code
|
46
61
|
|
47
|
-
|
48
|
-
# Returns an Array of all of the `EcwidApi::Category` objects
|
62
|
+
token = @auth.access_token(params[:code])
|
49
63
|
|
50
|
-
|
51
|
-
#
|
52
|
-
# store
|
64
|
+
token.access_token # the token for the Client
|
65
|
+
token.store_id # the store_id for the Client
|
53
66
|
|
54
|
-
|
55
|
-
|
67
|
+
### Configure an new Client
|
68
|
+
|
69
|
+
A `Client` will interface with a single Ecwid store. The `store_id` and OAuth
|
70
|
+
`access_token` will need to be provided to the client.
|
71
|
+
|
72
|
+
require 'ecwid_api'
|
73
|
+
|
74
|
+
client = EcwidApi::Client.new(store_id, access_token)
|
75
|
+
|
76
|
+
## The APIs
|
56
77
|
|
57
|
-
|
78
|
+
### Entities
|
58
79
|
|
59
|
-
|
60
|
-
|
80
|
+
Instead of returning raw JSON from the API, there are Entities that will help
|
81
|
+
you work with the data. The [Ecwid API](http://api.ecwid.com)
|
82
|
+
will give you all of the fields that are available for every entity. Our
|
83
|
+
Entities will give you access to the data with the `[]` method, or a snake_case
|
84
|
+
version of the property name. For example, with an `EcwidApi::Category` the
|
85
|
+
following would be possible:
|
61
86
|
|
62
87
|
cat = client.categories.find(123)
|
63
88
|
# An example response from the API
|
@@ -76,7 +101,27 @@ method, or with special snake_cased helper methods.
|
|
76
101
|
cat.parent_id # Access with a snake_case method
|
77
102
|
# => 456
|
78
103
|
|
79
|
-
|
104
|
+
### Category API
|
105
|
+
|
106
|
+
The Category API will allow you to access the categories for an Ecwid store.
|
107
|
+
An instance of the Category API is available on the client.
|
108
|
+
|
109
|
+
api = client.categories
|
110
|
+
# => #<EcwidApi::Api::Categories>
|
111
|
+
|
112
|
+
api.all
|
113
|
+
# Returns an Array of all of the `EcwidApi::Category` objects
|
114
|
+
|
115
|
+
api.root
|
116
|
+
# Returns an Array of the top-level `EcwidApi::Category` objects for the
|
117
|
+
# store
|
118
|
+
|
119
|
+
api.find(123)
|
120
|
+
# Returns the `EcwidApi::Category` with an ID of 123
|
121
|
+
|
122
|
+
#### EcwidApi::Category Entities
|
123
|
+
|
124
|
+
Each `EcwidApi::Category` has methods to find sub-categories and the
|
80
125
|
parent category, if there is one.
|
81
126
|
|
82
127
|
cat.parent
|
@@ -85,13 +130,52 @@ parent category, if there is one.
|
|
85
130
|
cat.sub_categories
|
86
131
|
# Returns an Array of `EcwidApi::Category`
|
87
132
|
|
133
|
+
### Order API
|
134
|
+
|
135
|
+
The Order API will allow you to access the orders that have been placed in an
|
136
|
+
Ecwid store. An instance of the Order API is available to the client
|
137
|
+
|
138
|
+
api = client.orders
|
139
|
+
|
140
|
+
api.all
|
141
|
+
# Returns a `PagedEnumerator` containing all of the orders for the store
|
142
|
+
|
143
|
+
api.all({createdFrom: "1982-05-17"})
|
144
|
+
# Paremters can be passed as a Hash.
|
145
|
+
# See http://api.ecwid.com/#search-orders
|
146
|
+
# a list of available parameters
|
147
|
+
|
148
|
+
api.find(123)
|
149
|
+
# Returns an `EcwidApi::Order` object for order 123
|
150
|
+
|
151
|
+
#### EcwidApi::Order Entities
|
152
|
+
|
153
|
+
There are a few helper methods on the `EcwidApi::Order` that assist in accessing
|
154
|
+
related Entities.
|
155
|
+
|
156
|
+
order.billing_person
|
157
|
+
# Returns a EcwidApi::Person
|
158
|
+
|
159
|
+
order.shipping_person
|
160
|
+
# Returns an EcwidApi::Person
|
161
|
+
|
162
|
+
order.items
|
163
|
+
# Returns an Array of EcwidApi::OrderItem objects
|
164
|
+
|
165
|
+
The fulfillment status and shipping tracking code can also be updated for an
|
166
|
+
`EcwidApi::Order` object.
|
167
|
+
|
168
|
+
order.fulfillment_status = :processing
|
169
|
+
order.shipping_tracking_code = "1Z1234567890"
|
170
|
+
order.save
|
171
|
+
|
88
172
|
### Making Ad-Hoc Requests with the Client
|
89
173
|
|
90
174
|
To make a request, simply call the `#get` method on the client passing in the
|
91
175
|
relative path and any parameters it requires.
|
92
176
|
For example, to get some categories:
|
93
177
|
|
94
|
-
# GET https://app.ecwid.com/api/
|
178
|
+
# GET https://app.ecwid.com/api/v3/[STORE-ID]/categories?parent=1
|
95
179
|
|
96
180
|
client.get("categories", parent: 1)
|
97
181
|
|
@@ -104,7 +188,7 @@ JSON.
|
|
104
188
|
|
105
189
|
### Ecwid API Documentation
|
106
190
|
|
107
|
-
The [Ecwid API documentation](http://
|
191
|
+
The [Ecwid API documentation](http://api.ecwid.com)
|
108
192
|
should give you a good idea of what is possible to retreive. It also defines
|
109
193
|
which properties are available on each of the entities it provies. Please note
|
110
194
|
that resources requiring the secret keys will be inaccessible until we implement
|
@@ -112,12 +196,20 @@ that feature.
|
|
112
196
|
|
113
197
|
## Contributing
|
114
198
|
|
115
|
-
1. Fork it ( http://github.com/
|
199
|
+
1. Fork it ( http://github.com/vishalzambre/ecwid_api/fork )
|
116
200
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
117
201
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
118
202
|
4. Push to the branch (`git push origin my-new-feature`)
|
119
203
|
5. Create new Pull Request
|
120
204
|
|
205
|
+
## Authors
|
206
|
+
|
207
|
+
* **Vishal Zambre** - *Current work* - [vishalzambre](https://github.com/vishalzambre)
|
208
|
+
* **David Biehl** - *Initial work* - [davidbiehl](https://github.com/davidbiehl)
|
209
|
+
|
210
|
+
See also the list of [contributors](https://github.com/vishalzambre/ecwid_api/contributors) who participated in this project.
|
211
|
+
|
212
|
+
|
121
213
|
## License
|
122
214
|
|
123
215
|
The MIT License (MIT)
|
data/ecwid_api.gemspec
CHANGED
@@ -6,21 +6,23 @@ require 'ecwid_api/version'
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "ecwid_api"
|
8
8
|
spec.version = EcwidApi::VERSION
|
9
|
-
spec.authors = ["David Biehl"]
|
10
|
-
spec.email = ["
|
9
|
+
spec.authors = ["David Biehl", "Vishal Zambre"]
|
10
|
+
spec.email = ["v.zambre@gmail.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/vishalzambre/ecwid_api"
|
13
14
|
spec.license = "MIT"
|
15
|
+
spec.post_install_message = "Thanks for installing!"
|
14
16
|
|
15
17
|
spec.files = `git ls-files -z`.split("\x0")
|
16
18
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
19
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
20
|
spec.require_paths = ["lib"]
|
19
21
|
|
20
|
-
spec.add_development_dependency "bundler", "~> 1.5"
|
21
|
-
spec.add_development_dependency "rake"
|
22
|
-
spec.add_development_dependency "rspec", "~>
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.5", ">= 1.5"
|
23
|
+
spec.add_development_dependency "rake", "~> 0"
|
24
|
+
spec.add_development_dependency "rspec", "~> 3.5", ">= 3.5"
|
23
25
|
|
24
|
-
spec.add_dependency "faraday", "~> 0.9
|
25
|
-
spec.add_dependency "faraday_middleware", "~> 0.9
|
26
|
+
spec.add_dependency "faraday", "~> 0.9"
|
27
|
+
spec.add_dependency "faraday_middleware", "~> 0.9"
|
26
28
|
end
|
data/lib/ecwid_api.rb
CHANGED
@@ -1,39 +1,28 @@
|
|
1
1
|
require "ecwid_api/version"
|
2
2
|
require "ext/string"
|
3
|
+
require 'faraday'
|
4
|
+
require 'faraday_middleware'
|
5
|
+
|
6
|
+
require_relative "ecwid_api/error"
|
3
7
|
|
4
8
|
# Public: This is the main namespace for the EcwidApi. It can be used to store
|
5
9
|
# the default client.
|
6
10
|
#
|
7
11
|
module EcwidApi
|
8
|
-
|
9
|
-
|
10
|
-
|
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"
|
11
17
|
|
12
|
-
|
13
|
-
|
18
|
+
require_relative "ecwid_api/category"
|
19
|
+
require_relative "ecwid_api/customer"
|
20
|
+
require_relative "ecwid_api/order"
|
21
|
+
require_relative "ecwid_api/order_item"
|
22
|
+
require_relative "ecwid_api/person"
|
23
|
+
require_relative "ecwid_api/product_combination"
|
14
24
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
# To configure the default client, just pass a block.
|
19
|
-
#
|
20
|
-
# Examples
|
21
|
-
#
|
22
|
-
# EcwidApi.default_client do |config|
|
23
|
-
# config.store_id = '12345'
|
24
|
-
# config.order_secret_key = 'ORDER_SECRET_KEY'
|
25
|
-
# config.product_secret_key = 'PRODUCT_SECRET_KEY'
|
26
|
-
# end
|
27
|
-
#
|
28
|
-
# client = EcwidApi.default_client.store_id
|
29
|
-
# # => "12345"
|
30
|
-
#
|
31
|
-
# Returns an EcwidApi::Client, or null if one hasn't been configured
|
32
|
-
def default_client(&block)
|
33
|
-
if block_given?
|
34
|
-
@default_client = Client.new(&block)
|
35
|
-
end
|
36
|
-
@default_client
|
37
|
-
end
|
38
|
-
end
|
25
|
+
require_relative "ecwid_api/product"
|
26
|
+
require_relative "ecwid_api/product_type"
|
27
|
+
require_relative "ecwid_api/product_type_attribute"
|
39
28
|
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module EcwidApi
|
2
|
+
module Api
|
3
|
+
require_relative "api/base"
|
4
|
+
|
5
|
+
require_relative "api/categories"
|
6
|
+
require_relative "api/customers"
|
7
|
+
require_relative "api/orders"
|
8
|
+
require_relative "api/product_combinations"
|
9
|
+
require_relative "api/product_types"
|
10
|
+
require_relative "api/products"
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,18 @@
|
|
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
|
18
|
+
end
|
@@ -0,0 +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
|
+
find(response.body["id"])
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require_relative "../paged_ecwid_response"
|
2
|
+
|
3
|
+
module EcwidApi
|
4
|
+
module Api
|
5
|
+
class Customers < Base
|
6
|
+
# Public: Get all of the Customer objects for the Ecwid store
|
7
|
+
#
|
8
|
+
# Returns an Array of Customer objects
|
9
|
+
def all(params = {})
|
10
|
+
PagedEcwidResponse.new(client, "customers", params) do |customer_hash|
|
11
|
+
Customer.new(customer_hash, client: client)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
# Public: Finds a single customer by customer ID
|
16
|
+
#
|
17
|
+
# id - an Ecwid customer ID
|
18
|
+
#
|
19
|
+
# Returns a Customer object, or nil if one can't be found
|
20
|
+
def find(id)
|
21
|
+
response = client.get("customers/#{id}")
|
22
|
+
if response.success?
|
23
|
+
Customer.new(response.body, client: client)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
# Public: Creates a new Customer
|
28
|
+
#
|
29
|
+
# params - a Hash
|
30
|
+
#
|
31
|
+
# Raises an Error if there is a problem
|
32
|
+
#
|
33
|
+
# Returns a Customer object
|
34
|
+
def create(params)
|
35
|
+
response = client.post("customers", params)
|
36
|
+
find(response.body["id"])
|
37
|
+
end
|
38
|
+
|
39
|
+
# Public: Updates an existing Customer
|
40
|
+
#
|
41
|
+
# id - the Ecwid customer ID
|
42
|
+
# params - a Hash
|
43
|
+
#
|
44
|
+
# Raises an Error if there is a problem
|
45
|
+
#
|
46
|
+
# Returns a Customer object
|
47
|
+
def update(id, params)
|
48
|
+
client.put("customers/#{id}", params)
|
49
|
+
find(id)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|