spree_api 3.3.6 → 3.4.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.
Files changed (85) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/spree/api/base_controller.rb +17 -21
  3. data/app/controllers/spree/api/v1/countries_controller.rb +2 -4
  4. data/app/controllers/spree/api/v1/credit_cards_controller.rb +9 -10
  5. data/app/controllers/spree/api/v1/images_controller.rb +1 -2
  6. data/app/controllers/spree/api/v1/inventory_units_controller.rb +2 -2
  7. data/app/controllers/spree/api/v1/line_items_controller.rb +24 -28
  8. data/app/controllers/spree/api/v1/option_types_controller.rb +5 -5
  9. data/app/controllers/spree/api/v1/option_values_controller.rb +16 -17
  10. data/app/controllers/spree/api/v1/orders_controller.rb +39 -49
  11. data/app/controllers/spree/api/v1/payments_controller.rb +15 -17
  12. data/app/controllers/spree/api/v1/product_properties_controller.rb +2 -3
  13. data/app/controllers/spree/api/v1/products_controller.rb +24 -25
  14. data/app/controllers/spree/api/v1/promotions_controller.rb +9 -8
  15. data/app/controllers/spree/api/v1/properties_controller.rb +14 -16
  16. data/app/controllers/spree/api/v1/return_authorizations_controller.rb +0 -1
  17. data/app/controllers/spree/api/v1/shipments_controller.rb +17 -26
  18. data/app/controllers/spree/api/v1/states_controller.rb +9 -10
  19. data/app/controllers/spree/api/v1/stock_items_controller.rb +2 -2
  20. data/app/controllers/spree/api/v1/stores_controller.rb +0 -1
  21. data/app/controllers/spree/api/v1/tags_controller.rb +1 -1
  22. data/app/controllers/spree/api/v1/taxonomies_controller.rb +1 -3
  23. data/app/controllers/spree/api/v1/taxons_controller.rb +15 -16
  24. data/app/controllers/spree/api/v1/users_controller.rb +1 -4
  25. data/app/controllers/spree/api/v1/variants_controller.rb +22 -22
  26. data/app/controllers/spree/api/v1/zones_controller.rb +0 -1
  27. data/app/helpers/spree/api/api_helpers.rb +5 -5
  28. data/app/views/spree/api/errors/gateway_error.v1.rabl +1 -1
  29. data/app/views/spree/api/errors/invalid_api_key.v1.rabl +1 -1
  30. data/app/views/spree/api/errors/invalid_resource.v1.rabl +1 -1
  31. data/app/views/spree/api/errors/must_specify_api_key.v1.rabl +1 -1
  32. data/app/views/spree/api/errors/not_found.v1.rabl +1 -1
  33. data/app/views/spree/api/errors/unauthorized.v1.rabl +1 -1
  34. data/app/views/spree/api/v1/addresses/show.v1.rabl +2 -2
  35. data/app/views/spree/api/v1/credit_cards/index.v1.rabl +1 -1
  36. data/app/views/spree/api/v1/images/index.v1.rabl +1 -1
  37. data/app/views/spree/api/v1/images/show.v1.rabl +1 -1
  38. data/app/views/spree/api/v1/line_items/show.v1.rabl +3 -3
  39. data/app/views/spree/api/v1/option_types/index.v1.rabl +1 -1
  40. data/app/views/spree/api/v1/option_types/show.v1.rabl +1 -1
  41. data/app/views/spree/api/v1/option_values/index.v1.rabl +1 -1
  42. data/app/views/spree/api/v1/option_values/show.v1.rabl +1 -1
  43. data/app/views/spree/api/v1/orders/could_not_transition.v1.rabl +1 -1
  44. data/app/views/spree/api/v1/orders/index.v1.rabl +1 -1
  45. data/app/views/spree/api/v1/orders/invalid_shipping_method.v1.rabl +1 -1
  46. data/app/views/spree/api/v1/orders/mine.v1.rabl +1 -1
  47. data/app/views/spree/api/v1/orders/order.v1.rabl +5 -5
  48. data/app/views/spree/api/v1/orders/show.v1.rabl +7 -7
  49. data/app/views/spree/api/v1/product_properties/index.v1.rabl +1 -1
  50. data/app/views/spree/api/v1/product_properties/new.v1.rabl +1 -1
  51. data/app/views/spree/api/v1/products/index.v1.rabl +1 -1
  52. data/app/views/spree/api/v1/products/show.v1.rabl +5 -5
  53. data/app/views/spree/api/v1/return_authorizations/show.v1.rabl +1 -1
  54. data/app/views/spree/api/v1/shared/stock_location_required.v1.rabl +1 -1
  55. data/app/views/spree/api/v1/shipments/big.v1.rabl +8 -8
  56. data/app/views/spree/api/v1/shipments/cannot_ready_shipment.v1.rabl +1 -1
  57. data/app/views/spree/api/v1/shipments/mine.v1.rabl +1 -1
  58. data/app/views/spree/api/v1/shipments/show.v1.rabl +5 -5
  59. data/app/views/spree/api/v1/shipments/small.v1.rabl +5 -5
  60. data/app/views/spree/api/v1/shipping_rates/show.v1.rabl +1 -1
  61. data/app/views/spree/api/v1/states/index.v1.rabl +1 -3
  62. data/app/views/spree/api/v1/stock_items/show.v1.rabl +1 -1
  63. data/app/views/spree/api/v1/stock_locations/show.v1.rabl +2 -2
  64. data/app/views/spree/api/v1/stock_movements/show.v1.rabl +1 -1
  65. data/app/views/spree/api/v1/taxonomies/index.v1.rabl +1 -1
  66. data/app/views/spree/api/v1/taxonomies/jstree.rabl +2 -3
  67. data/app/views/spree/api/v1/taxonomies/nested.v1.rabl +1 -1
  68. data/app/views/spree/api/v1/taxonomies/show.v1.rabl +1 -1
  69. data/app/views/spree/api/v1/taxons/index.v1.rabl +1 -3
  70. data/app/views/spree/api/v1/taxons/jstree.rabl +3 -4
  71. data/app/views/spree/api/v1/taxons/taxons.v1.rabl +1 -1
  72. data/app/views/spree/api/v1/users/index.v1.rabl +1 -1
  73. data/app/views/spree/api/v1/users/show.v1.rabl +3 -3
  74. data/app/views/spree/api/v1/variants/big.v1.rabl +1 -1
  75. data/app/views/spree/api/v1/variants/index.v1.rabl +1 -1
  76. data/app/views/spree/api/v1/variants/show.v1.rabl +1 -1
  77. data/app/views/spree/api/v1/variants/small.v1.rabl +7 -7
  78. data/config/routes.rb +3 -3
  79. data/lib/spree/api/controller_setup.rb +2 -2
  80. data/lib/spree/api/engine.rb +3 -3
  81. data/lib/spree/api/responders/rabl_template.rb +1 -3
  82. data/lib/spree/api/testing_support/caching.rb +3 -3
  83. data/lib/spree/api/testing_support/helpers.rb +4 -4
  84. data/lib/spree/api/testing_support/setup.rb +2 -2
  85. metadata +7 -7
