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.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +0 -0
  3. data/.rspec +0 -0
  4. data/.travis.yml +0 -0
  5. data/Gemfile +0 -2
  6. data/LICENSE.txt +0 -0
  7. data/README.md +228 -228
  8. data/Rakefile +0 -0
  9. data/ecwid_api.gemspec +4 -4
  10. data/lib/ecwid_api.rb +25 -25
  11. data/lib/ecwid_api/api.rb +8 -30
  12. data/lib/ecwid_api/api/base.rb +17 -16
  13. data/lib/ecwid_api/api/categories.rb +55 -56
  14. data/lib/ecwid_api/api/orders.rb +36 -36
  15. data/lib/ecwid_api/api/product_combinations.rb +2 -5
  16. data/lib/ecwid_api/api/products.rb +61 -63
  17. data/lib/ecwid_api/category.rb +1 -7
  18. data/lib/ecwid_api/client.rb +99 -65
  19. data/lib/ecwid_api/entity.rb +4 -6
  20. data/lib/ecwid_api/error.rb +12 -12
  21. data/lib/ecwid_api/o_auth.rb +105 -105
  22. data/lib/ecwid_api/order.rb +0 -0
  23. data/lib/ecwid_api/order_item.rb +0 -0
  24. data/lib/ecwid_api/paged_ecwid_response.rb +0 -0
  25. data/lib/ecwid_api/paged_enumerator.rb +0 -0
  26. data/lib/ecwid_api/person.rb +0 -0
  27. data/lib/ecwid_api/product.rb +3 -15
  28. data/lib/ecwid_api/product_combination.rb +1 -5
  29. data/lib/ecwid_api/version.rb +1 -1
  30. data/lib/ext/string.rb +12 -12
  31. data/spec/api/categories_spec.rb +30 -30
  32. data/spec/api/orders_spec.rb +29 -29
  33. data/spec/api/products_spec.rb +0 -0
  34. data/spec/category_spec.rb +33 -33
  35. data/spec/client_spec.rb +20 -20
  36. data/spec/entity_spec.rb +0 -0
  37. data/spec/fixtures/categories.json +0 -0
  38. data/spec/fixtures/category.json +0 -0
  39. data/spec/fixtures/order.json +0 -0
  40. data/spec/fixtures/orders.json +0 -0
  41. data/spec/fixtures/products.json +0 -0
  42. data/spec/helpers/client.rb +31 -31
  43. data/spec/oauth_spec.rb +39 -39
  44. data/spec/order_item_spec.rb +11 -11
  45. data/spec/order_spec.rb +0 -0
  46. data/spec/paged_enumerator_spec.rb +0 -0
  47. data/spec/spec_helper.rb +24 -24
  48. metadata +26 -34
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 115d13f16d0747c45335873d314215544f80bd4c
4
- data.tar.gz: c5e1874c0963ec608800587e42a9a19d2d648949
3
+ metadata.gz: bbabb8c01870c216ea0e6c14105eb6a85456453b
4
+ data.tar.gz: 523b87bef0bb0a681748f2ef0c729d09c6ff5527
5
5
  SHA512:
6
- metadata.gz: 3d057bae684a112491485aa7338c54680ed9b961a069b4f28d7ca58d325219218e8ca0c13eb971b73565a5eb803913186ef430e4ef26712bd73d9a74fb25e723
7
- data.tar.gz: e769e8ca8535b17e3f15b1df4ce239a01d2c7fc2acc8b193d177f98910c7f6d6d21ba0a0bc06e65a88e36b7845a1e9ac4f9daea613a56d34c1123c08a1bf3de4
6
+ metadata.gz: 401646199cbc23ea644b7fee9693da8b418727a0a0158c19cf4c5609e5da2ac554b5cc321b48a617825c32485214b4c9fb281c2958059b57dfa7a44a81f96412
7
+ data.tar.gz: 10eb888f3feb60cd4e7526b353d665f4dfbc8dfa8f7de589ca585ada79e06165c3a523b87d7accd650a8decc1363e0ee266a7bbea4903d0bd038fa0e544fe9c4
data/.gitignore CHANGED
File without changes
data/.rspec CHANGED
File without changes
File without changes
data/Gemfile CHANGED
@@ -2,5 +2,3 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in ecwid_api.gemspec
4
4
  gemspec
