spree_api 4.4.0 → 4.5.0

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 (176) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/concerns/spree/api/v2/product_list_includes.rb +10 -8
  3. data/app/controllers/spree/api/v2/platform/orders_controller.rb +1 -1
  4. data/app/controllers/spree/api/v2/platform/products_controller.rb +5 -1
  5. data/app/controllers/spree/api/v2/storefront/checkout_controller.rb +1 -1
  6. data/app/controllers/spree/api/v2/storefront/digitals_controller.rb +5 -1
  7. data/app/controllers/spree/api/v2/storefront/stores_controller.rb +4 -0
  8. data/app/helpers/spree/api/v2/store_media_serializer_images_concern.rb +35 -0
  9. data/app/models/concerns/spree/webhooks/has_webhooks.rb +31 -7
  10. data/app/models/spree/api/webhooks/product_decorator.rb +21 -2
  11. data/app/models/spree/webhooks/subscriber.rb +4 -0
  12. data/app/serializers/spree/api/v2/platform/cms_section_image_one_serializer.rb +9 -0
  13. data/app/serializers/spree/api/v2/platform/cms_section_image_three_serializer.rb +9 -0
  14. data/app/serializers/spree/api/v2/platform/cms_section_image_two_serializer.rb +9 -0
  15. data/app/serializers/spree/api/v2/platform/hero_image_serializer.rb +10 -0
  16. data/app/serializers/spree/api/v2/platform/image_gallery_serializer.rb +10 -0
  17. data/app/serializers/spree/api/v2/platform/side_by_side_image_serializer.rb +10 -0
  18. data/app/serializers/spree/api/v2/platform/store_serializer.rb +1 -0
  19. data/app/serializers/spree/api/v2/platform/user_serializer.rb +1 -1
  20. data/app/serializers/spree/v2/storefront/cms_section_serializer.rb +3 -3
  21. data/app/serializers/spree/v2/storefront/order_serializer.rb +9 -0
  22. data/app/serializers/spree/v2/storefront/product_property_serializer.rb +1 -1
  23. data/app/serializers/spree/v2/storefront/product_serializer.rb +1 -1
  24. data/app/serializers/spree/v2/storefront/shipment_serializer.rb +3 -0
  25. data/app/serializers/spree/v2/storefront/store_serializer.rb +5 -10
  26. data/app/serializers/spree/v2/storefront/user_serializer.rb +1 -1
  27. data/app/serializers/spree/v2/storefront/variant_serializer.rb +1 -1
  28. data/app/services/spree/webhooks/subscribers/queue_requests.rb +8 -2
  29. data/config/routes.rb +1 -120
  30. data/docs/v2/platform/index.yaml +1597 -998
  31. data/docs/v2/storefront/index.yaml +357 -33
  32. data/lib/spree/api/configuration.rb +11 -0
  33. data/lib/spree/api/dependencies.rb +165 -0
  34. data/lib/spree/api/engine.rb +5 -16
  35. data/lib/spree/api/testing_support/v2/platform_contexts.rb +0 -1
  36. data/lib/spree/api.rb +0 -4
  37. data/lib/spree_api.rb +0 -1
  38. data/spree_api.gemspec +0 -2
  39. metadata +16 -177
  40. data/app/controllers/spree/api/base_controller.rb +0 -171
  41. data/app/controllers/spree/api/v1/addresses_controller.rb +0 -46
  42. data/app/controllers/spree/api/v1/checkouts_controller.rb +0 -106
  43. data/app/controllers/spree/api/v1/classifications_controller.rb +0 -21
  44. data/app/controllers/spree/api/v1/countries_controller.rb +0 -22
  45. data/app/controllers/spree/api/v1/credit_cards_controller.rb +0 -26
  46. data/app/controllers/spree/api/v1/customer_returns_controller.rb +0 -25
  47. data/app/controllers/spree/api/v1/images_controller.rb +0 -58
  48. data/app/controllers/spree/api/v1/inventory_units_controller.rb +0 -54
  49. data/app/controllers/spree/api/v1/line_items_controller.rb +0 -70
  50. data/app/controllers/spree/api/v1/option_types_controller.rb +0 -60
  51. data/app/controllers/spree/api/v1/option_values_controller.rb +0 -62
  52. data/app/controllers/spree/api/v1/orders_controller.rb +0 -160
  53. data/app/controllers/spree/api/v1/payments_controller.rb +0 -82
  54. data/app/controllers/spree/api/v1/product_properties_controller.rb +0 -73
  55. data/app/controllers/spree/api/v1/products_controller.rb +0 -131
  56. data/app/controllers/spree/api/v1/promotions_controller.rb +0 -30
  57. data/app/controllers/spree/api/v1/properties_controller.rb +0 -70
  58. data/app/controllers/spree/api/v1/reimbursements_controller.rb +0 -25
  59. data/app/controllers/spree/api/v1/return_authorizations_controller.rb +0 -70
  60. data/app/controllers/spree/api/v1/shipments_controller.rb +0 -196
  61. data/app/controllers/spree/api/v1/states_controller.rb +0 -36
  62. data/app/controllers/spree/api/v1/stock_items_controller.rb +0 -82
  63. data/app/controllers/spree/api/v1/stock_locations_controller.rb +0 -53
  64. data/app/controllers/spree/api/v1/stock_movements_controller.rb +0 -45
  65. data/app/controllers/spree/api/v1/stores_controller.rb +0 -56
  66. data/app/controllers/spree/api/v1/taxonomies_controller.rb +0 -67
  67. data/app/controllers/spree/api/v1/taxons_controller.rb +0 -100
  68. data/app/controllers/spree/api/v1/users_controller.rb +0 -97
  69. data/app/controllers/spree/api/v1/variants_controller.rb +0 -81
  70. data/app/controllers/spree/api/v1/zones_controller.rb +0 -55
  71. data/app/helpers/spree/api/api_helpers.rb +0 -190
  72. data/app/models/spree/api_configuration.rb +0 -10
  73. data/app/views/spree/api/errors/gateway_error.rabl +0 -2
  74. data/app/views/spree/api/errors/invalid_api_key.rabl +0 -2
  75. data/app/views/spree/api/errors/invalid_resource.rabl +0 -3
  76. data/app/views/spree/api/errors/must_specify_api_key.rabl +0 -2
  77. data/app/views/spree/api/errors/not_found.rabl +0 -2
  78. data/app/views/spree/api/errors/unauthorized.rabl +0 -2
  79. data/app/views/spree/api/v1/addresses/show.rabl +0 -10
  80. data/app/views/spree/api/v1/adjustments/show.rabl +0 -4
  81. data/app/views/spree/api/v1/countries/index.rabl +0 -7
  82. data/app/views/spree/api/v1/countries/show.rabl +0 -5
  83. data/app/views/spree/api/v1/credit_cards/index.rabl +0 -7
  84. data/app/views/spree/api/v1/credit_cards/show.rabl +0 -3
  85. data/app/views/spree/api/v1/customer_returns/index.rabl +0 -7
  86. data/app/views/spree/api/v1/images/index.rabl +0 -4
  87. data/app/views/spree/api/v1/images/new.rabl +0 -3
  88. data/app/views/spree/api/v1/images/show.rabl +0 -6
  89. data/app/views/spree/api/v1/inventory_units/show.rabl +0 -2
  90. data/app/views/spree/api/v1/line_items/new.rabl +0 -3
  91. data/app/views/spree/api/v1/line_items/show.rabl +0 -14
  92. data/app/views/spree/api/v1/option_types/index.rabl +0 -3
  93. data/app/views/spree/api/v1/option_types/new.rabl +0 -3
  94. data/app/views/spree/api/v1/option_types/show.rabl +0 -5
  95. data/app/views/spree/api/v1/option_values/index.rabl +0 -3
  96. data/app/views/spree/api/v1/option_values/new.rabl +0 -3
  97. data/app/views/spree/api/v1/option_values/show.rabl +0 -2
  98. data/app/views/spree/api/v1/orders/address.rabl +0 -0
  99. data/app/views/spree/api/v1/orders/canceled.rabl +0 -0
  100. data/app/views/spree/api/v1/orders/cart.rabl +0 -0
  101. data/app/views/spree/api/v1/orders/complete.rabl +0 -0
  102. data/app/views/spree/api/v1/orders/could_not_apply_coupon.rabl +0 -2
  103. data/app/views/spree/api/v1/orders/could_not_transition.rabl +0 -3
  104. data/app/views/spree/api/v1/orders/index.rabl +0 -7
  105. data/app/views/spree/api/v1/orders/insufficient_quantity.rabl +0 -2
  106. data/app/views/spree/api/v1/orders/invalid_shipping_method.rabl +0 -2
  107. data/app/views/spree/api/v1/orders/mine.rabl +0 -9
  108. data/app/views/spree/api/v1/orders/order.rabl +0 -10
  109. data/app/views/spree/api/v1/orders/payment.rabl +0 -3
  110. data/app/views/spree/api/v1/orders/show.rabl +0 -51
  111. data/app/views/spree/api/v1/payments/credit_over_limit.rabl +0 -2
  112. data/app/views/spree/api/v1/payments/index.rabl +0 -7
  113. data/app/views/spree/api/v1/payments/new.rabl +0 -5
  114. data/app/views/spree/api/v1/payments/show.rabl +0 -2
  115. data/app/views/spree/api/v1/payments/update_forbidden.rabl +0 -2
  116. data/app/views/spree/api/v1/product_properties/index.rabl +0 -7
  117. data/app/views/spree/api/v1/product_properties/new.rabl +0 -2
  118. data/app/views/spree/api/v1/product_properties/show.rabl +0 -2
  119. data/app/views/spree/api/v1/products/index.rabl +0 -9
  120. data/app/views/spree/api/v1/products/new.rabl +0 -3
  121. data/app/views/spree/api/v1/products/product.rabl +0 -1
  122. data/app/views/spree/api/v1/products/show.rabl +0 -36
  123. data/app/views/spree/api/v1/promotions/handler.rabl +0 -5
  124. data/app/views/spree/api/v1/promotions/show.rabl +0 -2
  125. data/app/views/spree/api/v1/properties/index.rabl +0 -7
  126. data/app/views/spree/api/v1/properties/new.rabl +0 -2
  127. data/app/views/spree/api/v1/properties/show.rabl +0 -2
  128. data/app/views/spree/api/v1/reimbursements/index.rabl +0 -7
  129. data/app/views/spree/api/v1/return_authorizations/index.rabl +0 -7
  130. data/app/views/spree/api/v1/return_authorizations/new.rabl +0 -3
  131. data/app/views/spree/api/v1/return_authorizations/show.rabl +0 -2
  132. data/app/views/spree/api/v1/shared/stock_location_required.rabl +0 -2
  133. data/app/views/spree/api/v1/shipments/big.rabl +0 -48
  134. data/app/views/spree/api/v1/shipments/cannot_ready_shipment.rabl +0 -2
  135. data/app/views/spree/api/v1/shipments/mine.rabl +0 -9
  136. data/app/views/spree/api/v1/shipments/show.rabl +0 -32
  137. data/app/views/spree/api/v1/shipments/small.rabl +0 -37
  138. data/app/views/spree/api/v1/shipping_rates/show.rabl +0 -2
  139. data/app/views/spree/api/v1/states/index.rabl +0 -12
  140. data/app/views/spree/api/v1/states/show.rabl +0 -2
  141. data/app/views/spree/api/v1/stock_items/index.rabl +0 -7
  142. data/app/views/spree/api/v1/stock_items/show.rabl +0 -5
  143. data/app/views/spree/api/v1/stock_locations/index.rabl +0 -7
  144. data/app/views/spree/api/v1/stock_locations/show.rabl +0 -8
  145. data/app/views/spree/api/v1/stock_movements/index.rabl +0 -7
  146. data/app/views/spree/api/v1/stock_movements/show.rabl +0 -5
  147. data/app/views/spree/api/v1/stores/index.rabl +0 -4
  148. data/app/views/spree/api/v1/stores/show.rabl +0 -2
  149. data/app/views/spree/api/v1/tags/index.rabl +0 -9
  150. data/app/views/spree/api/v1/taxonomies/index.rabl +0 -7
  151. data/app/views/spree/api/v1/taxonomies/jstree.rabl +0 -7
  152. data/app/views/spree/api/v1/taxonomies/nested.rabl +0 -11
  153. data/app/views/spree/api/v1/taxonomies/new.rabl +0 -3
  154. data/app/views/spree/api/v1/taxonomies/show.rabl +0 -15
  155. data/app/views/spree/api/v1/taxons/index.rabl +0 -10
  156. data/app/views/spree/api/v1/taxons/jstree.rabl +0 -7
  157. data/app/views/spree/api/v1/taxons/new.rabl +0 -3
  158. data/app/views/spree/api/v1/taxons/show.rabl +0 -6
  159. data/app/views/spree/api/v1/taxons/taxons.rabl +0 -5
  160. data/app/views/spree/api/v1/users/index.rabl +0 -7
  161. data/app/views/spree/api/v1/users/new.rabl +0 -3
  162. data/app/views/spree/api/v1/users/show.rabl +0 -11
  163. data/app/views/spree/api/v1/variants/big.rabl +0 -14
  164. data/app/views/spree/api/v1/variants/index.rabl +0 -9
  165. data/app/views/spree/api/v1/variants/new.rabl +0 -2
  166. data/app/views/spree/api/v1/variants/show.rabl +0 -3
  167. data/app/views/spree/api/v1/variants/small.rabl +0 -18
  168. data/app/views/spree/api/v1/zones/index.rabl +0 -7
  169. data/app/views/spree/api/v1/zones/show.rabl +0 -6
  170. data/config/initializers/rabl.rb +0 -9
  171. data/lib/spree/api/api_dependencies.rb +0 -163
  172. data/lib/spree/api/controller_setup.rb +0 -19
  173. data/lib/spree/api/responders/rabl_template.rb +0 -28
  174. data/lib/spree/api/responders.rb +0 -11
  175. data/lib/spree/api/testing_support/helpers.rb +0 -44
  176. data/lib/spree/api/testing_support/setup.rb +0 -16
