spree-api-client 0.0.1
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.
- data/.gitignore +17 -0
- data/.travis.yml +9 -0
- data/CONTRIBUTING.md +8 -0
- data/Gemfile +3 -0
- data/LICENSE +22 -0
- data/README.md +61 -0
- data/Rakefile +7 -0
- data/lib/spree-api-client.rb +49 -0
- data/lib/spree-api-client/addresses.rb +15 -0
- data/lib/spree-api-client/connection.rb +30 -0
- data/lib/spree-api-client/countries.rb +15 -0
- data/lib/spree-api-client/line_items.rb +19 -0
- data/lib/spree-api-client/orders.rb +31 -0
- data/lib/spree-api-client/payments.rb +43 -0
- data/lib/spree-api-client/products.rb +31 -0
- data/lib/spree-api-client/properties.rb +31 -0
- data/lib/spree-api-client/request.rb +49 -0
- data/lib/spree-api-client/return_authorizations.rb +31 -0
- data/lib/spree-api-client/shipments.rb +15 -0
- data/lib/spree-api-client/taxonomies.rb +31 -0
- data/lib/spree-api-client/taxons.rb +27 -0
- data/lib/spree-api-client/variants.rb +31 -0
- data/lib/spree-api-client/version.rb +7 -0
- data/lib/spree-api-client/zones.rb +31 -0
- data/spec/addresses_spec.rb +11 -0
- data/spec/client_spec.rb +31 -0
- data/spec/countries_spec.rb +11 -0
- data/spec/orders_spec.rb +11 -0
- data/spec/payments_spec.rb +11 -0
- data/spec/products_spec.rb +11 -0
- data/spec/properties_spec.rb +11 -0
- data/spec/return_authorizations_spec.rb +11 -0
- data/spec/shipments_spec.rb +11 -0
- data/spec/spec_helper.rb +5 -0
- data/spec/taxonomies_spec.rb +11 -0
- data/spec/taxons_spec.rb +11 -0
- data/spec/variants_spec.rb +11 -0
- data/spec/zones_spec.rb +11 -0
- data/spree-api-client.gemspec +27 -0
- metadata +164 -0
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/CONTRIBUTING.md
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
## Contributing
|
2
|
+
* Fork the project.
|
3
|
+
* Make your feature addition or bug fix.
|
4
|
+
* Add tests for it. This is important so I don't break it in a
|
5
|
+
future version unintentionally.
|
6
|
+
* Commit, do not mess with rakefile, version, or history.
|
7
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
8
|
+
* Send a pull request. Bonus points for topic branches.
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Andrew Nesbitt
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
# Spree::API::Client
|
2
|
+
|
3
|
+
[](https://travis-ci.org/andrew/spree-api-client)
|
4
|
+
|
5
|
+
** Beware: very alpha and untested **
|
6
|
+
|
7
|
+
A rubygem for interacting with the Spree API: http://api.spreecommerce.com/v1/
|
8
|
+
|
9
|
+
Heavily inspired by the excellent Octokit: https://github.com/pengwynn/octokit
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
Add this line to your application's Gemfile:
|
14
|
+
|
15
|
+
gem 'spree-api-client'
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
$ bundle
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
$ gem install spree-api-client
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
client = Spree::API::Client.new('http://example/api', 'yourapitokenstring')
|
28
|
+
products = client.products
|
29
|
+
|
30
|
+
## TODO
|
31
|
+
|
32
|
+
* More tests
|
33
|
+
* Mock web requests in tests
|
34
|
+
* documentation
|
35
|
+
* rdoc generation
|
36
|
+
* release to rubygems.org
|
37
|
+
* gemnasium
|
38
|
+
* code climate
|
39
|
+
* Error handling
|
40
|
+
* Autopagination?
|
41
|
+
|
42
|
+
## Development
|
43
|
+
|
44
|
+
Source hosted at [GitHub](http://github.com/andrew/spree-api-client).
|
45
|
+
Report Issues/Feature requests on [GitHub Issues](http://github.com/andrew/spree-api-client/issues).
|
46
|
+
|
47
|
+
Tests can be ran with `rake spec`
|
48
|
+
|
49
|
+
### Note on Patches/Pull Requests
|
50
|
+
|
51
|
+
* Fork the project.
|
52
|
+
* Make your feature addition or bug fix.
|
53
|
+
* Add tests for it. This is important so I don't break it in a
|
54
|
+
future version unintentionally.
|
55
|
+
* Commit, do not mess with rakefile, version, or history.
|
56
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
57
|
+
* Send me a pull request. Bonus points for topic branches.
|
58
|
+
|
59
|
+
## Copyright
|
60
|
+
|
61
|
+
Copyright (c) 2012 Andrew Nesbitt. See [LICENSE](https://github.com/andrew/spree-api-client/blob/master/LICENSE) for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'faraday_middleware'
|
2
|
+
require "spree-api-client/version"
|
3
|
+
|
4
|
+
require 'spree-api-client/connection'
|
5
|
+
require 'spree-api-client/request'
|
6
|
+
|
7
|
+
require 'spree-api-client/products'
|
8
|
+
require 'spree-api-client/variants'
|
9
|
+
require 'spree-api-client/orders'
|
10
|
+
require 'spree-api-client/taxonomies'
|
11
|
+
require 'spree-api-client/addresses'
|
12
|
+
require 'spree-api-client/countries'
|
13
|
+
require 'spree-api-client/zones'
|
14
|
+
require 'spree-api-client/properties'
|
15
|
+
require 'spree-api-client/line_items'
|
16
|
+
require 'spree-api-client/return_authorizations'
|
17
|
+
require 'spree-api-client/taxons'
|
18
|
+
require 'spree-api-client/payments'
|
19
|
+
require 'spree-api-client/shipments'
|
20
|
+
|
21
|
+
module Spree
|
22
|
+
module API
|
23
|
+
class Client
|
24
|
+
include Spree::API::Client::Connection
|
25
|
+
include Spree::API::Client::Request
|
26
|
+
|
27
|
+
include Spree::API::Client::Products
|
28
|
+
include Spree::API::Client::Variants
|
29
|
+
include Spree::API::Client::Orders
|
30
|
+
include Spree::API::Client::Taxonomies
|
31
|
+
include Spree::API::Client::Addresses
|
32
|
+
include Spree::API::Client::Countries
|
33
|
+
include Spree::API::Client::Zones
|
34
|
+
include Spree::API::Client::Properties
|
35
|
+
include Spree::API::Client::LineItems
|
36
|
+
include Spree::API::Client::ReturnAuthorizations
|
37
|
+
include Spree::API::Client::Taxons
|
38
|
+
include Spree::API::Client::Payments
|
39
|
+
include Spree::API::Client::Shipments
|
40
|
+
|
41
|
+
attr_accessor :api_endpoint, :api_token, :per_page
|
42
|
+
def initialize(api_endpoint, api_token, options={})
|
43
|
+
@api_endpoint = api_endpoint
|
44
|
+
@api_token = api_token
|
45
|
+
@per_page = options.fetch(:per_page, 30)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Spree
|
2
|
+
module API
|
3
|
+
class Client
|
4
|
+
module Connection
|
5
|
+
def connection(options={})
|
6
|
+
options = {
|
7
|
+
:authenticate => true,
|
8
|
+
:force_urlencoded => false,
|
9
|
+
:raw => false,
|
10
|
+
:ssl => { :verify => false },
|
11
|
+
:url => 'http://localhost:4000/store/api', #api_endpoint
|
12
|
+
:path_prefix => '/api'
|
13
|
+
}.merge(options)
|
14
|
+
|
15
|
+
connection = Faraday.new(options) do |builder|
|
16
|
+
builder.request :json
|
17
|
+
|
18
|
+
builder.use FaradayMiddleware::FollowRedirects
|
19
|
+
builder.use FaradayMiddleware::Mashify
|
20
|
+
|
21
|
+
builder.use FaradayMiddleware::ParseJson, :content_type => /\bjson$/
|
22
|
+
|
23
|
+
builder.adapter Faraday.default_adapter
|
24
|
+
end
|
25
|
+
connection
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Spree
|
2
|
+
module API
|
3
|
+
class Client
|
4
|
+
module LineItems
|
5
|
+
def create_line_item(order_number, options={})
|
6
|
+
post("orders/#{order_number}/line_items/", options)
|
7
|
+
end
|
8
|
+
|
9
|
+
def update_line_item(order_number, line_item_id, options={})
|
10
|
+
put("orders/#{order_number}/line_items/#{line_item_id}", options)
|
11
|
+
end
|
12
|
+
|
13
|
+
def delete_line_item(order_number, line_item_id, options={})
|
14
|
+
delete("orders/#{order_number}/line_items/#{line_item_id}", options)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Spree
|
2
|
+
module API
|
3
|
+
class Client
|
4
|
+
module Orders
|
5
|
+
def orders(options={})
|
6
|
+
get('orders', options)['orders']
|
7
|
+
end
|
8
|
+
|
9
|
+
def order(order_number, options={})
|
10
|
+
get("orders/#{order_number}", options)
|
11
|
+
end
|
12
|
+
|
13
|
+
def create_order(options={})
|
14
|
+
post("orders", options)
|
15
|
+
end
|
16
|
+
|
17
|
+
def update_order_address(order_number, options={})
|
18
|
+
put("orders/#{order_number}/address", options)
|
19
|
+
end
|
20
|
+
|
21
|
+
def set_order_shipping_method(order_number, shipping_method_id, options={})
|
22
|
+
put("orders/#{order_number}", options.merge(:shipping_method_id => shipping_method_id))
|
23
|
+
end
|
24
|
+
|
25
|
+
def empty_order(order_number, options={})
|
26
|
+
put("orders/#{order_number}/empty", options)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module Spree
|
2
|
+
module API
|
3
|
+
class Client
|
4
|
+
module Payments
|
5
|
+
def payments(order_number, options={})
|
6
|
+
get("orders/#{order_number}/payments", options)['payments']
|
7
|
+
end
|
8
|
+
|
9
|
+
def payment(order_number, payment_id, options={})
|
10
|
+
get("orders/#{order_number}/payments/#{payment_id}", options)
|
11
|
+
end
|
12
|
+
|
13
|
+
def new_payment(order_number, options={})
|
14
|
+
get("orders/#{order_number}/payments/new", options)
|
15
|
+
end
|
16
|
+
|
17
|
+
def create_payment(order_number, options={})
|
18
|
+
post("orders/#{order_number}/payments/", options)
|
19
|
+
end
|
20
|
+
|
21
|
+
def authorize_payment(order_number, payment_id, options={})
|
22
|
+
put("orders/#{order_number}/payments/#{payment_id}/authorize", options)
|
23
|
+
end
|
24
|
+
|
25
|
+
def capture_payment(order_number, payment_id, options={})
|
26
|
+
put("orders/#{order_number}/payments/#{payment_id}/capture", options)
|
27
|
+
end
|
28
|
+
|
29
|
+
def purchase_payment(order_number, payment_id, options={})
|
30
|
+
put("orders/#{order_number}/payments/#{payment_id}/purchase", options)
|
31
|
+
end
|
32
|
+
|
33
|
+
def void_payment(order_number, payment_id, options={})
|
34
|
+
put("orders/#{order_number}/payments/#{payment_id}.void", options)
|
35
|
+
end
|
36
|
+
|
37
|
+
def credit_payment(order_number, payment_id, options={})
|
38
|
+
put("orders/#{order_number}/payments/#{payment_id}/credit", options)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Spree
|
2
|
+
module API
|
3
|
+
class Client
|
4
|
+
module Products
|
5
|
+
def products(options={})
|
6
|
+
get('products', options)['products']
|
7
|
+
end
|
8
|
+
|
9
|
+
def product(permalink_or_id, options={})
|
10
|
+
get("products/#{permalink_or_id}", options)
|
11
|
+
end
|
12
|
+
|
13
|
+
def new_product(options={})
|
14
|
+
get("products/#{permalink_or_id}/new", options)
|
15
|
+
end
|
16
|
+
|
17
|
+
def create_product(options={})
|
18
|
+
post("products", options)
|
19
|
+
end
|
20
|
+
|
21
|
+
def update_product(permalink_or_id, options={})
|
22
|
+
put("products/#{permalink_or_id}", options)
|
23
|
+
end
|
24
|
+
|
25
|
+
def delete_product(permalink_or_id, options={})
|
26
|
+
delete("products/#{permalink_or_id}", options)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Spree
|
2
|
+
module API
|
3
|
+
class Client
|
4
|
+
module Properties
|
5
|
+
def properties(product_id, options={})
|
6
|
+
get("products/#{product_id}/product_properties", options)['product_properties']
|
7
|
+
end
|
8
|
+
|
9
|
+
def property(product_id, property_id, options={})
|
10
|
+
get("products/#{product_id}/product_properties/#{property_id}", options)
|
11
|
+
end
|
12
|
+
|
13
|
+
def new_property(product_id, options={})
|
14
|
+
get("products/#{product_id}/product_properties/new", options)
|
15
|
+
end
|
16
|
+
|
17
|
+
def create_property(product_id, options={})
|
18
|
+
post("products/#{product_id}/product_properties/", options)
|
19
|
+
end
|
20
|
+
|
21
|
+
def update_property(product_id, property_id, options={})
|
22
|
+
put("products/#{product_id}/product_properties/#{property_id}", options)
|
23
|
+
end
|
24
|
+
|
25
|
+
def delete_property(product_id, property_id, options={})
|
26
|
+
delete("products/#{product_id}/product_properties/#{property_id}", options)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module Spree
|
2
|
+
module API
|
3
|
+
class Client
|
4
|
+
module Request
|
5
|
+
def request(method, path, options = {})
|
6
|
+
token = options.delete(:api_token) || api_token
|
7
|
+
|
8
|
+
response = connection.send(method) do |request|
|
9
|
+
|
10
|
+
request.headers['Accept'] = options.delete(:accept) || 'application/json'
|
11
|
+
|
12
|
+
if token
|
13
|
+
request.headers['X-Spree-Token'] = token
|
14
|
+
end
|
15
|
+
|
16
|
+
case method
|
17
|
+
when :get
|
18
|
+
options.merge!(:per_page => per_page) if per_page
|
19
|
+
request.url(path, options)
|
20
|
+
when :delete, :head
|
21
|
+
request.url(path, options)
|
22
|
+
when :patch, :post, :put
|
23
|
+
request.path = path
|
24
|
+
request.body = MultiJson.dump(options) unless options.empty?
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
response
|
29
|
+
end
|
30
|
+
|
31
|
+
def get(path, options = {})
|
32
|
+
request(:get, path, options = {}).body
|
33
|
+
end
|
34
|
+
|
35
|
+
def post(path, options={})
|
36
|
+
request(:post, path, options).body
|
37
|
+
end
|
38
|
+
|
39
|
+
def put(path, options={})
|
40
|
+
request(:put, path, options).body
|
41
|
+
end
|
42
|
+
|
43
|
+
def delete(path, options={})
|
44
|
+
request(:delete, path, options).body
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Spree
|
2
|
+
module API
|
3
|
+
class Client
|
4
|
+
module ReturnAuthorizations
|
5
|
+
def return_authorizations(order_number, options={})
|
6
|
+
get("orders/#{order_number}/return_authorizations", options)['return_authorizations']
|
7
|
+
end
|
8
|
+
|
9
|
+
def return_authorization(order_number, return_authorization_id, options={})
|
10
|
+
get("orders/#{order_number}/return_authorizations/#{return_authorization_id}", options)
|
11
|
+
end
|
12
|
+
|
13
|
+
def new_return_authorization(order_number, options={})
|
14
|
+
get("orders/#{order_number}/return_authorizations/new", options)
|
15
|
+
end
|
16
|
+
|
17
|
+
def create_return_authorization(order_number, options={})
|
18
|
+
post("orders/#{order_number}/return_authorizations/", options)
|
19
|
+
end
|
20
|
+
|
21
|
+
def update_return_authorization(product_id, return_authorization_id, options={})
|
22
|
+
put("orders/#{order_number}/return_authorizations/#{return_authorization_id}", options)
|
23
|
+
end
|
24
|
+
|
25
|
+
def delete_return_authorization(product_id, return_authorization_id, options={})
|
26
|
+
delete("orders/#{order_number}/return_authorizations/#{return_authorization_id}", options)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Spree
|
2
|
+
module API
|
3
|
+
class Client
|
4
|
+
module Shipments
|
5
|
+
def shipment_ready(order_number, shipment_id, options={})
|
6
|
+
put("orders/#{order_number}/shipments/#{shipment_id}/ready", options)
|
7
|
+
end
|
8
|
+
|
9
|
+
def ship_shipment(order_number, shipment_id, options={})
|
10
|
+
put("orders/#{order_number}/shipments/#{shipment_id}/ship", options)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Spree
|
2
|
+
module API
|
3
|
+
class Client
|
4
|
+
module Taxonomies
|
5
|
+
def taxonomies(options={})
|
6
|
+
get('taxonomies', options)['taxonomies']
|
7
|
+
end
|
8
|
+
|
9
|
+
def taxonomy(id, options={})
|
10
|
+
get("taxonomies/#{id}", options)
|
11
|
+
end
|
12
|
+
|
13
|
+
def new_taxonomy(options={})
|
14
|
+
get("taxonomies/#{id}/new", options)
|
15
|
+
end
|
16
|
+
|
17
|
+
def create_taxonomy(options={})
|
18
|
+
post("taxonomies", options)
|
19
|
+
end
|
20
|
+
|
21
|
+
def update_taxonomy(id, options={})
|
22
|
+
put("taxonomies/#{id}", options)
|
23
|
+
end
|
24
|
+
|
25
|
+
def delete_taxonomy(id, options={})
|
26
|
+
delete("taxonomies/#{id}", options)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Spree
|
2
|
+
module API
|
3
|
+
class Client
|
4
|
+
module Taxons
|
5
|
+
def taxons(taxonomy_id, options={})
|
6
|
+
get("taxonomies/#{taxonomy_id}/taxons", options)
|
7
|
+
end
|
8
|
+
|
9
|
+
def taxon(taxonomy_id, taxon_id, options={})
|
10
|
+
get("taxonomies/#{taxonomy_id}/taxons/#{taxon_id}", options)
|
11
|
+
end
|
12
|
+
|
13
|
+
def create_taxon(taxonomy_id, options={})
|
14
|
+
post("taxonomies/#{taxonomy_id}/taxons/", options)
|
15
|
+
end
|
16
|
+
|
17
|
+
def update_taxon(taxonomy_id, taxon_id, options={})
|
18
|
+
put("taxonomies/#{taxonomy_id}/taxons/#{taxon_id}", options)
|
19
|
+
end
|
20
|
+
|
21
|
+
def delete_taxon(taxonomy_id, taxon_id, options={})
|
22
|
+
delete("taxonomies/#{taxonomy_id}/taxons/#{taxon_id}", options)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Spree
|
2
|
+
module API
|
3
|
+
class Client
|
4
|
+
module Variants
|
5
|
+
def variants(product_id, options={})
|
6
|
+
get("products/#{product_id}/variants", options)['variants']
|
7
|
+
end
|
8
|
+
|
9
|
+
def variant(product_id, variant_id, options={})
|
10
|
+
get("products/#{product_id}/variants/#{variant_id}", options)
|
11
|
+
end
|
12
|
+
|
13
|
+
def new_variant(product_id, options={})
|
14
|
+
get("products/#{product_id}/variants/new", options)
|
15
|
+
end
|
16
|
+
|
17
|
+
def create_variant(product_id, options={})
|
18
|
+
post("products/#{product_id}/variants/", options)
|
19
|
+
end
|
20
|
+
|
21
|
+
def update_variant(product_id, variant_id, options={})
|
22
|
+
put("products/#{product_id}/variants/#{variant_id}", options)
|
23
|
+
end
|
24
|
+
|
25
|
+
def delete_variant(product_id, variant_id, options={})
|
26
|
+
delete("products/#{product_id}/variants/#{variant_id}", options)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Spree
|
2
|
+
module API
|
3
|
+
class Client
|
4
|
+
module Zones
|
5
|
+
def zones(options={})
|
6
|
+
get('zones', options)['zones']
|
7
|
+
end
|
8
|
+
|
9
|
+
def zone(id, options={})
|
10
|
+
get("zones/#{id}", options)
|
11
|
+
end
|
12
|
+
|
13
|
+
def new_zone(options={})
|
14
|
+
get("zones/#{id}/new", options)
|
15
|
+
end
|
16
|
+
|
17
|
+
def create_zone(options={})
|
18
|
+
post("zones", options)
|
19
|
+
end
|
20
|
+
|
21
|
+
def update_zone(id, options={})
|
22
|
+
put("zones/#{id}", options)
|
23
|
+
end
|
24
|
+
|
25
|
+
def delete_zone(id, options={})
|
26
|
+
delete("zones/#{id}", options)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Spree::API::Client::Addresses do
|
4
|
+
describe 'address' do
|
5
|
+
it 'should load address' do
|
6
|
+
client = Spree::API::Client.new('http://localhost:4000/store/api', 'b56019f04b61a50553ee323f5ab68c6b435871971e79c987')
|
7
|
+
address = client.address(1)
|
8
|
+
address.should be_a(Hashie::Mash)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
data/spec/client_spec.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Spree::API::Client do
|
4
|
+
describe ".new" do
|
5
|
+
it "is a Spree::API::Client" do
|
6
|
+
Spree::API::Client.new('http://example.com/api', 'randomtokenstring').should be_a(Spree::API::Client)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
describe 'api_endpoint' do
|
11
|
+
it 'should be stored' do
|
12
|
+
client = Spree::API::Client.new('http://example.com/api', 'randomtokenstring')
|
13
|
+
client.api_endpoint.should eql('http://example.com/api')
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe 'api_token' do
|
18
|
+
it 'should be stored' do
|
19
|
+
client = Spree::API::Client.new('http://example.com/api', 'randomtokenstring')
|
20
|
+
client.api_token.should eql('randomtokenstring')
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe 'request' do
|
25
|
+
it 'should load stuff from the api' do
|
26
|
+
client = Spree::API::Client.new('http://localhost:4000/store/api', 'randomtokenstring')
|
27
|
+
response = client.request(:get, 'products')
|
28
|
+
response.should be_a(Faraday::Response)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Spree::API::Client::Countries do
|
4
|
+
describe 'countries' do
|
5
|
+
it 'should load countries' do
|
6
|
+
client = Spree::API::Client.new('http://localhost:4000/store/api', 'b56019f04b61a50553ee323f5ab68c6b435871971e79c987')
|
7
|
+
countries = client.countries
|
8
|
+
countries.should be_a(Array)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
data/spec/orders_spec.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Spree::API::Client::Orders do
|
4
|
+
describe 'orders' do
|
5
|
+
it 'should load orders' do
|
6
|
+
client = Spree::API::Client.new('http://localhost:4000/store/api', 'b56019f04b61a50553ee323f5ab68c6b435871971e79c987')
|
7
|
+
orders = client.orders
|
8
|
+
orders.should be_a(Array)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Spree::API::Client::Payments do
|
4
|
+
describe 'payments' do
|
5
|
+
it 'should load payments' do
|
6
|
+
client = Spree::API::Client.new('http://localhost:4000/store/api', 'b56019f04b61a50553ee323f5ab68c6b435871971e79c987')
|
7
|
+
payments = client.payments('R610162112')
|
8
|
+
payments.should be_a(Array)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Spree::API::Client::Products do
|
4
|
+
describe 'products' do
|
5
|
+
it 'should load products' do
|
6
|
+
client = Spree::API::Client.new('http://localhost:4000/store/api', 'b56019f04b61a50553ee323f5ab68c6b435871971e79c987')
|
7
|
+
products = client.products
|
8
|
+
products.should be_a(Array)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Spree::API::Client::Properties do
|
4
|
+
describe 'properties' do
|
5
|
+
it 'should load properties' do
|
6
|
+
client = Spree::API::Client.new('http://localhost:4000/store/api', 'b56019f04b61a50553ee323f5ab68c6b435871971e79c987')
|
7
|
+
properties = client.properties(1)
|
8
|
+
properties.should be_a(Array)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Spree::API::Client::ReturnAuthorizations do
|
4
|
+
describe 'return_authorizations' do
|
5
|
+
it 'should load return_authorizations' do
|
6
|
+
client = Spree::API::Client.new('http://localhost:4000/store/api', 'b56019f04b61a50553ee323f5ab68c6b435871971e79c987')
|
7
|
+
return_authorizations = client.return_authorizations('R781501551')
|
8
|
+
return_authorizations.should be_a(Array)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Spree::API::Client::Shipments do
|
4
|
+
describe 'shipment_ready' do
|
5
|
+
it 'should set a shipment to ready' do
|
6
|
+
client = Spree::API::Client.new('http://localhost:4000/store/api', 'b56019f04b61a50553ee323f5ab68c6b435871971e79c987')
|
7
|
+
shipment = client.shipment_ready(1, 1)
|
8
|
+
shipment.should be_a(Hashie::Mash)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Spree::API::Client::Taxonomies do
|
4
|
+
describe 'taxonomies' do
|
5
|
+
it 'should load taxonomies' do
|
6
|
+
client = Spree::API::Client.new('http://localhost:4000/store/api', 'b56019f04b61a50553ee323f5ab68c6b435871971e79c987')
|
7
|
+
taxonomies = client.taxonomies
|
8
|
+
taxonomies.should be_a(Array)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
data/spec/taxons_spec.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Spree::API::Client::Taxons do
|
4
|
+
describe 'taxons' do
|
5
|
+
it 'should load taxons' do
|
6
|
+
client = Spree::API::Client.new('http://localhost:4000/store/api', 'b56019f04b61a50553ee323f5ab68c6b435871971e79c987')
|
7
|
+
taxons = client.taxons(1)
|
8
|
+
taxons.should be_a(Array)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Spree::API::Client::Variants do
|
4
|
+
describe 'variants' do
|
5
|
+
it 'should load variants' do
|
6
|
+
client = Spree::API::Client.new('http://localhost:4000/store/api', 'b56019f04b61a50553ee323f5ab68c6b435871971e79c987')
|
7
|
+
variants = client.variants(1)
|
8
|
+
variants.should be_a(Array)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
data/spec/zones_spec.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Spree::API::Client::Zones do
|
4
|
+
describe 'zones' do
|
5
|
+
it 'should load zones' do
|
6
|
+
client = Spree::API::Client.new('http://localhost:4000/store/api', 'b56019f04b61a50553ee323f5ab68c6b435871971e79c987')
|
7
|
+
zones = client.zones
|
8
|
+
zones.should be_a(Array)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'spree-api-client/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "spree-api-client"
|
8
|
+
gem.version = Spree::API::Client::VERSION
|
9
|
+
gem.authors = ["Andrew Nesbitt"]
|
10
|
+
gem.email = ["andrewnez@gmail.com"]
|
11
|
+
gem.description = %q{A rubygem for interacting with the Spree API}
|
12
|
+
gem.summary = %q{A rubygem for interacting with the Spree API}
|
13
|
+
gem.homepage = "https://github.com/andrew/spree-api-client"
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
|
20
|
+
gem.add_dependency 'faraday', '~> 0.8'
|
21
|
+
gem.add_dependency 'faraday_middleware', '~> 0.9'
|
22
|
+
gem.add_dependency 'hashie', '~> 1.2'
|
23
|
+
gem.add_dependency 'multi_json', '~> 1.3'
|
24
|
+
|
25
|
+
gem.add_development_dependency 'rake'
|
26
|
+
gem.add_development_dependency 'rspec'
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,164 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: spree-api-client
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Andrew Nesbitt
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-12-06 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: faraday
|
16
|
+
requirement: &70322126250800 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0.8'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70322126250800
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: faraday_middleware
|
27
|
+
requirement: &70322126263240 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ~>
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0.9'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70322126263240
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: hashie
|
38
|
+
requirement: &70322126262760 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ~>
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '1.2'
|
44
|
+
type: :runtime
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *70322126262760
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: multi_json
|
49
|
+
requirement: &70322126261720 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.3'
|
55
|
+
type: :runtime
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *70322126261720
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: rake
|
60
|
+
requirement: &70322126260140 !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
type: :development
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: *70322126260140
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: &70322126257560 !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: *70322126257560
|
80
|
+
description: A rubygem for interacting with the Spree API
|
81
|
+
email:
|
82
|
+
- andrewnez@gmail.com
|
83
|
+
executables: []
|
84
|
+
extensions: []
|
85
|
+
extra_rdoc_files: []
|
86
|
+
files:
|
87
|
+
- .gitignore
|
88
|
+
- .travis.yml
|
89
|
+
- CONTRIBUTING.md
|
90
|
+
- Gemfile
|
91
|
+
- LICENSE
|
92
|
+
- README.md
|
93
|
+
- Rakefile
|
94
|
+
- lib/spree-api-client.rb
|
95
|
+
- lib/spree-api-client/addresses.rb
|
96
|
+
- lib/spree-api-client/connection.rb
|
97
|
+
- lib/spree-api-client/countries.rb
|
98
|
+
- lib/spree-api-client/line_items.rb
|
99
|
+
- lib/spree-api-client/orders.rb
|
100
|
+
- lib/spree-api-client/payments.rb
|
101
|
+
- lib/spree-api-client/products.rb
|
102
|
+
- lib/spree-api-client/properties.rb
|
103
|
+
- lib/spree-api-client/request.rb
|
104
|
+
- lib/spree-api-client/return_authorizations.rb
|
105
|
+
- lib/spree-api-client/shipments.rb
|
106
|
+
- lib/spree-api-client/taxonomies.rb
|
107
|
+
- lib/spree-api-client/taxons.rb
|
108
|
+
- lib/spree-api-client/variants.rb
|
109
|
+
- lib/spree-api-client/version.rb
|
110
|
+
- lib/spree-api-client/zones.rb
|
111
|
+
- spec/addresses_spec.rb
|
112
|
+
- spec/client_spec.rb
|
113
|
+
- spec/countries_spec.rb
|
114
|
+
- spec/orders_spec.rb
|
115
|
+
- spec/payments_spec.rb
|
116
|
+
- spec/products_spec.rb
|
117
|
+
- spec/properties_spec.rb
|
118
|
+
- spec/return_authorizations_spec.rb
|
119
|
+
- spec/shipments_spec.rb
|
120
|
+
- spec/spec_helper.rb
|
121
|
+
- spec/taxonomies_spec.rb
|
122
|
+
- spec/taxons_spec.rb
|
123
|
+
- spec/variants_spec.rb
|
124
|
+
- spec/zones_spec.rb
|
125
|
+
- spree-api-client.gemspec
|
126
|
+
homepage: https://github.com/andrew/spree-api-client
|
127
|
+
licenses: []
|
128
|
+
post_install_message:
|
129
|
+
rdoc_options: []
|
130
|
+
require_paths:
|
131
|
+
- lib
|
132
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
133
|
+
none: false
|
134
|
+
requirements:
|
135
|
+
- - ! '>='
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: '0'
|
138
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
139
|
+
none: false
|
140
|
+
requirements:
|
141
|
+
- - ! '>='
|
142
|
+
- !ruby/object:Gem::Version
|
143
|
+
version: '0'
|
144
|
+
requirements: []
|
145
|
+
rubyforge_project:
|
146
|
+
rubygems_version: 1.8.11
|
147
|
+
signing_key:
|
148
|
+
specification_version: 3
|
149
|
+
summary: A rubygem for interacting with the Spree API
|
150
|
+
test_files:
|
151
|
+
- spec/addresses_spec.rb
|
152
|
+
- spec/client_spec.rb
|
153
|
+
- spec/countries_spec.rb
|
154
|
+
- spec/orders_spec.rb
|
155
|
+
- spec/payments_spec.rb
|
156
|
+
- spec/products_spec.rb
|
157
|
+
- spec/properties_spec.rb
|
158
|
+
- spec/return_authorizations_spec.rb
|
159
|
+
- spec/shipments_spec.rb
|
160
|
+
- spec/spec_helper.rb
|
161
|
+
- spec/taxonomies_spec.rb
|
162
|
+
- spec/taxons_spec.rb
|
163
|
+
- spec/variants_spec.rb
|
164
|
+
- spec/zones_spec.rb
|