@@ -2,7 +2,6 @@ module Spree
2
2
  module Api
3
3
  module V1
4
4
  class PaymentsController < Spree::Api::BaseController
5
-
6
5
  before_action :find_order
7
6
  before_action :find_payment, only: [:update, :show, :authorize, :purchase, :capture, :void]
8
7
 
@@ -17,7 +16,6 @@ module Spree
17
16
  end
18
17
 
19
18
  def create
20
- @order.validate_payments_attributes([payment_params])
21
19
  @payment = @order.payments.build(payment_params)
22
20
  if @payment.save
23
21
  respond_with(@payment, status: 201, default_template: :show)
@@ -59,24 +57,24 @@ module Spree
59
57
 
60
58
  private
61
59
 
62
- def find_order
63
- @order = Spree::Order.find_by!(number: order_id)
64
- authorize! :read, @order, order_token
65
- end
60
+ def find_order
61
+ @order = Spree::Order.find_by!(number: order_id)
62
+ authorize! :read, @order, order_token
63
+ end
66
64
 
67
- def find_payment
68
- @payment = @order.payments.find_by!(number: params[:id])
69
- end
65
+ def find_payment
66
+ @payment = @order.payments.find_by!(number: params[:id])
67
+ end
70
68
 
71
- def perform_payment_action(action, *args)
72
- authorize! action, Payment
73
- @payment.send("#{action}!", *args)
74
- respond_with(@payment, default_template: :show)
75
- end
69
+ def perform_payment_action(action, *args)
70
+ authorize! action, Payment
71
+ @payment.send("#{action}!", *args)
72
+ respond_with(@payment, default_template: :show)
73
+ end
76
74
 
