spree_api 4.2.4 → 4.3.0.rc3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (99) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +14 -1
  3. data/app/controllers/concerns/spree/api/v2/caching.rb +33 -0
  4. data/app/controllers/concerns/spree/api/v2/product_list_includes.rb +23 -0
  5. data/app/controllers/spree/api/v1/classifications_controller.rb +4 -3
  6. data/app/controllers/spree/api/v1/orders_controller.rb +5 -1
  7. data/app/controllers/spree/api/v1/products_controller.rb +2 -2
  8. data/app/controllers/spree/api/v1/taxonomies_controller.rb +1 -1
  9. data/app/controllers/spree/api/v2/base_controller.rb +31 -6
  10. data/app/controllers/spree/api/v2/platform/addresses_controller.rb +19 -0
  11. data/app/controllers/spree/api/v2/platform/classifications_controller.rb +43 -0
  12. data/app/controllers/spree/api/v2/platform/cms_pages_controller.rb +15 -0
  13. data/app/controllers/spree/api/v2/platform/cms_sections_controller.rb +34 -0
  14. data/app/controllers/spree/api/v2/platform/countries_controller.rb +19 -0
  15. data/app/controllers/spree/api/v2/platform/menu_items_controller.rb +35 -0
  16. data/app/controllers/spree/api/v2/platform/menus_controller.rb +23 -0
  17. data/app/controllers/spree/api/v2/platform/option_types_controller.rb +15 -0
  18. data/app/controllers/spree/api/v2/platform/option_values_controller.rb +19 -0
  19. data/app/controllers/spree/api/v2/platform/products_controller.rb +33 -0
  20. data/app/controllers/spree/api/v2/platform/resource_controller.rb +115 -0
  21. data/app/controllers/spree/api/v2/platform/taxons_controller.rb +30 -0
  22. data/app/controllers/spree/api/v2/platform/users_controller.rb +28 -0
  23. data/app/controllers/spree/api/v2/resource_controller.rb +24 -7
  24. data/app/controllers/spree/api/v2/storefront/account/addresses_controller.rb +2 -14
  25. data/app/controllers/spree/api/v2/storefront/account/credit_cards_controller.rb +13 -11
  26. data/app/controllers/spree/api/v2/storefront/account/orders_controller.rb +6 -2
  27. data/app/controllers/spree/api/v2/storefront/account_controller.rb +32 -1
  28. data/app/controllers/spree/api/v2/storefront/cart_controller.rb +28 -6
  29. data/app/controllers/spree/api/v2/storefront/checkout_controller.rb +2 -1
  30. data/app/controllers/spree/api/v2/storefront/cms_pages_controller.rb +41 -0
  31. data/app/controllers/spree/api/v2/storefront/countries_controller.rb +16 -14
  32. data/app/controllers/spree/api/v2/storefront/menus_controller.rb +35 -0
  33. data/app/controllers/spree/api/v2/storefront/order_status_controller.rb +1 -1
  34. data/app/controllers/spree/api/v2/storefront/products_controller.rb +10 -12
  35. data/app/controllers/spree/api/v2/storefront/stores_controller.rb +1 -1
  36. data/app/controllers/spree/api/v2/storefront/taxons_controller.rb +7 -8
  37. data/app/helpers/spree/api/v2/display_money_helper.rb +2 -2
  38. data/app/models/spree/api_configuration.rb +4 -1
  39. data/app/models/spree/api_dependencies.rb +20 -5
  40. data/app/serializers/concerns/spree/api/v2/image_transformation_concern.rb +15 -0
  41. data/app/serializers/concerns/spree/api/v2/resource_serializer_concern.rb +16 -0
  42. data/app/serializers/concerns/spree/api/v2/taxon_image_transformation_concern.rb +15 -0
  43. data/app/serializers/spree/api/v2/base_serializer.rb +32 -0
  44. data/app/serializers/spree/api/v2/platform/address_serializer.rb +15 -0
  45. data/app/serializers/spree/api/v2/platform/base_serializer.rb +10 -0
  46. data/app/serializers/spree/api/v2/platform/classification_serializer.rb +14 -0
  47. data/app/serializers/spree/api/v2/platform/cms_page_serializer.rb +13 -0
  48. data/app/serializers/spree/api/v2/platform/cms_section_serializer.rb +11 -0
  49. data/app/serializers/spree/api/v2/platform/country_serializer.rb +13 -0
  50. data/app/serializers/spree/api/v2/platform/icon_serializer.rb +16 -0
  51. data/app/serializers/spree/api/v2/platform/image_serializer.rb +17 -0
  52. data/app/serializers/spree/api/v2/platform/menu_item_serializer.rb +45 -0
  53. data/app/serializers/spree/api/v2/platform/menu_serializer.rb +13 -0
  54. data/app/serializers/spree/api/v2/platform/option_type_serializer.rb +13 -0
  55. data/app/serializers/spree/api/v2/platform/option_value_serializer.rb +13 -0
  56. data/app/serializers/spree/api/v2/platform/product_property_serializer.rb +11 -0
  57. data/app/serializers/spree/api/v2/platform/product_serializer.rb +78 -0
  58. data/app/serializers/spree/api/v2/platform/state_serializer.rb +13 -0
  59. data/app/serializers/spree/api/v2/platform/stock_item_serializer.rb +20 -0
  60. data/app/serializers/spree/api/v2/platform/stock_location_serializer.rb +16 -0
  61. data/app/serializers/spree/api/v2/platform/store_serializer.rb +14 -0
  62. data/app/serializers/spree/api/v2/platform/tax_category_serializer.rb +13 -0
  63. data/app/serializers/spree/api/v2/platform/taxon_image_serializer.rb +15 -0
  64. data/app/serializers/spree/api/v2/platform/taxon_serializer.rb +38 -0
  65. data/app/serializers/spree/api/v2/platform/taxonomy_serializer.rb +14 -0
  66. data/app/serializers/spree/api/v2/platform/user_serializer.rb +37 -0
  67. data/app/serializers/spree/api/v2/platform/variant_serializer.rb +57 -0
  68. data/app/serializers/spree/v2/storefront/base_serializer.rb +3 -2
  69. data/app/serializers/spree/v2/storefront/cms_page_serializer.rb +14 -0
  70. data/app/serializers/spree/v2/storefront/cms_section_serializer.rb +28 -0
  71. data/app/serializers/spree/v2/storefront/country_serializer.rb +4 -4
  72. data/app/serializers/spree/v2/storefront/estimated_shipping_rate_serializer.rb +2 -0
  73. data/app/serializers/spree/v2/storefront/icon_serializer.rb +14 -0
  74. data/app/serializers/spree/v2/storefront/image_serializer.rb +3 -1
  75. data/app/serializers/spree/v2/storefront/menu_item_serializer.rb +43 -0
  76. data/app/serializers/spree/v2/storefront/menu_serializer.rb +13 -0
  77. data/app/serializers/spree/v2/storefront/payment_method_serializer.rb +4 -0
  78. data/app/serializers/spree/v2/storefront/product_property_serializer.rb +1 -1
  79. data/app/serializers/spree/v2/storefront/product_serializer.rb +21 -12
  80. data/app/serializers/spree/v2/storefront/store_serializer.rb +10 -0
  81. data/app/serializers/spree/v2/storefront/taxon_image_serializer.rb +3 -1
  82. data/app/serializers/spree/v2/storefront/taxon_serializer.rb +6 -5
  83. data/config/initializers/doorkeeper.rb +8 -1
  84. data/config/initializers/rabl.rb +9 -0
  85. data/config/locales/en.yml +1 -1
  86. data/config/routes.rb +115 -3
  87. data/db/migrate/20210727102516_change_integer_id_columns_type.rb +9 -0
  88. data/docs/oauth/index.yml +4 -4
  89. data/docs/v2/platform/index.yaml +3597 -0
  90. data/docs/v2/storefront/index.yaml +12117 -1610
  91. data/lib/spree/api/engine.rb +6 -17
  92. data/lib/spree/api/testing_support/v2/base.rb +1 -1
  93. data/lib/spree/api/testing_support/v2/platform_contexts.rb +214 -0
  94. data/lib/spree/api/testing_support/v2/serializers_params.rb +14 -0
  95. data/lib/spree/api.rb +1 -0
  96. data/spree_api.gemspec +6 -3
  97. metadata +114 -13
  98. data/app/assets/javascripts/spree/api/main.js +0 -36
  99. data/app/assets/javascripts/spree/api/storefront/cart.js +0 -49
