spree_api 1.2.5 → 1.3.0.rc1
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/.rspec +1 -0
- data/app/controllers/spree/api/addresses_controller.rb +17 -0
- data/app/controllers/spree/api/base_controller.rb +111 -0
- data/app/controllers/spree/api/countries_controller.rb +14 -0
- data/app/controllers/spree/api/images_controller.rb +29 -0
- data/app/controllers/spree/api/line_items_controller.rb +38 -0
- data/app/controllers/spree/api/orders_controller.rb +81 -0
- data/app/controllers/spree/api/payments_controller.rb +75 -0
- data/app/controllers/spree/api/product_properties_controller.rb +61 -0
- data/app/controllers/spree/api/products_controller.rb +45 -0
- data/app/controllers/spree/api/return_authorizations_controller.rb +50 -0
- data/app/controllers/spree/api/shipments_controller.rb +41 -0
- data/app/controllers/spree/api/taxonomies_controller.rb +46 -0
- data/app/controllers/spree/api/taxons_controller.rb +49 -0
- data/app/controllers/spree/api/variants_controller.rb +71 -0
- data/app/controllers/spree/api/zones_controller.rb +43 -0
- data/app/helpers/spree/api/api_helpers.rb +0 -5
- data/app/overrides/api_admin_user_edit_form.rb +1 -1
- data/app/views/spree/admin/users/_api_fields.html.erb +26 -14
- data/app/views/spree/api/{v1/addresses/show.rabl → addresses/show.v1.rabl} +0 -0
- data/app/views/spree/api/{v1/countries/index.rabl → countries/index.v1.rabl} +0 -0
- data/app/views/spree/api/{v1/countries/show.rabl → countries/show.v1.rabl} +0 -0
- data/app/views/spree/api/{v1/errors/gateway_error.rabl → errors/gateway_error.v1.rabl} +0 -0
- data/app/views/spree/api/{v1/errors/invalid_api_key.rabl → errors/invalid_api_key.v1.rabl} +0 -0
- data/app/views/spree/api/{v1/errors/invalid_resource.rabl → errors/invalid_resource.v1.rabl} +0 -0
- data/app/views/spree/api/{v1/errors/must_specify_api_key.rabl → errors/must_specify_api_key.v1.rabl} +0 -0
- data/app/views/spree/api/{v1/errors/not_found.rabl → errors/not_found.v1.rabl} +0 -0
- data/app/views/spree/api/{v1/errors/unauthorized.rabl → errors/unauthorized.v1.rabl} +0 -0
- data/app/views/spree/api/{v1/images/show.rabl → images/show.v1.rabl} +0 -0
- data/app/views/spree/api/{v1/line_items/new.rabl → line_items/new.v1.rabl} +0 -0
- data/app/views/spree/api/{v1/line_items/show.rabl → line_items/show.v1.rabl} +1 -1
- data/app/views/spree/api/{v1/orders/address.rabl → orders/address.v1.rabl} +0 -0
- data/app/views/spree/api/{v1/orders/canceled.rabl → orders/canceled.v1.rabl} +0 -0
- data/app/views/spree/api/{v1/orders/cart.rabl → orders/cart.v1.rabl} +0 -0
- data/app/views/spree/api/{v1/orders/complete.rabl → orders/complete.v1.rabl} +0 -0
- data/app/views/spree/api/{v1/orders/could_not_transition.rabl → orders/could_not_transition.v1.rabl} +0 -0
- data/app/views/spree/api/{v1/orders/delivery.rabl → orders/delivery.v1.rabl} +0 -0
- data/app/views/spree/api/{v1/orders/index.rabl → orders/index.v1.rabl} +0 -0
- data/app/views/spree/api/{v1/orders/invalid_shipping_method.rabl → orders/invalid_shipping_method.v1.rabl} +0 -0
- data/app/views/spree/api/{v1/orders/payment.rabl → orders/payment.v1.rabl} +0 -0
- data/app/views/spree/api/{v1/orders/show.rabl → orders/show.v1.rabl} +6 -6
- data/app/views/spree/api/{v1/payments/credit_over_limit.rabl → payments/credit_over_limit.v1.rabl} +0 -0
- data/app/views/spree/api/{v1/payments/index.rabl → payments/index.v1.rabl} +0 -0
- data/app/views/spree/api/{v1/payments/new.rabl → payments/new.v1.rabl} +0 -0
- data/app/views/spree/api/{v1/payments/show.rabl → payments/show.v1.rabl} +0 -0
- data/app/views/spree/api/{v1/product_properties/index.rabl → product_properties/index.v1.rabl} +0 -0
- data/app/views/spree/api/{v1/product_properties/new.rabl → product_properties/new.v1.rabl} +0 -0
- data/app/views/spree/api/{v1/product_properties/show.rabl → product_properties/show.v1.rabl} +0 -0
- data/app/views/spree/api/{v1/products/index.rabl → products/index.v1.rabl} +1 -2
- data/app/views/spree/api/{v1/products/new.rabl → products/new.v1.rabl} +0 -0
- data/app/views/spree/api/{v1/products/product.rabl → products/product.v1.rabl} +0 -0
- data/app/views/spree/api/{v1/products/show.rabl → products/show.v1.rabl} +1 -1
- data/app/views/spree/api/{v1/return_authorizations/index.rabl → return_authorizations/index.v1.rabl} +0 -0
- data/app/views/spree/api/{v1/return_authorizations/new.rabl → return_authorizations/new.v1.rabl} +0 -0
- data/app/views/spree/api/{v1/return_authorizations/show.rabl → return_authorizations/show.v1.rabl} +0 -0
- data/app/views/spree/api/{v1/shipments/cannot_ready_shipment.rabl → shipments/cannot_ready_shipment.v1.rabl} +0 -0
- data/app/views/spree/api/{v1/shipments/show.rabl → shipments/show.v1.rabl} +0 -0
- data/app/views/spree/api/{v1/taxonomies/index.rabl → taxonomies/index.v1.rabl} +1 -1
- data/app/views/spree/api/{v1/taxonomies/nested.rabl → taxonomies/nested.v1.rabl} +1 -1
- data/app/views/spree/api/{v1/taxonomies/new.rabl → taxonomies/new.v1.rabl} +0 -0
- data/app/views/spree/api/{v1/taxonomies/show.rabl → taxonomies/show.v1.rabl} +1 -1
- data/app/views/spree/api/{v1/taxons/index.rabl → taxons/index.v1.rabl} +1 -1
- data/app/views/spree/api/{v1/taxons/new.rabl → taxons/new.v1.rabl} +0 -0
- data/app/views/spree/api/{v1/taxons/show.rabl → taxons/show.v1.rabl} +0 -0
- data/app/views/spree/api/{v1/taxons/taxons.rabl → taxons/taxons.v1.rabl} +1 -1
- data/app/views/spree/api/{v1/variants/index.rabl → variants/index.v1.rabl} +0 -0
- data/app/views/spree/api/{v1/variants/new.rabl → variants/new.v1.rabl} +0 -0
- data/app/views/spree/api/{v1/variants/show.rabl → variants/show.v1.rabl} +1 -1
- data/app/views/spree/api/{v1/variants/variant.rabl → variants/variant.v1.rabl} +0 -0
- data/app/views/spree/api/{v1/zones/index.rabl → zones/index.v1.rabl} +1 -1
- data/app/views/spree/api/{v1/zones/show.rabl → zones/show.v1.rabl} +0 -0
- data/config/initializers/metal_load_paths.rb +1 -1
- data/config/routes.rb +34 -37
- data/db/migrate/20120411123334_resize_api_key_field.rb +1 -1
- data/lib/spree/api/engine.rb +8 -1
- data/lib/spree_api.rb +1 -0
- data/spec/controllers/spree/api/{v1/addresses_controller_spec.rb → addresses_controller_spec.rb} +3 -3
- data/spec/controllers/spree/api/{v1/base_controller_spec.rb → base_controller_spec.rb} +2 -9
- data/spec/controllers/spree/api/{v1/countries_controller_spec.rb → countries_controller_spec.rb} +5 -5
- data/spec/controllers/spree/api/{v1/images_controller_spec.rb → images_controller_spec.rb} +1 -1
- data/spec/controllers/spree/api/{v1/line_items_controller_spec.rb → line_items_controller_spec.rb} +2 -2
- data/spec/controllers/spree/api/{v1/orders_controller_spec.rb → orders_controller_spec.rb} +7 -12
- data/spec/controllers/spree/api/{v1/payments_controller_spec.rb → payments_controller_spec.rb} +2 -2
- data/spec/controllers/spree/api/{v1/product_properties_controller_spec.rb → product_properties_controller_spec.rb} +2 -3
- data/spec/controllers/spree/api/{v1/products_controller_spec.rb → products_controller_spec.rb} +14 -7
- data/spec/controllers/spree/api/{v1/return_authorizations_controller_spec.rb → return_authorizations_controller_spec.rb} +4 -4
- data/spec/controllers/spree/api/{v1/shipments_controller_spec.rb → shipments_controller_spec.rb} +4 -9
- data/spec/controllers/spree/api/{v1/taxonomies_controller_spec.rb → taxonomies_controller_spec.rb} +11 -11
- data/spec/controllers/spree/api/{v1/taxons_controller_spec.rb → taxons_controller_spec.rb} +7 -7
- data/spec/controllers/spree/api/{v1/unauthenticated_products_controller_spec.rb → unauthenticated_products_controller_spec.rb} +1 -1
- data/spec/controllers/spree/api/{v1/variants_controller_spec.rb → variants_controller_spec.rb} +4 -5
- data/spec/controllers/spree/api/{v1/zones_controller_spec.rb → zones_controller_spec.rb} +7 -7
- data/spec/support/controller_hacks.rb +1 -1
- data/spec/support/have_attributes_matcher.rb +2 -2
- data/spree_api.gemspec +1 -0
- metadata +139 -115
- checksums.yaml +0 -7
- data/app/controllers/spree/api/v1/addresses_controller.rb +0 -19
- data/app/controllers/spree/api/v1/base_controller.rb +0 -111
- data/app/controllers/spree/api/v1/countries_controller.rb +0 -18
- data/app/controllers/spree/api/v1/images_controller.rb +0 -32
- data/app/controllers/spree/api/v1/inventory_units_controller.rb +0 -50
- data/app/controllers/spree/api/v1/line_items_controller.rb +0 -40
- data/app/controllers/spree/api/v1/orders_controller.rb +0 -83
- data/app/controllers/spree/api/v1/payments_controller.rb +0 -77
- data/app/controllers/spree/api/v1/product_properties_controller.rb +0 -64
- data/app/controllers/spree/api/v1/products_controller.rb +0 -47
- data/app/controllers/spree/api/v1/return_authorizations_controller.rb +0 -53
- data/app/controllers/spree/api/v1/shipments_controller.rb +0 -43
- data/app/controllers/spree/api/v1/taxonomies_controller.rb +0 -50
- data/app/controllers/spree/api/v1/taxons_controller.rb +0 -51
- data/app/controllers/spree/api/v1/variants_controller.rb +0 -74
- data/app/controllers/spree/api/v1/zones_controller.rb +0 -45
- data/app/views/spree/api/v1/inventory_units/show.rabl +0 -2
- data/spec/controllers/spree/api/v1/inventory_units_controller_spec.rb +0 -46
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
module Spree
|
|
2
|
-
module Api
|
|
3
|
-
module V1
|
|
4
|
-
class ProductPropertiesController < Spree::Api::V1::BaseController
|
|
5
|
-
before_filter :find_product
|
|
6
|
-
before_filter :product_property, :only => [:show, :update, :destroy]
|
|
7
|
-
|
|
8
|
-
def index
|
|
9
|
-
@product_properties = @product.product_properties.
|
|
10
|
-
ransack(params[:q]).result.
|
|
11
|
-
page(params[:page]).per(params[:per_page])
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
def show
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
def new
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
def create
|
|
21
|
-
authorize! :create, ProductProperty
|
|
22
|
-
@product_property = @product.product_properties.new(params[:product_property])
|
|
23
|
-
if @product_property.save
|
|
24
|
-
render :show, :status => 201
|
|
25
|
-
else
|
|
26
|
-
invalid_resource!(@product_property)
|
|
27
|
-
end
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
def update
|
|
31
|
-
authorize! :update, ProductProperty
|
|
32
|
-
if @product_property && @product_property.update_attributes(params[:product_property])
|
|
33
|
-
render :show, :status => 200
|
|
34
|
-
else
|
|
35
|
-
invalid_resource!(@product_property)
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
def destroy
|
|
40
|
-
authorize! :delete, ProductProperty
|
|
41
|
-
if(@product_property)
|
|
42
|
-
@product_property.destroy
|
|
43
|
-
render :text => nil, :status => 204
|
|
44
|
-
else
|
|
45
|
-
invalid_resource!(@product_property)
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
private
|
|
51
|
-
def find_product
|
|
52
|
-
@product = super(params[:product_id])
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
def product_property
|
|
56
|
-
if @product
|
|
57
|
-
@product_property ||= @product.product_properties.find_by_id(params[:id])
|
|
58
|
-
@product_property ||= @product.product_properties.joins(:property).where('spree_properties.name' => params[:id]).readonly(false).first
|
|
59
|
-
end
|
|
60
|
-
end
|
|
61
|
-
end
|
|
62
|
-
end
|
|
63
|
-
end
|
|
64
|
-
end
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
module Spree
|
|
2
|
-
module Api
|
|
3
|
-
module V1
|
|
4
|
-
class ProductsController < Spree::Api::V1::BaseController
|
|
5
|
-
def index
|
|
6
|
-
@products = product_scope.ransack(params[:q]).result.page(params[:page]).per(params[:per_page])
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
def show
|
|
10
|
-
@product = find_product(params[:id])
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def new
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
def create
|
|
17
|
-
authorize! :create, Product
|
|
18
|
-
params[:product][:available_on] ||= Time.now
|
|
19
|
-
@product = Product.new(params[:product])
|
|
20
|
-
if @product.save
|
|
21
|
-
render :show, :status => 201
|
|
22
|
-
else
|
|
23
|
-
invalid_resource!(@product)
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
def update
|
|
28
|
-
authorize! :update, Product
|
|
29
|
-
@product = find_product(params[:id])
|
|
30
|
-
if @product.update_attributes(params[:product])
|
|
31
|
-
render :show, :status => 200
|
|
32
|
-
else
|
|
33
|
-
invalid_resource!(@product)
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
def destroy
|
|
38
|
-
authorize! :delete, Product
|
|
39
|
-
@product = find_product(params[:id])
|
|
40
|
-
@product.update_attribute(:deleted_at, Time.now)
|
|
41
|
-
@product.variants_including_master.update_all(:deleted_at => Time.now)
|
|
42
|
-
render :text => nil, :status => 204
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
end
|
|
46
|
-
end
|
|
47
|
-
end
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
module Spree
|
|
2
|
-
module Api
|
|
3
|
-
module V1
|
|
4
|
-
class ReturnAuthorizationsController < Spree::Api::V1::BaseController
|
|
5
|
-
before_filter :authorize_admin!
|
|
6
|
-
|
|
7
|
-
def index
|
|
8
|
-
@return_authorizations = order.return_authorizations.
|
|
9
|
-
ransack(params[:q]).result.
|
|
10
|
-
page(params[:page]).per(params[:per_page])
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def show
|
|
14
|
-
@return_authorization = order.return_authorizations.find(params[:id])
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
def create
|
|
18
|
-
@return_authorization = order.return_authorizations.build(params[:return_authorization], :as => :api)
|
|
19
|
-
if @return_authorization.save
|
|
20
|
-
render :show, :status => 201
|
|
21
|
-
else
|
|
22
|
-
invalid_resource!(@return_authorization)
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
def update
|
|
27
|
-
@return_authorization = order.return_authorizations.find(params[:id])
|
|
28
|
-
if @return_authorization.update_attributes(params[:return_authorization])
|
|
29
|
-
render :show
|
|
30
|
-
else
|
|
31
|
-
invalid_resource!(@return_authorization)
|
|
32
|
-
end
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
def destroy
|
|
36
|
-
@return_authorization = order.return_authorizations.find(params[:id])
|
|
37
|
-
@return_authorization.destroy
|
|
38
|
-
render :text => nil, :status => 204
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
private
|
|
42
|
-
|
|
43
|
-
def order
|
|
44
|
-
@order ||= Order.find_by_number!(params[:order_id])
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
def authorize_admin!
|
|
48
|
-
authorize! :manage, Spree::ReturnAuthorization
|
|
49
|
-
end
|
|
50
|
-
end
|
|
51
|
-
end
|
|
52
|
-
end
|
|
53
|
-
end
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
module Spree
|
|
2
|
-
module Api
|
|
3
|
-
module V1
|
|
4
|
-
class ShipmentsController < BaseController
|
|
5
|
-
before_filter :find_order
|
|
6
|
-
before_filter :find_and_update_shipment, :only => [:ship, :ready]
|
|
7
|
-
|
|
8
|
-
def ready
|
|
9
|
-
authorize! :read, Shipment
|
|
10
|
-
unless @shipment.ready?
|
|
11
|
-
if @shipment.can_ready?
|
|
12
|
-
@shipment.ready!
|
|
13
|
-
else
|
|
14
|
-
render "spree/api/v1/shipments/cannot_ready_shipment", :status => 422 and return
|
|
15
|
-
end
|
|
16
|
-
end
|
|
17
|
-
render :show
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
def ship
|
|
21
|
-
authorize! :read, Shipment
|
|
22
|
-
unless @shipment.shipped?
|
|
23
|
-
@shipment.ship!
|
|
24
|
-
end
|
|
25
|
-
render :show
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
private
|
|
29
|
-
|
|
30
|
-
def find_order
|
|
31
|
-
@order = Spree::Order.find_by_number!(params[:order_id])
|
|
32
|
-
authorize! :read, @order
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
def find_and_update_shipment
|
|
36
|
-
@shipment = @order.shipments.find_by_number!(params[:id])
|
|
37
|
-
@shipment.update_attributes(params[:shipment])
|
|
38
|
-
@shipment.reload
|
|
39
|
-
end
|
|
40
|
-
end
|
|
41
|
-
end
|
|
42
|
-
end
|
|
43
|
-
end
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
module Spree
|
|
2
|
-
module Api
|
|
3
|
-
module V1
|
|
4
|
-
class TaxonomiesController < Spree::Api::V1::BaseController
|
|
5
|
-
def index
|
|
6
|
-
@taxonomies = Taxonomy.
|
|
7
|
-
order('name').includes(:root => :children).
|
|
8
|
-
ransack(params[:q]).result.
|
|
9
|
-
page(params[:page]).per(params[:per_page])
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
def show
|
|
13
|
-
@taxonomy = Taxonomy.find(params[:id])
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
def create
|
|
17
|
-
authorize! :create, Taxonomy
|
|
18
|
-
@taxonomy = Taxonomy.new(params[:taxonomy])
|
|
19
|
-
if @taxonomy.save
|
|
20
|
-
render :show, :status => 201
|
|
21
|
-
else
|
|
22
|
-
invalid_resource!(@taxonomy)
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
def update
|
|
27
|
-
authorize! :update, Taxonomy
|
|
28
|
-
if taxonomy.update_attributes(params[:taxonomy])
|
|
29
|
-
render :show, :status => 200
|
|
30
|
-
else
|
|
31
|
-
invalid_resource!(taxonomy)
|
|
32
|
-
end
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
def destroy
|
|
36
|
-
authorize! :delete, Taxonomy
|
|
37
|
-
taxonomy.destroy
|
|
38
|
-
render :text => nil, :status => 204
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
private
|
|
42
|
-
|
|
43
|
-
def taxonomy
|
|
44
|
-
@taxonomy ||= Taxonomy.find(params[:id])
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
end
|
|
48
|
-
end
|
|
49
|
-
end
|
|
50
|
-
end
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
module Spree
|
|
2
|
-
module Api
|
|
3
|
-
module V1
|
|
4
|
-
class TaxonsController < Spree::Api::V1::BaseController
|
|
5
|
-
def index
|
|
6
|
-
@taxons = taxonomy.root.children
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
def show
|
|
10
|
-
@taxon = taxon
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def create
|
|
14
|
-
authorize! :create, Taxon
|
|
15
|
-
@taxon = Taxon.new(params[:taxon])
|
|
16
|
-
if @taxon.save
|
|
17
|
-
render :show, :status => 201
|
|
18
|
-
else
|
|
19
|
-
invalid_resource!(@taxon)
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
def update
|
|
24
|
-
authorize! :update, Taxon
|
|
25
|
-
if taxon.update_attributes(params[:taxon])
|
|
26
|
-
render :show, :status => 200
|
|
27
|
-
else
|
|
28
|
-
invalid_resource!(taxon)
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
def destroy
|
|
33
|
-
authorize! :delete, Taxon
|
|
34
|
-
taxon.destroy
|
|
35
|
-
render :text => nil, :status => 204
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
private
|
|
39
|
-
|
|
40
|
-
def taxonomy
|
|
41
|
-
@taxonomy ||= Taxonomy.find(params[:taxonomy_id])
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
def taxon
|
|
45
|
-
@taxon ||= taxonomy.taxons.find(params[:id])
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
end
|
|
49
|
-
end
|
|
50
|
-
end
|
|
51
|
-
end
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
module Spree
|
|
2
|
-
module Api
|
|
3
|
-
module V1
|
|
4
|
-
class VariantsController < Spree::Api::V1::BaseController
|
|
5
|
-
before_filter :product
|
|
6
|
-
|
|
7
|
-
def index
|
|
8
|
-
@variants = scope.
|
|
9
|
-
includes(:option_values).ransack(params[:q]).result.
|
|
10
|
-
page(params[:page]).per(params[:per_page])
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def show
|
|
14
|
-
@variant = scope.includes(:option_values).find(params[:id])
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
def new
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
def create
|
|
21
|
-
authorize! :create, Variant
|
|
22
|
-
@variant = scope.new(params[:variant])
|
|
23
|
-
if @variant.save
|
|
24
|
-
render :show, :status => 201
|
|
25
|
-
else
|
|
26
|
-
invalid_resource!(@variant)
|
|
27
|
-
end
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
def update
|
|
31
|
-
authorize! :update, Variant
|
|
32
|
-
@variant = scope.find(params[:id])
|
|
33
|
-
if @variant.update_attributes(params[:variant])
|
|
34
|
-
render :show, :status => 200
|
|
35
|
-
else
|
|
36
|
-
invalid_resource!(@product)
|
|
37
|
-
end
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
def destroy
|
|
41
|
-
authorize! :delete, Variant
|
|
42
|
-
@variant = scope.find(params[:id])
|
|
43
|
-
@variant.destroy
|
|
44
|
-
render :text => nil, :status => 204
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
private
|
|
48
|
-
def product
|
|
49
|
-
@product ||= Spree::Product.find_by_permalink(params[:product_id]) if params[:product_id]
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
def scope
|
|
53
|
-
if @product
|
|
54
|
-
unless current_api_user.has_spree_role?("admin") || params[:show_deleted]
|
|
55
|
-
variants = @product.variants_including_master
|
|
56
|
-
else
|
|
57
|
-
variants = @product.variants_including_master_and_deleted
|
|
58
|
-
end
|
|
59
|
-
else
|
|
60
|
-
variants = Variant.scoped
|
|
61
|
-
if current_api_user.has_spree_role?("admin")
|
|
62
|
-
unless params[:show_deleted]
|
|
63
|
-
variants = Variant.active
|
|
64
|
-
end
|
|
65
|
-
else
|
|
66
|
-
variants = variants.active
|
|
67
|
-
end
|
|
68
|
-
end
|
|
69
|
-
variants
|
|
70
|
-
end
|
|
71
|
-
end
|
|
72
|
-
end
|
|
73
|
-
end
|
|
74
|
-
end
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
module Spree
|
|
2
|
-
module Api
|
|
3
|
-
module V1
|
|
4
|
-
class ZonesController < Spree::Api::V1::BaseController
|
|
5
|
-
def index
|
|
6
|
-
@zones = Zone.order('name ASC').ransack(params[:q]).result.page(params[:page]).per(params[:per_page])
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
def show
|
|
10
|
-
zone
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def create
|
|
14
|
-
authorize! :create, Zone
|
|
15
|
-
@zone = Zone.new(map_nested_attributes_keys(Spree::Zone, params[:zone]))
|
|
16
|
-
if @zone.save
|
|
17
|
-
render :show, :status => 201
|
|
18
|
-
else
|
|
19
|
-
invalid_resource!(@zone)
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
def update
|
|
24
|
-
authorize! :update, Zone
|
|
25
|
-
if zone.update_attributes(map_nested_attributes_keys(Spree::Zone, params[:zone]))
|
|
26
|
-
render :show, :status => 200
|
|
27
|
-
else
|
|
28
|
-
invalid_resource!(@zone)
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
def destroy
|
|
33
|
-
authorize! :delete, Zone
|
|
34
|
-
zone.destroy
|
|
35
|
-
render :text => nil, :status => 204
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
private
|
|
39
|
-
def zone
|
|
40
|
-
@zone ||= Spree::Zone.find(params[:id])
|
|
41
|
-
end
|
|
42
|
-
end
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
end
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
module Spree
|
|
4
|
-
describe Api::V1::InventoryUnitsController do
|
|
5
|
-
render_views
|
|
6
|
-
|
|
7
|
-
before do
|
|
8
|
-
stub_authentication!
|
|
9
|
-
@inventory_unit = create(:inventory_unit)
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
it "gets an inventory unit" do
|
|
13
|
-
api_get :show, :id => @inventory_unit.id
|
|
14
|
-
json_response['inventory_unit']['state'].should eq @inventory_unit.state
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
it "updates an inventory unit (only shipment is accessable by default)" do
|
|
18
|
-
api_put :update, :id => @inventory_unit.id,
|
|
19
|
-
:inventory_unit => { :shipment => nil }
|
|
20
|
-
json_response['inventory_unit']['shipment_id'].should be_nil
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
context 'fires state event' do
|
|
24
|
-
it 'if supplied with :fire param' do
|
|
25
|
-
api_put :update, :id => @inventory_unit.id,
|
|
26
|
-
:fire => 'ship',
|
|
27
|
-
:inventory_unit => { :shipment => nil }
|
|
28
|
-
|
|
29
|
-
json_response['inventory_unit']['state'].should eq 'shipped'
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
it 'and returns exception if cannot fire' do
|
|
33
|
-
api_put :update, :id => @inventory_unit.id,
|
|
34
|
-
:fire => 'return'
|
|
35
|
-
json_response['exception'].should match /cannot transition to return/
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
it 'and returns exception bad state' do
|
|
39
|
-
api_put :update, :id => @inventory_unit.id,
|
|
40
|
-
:fire => 'bad'
|
|
41
|
-
json_response['exception'].should match /cannot transition to bad/
|
|
42
|
-
end
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
end
|
|
46
|
-
end
|