77
- def payment_params
78
- params.require(:payment).permit(permitted_payment_attributes)
79
- end
75
+ def payment_params
76
+ params.require(:payment).permit(permitted_payment_attributes)
77
+ end
80
78
  end
81
79
  end
82
80
  end
@@ -16,8 +16,7 @@ module Spree
16
16
  respond_with(@product_property)
17
17
  end
18
18
 
19
- def new
20
- end
19
+ def new; end
21
20
 
22
21
  def create
23
22
  authorize! :create, ProductProperty
@@ -56,7 +55,7 @@ module Spree
56
55
  if @product
57
56
  @product_property ||= @product.product_properties.find_by(id: params[:id])
58
57
  @product_property ||= @product.product_properties.includes(:property).where(spree_properties: { name: params[:id] }).first
59
- fail ActiveRecord::RecordNotFound unless @product_property
58
+ raise ActiveRecord::RecordNotFound unless @product_property
60
59
  authorize! :read, @product_property
61
60
  end
62
61
  end
@@ -2,10 +2,9 @@ module Spree
2
2
  module Api
3
3
  module V1
4
4
  class ProductsController < Spree::Api::BaseController
5
-
6
5
  def index
7
6
  if params[:ids]
8
- @products = product_scope.where(id: params[:ids].split(",").flatten)
7
+ @products = product_scope.where(id: params[:ids].split(',').flatten)
9
8
  else
10
9
  @products = product_scope.ransack(params[:q]).result
11
10
  end
@@ -20,7 +19,7 @@ module Spree
20
19
  @product = find_product(params[:id])
21
20
  expires_in 15.minutes, public: true
22
21
  headers['Surrogate-Control'] = "max-age=#{15.minutes}"
23
- headers['Surrogate-Key'] = "product_id=1"
22
+ headers['Surrogate-Key'] = 'product_id=1'
24
23
  respond_with(@product)
25
24
  end
26
25
 
@@ -57,8 +56,7 @@ module Spree
57
56
  # shipping_category: "Free Shipping Items"
58
57
  # }
59
58
  #
60
- def new
61
- end
59
+ def new; end
62
60
 
63
61
  def create
64
62
  authorize! :create, Product
@@ -97,32 +95,33 @@ module Spree
97
95
  end
98
96
 
99
97
  private
100
- def product_params
101
- params.require(:product).permit(permitted_product_attributes)
102
- end
103
98
 
104
- def variants_params
105
- variants_key = if params[:product].has_key? :variants
106
- :variants
107
- else
108
- :variants_attributes
109
- end
99
+ def product_params
100
+ params.require(:product).permit(permitted_product_attributes)
101
+ end
110
102
 
111
- params.require(:product).permit(
112
- variants_key => [permitted_variant_attributes, :id],
113
- ).delete(variants_key) || []
103
+ def variants_params
104
+ variants_key = if params[:product].key? :variants
105
+ :variants
106
+ else
107
+ :variants_attributes
114
108
  end
115
109
 
116
- def option_types_params
117
- params[:product].fetch(:option_types, [])
118
- end
110
+ params.require(:product).permit(
111
+ variants_key => [permitted_variant_attributes, :id]
112
+ ).delete(variants_key) || []
113
+ end
114
+
115
+ def option_types_params
116
+ params[:product].fetch(:option_types, [])
117
+ end
119
118
 
120
- def set_up_shipping_category
121
- if shipping_category = params[:product].delete(:shipping_category)
122
- id = ShippingCategory.find_or_create_by(name: shipping_category).id
123
- params[:product][:shipping_category_id] = id
124
- end
119
+ def set_up_shipping_category
120
+ if shipping_category = params[:product].delete(:shipping_category)
121
+ id = ShippingCategory.find_or_create_by(name: shipping_category).id
122
+ params[:product][:shipping_category_id] = id
125
123
  end