5
-
6
- # gem "faraday", git: "https://github.com/davidbiehl/faraday.git", branch: "preserve_raw"
File without changes
data/README.md CHANGED
@@ -1,228 +1,228 @@
1
- # EcwidApi
2
-
3
- A gem to interface with the Ecwid REST APIs.
4
-
5
- [![Code Climate](https://codeclimate.com/github/davidbiehl/ecwid_api.png)](https://codeclimate.com/github/davidbiehl/ecwid_api)
6
- [![Build Status](https://travis-ci.org/davidbiehl/ecwid_api.svg?branch=master)](https://travis-ci.org/davidbiehl/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/davidbiehl/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.
19
-
20
- ## Installation
21
-
22
- Add this line to your application's Gemfile:
23
-
24
- gem 'ecwid_api'
25
-
26
- And then execute:
27
-
28
- $ bundle
29
-
30
- Or install it yourself as:
31
-
32
- $ gem install ecwid_api
33
-
34
- ## Usage
35
-
36
- ### Get Authorized with OAuth2
37
-
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:
42
-
43
- @auth = EcwidApi::OAuth.new do |config|
44
- config.client_id = "the client id"
45
- config.client_secret = "the client secret (shh...)"
46
- config.request_uri = "https://example.com/oauth"
47
- config.scope = "the_permissions_i_want"
48
- end
49
-
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:
52
-
53
- link_to @auth.oauth_url, "Click here to Authorize this Groovy App!"
54
-
55
- When the user authorizes your app, they will be redirected to the `request_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`.
59
-
60
- # https://example.com/oauth?code=super_secret_temporary_code
61
-
62
- token = @auth.access_token(params[:code])
63
-
64
- token.access_token # the token for the Client
65
- token.store_id # the store_id for the Client
66
-
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
77
-
78
- ### Entities
79
-
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:
86
-
87
- cat = client.categories.find(123)
88
- # An example response from the API
89
- # {
90
- # "id": 123,
91
- # "parentId": 456,
92
- # "name": "Special Category"
93
- # }
94
-
95
- cat[:id] # Access with a Symbol
96
- # => 123
97
-
98
- cat["parentId"] # Access with a String (case sensitive)
99
- # => 456
100
-
101
- cat.parent_id # Access with a snake_case method
102
- # => 456
103
-
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
125
- parent category, if there is one.
126
-
127
- cat.parent
128
- # Returns the parent `EcwidApi::Category`
129
-
130
- cat.sub_categories
131
- # Returns an Array of `EcwidApi::Category`
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({date: "1982-05-17"})
144
- # Paremters can be passed as a Hash.
145
- # See http://kb.ecwid.com/w/page/43697230/Order%20API#Parameters for
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
-
172
- ### Making Ad-Hoc Requests with the Client
173
-
174
- To make a request, simply call the `#get` method on the client passing in the
175
- relative path and any parameters it requires.
176
- For example, to get some categories:
177
-
178
- # GET https://app.ecwid.com/api/v3/[STORE-ID]/categories?parent=1
179
-
180
- client.get("categories", parent: 1)
181
-
182
- # => #<Faraday::Response>
183
-
184
- The `Client` is responsible for making raw requests, which is why it returns
185
- a `Faraday::Response`. The JSON parsing middleware is also active on the Faraday
186
- connection, so calling `Faraday::Response#body` will return a Hash of the parsed
187
- JSON.
188
-
189
- ### Ecwid API Documentation
190
-
191
- The [Ecwid API documentation](http://api.ecwid.com)
192
- should give you a good idea of what is possible to retreive. It also defines
193
- which properties are available on each of the entities it provies. Please note
194
- that resources requiring the secret keys will be inaccessible until we implement
195
- that feature.
196
-
197
- ## Contributing
198
-
199
- 1. Fork it ( http://github.com/davidbiehl/ecwid_api/fork )
200
- 2. Create your feature branch (`git checkout -b my-new-feature`)
201
- 3. Commit your changes (`git commit -am 'Add some feature'`)
202
- 4. Push to the branch (`git push origin my-new-feature`)
203
- 5. Create new Pull Request
204
-
205
- ## License
206
-
207
- The MIT License (MIT)
208
-
209
- Copyright (c) 2014 David Biehl
210
-
211
- Permission is hereby granted, free of charge, to any person obtaining a copy
212
- of this software and associated documentation files (the "Software"), to deal
213
- in the Software without restriction, including without limitation the rights
214
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
215
- copies of the Software, and to permit persons to whom the Software is
216
- furnished to do so, subject to the following conditions:
217
-
218
- The above copyright notice and this permission notice shall be included in
219
- all copies or substantial portions of the Software.
220
-
221
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
222
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
223
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
224
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
225
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
226
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
227
- THE SOFTWARE.
228
-
1
+ # EcwidApi
2
+
3
+ A gem to interface with the Ecwid REST APIs.
4
+
5
+ [![Code Climate](https://codeclimate.com/github/davidbiehl/ecwid_api.png)](https://codeclimate.com/github/davidbiehl/ecwid_api)
6
+ [![Build Status](https://travis-ci.org/davidbiehl/ecwid_api.svg?branch=master)](https://travis-ci.org/davidbiehl/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/davidbiehl/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.
19
+
20
+ ## Installation
21
+
22
+ Add this line to your application's Gemfile:
23
+
24
+ gem 'ecwid_api'
25
+
26
+ And then execute:
27
+
28
+ $ bundle
29
+
30
+ Or install it yourself as:
31
+
32
+ $ gem install ecwid_api
33
+
34
+ ## Usage
35
+
36
+ ### Get Authorized with OAuth2
37
+
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:
42
+
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"
48
+ end
49
+
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:
52
+
53
+ link_to @auth.oauth_url, "Click here to Authorize this Groovy App!"
54
+
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`.
59
+
60
+ # https://example.com/oauth?code=super_secret_temporary_code
61
+
62
+ token = @auth.access_token(params[:code])
63
+
64
+ token.access_token # the token for the Client
65
+ token.store_id # the store_id for the Client
66
+
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
77
+
78
+ ### Entities
79
+
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:
86
+
87
+ cat = client.categories.find(123)
88
+ # An example response from the API
89
+ # {
90
+ # "id": 123,
91
+ # "parentId": 456,
92
+ # "name": "Special Category"
93
+ # }
94
+
95
+ cat[:id] # Access with a Symbol
96
+ # => 123
97
+
98
+ cat["parentId"] # Access with a String (case sensitive)
99
+ # => 456
100
+
101
+ cat.parent_id # Access with a snake_case method
102
+ # => 456
103
+
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
125
+ parent category, if there is one.
126
+
127
+ cat.parent
128
+ # Returns the parent `EcwidApi::Category`
129
+
130
+ cat.sub_categories
131
+ # Returns an Array of `EcwidApi::Category`
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
+
172
+ ### Making Ad-Hoc Requests with the Client
173
+
174
+ To make a request, simply call the `#get` method on the client passing in the
175
+ relative path and any parameters it requires.
176
+ For example, to get some categories:
177
+
178
+ # GET https://app.ecwid.com/api/v3/[STORE-ID]/categories?parent=1
179
+
180
+ client.get("categories", parent: 1)
181
+
182
+ # => #<Faraday::Response>
183
+
184
+ The `Client` is responsible for making raw requests, which is why it returns
185
+ a `Faraday::Response`. The JSON parsing middleware is also active on the Faraday
186
+ connection, so calling `Faraday::Response#body` will return a Hash of the parsed
187
+ JSON.
188
+
189
+ ### Ecwid API Documentation
190
+
191
+ The [Ecwid API documentation](http://api.ecwid.com)
192
+ should give you a good idea of what is possible to retreive. It also defines
193
+ which properties are available on each of the entities it provies. Please note
194
+ that resources requiring the secret keys will be inaccessible until we implement
195
+ that feature.
196
+
197
+ ## Contributing
198
+
199
+ 1. Fork it ( http://github.com/davidbiehl/ecwid_api/fork )
200
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
201
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
202
+ 4. Push to the branch (`git push origin my-new-feature`)
203
+ 5. Create new Pull Request
204
+
205
+ ## License
206
+
207
+ The MIT License (MIT)
208
+
209
+ Copyright (c) 2014 David Biehl
210
+
211
+ Permission is hereby granted, free of charge, to any person obtaining a copy
212
+ of this software and associated documentation files (the "Software"), to deal
213
+ in the Software without restriction, including without limitation the rights
214
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
215
+ copies of the Software, and to permit persons to whom the Software is
216
+ furnished to do so, subject to the following conditions:
217
+
218
+ The above copyright notice and this permission notice shall be included in
219
+ all copies or substantial portions of the Software.
220
+
221
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
222
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
223
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
224
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
225
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
226
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
227
+ THE SOFTWARE.
228
+