@@ -1,100 +0,0 @@
1
- module Spree
2
- module Api
3
- module V1
4
- class TaxonsController < Spree::Api::BaseController
5
- def index
6
- @taxons = if taxonomy
7
- taxonomy.root.children
8
- elsif params[:ids]
9
- Spree::Taxon.includes(:children).accessible_by(current_ability).where(id: params[:ids].split(','))
10
- else
11
- Spree::Taxon.includes(:children).accessible_by(current_ability).order(:taxonomy_id, :lft)
12
- end
13
- @taxons = @taxons.ransack(params[:q]).result
14
- @taxons = @taxons.page(params[:page]).per(params[:per_page])
15
- respond_with(@taxons)
16
- end
17
-
18
- def show
19
- @taxon = taxon
20
- respond_with(@taxon)
21
- end
22
-
23
- def jstree
24
- show
25
- end
26
-
27
- def new; end
28
-
29
- def create
30
- authorize! :create, Taxon
31
- @taxon = Spree::Taxon.new(taxon_params)
32
- @taxon.taxonomy_id = params[:taxonomy_id]
33
- taxonomy = Spree::Taxonomy.find_by(id: params[:taxonomy_id])
34
-
35
- if taxonomy.nil?
36
- @taxon.errors.add(:taxonomy_id, I18n.t('spree.api.invalid_taxonomy_id'))
37
- invalid_resource!(@taxon) and return
38
- end
39
-
40
- @taxon.parent_id = taxonomy.root_id unless params[:taxon][:parent_id]
41
-
42
- if @taxon.save
43
- respond_with(@taxon, status: 201, default_template: :show)
44
- else
45
- invalid_resource!(@taxon)
46
- end
47
- end
48
-
49
- def update
50
- authorize! :update, taxon
51
- if taxon.update(taxon_params)
52
- respond_with(taxon, status: 200, default_template: :show)
53
- else
54
- invalid_resource!(taxon)
55
- end
56
- end
57
-
58
- def destroy
59
- authorize! :destroy, taxon
60
- taxon.destroy
61
- respond_with(taxon, status: 204)
62
- end
63
-
64
- def products
65
- # Returns the products sorted by their position with the classification
66
- # Products#index does not do the sorting.
67
- taxon = Spree::Taxon.find(params[:id])
68
- @products = taxon.products.ransack(params[:q]).result
69
- @products = @products.page(params[:page]).per(params[:per_page] || 500)
70
- render 'spree/api/v1/products/index'
71
- end
72
-
73
- private
74
-
75
- def taxonomy
76
- if params[:taxonomy_id].present?
77
- @taxonomy ||=
78
- if defined?(SpreeGlobalize)
79
- Spree::Taxonomy.includes(:translations, taxons: [:translations]).accessible_by(current_ability, :show).find(params[:taxonomy_id])
80
- else
81
- Spree::Taxonomy.accessible_by(current_ability, :show).find(params[:taxonomy_id])
82
- end
83
- end
84
- end
85
-
86
- def taxon
87
- @taxon ||= taxonomy.taxons.accessible_by(current_ability, :show).find(params[:id])
88
- end
89
-
90
- def taxon_params
91
- if params[:taxon] && !params[:taxon].empty?
92
- params.require(:taxon).permit(permitted_taxon_attributes)
93
- else
94
- {}
95
- end
96
- end
97
- end
98
- end
99
- end
100
- end
@@ -1,97 +0,0 @@
1
- module Spree
2
- module Api
3
- module V1
4
- class UsersController < Spree::Api::BaseController
5
- rescue_from Spree::Core::DestroyWithOrdersError, with: :error_during_processing
6
-
7
- def index
8
- users
9
-
10
- if params[:ids]
11
- load_users_by_ids
12
- elsif params.dig(:q, :ship_address_firstname_start)
13
- load_users_by_address
14
- elsif params.dig(:q, :email_start)
15
- load_users_by_email
16
- end
17
-
18
- prepare_index_response
19
- respond_with(@users)
20
- end
21
-
22
- def users
23
- @users ||= Spree.user_class.accessible_by(current_ability, :show)
24
- end
25
-
26
- def load_users_by_ids
27
- @users = @users.where(id: params[:ids])
28
- end
29
-
30
- def load_users_by_address
31
- address_params = params[:q][:ship_address_firstname_start] ||
32
- params[:q][:ship_address_lastname_start] ||
33
- params[:q][:bill_address_firstname_start] ||
34
- params[:q][:bill_address_lastname_start]
35
- @users = @users.with_email_or_address(params[:q][:email_start], address_params)
36
- end
37
-
38
- def load_users_by_email
39
- @users = @users.with_email(params[:q][:email_start])
40
- end
41
-
42
- def paginate_users
43
- @users = @users.page(params[:page]).per(params[:per_page])
44
- end
45
-
46
- def prepare_index_response
47
- paginate_users
48
- expires_in 15.minutes, public: true
49
- headers['Surrogate-Control'] = "max-age=#{15.minutes}"
50
- end
51
-
52
- def show
53
- respond_with(user)
54
- end
55
-
56
- def new; end
57
-
58
- def create
59
- authorize! :create, Spree.user_class
60
- @user = Spree.user_class.new(user_params)
61
- if @user.save
62
- respond_with(@user, status: 201, default_template: :show)
63
- else
64
- invalid_resource!(@user)
65
- end
66
- end
67
-
68
- def update
69
- authorize! :update, user
70
- if user.update(user_params)
71
- respond_with(user, status: 200, default_template: :show)
72
- else
73
- invalid_resource!(user)
74
- end
75
- end
76
-
77
- def destroy
78
- authorize! :destroy, user
79
- user.destroy
80
- respond_with(user, status: 204)
81
- end
82
-
83
- private
84
-
85
- def user
86
- @user ||= Spree.user_class.accessible_by(current_ability, :show).find(params[:id])
87
- end
88
-
89
- def user_params
90
- params.require(:user).permit(permitted_user_attributes |
91
- [bill_address_attributes: permitted_address_attributes,
92
- ship_address_attributes: permitted_address_attributes])
93
- end
94
- end
95
- end
96
- end
97
- end
@@ -1,81 +0,0 @@
1
- module Spree
2
- module Api
3
- module V1
4
- class VariantsController < Spree::Api::BaseController
5
- before_action :product
6
-
7
- def create
8
- authorize! :create, Variant
9
- @variant = scope.new(variant_params)
10
- if @variant.save
11
- respond_with(@variant, status: 201, default_template: :show)
12
- else
13
- invalid_resource!(@variant)
14
- end
15
- end
16
-
17
- def destroy
18
- @variant = scope.accessible_by(current_ability, :destroy).find(params[:id])
19
- @variant.destroy
20
- respond_with(@variant, status: 204)
21
- end
22
-
23
- # The lazyloaded associations here are pretty much attached to which nodes
24
- # we render on the view so we better update it any time a node is included
25
- # or removed from the views.
26
- def index
27
- @variants = scope.includes(*variant_includes).for_currency_and_available_price_amount.
28
- ransack(params[:q]).result.page(params[:page]).per(params[:per_page])
29
- respond_with(@variants)
30
- end
31
-
32
- def new; end
33
-
34
- def show
35
- @variant = scope.includes(*variant_includes).find(params[:id])
36
- respond_with(@variant)
37
- end
38
-
39
- def update
40
- @variant = scope.accessible_by(current_ability, :update).find(params[:id])
41
- if @variant.update(variant_params)
42
- respond_with(@variant, status: 200, default_template: :show)
43
- else
44
- invalid_resource!(@product)
45
- end
46
- end
47
-
48
- private
49
-
50
- def product
51
- if params[:product_id]
52
- @product ||= Spree::Product.accessible_by(current_ability, :show).
53
- friendly.find(params[:product_id])
54
- end
55
- end
56
-
57
- def scope
58
- variants = if @product
59
- @product.variants_including_master
60
- else
61
- Variant
62
- end
63
-
64
- if current_ability.can?(:manage, Variant) && params[:show_deleted]
65
- variants = variants.with_deleted
66
- end
67
-
68
- variants.eligible.accessible_by(current_ability)
69
- end
70
-
71
- def variant_params
72
- params.require(:variant).permit(permitted_variant_attributes)
73
- end
74
-
75
- def variant_includes
76
- [{ option_values: :option_type }, :product, :default_price, :images, { stock_items: :stock_location }]
77
- end
78
- end
79
- end
80
- end
81
- end
@@ -1,55 +0,0 @@
1
- module Spree
2
- module Api
3
- module V1
4
- class ZonesController < Spree::Api::BaseController
5
- def create
6
- authorize! :create, Zone
7
- @zone = Spree::Zone.new(zone_params)
8
- if @zone.save
9
- respond_with(@zone, status: 201, default_template: :show)
10
- else
11
- invalid_resource!(@zone)
12
- end
13
- end
14
-
15
- def destroy
16
- authorize! :destroy, zone
17
- zone.destroy
18
- respond_with(zone, status: 204)
19
- end
20
-
21
- def index
22
- @zones = Zone.accessible_by(current_ability).order('name ASC').ransack(params[:q]).result.page(params[:page]).per(params[:per_page])
23
- respond_with(@zones)
24
- end
25
-
26
- def show
27
- respond_with(zone)
28
- end
29
-
30
- def update
31
- authorize! :update, zone
32
- if zone.update(zone_params)
33
- respond_with(zone, status: 200, default_template: :show)
34
- else
35
- invalid_resource!(zone)
36
- end
37
- end
38
-
39
- private
40
-
41
- def zone_params
42
- attrs = params.require(:zone).permit!
43
- if attrs[:zone_members]
44
- attrs[:zone_members_attributes] = attrs.delete(:zone_members)
45
- end
46
- attrs
47
- end
48
-
49
- def zone
50
- @zone ||= Spree::Zone.accessible_by(current_ability, :show).find(params[:id])
51
- end
52
- end
53
- end
54
- end
55
- end
@@ -1,190 +0,0 @@
1
- module Spree
2
- module Api
3
- module ApiHelpers
4
- ATTRIBUTES = [
5
- :product_attributes,
6
- :product_property_attributes,
7
- :variant_attributes,
8
- :image_attributes,
9
- :option_value_attributes,
10
- :order_attributes,
11
- :line_item_attributes,
12
- :option_type_attributes,
13
- :payment_attributes,
14
- :payment_method_attributes,
15
- :shipment_attributes,
16
- :taxonomy_attributes,
17
- :taxon_attributes,
18
- :address_attributes,
19
- :country_attributes,
20
- :state_attributes,
21
- :adjustment_attributes,
22
- :inventory_unit_attributes,
23
- :return_authorization_attributes,
24
- :creditcard_attributes,
25
- :payment_source_attributes,
26
- :user_attributes,
27
- :property_attributes,
28
- :stock_location_attributes,
29
- :stock_movement_attributes,
30
- :stock_item_attributes,
31
- :promotion_attributes,
32
- :store_attributes,
33
- :tag_attributes,
34
- :customer_return_attributes,
35
- :reimbursement_attributes
36
- ]
37
-
38
- mattr_reader *ATTRIBUTES
39
-
40
- def required_fields_for(model)
41
- required_fields = model._validators.select do |_field, validations|
42
- validations.any? { |v| v.is_a?(ActiveModel::Validations::PresenceValidator) }
43
- end.map(&:first) # get fields that are invalid
44
- # Permalinks presence is validated, but are really automatically generated
45
- # Therefore we shouldn't tell API clients that they MUST send one through
46
- required_fields.map!(&:to_s).delete('permalink')
47
- # Do not require slugs, either
48
- required_fields.delete('slug')
49
- required_fields
50
- end
51
-
52
- @@product_attributes = [
53
- :id, :name, :description, :price, :display_price, :available_on,
54
- :slug, :meta_description, :meta_keywords, :shipping_category_id,
55
- :taxon_ids, :total_on_hand
56
- ]
57
-
58
- @@product_property_attributes = [
59
- :id, :product_id, :property_id, :value, :property_name
60
- ]
61
-
62
- @@variant_attributes = [
63
- :id, :name, :sku, :price, :weight, :height, :width, :depth, :is_master,
64
- :slug, :description, :track_inventory
65
- ]
66
-
67
- @@image_attributes = [
68
- :id, :position, :attachment_content_type, :attachment_file_name, :type,
69
- :attachment_updated_at, :attachment_width, :attachment_height, :alt
70
- ]
71
-
72
- @@option_value_attributes = [
73
- :id, :name, :presentation, :option_type_name, :option_type_id,
74
- :option_type_presentation
75
- ]
76
-
77
- @@order_attributes = [
78
- :id, :number, :item_total, :total, :ship_total, :state, :adjustment_total,
79
- :user_id, :created_at, :updated_at, :completed_at, :payment_total,
80
- :shipment_state, :payment_state, :email, :special_instructions, :channel,
81
- :included_tax_total, :additional_tax_total, :display_included_tax_total,
82
- :display_additional_tax_total, :tax_total, :currency, :considered_risky,
83
- :canceler_id
84
- ]
85
-
86
- @@line_item_attributes = [:id, :quantity, :price, :variant_id]
87
-
88
- @@option_type_attributes = [:id, :name, :presentation, :position]
89
-
90
- @@payment_attributes = [
91
- :id, :source_type, :source_id, :amount, :display_amount,
92
- :payment_method_id, :state, :avs_response, :created_at,
93
- :updated_at, :number
94
- ]
95
-
96
- @@payment_method_attributes = [:id, :name, :description]
97
-
98
- @@shipment_attributes = [:id, :tracking, :number, :cost, :shipped_at, :state]
99
-
100
- @@taxonomy_attributes = [:id, :name]
101
-
102
- @@taxon_attributes = [
103
- :id, :name, :pretty_name, :permalink, :parent_id,
104
- :taxonomy_id, :meta_title, :meta_description
105
- ]
106
-
107
- @@inventory_unit_attributes = [
108
- :id, :lock_version, :state, :variant_id, :shipment_id,
109
- :return_authorization_id
110
- ]
111
-
112
- @@return_authorization_attributes = [
113
- :id, :number, :state, :order_id, :memo, :created_at, :updated_at
114
- ]
115
-
116
- @@address_attributes = [
117
- :id, :firstname, :lastname, :full_name, :address1, :address2, :city,
118
- :zipcode, :phone, :company, :alternative_phone, :country_id, :state_id,
119
- :label, :state_name, :state_text
120
- ]
121
-
122
- @@country_attributes = [:id, :iso_name, :iso, :iso3, :name, :numcode]
123
-
124
- @@state_attributes = [:id, :name, :abbr, :country_id]
125
-
126
- @@adjustment_attributes = [
127
- :id, :source_type, :source_id, :adjustable_type, :adjustable_id,
128
- :originator_type, :originator_id, :amount, :label, :mandatory,
129
- :locked, :eligible, :created_at, :updated_at
130
- ]
131
-
132
- @@creditcard_attributes = [
133
- :id, :month, :year, :cc_type, :last_digits, :name,
134
- :gateway_customer_profile_id, :gateway_payment_profile_id
135
- ]
136
-
137
- @@payment_source_attributes = [
138
- :id, :month, :year, :cc_type, :last_digits, :name
139
- ]
140
-
141
- @@user_attributes = [:id, :email, :created_at, :updated_at]
142
-
143
- @@property_attributes = [:id, :name, :presentation]
144
-
145
- @@stock_location_attributes = [
146
- :id, :name, :address1, :address2, :city, :state_id, :state_name,
147
- :country_id, :zipcode, :phone, :active
148
- ]
149
-
150
- @@stock_movement_attributes = [:id, :quantity, :stock_item_id]
151
-
152
- @@stock_item_attributes = [
153
- :id, :count_on_hand, :backorderable, :lock_version, :stock_location_id,
154
- :variant_id
155
- ]
156
-
157
- @@promotion_attributes = [
158
- :id, :name, :description, :expires_at, :starts_at, :type, :usage_limit,
159
- :match_policy, :code, :advertise, :path
160
- ]
161
-
162
- @@store_attributes = [
163
- :id, :name, :url, :meta_description, :meta_keywords, :seo_title,
164
- :mail_from_address, :customer_support_email, :default_currency,
165
- :code, :default, :facebook, :twitter, :instagram,
166
- :supported_currencies, :default_locale, :supported_locales
167
- ]
168
-
169
- @@tag_attributes = [:id, :name]
170
-
171
- @@customer_return_attributes = [
172
- :id, :number, :order_id, :fully_reimbursed?, :pre_tax_total,
173
- :created_at, :updated_at
174
- ]
175
-
176
- @@reimbursement_attributes = [
177
- :id, :reimbursement_status, :customer_return_id, :order_id,
178
- :number, :total, :created_at, :updated_at
179
- ]
180
-
181
- def variant_attributes
182
- if @current_user_roles&.include?('admin')
183
- @@variant_attributes + [:cost_price]
184
- else
185
- @@variant_attributes
186
- end
187
- end
188
- end
189
- end
190
- end
@@ -1,10 +0,0 @@
1
- module Spree
2
- class ApiConfiguration < Preferences::Configuration
3
- preference :requires_authentication, :boolean, default: true
4
- preference :api_v2_serializers_cache_ttl, :integer, default: 3600 # 1 hour in seconds
5
- preference :api_v2_collection_cache_ttl, :integer, default: 3600 # 1 hour in seconds
6
- preference :api_v2_collection_cache_namespace, :string, default: 'api_v2_collection_cache'
7
- preference :api_v2_content_type, :string, default: 'application/vnd.api+json'
8
- preference :api_v2_per_page_limit, :integer, default: 500
9
- end
10
- end
@@ -1,2 +0,0 @@
1
- object false
2
- node(:error) { I18n.t(:gateway_error, scope: 'spree.api', text: @error) }
@@ -1,2 +0,0 @@
1
- object false
2
- node(:error) { I18n.t(:invalid_api_key, key: api_key, scope: 'spree.api') }
@@ -1,3 +0,0 @@
1
- object false
2
- node(:error) { I18n.t(:invalid_resource, scope: 'spree.api') }
3
- node(:errors) { @resource.errors.to_hash }
@@ -1,2 +0,0 @@
1
- object false
2
- node(:error) { I18n.t(:must_specify_api_key, scope: 'spree.api') }
@@ -1,2 +0,0 @@
1
- object false
2
- node(:error) { I18n.t(:resource_not_found, scope: 'spree.api') }
@@ -1,2 +0,0 @@
1
- object false
2
- node(:error) { I18n.t(:unauthorized, scope: 'spree.api') }
@@ -1,10 +0,0 @@
1
- object @address
2
- cache [I18n.locale, root_object]
3
- attributes *address_attributes
4
-
5
- child(:country) do |_address|
6
- attributes *country_attributes
7
- end
8
- child(:state) do |_address|
9
- attributes *state_attributes
10
- end
@@ -1,4 +0,0 @@
1
- object @adjustment
2
- cache [I18n.locale, root_object]
3
- attributes *adjustment_attributes
4
- node(:display_amount) { |a| a.display_amount.to_s }
@@ -1,7 +0,0 @@
1
- object false
2
- child(@countries => :countries) do
3
- attributes *country_attributes
4
- end
5
- node(:count) { @countries.count }
6
- node(:current_page) { params[:page].try(:to_i) || 1 }
7
- node(:pages) { @countries.total_pages }
@@ -1,5 +0,0 @@
1
- object @country
2
- attributes *country_attributes
3
- child states: :states do
4
- attributes :id, :name, :abbr, :country_id
5
- end
@@ -1,7 +0,0 @@
1
- object false
2
- child(@credit_cards => :credit_cards) do
3
- extends 'spree/api/v1/credit_cards/show'
4
- end
5
- node(:count) { @credit_cards.count }
6
- node(:current_page) { params[:page].try(:to_i) || 1 }
7
- node(:pages) { @credit_cards.total_pages }
@@ -1,3 +0,0 @@
1
- object @credit_card
2
- cache [I18n.locale, root_object]
3
- attributes *creditcard_attributes
@@ -1,7 +0,0 @@
1
- object false
2
- child(@collection => :customer_returns) do
3
- attributes *customer_return_attributes
4
- end
5
- node(:count) { @collection.count }
6
- node(:current_page) { params[:page].try(:to_i) || 1 }
7
- node(:pages) { @collection.total_pages }
@@ -1,4 +0,0 @@
1
- object false
2
- child(@images => :images) do
3
- extends 'spree/api/v1/images/show'
4
- end
@@ -1,3 +0,0 @@
1
- object false
2
- node(:attributes) { [*image_attributes] }
3
- node(:required_attributes) { required_fields_for(Spree::Image) }
@@ -1,6 +0,0 @@
1
- object @image
2
- attributes *image_attributes
3
- attributes :viewable_type, :viewable_id
4
- Spree::Image.styles.each do |k, _v|
5
- node("#{k}_url") { |i| main_app.url_for(i.url(k)) }
6
- end
@@ -1,2 +0,0 @@
1
- object @inventory_unit
2
- attributes *inventory_unit_attributes
@@ -1,3 +0,0 @@
1
- object false
2
- node(:attributes) { [*line_item_attributes] - [:id] }
3
- node(:required_attributes) { [:variant_id, :quantity] }
@@ -1,14 +0,0 @@
1
- object @line_item
2
- cache [I18n.locale, root_object]
3
- attributes *line_item_attributes
4
- node(:single_display_amount) { |li| li.single_display_amount.to_s }
5
- node(:display_amount) { |li| li.display_amount.to_s }
6
- node(:total, &:total)
7
- child :variant do
8
- extends 'spree/api/v1/variants/small'
9
- attributes :product_id
10
- end
11
-
12
- child adjustments: :adjustments do
13
- extends 'spree/api/v1/adjustments/show'
14
- end
@@ -1,3 +0,0 @@
1
- collection @option_types
2
-
3
- extends 'spree/api/v1/option_types/show'
@@ -1,3 +0,0 @@
1
- object false
2
- node(:attributes) { [*option_type_attributes] }
3
- node(:required_attributes) { required_fields_for(Spree::OptionType) }
@@ -1,5 +0,0 @@
1
- object @option_type
2
- attributes *option_type_attributes
3
- child option_values: :option_values do
4
- attributes *option_value_attributes
5
- end
@@ -1,3 +0,0 @@
1
- collection @option_values
2
-
3
- extends 'spree/api/v1/option_values/show'