124
+ end
126
125
  end
127
126
  end
128
127
  end
@@ -13,15 +13,16 @@ module Spree
13
13
  end
14
14
  end
15
15
 
16
- private
17
- def requires_admin
18
- return if @current_user_roles.include?("admin")
19
- unauthorized and return
20
- end
16
+ private
21
17
 
22
- def load_promotion
23
- @promotion = Spree::Promotion.find_by(id: params[:id]) || Spree::Promotion.with_coupon_code(params[:id])
24
- end
18
+ def requires_admin
19
+ return if @current_user_roles.include?('admin')
20
+ unauthorized and return
21
+ end
22
+
23
+ def load_promotion
24
+ @promotion = Spree::Promotion.find_by(id: params[:id]) || Spree::Promotion.with_coupon_code(params[:id])
25
+ end
25
26
  end
26
27
  end
27
28
  end
@@ -2,17 +2,16 @@ module Spree
2
2
  module Api
3
3
  module V1
4
4
  class PropertiesController < Spree::Api::BaseController
5
-
6
5
  before_action :find_property, only: [:show, :update, :destroy]
7
6
 
8
7
  def index
9
8
  @properties = Spree::Property.accessible_by(current_ability, :read)
10
9
 
11
- if params[:ids]
12
- @properties = @properties.where(id: params[:ids].split(",").flatten)
13
- else
14
- @properties = @properties.ransack(params[:q]).result
15
- end
10
+ @properties = if params[:ids]
11
+ @properties.where(id: params[:ids].split(',').flatten)
12
+ else
13
+ @properties.ransack(params[:q]).result
14
+ end
16
15
 
17
16
  @properties = @properties.page(params[:page]).per(params[:per_page])
18
17
  respond_with(@properties)
@@ -22,8 +21,7 @@ module Spree
22
21
  respond_with(@property)
23
22
  end
24
23
 
25
- def new
26
- end
24
+ def new; end
27
25
 
28
26
  def create
29
27
  authorize! :create, Property
@@ -57,15 +55,15 @@ module Spree
57
55
 
58
56
  private
59
57
 
60
- def find_property
61
- @property = Spree::Property.accessible_by(current_ability, :read).find(params[:id])
62
- rescue ActiveRecord::RecordNotFound
63
- @property = Spree::Property.accessible_by(current_ability, :read).find_by!(name: params[:id])
64
- end
58
+ def find_property
59
+ @property = Spree::Property.accessible_by(current_ability, :read).find(params[:id])
60
+ rescue ActiveRecord::RecordNotFound
61
+ @property = Spree::Property.accessible_by(current_ability, :read).find_by!(name: params[:id])
62
+ end
65
63
 
66
- def property_params
67
- params.require(:property).permit(permitted_property_attributes)
68
- end
64
+ def property_params
65
+ params.require(:property).permit(permitted_property_attributes)
66
+ end
69
67
  end
70
68
  end
71
69
  end
@@ -2,7 +2,6 @@ module Spree
2
2
  module Api
3
3
  module V1
4
4
  class ReturnAuthorizationsController < Spree::Api::BaseController
5
-
6
5
  def create
7
6
  authorize! :create, ReturnAuthorization
8
7
  @return_authorization = order.return_authorizations.build(return_authorization_params)
@@ -2,20 +2,19 @@ module Spree
2
2
  module Api
3
3
  module V1
4
4
  class ShipmentsController < Spree::Api::BaseController
5
-
6
5
  before_action :find_and_update_shipment, only: [:ship, :ready, :add, :remove]
7
6
  before_action :load_transfer_params, only: [:transfer_to_location, :transfer_to_shipment]
8
7
 
9
8
  def mine
10
9
  if current_api_user.persisted?