@@ -0,0 +1,15 @@
1
+ module Spree
2
+ module Api
3
+ module V2
4
+ module TaxonImageTransformationConcern
5
+ extend ActiveSupport::Concern
6
+
7
+ def self.included(base)
8
+ base.attribute :transformed_url do |image, params|
9
+ image.generate_url(size: params.dig(:taxon_image_transformation, :size))
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,32 @@
1
+ module Spree
2
+ module Api
3
+ module V2
4
+ class BaseSerializer
5
+ include JSONAPI::Serializer
6
+
7
+ # to learn more about caching, please refer to:
8
+ # https://github.com/jsonapi-serializer/jsonapi-serializer#caching
9
+ # https://guides.rubyonrails.org/caching_with_rails.html#low-level-caching
10
+ cache_options(store: Rails.cache, namespace: 'jsonapi-serializer', expires_in: Spree::Api::Config[:api_v2_serializers_cache_ttl])
11
+
12
+ def self.record_cache_options(options, fieldset, include_list, params)
13
+ opts = options.dup
14
+
15
+ params_cache_key = params.map do |param|
16
+ next if param.nil? || param.last.nil?
17
+
18
+ if param.last.respond_to?(:cache_key_with_version)
19
+ param.last.cache_key_with_version
20
+ else
21
+ param.last.to_s.downcase
22
+ end
23
+ end.compact.reject(&:blank?).join('-')
24
+
25
+ opts[:namespace] += "-#{params_cache_key}"
26
+
27
+ super(opts, fieldset, include_list, params)
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,15 @@
1
+ module Spree
2
+ module Api
3
+ module V2
4
+ module Platform
5
+ class AddressSerializer < BaseSerializer
6
+ include ::Spree::Api::V2::ResourceSerializerConcern
7
+
8
+ belongs_to :country
9
+ belongs_to :state
10
+ belongs_to :user
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,10 @@
1
+ module Spree
2
+ module Api
3
+ module V2
4
+ module Platform
5
+ class BaseSerializer < ::Spree::Api::V2::BaseSerializer
6
+ end
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,14 @@
1
+ module Spree
2
+ module Api
3
+ module V2
4
+ module Platform
5
+ class ClassificationSerializer < BaseSerializer
6
+ include ::Spree::Api::V2::ResourceSerializerConcern
7
+
8
+ belongs_to :product
9
+ belongs_to :taxon
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,13 @@
1
+ module Spree
2
+ module Api
3
+ module V2
4
+ module Platform
5
+ class CmsPageSerializer < BaseSerializer
6
+ include ::Spree::Api::V2::ResourceSerializerConcern
7
+
8
+ has_many :cms_sections, serializer: :cms_section
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,11 @@
1
+ module Spree
2
+ module Api
3
+ module V2
4
+ module Platform
5
+ class CmsSectionSerializer < BaseSerializer
6
+ include ::Spree::Api::V2::ResourceSerializerConcern
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,13 @@
1
+ module Spree
2
+ module Api
3
+ module V2
4
+ module Platform
5
+ class CountrySerializer < BaseSerializer
6
+ include ::Spree::Api::V2::ResourceSerializerConcern
7
+
8
+ has_many :states
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,16 @@
1
+ module Spree
2
+ module Api
3
+ module V2
4
+ module Platform
5
+ class IconSerializer < BaseSerializer
6
+ set_type :icon
7
+
8
+ attribute :url do |icon|
9
+ url_helpers = Rails.application.routes.url_helpers
10
+ url_helpers.polymorphic_url(icon.attachment, only_path: true)
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,17 @@
1
+ module Spree
2
+ module Api
3
+ module V2
4
+ module Platform
5
+ class ImageSerializer < BaseSerializer
6
+ include ::Spree::Api::V2::ImageTransformationConcern
7
+
8
+ set_type :image
9
+
10
+ attributes :styles, :position, :alt, :created_at, :updated_at, :original_url
11
+
12
+ belongs_to :viewable, polymorphic: true
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,45 @@
1
+ module Spree
2
+ module Api
3
+ module V2
4
+ module Platform
5
+ class MenuItemSerializer < BaseSerializer
6
+ include ::Spree::Api::V2::ResourceSerializerConcern
7
+
8
+ attributes :link
9
+
10
+ attribute :is_container do |menu_item|
11
+ menu_item.container?
12
+ end
13
+
14
+ attribute :is_root do |menu_item|
15
+ menu_item.root?
16
+ end
17
+
18
+ attribute :is_child do |menu_item|
19
+ menu_item.child?
20
+ end
21
+
22
+ attribute :is_leaf do |menu_item|
23
+ menu_item.leaf?
24
+ end
25
+
26
+ has_one :icon,
27
+ object_method_name: :icon,
28
+ id_method_name: :icon_id,
29
+ record_type: :icon,
30
+ serializer: :icon
31
+
32
+ belongs_to :menu, serializer: :menu
33
+ belongs_to :parent, record_type: :menu_item, serializer: :menu_item
34
+ belongs_to :linked_resource, polymorphic: {
35
+ Spree::Cms::Pages::StandardPage => :cms_page,
36
+ Spree::Cms::Pages::FeaturePage => :cms_page,
37
+ Spree::Cms::Pages::Homepage => :cms_page
38
+ }
39
+
40
+ has_many :children, record_type: :menu_item, serializer: :menu_item
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,13 @@
1
+ module Spree
2
+ module Api
3
+ module V2
4
+ module Platform
5
+ class MenuSerializer < BaseSerializer
6
+ include ::Spree::Api::V2::ResourceSerializerConcern
7
+
8
+ has_many :menu_items
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ module Spree
2
+ module Api
3
+ module V2
4
+ module Platform
5
+ class OptionTypeSerializer < BaseSerializer
6
+ include ::Spree::Api::V2::ResourceSerializerConcern
7
+
8
+ has_many :option_values
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ module Spree
2
+ module Api
3
+ module V2
4
+ module Platform
5
+ class OptionValueSerializer < BaseSerializer
6
+ include ::Spree::Api::V2::ResourceSerializerConcern
7
+
8
+ belongs_to :option_type
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,11 @@
1
+ module Spree
2
+ module Api
3
+ module V2
4
+ module Platform
5
+ class ProductPropertySerializer < BaseSerializer
6
+ include ::Spree::Api::V2::ResourceSerializerConcern
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,78 @@
1
+ module Spree
2
+ module Api
3
+ module V2
4
+ module Platform
5
+ class ProductSerializer < BaseSerializer
6
+ include ::Spree::Api::V2::ResourceSerializerConcern
7
+ include ::Spree::Api::V2::DisplayMoneyHelper
8
+
9
+ attribute :purchasable do |product|
10
+ product.purchasable?
11
+ end
12
+
13
+ attribute :in_stock do |product|
14
+ product.in_stock?
15
+ end
16
+
17
+ attribute :backorderable do |product|
18
+ product.backorderable?
19
+ end
20
+
21
+ attribute :available do |product|
22
+ product.available?
23
+ end
24
+
25
+ attribute :currency do |_product, params|
26
+ params[:currency]
27
+ end
28
+
29
+ attribute :price do |product, params|
30
+ price(product, params[:currency])
31
+ end
32
+
33
+ attribute :display_price do |product, params|
34
+ display_price(product, params[:currency])
35
+ end
36
+
37
+ attribute :compare_at_price do |product, params|
38
+ compare_at_price(product, params[:currency])
39
+ end
40
+
41
+ attribute :display_compare_at_price do |product, params|
42
+ display_compare_at_price(product, params[:currency])
43
+ end
44
+
45
+ belongs_to :tax_category
46
+
47
+ has_one :primary_variant,
48
+ object_method_name: :master,
49
+ id_method_name: :master_id,
50
+ record_type: :variant,
51
+ serializer: :variant
52
+
53
+ has_one :default_variant,
54
+ object_method_name: :default_variant,
55
+ id_method_name: :default_variant_id,
56
+ record_type: :variant,
57
+ serializer: :variant
58
+
59
+ has_many :variants
60
+ has_many :option_types
61
+ has_many :product_properties
62
+ has_many :taxons, serializer: :taxon, record_type: :taxon do |object, params|
63
+ object.taxons_for_store(params[:store])
64
+ end
65
+
66
+ has_many :images,
67
+ object_method_name: :variant_images,
68
+ id_method_name: :variant_image_ids,
69
+ record_type: :image,
70
+ serializer: :image
71
+
72
+ # TODO: add stock items
73
+ # TODO: add prices
74
+ end
75
+ end
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,13 @@
1
+ module Spree
2
+ module Api
3
+ module V2
4
+ module Platform
5
+ class StateSerializer < BaseSerializer
6
+ include ::Spree::Api::V2::ResourceSerializerConcern
7
+
8
+ belongs_to :country
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,20 @@
1
+ module Spree
2
+ module Api
3
+ module V2
4
+ module Platform
5
+ class StockItemSerializer < BaseSerializer
6
+ include ::Spree::Api::V2::ResourceSerializerConcern
7
+
8
+ set_type :stock_item
9
+
10
+ attribute :is_available do |stock_item|
11
+ stock_item.available?
12
+ end
13
+
14
+ belongs_to :stock_location
15
+ belongs_to :variant
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,16 @@
1
+ module Spree
2
+ module Api
3
+ module V2
4
+ module Platform
5
+ class StockLocationSerializer < BaseSerializer
6
+ include ::Spree::Api::V2::ResourceSerializerConcern
7
+
8
+ attributes :name
9
+
10
+ has_many :shipments
11
+ has_many :stock_items
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,14 @@
1
+ module Spree
2
+ module Api
3
+ module V2
4
+ module Platform
5
+ class StoreSerializer < BaseSerializer
6
+ include ::Spree::Api::V2::ResourceSerializerConcern
7
+
8
+ has_many :menus
9
+ has_one :default_country, serializer: :country, record_type: :country, id_method_name: :default_country_id
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,13 @@
1
+ module Spree
2
+ module Api
3
+ module V2
4
+ module Platform
5
+ class TaxCategorySerializer < BaseSerializer
6
+ include ::Spree::Api::V2::ResourceSerializerConcern
7
+
8
+ # TODO: add tax_rates
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end