solidus_api 2.3.1 → 2.4.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of solidus_api might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/app/controllers/spree/api/base_controller.rb +9 -12
- data/app/controllers/spree/api/checkouts_controller.rb +3 -5
- data/app/controllers/spree/api/orders_controller.rb +2 -12
- data/app/controllers/spree/api/payments_controller.rb +0 -1
- data/app/controllers/spree/api/resource_controller.rb +2 -0
- data/app/controllers/spree/api/shipments_controller.rb +17 -6
- data/app/controllers/spree/api/stock_items_controller.rb +6 -0
- data/app/helpers/spree/api/api_helpers.rb +3 -4
- data/app/views/.rubocop.yml +4 -0
- data/app/views/spree/api/address_books/show.json.jbuilder +11 -0
- data/app/views/spree/api/addresses/_address.json.jbuilder +17 -0
- data/app/views/spree/api/addresses/show.json.jbuilder +1 -0
- data/app/views/spree/api/adjustments/_adjustment.json.jbuilder +4 -0
- data/app/views/spree/api/config/money.json.jbuilder +1 -0
- data/app/views/spree/api/config/show.json.jbuilder +2 -0
- data/app/views/spree/api/countries/index.json.jbuilder +2 -0
- data/app/views/spree/api/countries/show.json.jbuilder +4 -0
- data/app/views/spree/api/credit_cards/_credit_card.json.jbuilder +10 -0
- data/app/views/spree/api/credit_cards/index.json.jbuilder +4 -0
- data/app/views/spree/api/credit_cards/show.json.jbuilder +1 -0
- data/app/views/spree/api/errors/delete_restriction.json.jbuilder +1 -0
- data/app/views/spree/api/errors/gateway_error.json.jbuilder +1 -0
- data/app/views/spree/api/errors/invalid_api_key.json.jbuilder +1 -0
- data/app/views/spree/api/errors/invalid_resource.json.jbuilder +2 -0
- data/app/views/spree/api/errors/must_specify_api_key.json.jbuilder +1 -0
- data/app/views/spree/api/errors/not_found.json.jbuilder +1 -0
- data/app/views/spree/api/errors/unauthorized.json.jbuilder +1 -0
- data/app/views/spree/api/errors/variant_not_in_stock_transfer.json.jbuilder +1 -0
- data/app/views/spree/api/images/_image.json.jbuilder +5 -0
- data/app/views/spree/api/images/index.json.jbuilder +3 -0
- data/app/views/spree/api/images/show.json.jbuilder +1 -0
- data/app/views/spree/api/inventory_units/show.json.jbuilder +1 -0
- data/app/views/spree/api/line_items/_line_item.json.jbuilder +16 -0
- data/app/views/spree/api/line_items/new.json.jbuilder +2 -0
- data/app/views/spree/api/line_items/show.json.jbuilder +1 -0
- data/app/views/spree/api/option_types/_option_type.json.jbuilder +4 -0
- data/app/views/spree/api/option_types/index.json.jbuilder +3 -0
- data/app/views/spree/api/option_types/show.json.jbuilder +1 -0
- data/app/views/spree/api/option_values/_option_value.json.jbuilder +1 -0
- data/app/views/spree/api/option_values/index.json.jbuilder +3 -0
- data/app/views/spree/api/option_values/show.json.jbuilder +1 -0
- data/app/views/spree/api/orders/_big.json.jbuilder +49 -0
- data/app/views/spree/api/orders/_order.json.jbuilder +10 -0
- data/app/views/spree/api/orders/could_not_apply_coupon.json.jbuilder +1 -0
- data/app/views/spree/api/orders/could_not_transition.json.jbuilder +2 -0
- data/app/views/spree/api/orders/expected_total_mismatch.json.jbuilder +1 -0
- data/app/views/spree/api/orders/index.json.jbuilder +4 -0
- data/app/views/spree/api/orders/invalid_shipping_method.json.jbuilder +1 -0
- data/app/views/spree/api/orders/mine.json.jbuilder +4 -0
- data/app/views/spree/api/orders/show.json.jbuilder +1 -0
- data/app/views/spree/api/payments/credit_over_limit.json.jbuilder +1 -0
- data/app/views/spree/api/payments/index.json.jbuilder +2 -0
- data/app/views/spree/api/payments/new.json.jbuilder +4 -0
- data/app/views/spree/api/payments/show.json.jbuilder +1 -0
- data/app/views/spree/api/payments/update_forbidden.json.jbuilder +1 -0
- data/app/views/spree/api/product_properties/index.json.jbuilder +4 -0
- data/app/views/spree/api/product_properties/new.json.jbuilder +2 -0
- data/app/views/spree/api/product_properties/show.json.jbuilder +1 -0
- data/app/views/spree/api/products/_product.json.jbuilder +34 -0
- data/app/views/spree/api/products/index.json.jbuilder +4 -0
- data/app/views/spree/api/products/new.json.jbuilder +2 -0
- data/app/views/spree/api/products/show.json.jbuilder +1 -0
- data/app/views/spree/api/promotions/handler.json.jbuilder +4 -0
- data/app/views/spree/api/promotions/show.json.jbuilder +1 -0
- data/app/views/spree/api/properties/index.json.jbuilder +4 -0
- data/app/views/spree/api/properties/new.json.jbuilder +2 -0
- data/app/views/spree/api/properties/show.json.jbuilder +1 -0
- data/app/views/spree/api/return_authorizations/index.json.jbuilder +4 -0
- data/app/views/spree/api/return_authorizations/new.json.jbuilder +2 -0
- data/app/views/spree/api/return_authorizations/show.json.jbuilder +1 -0
- data/app/views/spree/api/shared/_pagination.json.jbuilder +5 -0
- data/app/views/spree/api/shipments/_big.json.jbuilder +51 -0
- data/app/views/spree/api/shipments/_small.json.jbuilder +32 -0
- data/app/views/spree/api/shipments/cannot_ready_shipment.json.jbuilder +1 -0
- data/app/views/spree/api/shipments/mine.json.jbuilder +4 -0
- data/app/views/spree/api/shipments/show.json.jbuilder +31 -0
- data/app/views/spree/api/shipping_rates/_shipping_rate.json.jbuilder +2 -0
- data/app/views/spree/api/states/index.json.jbuilder +5 -0
- data/app/views/spree/api/states/show.json.jbuilder +1 -0
- data/app/views/spree/api/stock_items/_stock_item.json.jbuilder +4 -0
- data/app/views/spree/api/stock_items/index.json.jbuilder +4 -0
- data/app/views/spree/api/stock_items/show.json.jbuilder +1 -0
- data/app/views/spree/api/stock_locations/_stock_location.json.jbuilder +15 -0
- data/app/views/spree/api/stock_locations/index.json.jbuilder +4 -0
- data/app/views/spree/api/stock_locations/show.json.jbuilder +1 -0
- data/app/views/spree/api/stock_movements/_stock_movement.json.jbuilder +4 -0
- data/app/views/spree/api/stock_movements/index.json.jbuilder +4 -0
- data/app/views/spree/api/stock_movements/show.json.jbuilder +1 -0
- data/app/views/spree/api/stock_transfers/receive.json.jbuilder +4 -0
- data/app/views/spree/api/store_credit_events/mine.json.jbuilder +5 -0
- data/app/views/spree/api/stores/index.json.jbuilder +1 -0
- data/app/views/spree/api/stores/show.json.jbuilder +1 -0
- data/app/views/spree/api/taxonomies/_nested.json.jbuilder +8 -0
- data/app/views/spree/api/taxonomies/_taxonomy.json.jbuilder +11 -0
- data/app/views/spree/api/taxonomies/index.json.jbuilder +4 -0
- data/app/views/spree/api/taxonomies/jstree.json.jbuilder +6 -0
- data/app/views/spree/api/taxonomies/new.json.jbuilder +2 -0
- data/app/views/spree/api/taxonomies/show.json.jbuilder +1 -0
- data/app/views/spree/api/taxons/_taxon.json.jbuilder +2 -0
- data/app/views/spree/api/taxons/_taxons.json.jbuilder +4 -0
- data/app/views/spree/api/taxons/index.json.jbuilder +7 -0
- data/app/views/spree/api/taxons/jstree.json.jbuilder +8 -0
- data/app/views/spree/api/taxons/new.json.jbuilder +2 -0
- data/app/views/spree/api/taxons/show.json.jbuilder +1 -0
- data/app/views/spree/api/transfer_items/_transfer_item.json.jbuilder +5 -0
- data/app/views/spree/api/transfer_items/show.json.jbuilder +1 -0
- data/app/views/spree/api/users/_user.json.jbuilder +15 -0
- data/app/views/spree/api/users/index.json.jbuilder +4 -0
- data/app/views/spree/api/users/new.json.jbuilder +2 -0
- data/app/views/spree/api/users/show.json.jbuilder +1 -0
- data/app/views/spree/api/variants/_big.json.jbuilder +13 -0
- data/app/views/spree/api/variants/_small.json.jbuilder +16 -0
- data/app/views/spree/api/variants/index.json.jbuilder +4 -0
- data/app/views/spree/api/variants/new.json.jbuilder +2 -0
- data/app/views/spree/api/variants/show.json.jbuilder +1 -0
- data/app/views/spree/api/zones/_zone.json.jbuilder +4 -0
- data/app/views/spree/api/zones/index.json.jbuilder +4 -0
- data/app/views/spree/api/zones/show.json.jbuilder +1 -0
- data/config/locales/en.yml +1 -0
- data/lib/spree/api/engine.rb +0 -14
- data/lib/spree/api.rb +1 -1
- data/lib/spree_api.rb +1 -0
- data/solidus_api.gemspec +3 -1
- data/spec/controllers/spree/api/base_controller_spec.rb +0 -56
- data/spec/requests/spree/api/checkouts_controller_spec.rb +8 -13
- data/spec/requests/spree/api/orders_controller_spec.rb +7 -60
- data/spec/requests/spree/api/payments_controller_spec.rb +0 -11
- data/spec/requests/spree/api/shipments_controller_spec.rb +16 -1
- data/spec/requests/spree/api/states_controller_spec.rb +1 -0
- data/spec/requests/spree/api/taxons_controller_spec.rb +25 -0
- data/spec/requests/spree/api/users_controller_spec.rb +1 -1
- data/spec/support/be_paginated_matcher.rb +7 -0
- data/spec/test_views/spree/api/widgets/_widget.json.jbuilder +1 -0
- data/spec/test_views/spree/api/widgets/index.json.jbuilder +7 -0
- data/spec/test_views/spree/api/widgets/new.json.jbuilder +1 -0
- data/spec/test_views/spree/api/widgets/show.json.jbuilder +1 -0
- metadata +166 -111
- data/app/views/spree/api/address_books/show.v1.rabl +0 -7
- data/app/views/spree/api/addresses/show.v1.rabl +0 -10
- data/app/views/spree/api/adjustments/show.v1.rabl +0 -4
- data/app/views/spree/api/config/money.v1.rabl +0 -2
- data/app/views/spree/api/config/show.v1.rabl +0 -3
- data/app/views/spree/api/countries/index.v1.rabl +0 -7
- data/app/views/spree/api/countries/show.v1.rabl +0 -5
- data/app/views/spree/api/credit_cards/index.v1.rabl +0 -7
- data/app/views/spree/api/credit_cards/show.v1.rabl +0 -7
- data/app/views/spree/api/errors/gateway_error.v1.rabl +0 -2
- data/app/views/spree/api/errors/invalid_api_key.v1.rabl +0 -2
- data/app/views/spree/api/errors/invalid_resource.v1.rabl +0 -3
- data/app/views/spree/api/errors/must_specify_api_key.v1.rabl +0 -2
- data/app/views/spree/api/errors/not_found.v1.rabl +0 -2
- data/app/views/spree/api/errors/unauthorized.v1.rabl +0 -2
- data/app/views/spree/api/errors/variant_not_in_stock_transfer.v1.rabl +0 -2
- data/app/views/spree/api/images/index.v1.rabl +0 -4
- data/app/views/spree/api/images/show.v1.rabl +0 -6
- data/app/views/spree/api/inventory_units/show.rabl +0 -2
- data/app/views/spree/api/line_items/new.v1.rabl +0 -3
- data/app/views/spree/api/line_items/show.v1.rabl +0 -15
- data/app/views/spree/api/option_types/index.v1.rabl +0 -3
- data/app/views/spree/api/option_types/show.v1.rabl +0 -5
- data/app/views/spree/api/option_values/index.v1.rabl +0 -3
- data/app/views/spree/api/option_values/show.v1.rabl +0 -2
- data/app/views/spree/api/orders/could_not_apply_coupon.v1.rabl +0 -2
- data/app/views/spree/api/orders/could_not_transition.v1.rabl +0 -3
- data/app/views/spree/api/orders/expected_total_mismatch.v1.rabl +0 -2
- data/app/views/spree/api/orders/index.v1.rabl +0 -7
- data/app/views/spree/api/orders/invalid_shipping_method.v1.rabl +0 -2
- data/app/views/spree/api/orders/mine.v1.rabl +0 -9
- data/app/views/spree/api/orders/order.v1.rabl +0 -9
- data/app/views/spree/api/orders/show.v1.rabl +0 -53
- data/app/views/spree/api/payments/credit_over_limit.v1.rabl +0 -2
- data/app/views/spree/api/payments/index.v1.rabl +0 -7
- data/app/views/spree/api/payments/new.v1.rabl +0 -5
- data/app/views/spree/api/payments/show.v1.rabl +0 -2
- data/app/views/spree/api/payments/update_forbidden.v1.rabl +0 -2
- data/app/views/spree/api/product_properties/index.v1.rabl +0 -7
- data/app/views/spree/api/product_properties/new.v1.rabl +0 -2
- data/app/views/spree/api/product_properties/show.v1.rabl +0 -2
- data/app/views/spree/api/products/index.v1.rabl +0 -9
- data/app/views/spree/api/products/new.v1.rabl +0 -3
- data/app/views/spree/api/products/product.v1.rabl +0 -1
- data/app/views/spree/api/products/show.v1.rabl +0 -42
- data/app/views/spree/api/promotions/handler.v1.rabl +0 -5
- data/app/views/spree/api/promotions/show.v1.rabl +0 -2
- data/app/views/spree/api/properties/index.v1.rabl +0 -7
- data/app/views/spree/api/properties/new.v1.rabl +0 -2
- data/app/views/spree/api/properties/show.v1.rabl +0 -2
- data/app/views/spree/api/return_authorizations/index.v1.rabl +0 -7
- data/app/views/spree/api/return_authorizations/new.v1.rabl +0 -3
- data/app/views/spree/api/return_authorizations/show.v1.rabl +0 -2
- data/app/views/spree/api/shipments/big.v1.rabl +0 -55
- data/app/views/spree/api/shipments/cannot_ready_shipment.v1.rabl +0 -2
- data/app/views/spree/api/shipments/mine.v1.rabl +0 -9
- data/app/views/spree/api/shipments/show.v1.rabl +0 -32
- data/app/views/spree/api/shipments/small.v1.rabl +0 -37
- data/app/views/spree/api/shipping_rates/show.v1.rabl +0 -2
- data/app/views/spree/api/states/index.v1.rabl +0 -14
- data/app/views/spree/api/states/show.v1.rabl +0 -2
- data/app/views/spree/api/stock_items/index.v1.rabl +0 -7
- data/app/views/spree/api/stock_items/show.v1.rabl +0 -5
- data/app/views/spree/api/stock_locations/index.v1.rabl +0 -7
- data/app/views/spree/api/stock_locations/show.v1.rabl +0 -8
- data/app/views/spree/api/stock_movements/index.v1.rabl +0 -7
- data/app/views/spree/api/stock_movements/show.v1.rabl +0 -5
- data/app/views/spree/api/stock_transfers/receive.v1.rabl +0 -5
- data/app/views/spree/api/store_credit_events/mine.v1.rabl +0 -10
- data/app/views/spree/api/stores/index.v1.rabl +0 -4
- data/app/views/spree/api/stores/show.v1.rabl +0 -2
- data/app/views/spree/api/taxonomies/index.v1.rabl +0 -7
- data/app/views/spree/api/taxonomies/jstree.rabl +0 -8
- data/app/views/spree/api/taxonomies/nested.v1.rabl +0 -11
- data/app/views/spree/api/taxonomies/new.v1.rabl +0 -3
- data/app/views/spree/api/taxonomies/show.v1.rabl +0 -15
- data/app/views/spree/api/taxons/index.v1.rabl +0 -12
- data/app/views/spree/api/taxons/jstree.rabl +0 -8
- data/app/views/spree/api/taxons/new.v1.rabl +0 -3
- data/app/views/spree/api/taxons/show.v1.rabl +0 -6
- data/app/views/spree/api/taxons/taxons.v1.rabl +0 -5
- data/app/views/spree/api/transfer_items/show.v1.rabl +0 -6
- data/app/views/spree/api/users/index.v1.rabl +0 -7
- data/app/views/spree/api/users/new.v1.rabl +0 -3
- data/app/views/spree/api/users/show.v1.rabl +0 -10
- data/app/views/spree/api/variants/big.v1.rabl +0 -20
- data/app/views/spree/api/variants/index.v1.rabl +0 -9
- data/app/views/spree/api/variants/new.v1.rabl +0 -2
- data/app/views/spree/api/variants/show.v1.rabl +0 -3
- data/app/views/spree/api/variants/small.v1.rabl +0 -17
- data/app/views/spree/api/zones/index.v1.rabl +0 -7
- data/app/views/spree/api/zones/show.v1.rabl +0 -6
- data/config/initializers/rails5_rabl_hacks.rb +0 -12
- data/spec/test_views/spree/api/widgets/index.v1.rabl +0 -7
- data/spec/test_views/spree/api/widgets/new.v1.rabl +0 -2
- data/spec/test_views/spree/api/widgets/show.v1.rabl +0 -2
@@ -0,0 +1,51 @@
|
|
1
|
+
json.cache! [I18n.locale, shipment] do
|
2
|
+
json.(shipment, *shipment_attributes)
|
3
|
+
json.selected_shipping_rate do
|
4
|
+
if shipment.selected_shipping_rate
|
5
|
+
json.partial!("spree/api/shipping_rates/shipping_rate", shipping_rate: shipment.selected_shipping_rate)
|
6
|
+
else
|
7
|
+
json.nil!
|
8
|
+
end
|
9
|
+
end
|
10
|
+
json.inventory_units(shipment.inventory_units) do |inventory_unit|
|
11
|
+
json.(inventory_unit, *inventory_unit_attributes)
|
12
|
+
json.variant do
|
13
|
+
json.partial!("spree/api/variants/small", variant: inventory_unit.variant)
|
14
|
+
json.(inventory_unit.variant, :product_id)
|
15
|
+
json.images(inventory_unit.variant.images) do |image|
|
16
|
+
json.partial!("spree/api/images/image", image: image)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
json.line_item do
|
20
|
+
json.(inventory_unit.line_item, *line_item_attributes)
|
21
|
+
json.single_display_amount(inventory_unit.line_item.single_display_amount.to_s)
|
22
|
+
json.display_amount(inventory_unit.line_item.display_amount.to_s)
|
23
|
+
json.total(inventory_unit.line_item.total)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
json.order do
|
27
|
+
json.partial!("spree/api/orders/order", order: shipment.order)
|
28
|
+
json.bill_address do
|
29
|
+
if shipment.order.billing_address
|
30
|
+
json.partial!("spree/api/addresses/address", address: shipment.order.billing_address)
|
31
|
+
else
|
32
|
+
json.nil!
|
33
|
+
end
|
34
|
+
end
|
35
|
+
json.ship_address do
|
36
|
+
json.partial!("spree/api/addresses/address", address: shipment.order.shipping_address)
|
37
|
+
end
|
38
|
+
json.adjustments(shipment.order.adjustments) do |adjustment|
|
39
|
+
json.partial!("spree/api/adjustments/adjustment", adjustment: adjustment)
|
40
|
+
end
|
41
|
+
json.payments(shipment.order.payments) do |payment|
|
42
|
+
json.(payment, :id, :amount, :display_amount, :state)
|
43
|
+
json.source do
|
44
|
+
attrs = [:id]
|
45
|
+
(attrs << :cc_type) if payment.source.respond_to?(:cc_type)
|
46
|
+
json.(payment.source, *attrs)
|
47
|
+
end
|
48
|
+
json.payment_method { json.(payment.payment_method, :id, :name) }
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
json.cache! [I18n.locale, shipment] do
|
2
|
+
json.(shipment, *shipment_attributes)
|
3
|
+
json.order_id(shipment.order.number)
|
4
|
+
json.stock_location_name(shipment.stock_location.name)
|
5
|
+
json.shipping_rates(shipment.shipping_rates) do |shipping_rate|
|
6
|
+
json.partial!("spree/api/shipping_rates/shipping_rate", shipping_rate: shipping_rate)
|
7
|
+
end
|
8
|
+
json.selected_shipping_rate do
|
9
|
+
if shipment.selected_shipping_rate
|
10
|
+
json.partial!("spree/api/shipping_rates/shipping_rate", shipping_rate: shipment.selected_shipping_rate)
|
11
|
+
else
|
12
|
+
json.nil!
|
13
|
+
end
|
14
|
+
end
|
15
|
+
json.shipping_methods(shipment.shipping_methods) do |shipping_method|
|
16
|
+
json.(shipping_method, :id, :code, :name)
|
17
|
+
json.zones(shipping_method.zones) do |zone|
|
18
|
+
json.(zone, :id, :name, :description)
|
19
|
+
end
|
20
|
+
json.shipping_categories(shipping_method.shipping_categories) do |shipping_category|
|
21
|
+
json.(shipping_category, :id, :name)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
json.manifest(shipment.manifest) do |manifest_item|
|
25
|
+
json.variant_id manifest_item.variant.id
|
26
|
+
json.quantity(manifest_item.quantity)
|
27
|
+
json.states(manifest_item.states)
|
28
|
+
end
|
29
|
+
json.adjustments(shipment.adjustments) do |adjustment|
|
30
|
+
json.partial!("spree/api/adjustments/adjustment", adjustment: adjustment)
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
json.error(I18n.t(:cannot_ready, scope: "spree.api.shipment"))
|
@@ -0,0 +1,31 @@
|
|
1
|
+
json.cache! [I18n.locale, @shipment] do
|
2
|
+
json.(@shipment, *shipment_attributes)
|
3
|
+
json.order_id(@shipment.order.number)
|
4
|
+
json.stock_location_name(@shipment.stock_location.name)
|
5
|
+
json.shipping_rates(@shipment.shipping_rates) do |shipping_rate|
|
6
|
+
json.partial!("spree/api/shipping_rates/shipping_rate", shipping_rate: shipping_rate)
|
7
|
+
end
|
8
|
+
json.selected_shipping_rate do
|
9
|
+
if @shipment.selected_shipping_rate
|
10
|
+
json.partial!("spree/api/shipping_rates/shipping_rate", shipping_rate: @shipment.selected_shipping_rate)
|
11
|
+
else
|
12
|
+
json.nil!
|
13
|
+
end
|
14
|
+
end
|
15
|
+
json.shipping_methods(@shipment.shipping_methods) do |shipping_method|
|
16
|
+
json.(shipping_method, :id, :name)
|
17
|
+
json.zones(shipping_method.zones) do |zone|
|
18
|
+
json.(zone, :id, :name, :description)
|
19
|
+
end
|
20
|
+
json.shipping_categories(shipping_method.shipping_categories) do |shipping_category|
|
21
|
+
json.(shipping_category, :id, :name)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
json.manifest(@shipment.manifest) do |manifest_item|
|
25
|
+
json.variant do
|
26
|
+
json.partial!("spree/api/variants/small", variant: manifest_item.variant)
|
27
|
+
end
|
28
|
+
json.quantity(manifest_item.quantity)
|
29
|
+
json.states(manifest_item.states)
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
json.(@state, *state_attributes)
|
@@ -0,0 +1 @@
|
|
1
|
+
json.partial!("spree/api/stock_items/stock_item", stock_item: @stock_item)
|
@@ -0,0 +1,15 @@
|
|
1
|
+
json.(stock_location, *stock_location_attributes)
|
2
|
+
json.country do
|
3
|
+
if stock_location.country
|
4
|
+
json.(stock_location.country, *country_attributes)
|
5
|
+
else
|
6
|
+
json.nil!
|
7
|
+
end
|
8
|
+
end
|
9
|
+
json.state do
|
10
|
+
if stock_location.state
|
11
|
+
json.(stock_location.state, *state_attributes)
|
12
|
+
else
|
13
|
+
json.nil!
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
json.partial!("spree/api/stock_locations/stock_location", stock_location: @stock_location)
|
@@ -0,0 +1 @@
|
|
1
|
+
json.partial!("spree/api/stock_movements/stock_movement", stock_movement: @stock_movement)
|
@@ -0,0 +1,5 @@
|
|
1
|
+
json.store_credit_events(@store_credit_events) do |store_credit_event|
|
2
|
+
json.(store_credit_event, *store_credit_history_attributes)
|
3
|
+
json.order_number(store_credit_event.order.try(:number))
|
4
|
+
end
|
5
|
+
json.partial! 'spree/api/shared/pagination', pagination: @store_credit_events
|
@@ -0,0 +1 @@
|
|
1
|
+
json.stores(@stores) { |store| json.(store, *store_attributes) }
|
@@ -0,0 +1 @@
|
|
1
|
+
json.(@store, *store_attributes)
|
@@ -0,0 +1,11 @@
|
|
1
|
+
if params[:set] == "nested"
|
2
|
+
json.partial!("spree/api/taxonomies/nested", taxonomy: taxonomy)
|
3
|
+
else
|
4
|
+
json.(taxonomy, *taxonomy_attributes)
|
5
|
+
json.root do
|
6
|
+
json.(taxonomy.root, *taxon_attributes)
|
7
|
+
json.taxons(taxonomy.root.children) do |taxon|
|
8
|
+
json.(taxon, *taxon_attributes)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
json.partial!("spree/api/taxonomies/taxonomy", taxonomy: @taxonomy)
|
@@ -0,0 +1 @@
|
|
1
|
+
json.partial!("spree/api/taxons/taxon", taxon: @taxon)
|
@@ -0,0 +1 @@
|
|
1
|
+
json.partial!("spree/api/transfer_items/transfer_item", transfer_item: @transfer_item)
|
@@ -0,0 +1,15 @@
|
|
1
|
+
json.(user, *user_attributes)
|
2
|
+
json.bill_address do
|
3
|
+
if user.bill_address
|
4
|
+
json.partial!("spree/api/addresses/address", address: user.bill_address)
|
5
|
+
else
|
6
|
+
json.nil!
|
7
|
+
end
|
8
|
+
end
|
9
|
+
json.ship_address do
|
10
|
+
if user.ship_address
|
11
|
+
json.partial!("spree/api/addresses/address", address: user.ship_address)
|
12
|
+
else
|
13
|
+
json.nil!
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
json.partial!("spree/api/users/user", user: @user)
|
@@ -0,0 +1,13 @@
|
|
1
|
+
json.cache! [I18n.locale, Spree::StockLocation.accessible_by(current_ability), variant] do
|
2
|
+
json.(variant, *variant_attributes)
|
3
|
+
json.partial!("spree/api/variants/small", variant: variant)
|
4
|
+
json.total_on_hand(variant.total_on_hand)
|
5
|
+
json.variant_properties(variant.variant_properties) do |variant_property|
|
6
|
+
json.(variant_property, *variant_property_attributes)
|
7
|
+
end
|
8
|
+
json.stock_items(variant.stock_items.accessible_by(current_ability)) do |stock_item|
|
9
|
+
json.(stock_item, :id, :count_on_hand, :stock_location_id, :backorderable)
|
10
|
+
json.available stock_item.available?
|
11
|
+
json.stock_location_name(stock_item.stock_location.name)
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
json.cache! [I18n.locale, variant] do
|
2
|
+
json.(variant, *variant_attributes)
|
3
|
+
json.display_price(variant.display_price.to_s)
|
4
|
+
json.options_text(variant.options_text)
|
5
|
+
json.track_inventory(variant.should_track_inventory?)
|
6
|
+
json.in_stock(variant.in_stock?)
|
7
|
+
json.is_backorderable(variant.is_backorderable?)
|
8
|
+
json.total_on_hand(variant.total_on_hand)
|
9
|
+
json.is_destroyed(variant.destroyed?)
|
10
|
+
json.option_values(variant.option_values) do |option_value|
|
11
|
+
json.(option_value, *option_value_attributes)
|
12
|
+
end
|
13
|
+
json.images(variant.images) do |image|
|
14
|
+
json.partial!("spree/api/images/image", image: image)
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
json.partial!("spree/api/variants/big", variant: @variant)
|
@@ -0,0 +1 @@
|
|
1
|
+
json.partial!("spree/api/zones/zone", zone: @zone)
|
data/config/locales/en.yml
CHANGED
@@ -7,6 +7,7 @@ en:
|
|
7
7
|
invalid_resource: "Invalid resource. Please fix errors and try again."
|
8
8
|
resource_not_found: "The resource you were looking for could not be found."
|
9
9
|
gateway_error: "There was a problem with the payment gateway: %{text}"
|
10
|
+
delete_restriction_error: "Cannot delete record."
|
10
11
|
access: "API Access"
|
11
12
|
key: "Key"
|
12
13
|
clear_key: "Clear key"
|
data/lib/spree/api/engine.rb
CHANGED
@@ -6,16 +6,6 @@ module Spree
|
|
6
6
|
isolate_namespace Spree
|
7
7
|
engine_name 'spree_api'
|
8
8
|
|
9
|
-
Rabl.configure do |config|
|
10
|
-
config.include_json_root = false
|
11
|
-
config.include_child_root = false
|
12
|
-
|
13
|
-
# Motivation here it make it call as_json when rendering timestamps
|
14
|
-
# and therefore display miliseconds. Otherwise it would fall to
|
15
|
-
# JSON.dump which doesn't display the miliseconds
|
16
|
-
config.json_engine = ActiveSupport::JSON
|
17
|
-
end
|
18
|
-
|
19
9
|
initializer "spree.api.environment", before: :load_config_initializers do |_app|
|
20
10
|
Spree::Api::Config = Spree::ApiConfiguration.new
|
21
11
|
end
|
@@ -29,10 +19,6 @@ module Spree
|
|
29
19
|
config.extraction_strategy = :http_header
|
30
20
|
end
|
31
21
|
end
|
32
|
-
|
33
|
-
def self.root
|
34
|
-
@root ||= Pathname.new(File.expand_path('../../../../', __FILE__))
|
35
|
-
end
|
36
22
|
end
|
37
23
|
end
|
38
24
|
end
|
data/lib/spree/api.rb
CHANGED
data/lib/spree_api.rb
CHANGED
data/solidus_api.gemspec
CHANGED
@@ -21,6 +21,8 @@ Gem::Specification.new do |gem|
|
|
21
21
|
gem.required_rubygems_version = '>= 1.8.23'
|
22
22
|
|
23
23
|
gem.add_dependency 'solidus_core', gem.version
|
24
|
-
gem.add_dependency 'rabl', '0.13.0' # FIXME: update for proper rails 5 support
|
25
24
|
gem.add_dependency 'versioncake', '~> 3.0'
|
25
|
+
gem.add_dependency 'responders'
|
26
|
+
gem.add_dependency 'jbuilder', '~> 2.6'
|
27
|
+
gem.add_dependency 'kaminari', '>= 0.17', '< 2.0'
|
26
28
|
end
|
@@ -62,66 +62,10 @@ describe Spree::Api::BaseController, type: :controller do
|
|
62
62
|
end
|
63
63
|
end
|
64
64
|
|
65
|
-
it 'chatches StandardError' do
|
66
|
-
expect(subject).to receive(:authenticate_user).and_return(true)
|
67
|
-
expect(subject).to receive(:load_user_roles).and_return(true)
|
68
|
-
expect(subject).to receive(:index).and_raise("no joy")
|
69
|
-
get :index, params: { token: "fake_key" }
|
70
|
-
expect(json_response).to eq({ "exception" => "no joy" })
|
71
|
-
expect(response.content_type).to eq("application/json")
|
72
|
-
end
|
73
|
-
|
74
|
-
it 'raises Exception' do
|
75
|
-
expect(subject).to receive(:authenticate_user).and_return(true)
|
76
|
-
expect(subject).to receive(:load_user_roles).and_return(true)
|
77
|
-
expect(subject).to receive(:index).and_raise(Exception.new("no joy"))
|
78
|
-
expect {
|
79
|
-
get :index, params: { token: "fake_key" }
|
80
|
-
}.to raise_error(Exception, "no joy")
|
81
|
-
end
|
82
|
-
|
83
65
|
it "lets a subclass override the product associations that are eager-loaded" do
|
84
66
|
expect(controller.respond_to?(:product_includes, true)).to be
|
85
67
|
end
|
86
68
|
|
87
|
-
describe '#error_during_processing' do
|
88
|
-
controller(FakesController) do
|
89
|
-
# GET /foo
|
90
|
-
# Simulates a failed API call.
|
91
|
-
def foo
|
92
|
-
raise StandardError
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
# What would be placed in config/initializers/spree.rb
|
97
|
-
Spree::Api::BaseController.error_notifier = proc do |e, controller|
|
98
|
-
MockHoneybadger.notify_or_ignore(e, rack_env: controller.request.env)
|
99
|
-
end
|
100
|
-
|
101
|
-
##
|
102
|
-
# Fake HB alert class
|
103
|
-
class MockHoneybadger
|
104
|
-
# https://github.com/honeybadger-io/honeybadger-ruby/blob/master/lib/honeybadger.rb#L136
|
105
|
-
def self.notify_or_ignore(_exception, _opts = {})
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
before do
|
110
|
-
user = double(email: "spree@example.com")
|
111
|
-
allow(user).to receive_message_chain :spree_roles, pluck: []
|
112
|
-
allow(Spree.user_class).to receive_messages find_by: user
|
113
|
-
@routes = ActionDispatch::Routing::RouteSet.new.tap do |r|
|
114
|
-
r.draw { get 'foo' => 'fakes#foo' }
|
115
|
-
end
|
116
|
-
end
|
117
|
-
|
118
|
-
it 'should notify notify_error_during_processing' do
|
119
|
-
expect(MockHoneybadger).to receive(:notify_or_ignore).once.with(kind_of(Exception), rack_env: kind_of(Hash))
|
120
|
-
get :foo, params: { token: 123 }
|
121
|
-
expect(response.status).to eq(422)
|
122
|
-
end
|
123
|
-
end
|
124
|
-
|
125
69
|
context 'insufficient stock' do
|
126
70
|
before do
|
127
71
|
expect(subject).to receive(:authenticate_user).and_return(true)
|
@@ -154,19 +154,6 @@ module Spree
|
|
154
154
|
expect(response.status).to eq(200)
|
155
155
|
end
|
156
156
|
|
157
|
-
context "with disallowed payment method" do
|
158
|
-
it "returns not found" do
|
159
|
-
order.update_column(:state, "payment")
|
160
|
-
allow_any_instance_of(Spree::PaymentMethod::BogusCreditCard).to receive(:source_required?).and_return(false)
|
161
|
-
@payment_method.update!(available_to_users: false)
|
162
|
-
expect {
|
163
|
-
put spree.api_checkout_path(order.to_param), params: { order_token: order.guest_token, order: { payments_attributes: [{ payment_method_id: @payment_method.id }] } }
|
164
|
-
}.not_to change { Spree::Payment.count }
|
165
|
-
expect(response.status).to eq(404)
|
166
|
-
end
|
167
|
-
end
|
168
|
-
|
169
|
-
|
170
157
|
it "returns errors when source is required and missing" do
|
171
158
|
order.update_column(:state, "payment")
|
172
159
|
put spree.api_checkout_path(order.to_param), params: { order_token: order.guest_token, order: { payments_attributes: [{ payment_method_id: @payment_method.id }] } }
|
@@ -362,6 +349,14 @@ module Spree
|
|
362
349
|
expect(PromotionHandler::Coupon).to receive(:new).with(order).and_call_original
|
363
350
|
expect_any_instance_of(PromotionHandler::Coupon).to receive(:apply).and_return({ coupon_applied?: true })
|
364
351
|
put spree.api_checkout_path(order.to_param), params: { order_token: order.guest_token, order: { coupon_code: "foobar" } }
|
352
|
+
expect(response.status).to eq(200)
|
353
|
+
end
|
354
|
+
|
355
|
+
it "renders error failing to apply coupon" do
|
356
|
+
order.update_column(:state, "payment")
|
357
|
+
put spree.api_checkout_path(order.to_param), params: { order_token: order.guest_token, order: { coupon_code: "foobar" } }
|
358
|
+
expect(response.status).to eq(422)
|
359
|
+
expect(json_response).to eq({ "error" => "The coupon code you entered doesn't exist. Please try again." })
|
365
360
|
end
|
366
361
|
end
|
367
362
|
|