11
- @shipments = Spree::Shipment
12
- .reverse_chronological
13
- .joins(:order)
14
- .where(spree_orders: {user_id: current_api_user.id})
15
- .includes(mine_includes)
16
- .ransack(params[:q]).result.page(params[:page]).per(params[:per_page])
10
+ @shipments = Spree::Shipment.
11
+ reverse_chronological.
12
+ joins(:order).
13
+ where(spree_orders: { user_id: current_api_user.id }).
14
+ includes(mine_includes).
15
+ ransack(params[:q]).result.page(params[:page]).per(params[:per_page])
17
16
  else
18
- render "spree/api/errors/unauthorized", status: :unauthorized
17
+ render 'spree/api/errors/unauthorized', status: :unauthorized
19
18
  end
20
19
  end
21
20
 
@@ -25,7 +24,9 @@ module Spree
25
24
  authorize! :create, Shipment
26
25
  quantity = params[:quantity].to_i
27
26
  @shipment = @order.shipments.create(stock_location_id: params.fetch(:stock_location_id))
28
- @order.contents.add(variant, quantity, {shipment: @shipment})
27
+ @order.contents.add(variant, quantity, shipment: @shipment)
28
+
29
+ @shipment.save!
29
30
 
30
31
  respond_with(@shipment.reload, default_template: :show)
31
32
  end
@@ -49,9 +50,7 @@ module Spree
49
50
  end
50
51
 
51
52
  def ship
52
- unless @shipment.shipped?
53
- @shipment.ship!
54
- end
53
+ @shipment.ship! unless @shipment.shipped?
55
54
  respond_with(@shipment, default_template: :show)
56
55
  end
57
56
 
@@ -59,23 +58,15 @@ module Spree
59
58
  quantity = params[:quantity].to_i
60
59
 
61
60
  @shipment.order.contents.add(variant, quantity, shipment: @shipment)
61
+
62
62
  respond_with(@shipment, default_template: :show)
63
63
  end
64
64
 
65
65
  def remove
66
- quantity = if params.key?(:quantity)
67
- params[:quantity].to_i
68
- else
69
- @shipment.inventory_units_for(variant).sum(:quantity)
70
- end
71
- @shipment.order.contents.remove(variant, quantity, shipment: @shipment)
72
-
73
- if @shipment.inventory_units.any?
74
- @shipment.reload
75
- else
76
- @shipment.destroy!
77
- end
66
+ quantity = params[:quantity].to_i
78
67
 
68
+ @shipment.order.contents.remove(variant, quantity, shipment: @shipment)
69
+ @shipment.reload if @shipment.persisted?
79
70
  respond_with(@shipment, default_template: :show)
80
71
  end
81
72
 
@@ -88,7 +79,7 @@ module Spree
88
79
  end
89
80
 
90
81
  @original_shipment.transfer_to_location(@variant, @quantity, @stock_location)
91
- render json: {success: true, message: Spree.t(:shipment_transfer_success)}, status: 201
82
+ render json: { success: true, message: Spree.t(:shipment_transfer_success) }, status: 201
92
83
  end
93
84
 
94
85
  def transfer_to_shipment
@@ -100,7 +91,7 @@ module Spree
100
91
  end
101
92
 
102
93
  @original_shipment.transfer_to_shipment(@variant, @quantity, @target_shipment)
103
- render json: {success: true, message: Spree.t(:shipment_transfer_success)}, status: 201
94
+ render json: { success: true, message: Spree.t(:shipment_transfer_success) }, status: 201
104
95
  end
105
96
 
106
97
  private
@@ -12,9 +12,7 @@ module Spree
12
12
  end
13
13
 
14
14
  state = @states.last
15
- if stale?(state)
16
- respond_with(@states)
17
- end
15
+ respond_with(@states) if stale?(state)
18
16
  end
19
17
 
20
18
  def show
@@ -23,14 +21,15 @@ module Spree
23
21
  end
24
22
 
25
23
  private
26
- def scope
27
- if params[:country_id]
28
- @country = Country.accessible_by(current_ability, :read).find(params[:country_id])
29
- return @country.states.accessible_by(current_ability, :read).order('name ASC')
30
- else
31
- return State.accessible_by(current_ability, :read).order('name ASC')
32
- end
24
+
25
+ def scope
26
+ if params[:country_id]
27
+ @country = Country.accessible_by(current_ability, :read).find(params[:country_id])
28
+ @country.states.accessible_by(current_ability, :read).order('name ASC')
29
+ else
30
+ State.accessible_by(current_ability, :read).order('name ASC')
33
31
  end
