spree-api-client 0.0.2 → 0.2.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.
- checksums.yaml +7 -0
- data/CHANGELOG.md +9 -0
- data/LICENSE.txt +674 -0
- data/README.md +31 -38
- data/lib/spree_client.rb +3 -0
- data/lib/spree_client.rb~ +71 -0
- data/lib/spree_client/api.rb +1 -0
- data/lib/spree_client/api/v1.rb +52 -0
- data/lib/spree_client/api/v1/products.rb +23 -0
- data/lib/spree_client/api/v1/properties.rb +12 -0
- data/lib/spree_client/api/v1/resources.rb +142 -0
- data/lib/spree_client/api/v1/stock_items.rb +27 -0
- data/lib/spree_client/api/v1/stock_locations.rb +33 -0
- data/lib/spree_client/api/v1/stock_movements.rb +16 -0
- data/lib/spree_client/api/v1/taxonomies.rb +12 -0
- data/lib/spree_client/api/v1/variants.rb +13 -0
- data/lib/spree_client/attributes.rb +26 -0
- data/lib/spree_client/models.rb +5 -0
- data/lib/spree_client/models/product.rb +7 -0
- data/lib/spree_client/models/property.rb +6 -0
- data/lib/spree_client/models/stock_item.rb +7 -0
- data/lib/spree_client/models/stock_location.rb +7 -0
- data/lib/spree_client/models/stock_movement.rb +7 -0
- data/lib/spree_client/models/store.rb +7 -0
- data/lib/spree_client/models/taxonomy.rb +5 -0
- data/lib/spree_client/models/variant.rb +7 -0
- metadata +73 -192
- data/.gitignore +0 -17
- data/.ruby-version +0 -1
- data/.travis.yml +0 -11
- data/CONTRIBUTING.md +0 -8
- data/Gemfile +0 -9
- data/LICENSE +0 -22
- data/Rakefile +0 -7
- data/fixtures/cassette_library/addresss.yml +0 -46
- data/fixtures/cassette_library/countries.yml +0 -52
- data/fixtures/cassette_library/orders.yml +0 -48
- data/fixtures/cassette_library/payments.yml +0 -48
- data/fixtures/cassette_library/products.yml +0 -66
- data/fixtures/cassette_library/properties.yml +0 -48
- data/fixtures/cassette_library/request.yml +0 -46
- data/fixtures/cassette_library/return_authorizations.yml +0 -48
- data/fixtures/cassette_library/shipment_ready.yml +0 -46
- data/fixtures/cassette_library/taxonomies.yml +0 -48
- data/fixtures/cassette_library/taxons.yml +0 -48
- data/fixtures/cassette_library/variants.yml +0 -63
- data/fixtures/cassette_library/zones.yml +0 -49
- data/lib/spree-api-client.rb +0 -49
- data/lib/spree-api-client/addresses.rb +0 -15
- data/lib/spree-api-client/connection.rb +0 -31
- data/lib/spree-api-client/countries.rb +0 -15
- data/lib/spree-api-client/error.rb +0 -47
- data/lib/spree-api-client/line_items.rb +0 -19
- data/lib/spree-api-client/orders.rb +0 -32
- data/lib/spree-api-client/payments.rb +0 -43
- data/lib/spree-api-client/products.rb +0 -31
- data/lib/spree-api-client/properties.rb +0 -31
- data/lib/spree-api-client/request.rb +0 -56
- data/lib/spree-api-client/return_authorizations.rb +0 -31
- data/lib/spree-api-client/shipments.rb +0 -15
- data/lib/spree-api-client/taxonomies.rb +0 -31
- data/lib/spree-api-client/taxons.rb +0 -27
- data/lib/spree-api-client/variants.rb +0 -31
- data/lib/spree-api-client/version.rb +0 -7
- data/lib/spree-api-client/zones.rb +0 -31
- data/spec/addresses_spec.rb +0 -12
- data/spec/client_spec.rb +0 -32
- data/spec/countries_spec.rb +0 -12
- data/spec/orders_spec.rb +0 -12
- data/spec/payments_spec.rb +0 -12
- data/spec/products_spec.rb +0 -12
- data/spec/properties_spec.rb +0 -12
- data/spec/return_authorizations_spec.rb +0 -12
- data/spec/shipments_spec.rb +0 -12
- data/spec/spec_helper.rb +0 -10
- data/spec/support/vcr.rb +0 -9
- data/spec/taxonomies_spec.rb +0 -12
- data/spec/taxons_spec.rb +0 -12
- data/spec/variants_spec.rb +0 -12
- data/spec/zones_spec.rb +0 -12
- data/spree-api-client.gemspec +0 -29
@@ -1,19 +0,0 @@
|
|
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
|
@@ -1,32 +0,0 @@
|
|
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
|
-
order_options = (options[:order] || {}).merge(:shipping_method_id => shipping_method_id)
|
23
|
-
put("orders/#{order_number}", options.merge(order: order_options))
|
24
|
-
end
|
25
|
-
|
26
|
-
def empty_order(order_number, options={})
|
27
|
-
put("orders/#{order_number}/empty", options)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
@@ -1,43 +0,0 @@
|
|
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
|
@@ -1,31 +0,0 @@
|
|
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
|
@@ -1,31 +0,0 @@
|
|
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
|
@@ -1,56 +0,0 @@
|
|
1
|
-
require 'spree-api-client/error'
|
2
|
-
|
3
|
-
module Spree
|
4
|
-
module API
|
5
|
-
class Client
|
6
|
-
module Request
|
7
|
-
def request(method, path, options = {})
|
8
|
-
token = options.delete(:api_token) || api_token
|
9
|
-
|
10
|
-
begin
|
11
|
-
response = connection.send(method) do |request|
|
12
|
-
|
13
|
-
request.headers['Accept'] = options.delete(:accept) || 'application/json'
|
14
|
-
|
15
|
-
if token
|
16
|
-
request.headers['X-Spree-Token'] = token
|
17
|
-
end
|
18
|
-
|
19
|
-
case method
|
20
|
-
when :get
|
21
|
-
options.merge(:per_page => per_page)
|
22
|
-
request.url(path, options)
|
23
|
-
when :delete, :head
|
24
|
-
request.url(path, options)
|
25
|
-
when :patch, :post, :put
|
26
|
-
request.path = path
|
27
|
-
request.body = MultiJson.dump(options) unless options.empty?
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
rescue Faraday::Error::ClientError => error
|
32
|
-
raise Spree::API::Client::Error::ClientError.new(error)
|
33
|
-
end
|
34
|
-
|
35
|
-
response
|
36
|
-
end
|
37
|
-
|
38
|
-
def get(path, options = {})
|
39
|
-
request(:get, path, options).body
|
40
|
-
end
|
41
|
-
|
42
|
-
def post(path, options={})
|
43
|
-
request(:post, path, options).body
|
44
|
-
end
|
45
|
-
|
46
|
-
def put(path, options={})
|
47
|
-
request(:put, path, options).body
|
48
|
-
end
|
49
|
-
|
50
|
-
def delete(path, options={})
|
51
|
-
request(:delete, path, options).body
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
@@ -1,31 +0,0 @@
|
|
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
|
@@ -1,15 +0,0 @@
|
|
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
|
@@ -1,31 +0,0 @@
|
|
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
|
@@ -1,27 +0,0 @@
|
|
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
|
@@ -1,31 +0,0 @@
|
|
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
|
@@ -1,31 +0,0 @@
|
|
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
|
data/spec/addresses_spec.rb
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Spree::API::Client::Addresses do
|
4
|
-
use_vcr_cassette "addresss", :record => :new_episodes
|
5
|
-
describe 'address' do
|
6
|
-
it 'should load address' do
|
7
|
-
client = Spree::API::Client.new('http://localhost:4000/store/api', 'b56019f04b61a50553ee323f5ab68c6b435871971e79c987')
|
8
|
-
address = client.address(1)
|
9
|
-
address.should be_a(Hashie::Mash)
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
data/spec/client_spec.rb
DELETED
@@ -1,32 +0,0 @@
|
|
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
|
-
use_vcr_cassette "request", :record => :new_episodes
|
26
|
-
it 'should load stuff from the api' do
|
27
|
-
client = Spree::API::Client.new('http://localhost:4000/store/api', 'randomtokenstring')
|
28
|
-
response = client.request(:get, 'products')
|
29
|
-
response.should be_a(Faraday::Response)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|