32
+ end
34
33
  end
35
34
  end
36
35
  end
@@ -18,7 +18,7 @@ module Spree
18
18
  authorize! :create, StockItem
19
19
 
20
20
  count_on_hand = 0
21
- if params[:stock_item].has_key?(:count_on_hand)
21
+ if params[:stock_item].key?(:count_on_hand)
22
22
  count_on_hand = params[:stock_item][:count_on_hand].to_i
23
23
  end
24
24
 
@@ -35,7 +35,7 @@ module Spree
35
35
  @stock_item = StockItem.accessible_by(current_ability, :update).find(params[:id])
36
36
 
37
37
  count_on_hand = 0
38
- if params[:stock_item].has_key?(:count_on_hand)
38
+ if params[:stock_item].key?(:count_on_hand)
39
39
  count_on_hand = params[:stock_item][:count_on_hand].to_i
40
40
  params[:stock_item].delete(:count_on_hand)
41
41
  end
@@ -2,7 +2,6 @@ module Spree
2
2
  module Api
3
3
  module V1
4
4
  class StoresController < Spree::Api::BaseController
5
-
6
5
  before_action :get_store, except: [:index, :create]
7
6
 
8
7
  def index
@@ -5,7 +5,7 @@ module Spree
5
5
  def index
6
6
  @tags =
7
7
  if params[:ids]
8
- Tag.where(id: params[:ids].split(",").flatten)
8
+ Tag.where(id: params[:ids].split(',').flatten)
9
9
  else
10
10
  Tag.ransack(params[:q]).result
11
11
  end
@@ -2,7 +2,6 @@ module Spree
2
2
  module Api
3
3
  module V1
4
4
  class TaxonomiesController < Spree::Api::BaseController
5
-
6
5
  def index
7
6
  respond_with(taxonomies)
8
7
  end
@@ -16,8 +15,7 @@ module Spree
16
15
  show
17
16
  end
18
17
 
19
- def new
20
- end
18
+ def new; end
21
19
 
22
20
  def create
23
21
  authorize! :create, Taxonomy
@@ -26,8 +26,7 @@ module Spree
26
26
  show
27
27
  end
28
28
 
29
- def new
30
- end
29
+ def new; end
31
30
 
32
31
  def create
33
32
  authorize! :create, Taxon
@@ -70,28 +69,28 @@ module Spree
70
69
  taxon = Spree::Taxon.find(params[:id])
71
70
  @products = taxon.products.ransack(params[:q]).result
72
71
  @products = @products.page(params[:page]).per(params[:per_page] || 500)
73
- render "spree/api/v1/products/index"
72
+ render 'spree/api/v1/products/index'
74
73
  end
75
74
 
76
75
  private
77
76
 
78
- def taxonomy
79
- if params[:taxonomy_id].present?
80
- @taxonomy ||= Spree::Taxonomy.accessible_by(current_ability, :read).find(params[:taxonomy_id])
81
- end
77
+ def taxonomy
78
+ if params[:taxonomy_id].present?
79
+ @taxonomy ||= Spree::Taxonomy.accessible_by(current_ability, :read).find(params[:taxonomy_id])
82
80
  end
81
+ end
83
82
 
84
- def taxon
85
- @taxon ||= taxonomy.taxons.accessible_by(current_ability, :read).find(params[:id])
86
- end
83
+ def taxon
84
+ @taxon ||= taxonomy.taxons.accessible_by(current_ability, :read).find(params[:id])
85
+ end
87
86
 
88
- def taxon_params
89
- if params[:taxon] && !params[:taxon].empty?
90
- params.require(:taxon).permit(permitted_taxon_attributes)
91
- else
92
- {}
93
- end
87
+ def taxon_params
88
+ if params[:taxon] && !params[:taxon].empty?
89
+ params.require(:taxon).permit(permitted_taxon_attributes)
90
+ else
91
+ {}
94
92
  end
93
+ end
95
94
  end
96
95
  end
97
96
  end