spree_api 4.2.0.rc5 → 4.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/concerns/spree/api/v2/storefront/order_concern.rb +8 -4
- data/app/controllers/spree/api/v2/base_controller.rb +38 -2
- data/app/controllers/spree/api/v2/resource_controller.rb +0 -24
- data/app/controllers/spree/api/v2/storefront/cart_controller.rb +1 -1
- data/app/helpers/spree/api/api_helpers.rb +1 -1
- data/app/models/spree/api_configuration.rb +1 -0
- data/app/models/spree/api_dependencies.rb +3 -1
- data/app/serializers/spree/v2/storefront/store_serializer.rb +1 -1
- data/app/services/spree/api/error_handler.rb +40 -0
- data/config/initializers/doorkeeper.rb +2 -0
- metadata +9 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aa0ba5ffcc873cf68159260e0b7f52879f39f54f7140887a438c73f1257293d2
|
4
|
+
data.tar.gz: 1f05304db222d36a1f31d563ea5a071a01cfe7eb80fa4c13a002b6a4dd6775f8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0d83abd3762d05c58b37e8290d0fddc8ead28edc15ad3dd1267915ed2abb234399a36071a8250d4d7a3e08a0871e5e438acff6a28a67d2512460ec718c1785dd
|
7
|
+
data.tar.gz: 41eee02e45c3491b25333eecda173b23a520e0595ba39ef4c38ad1eb7d356d4c206ee7f16d19fd927f5e291475e3a40f6a785a634f0c1055f29cf60ad1e82ea8
|
@@ -34,12 +34,16 @@ module Spree
|
|
34
34
|
)
|
35
35
|
end
|
36
36
|
|
37
|
-
def
|
38
|
-
|
37
|
+
def serialized_current_order
|
38
|
+
serialize_resource(spree_current_order)
|
39
39
|
end
|
40
40
|
|
41
|
-
def
|
42
|
-
|
41
|
+
def serialize_order(order)
|
42
|
+
ActiveSupport::Deprecation.warn(<<-DEPRECATION, caller)
|
43
|
+
`OrderConcern#serialize_order` is deprecated and will be removed in Spree 5.0.
|
44
|
+
Please use `serializer_resource` method
|
45
|
+
DEPRECATION
|
46
|
+
serialize_resource(order)
|
43
47
|
end
|
44
48
|
end
|
45
49
|
end
|
@@ -10,15 +10,41 @@ module Spree
|
|
10
10
|
rescue_from ActiveRecord::RecordNotFound, with: :record_not_found
|
11
11
|
rescue_from CanCan::AccessDenied, with: :access_denied
|
12
12
|
rescue_from Spree::Core::GatewayError, with: :gateway_error
|
13
|
+
rescue_from ActionController::ParameterMissing, with: :error_during_processing
|
14
|
+
rescue_from ArgumentError, with: :error_during_processing
|
13
15
|
|
14
16
|
def content_type
|
15
17
|
Spree::Api::Config[:api_v2_content_type]
|
16
18
|
end
|
17
19
|
|
20
|
+
protected
|
21
|
+
|
22
|
+
def serialize_collection(collection)
|
23
|
+
collection_serializer.new(
|
24
|
+
collection,
|
25
|
+
collection_options(collection).merge(params: serializer_params)
|
26
|
+
).serializable_hash
|
27
|
+
end
|
28
|
+
|
29
|
+
def serialize_resource(resource)
|
30
|
+
resource_serializer.new(
|
31
|
+
resource,
|
32
|
+
params: serializer_params,
|
33
|
+
include: resource_includes,
|
34
|
+
fields: sparse_fields
|
35
|
+
).serializable_hash
|
36
|
+
end
|
37
|
+
|
38
|
+
def paginated_collection
|
39
|
+
collection_paginator.new(sorted_collection, params).call
|
40
|
+
end
|
41
|
+
|
42
|
+
def collection_paginator
|
43
|
+
Spree::Api::Dependencies.storefront_collection_paginator.constantize
|
44
|
+
end
|
45
|
+
|
18
46
|
def render_serialized_payload(status = 200)
|
19
47
|
render json: yield, status: status, content_type: content_type
|
20
|
-
rescue ArgumentError => exception
|
21
|
-
render_error_payload(exception.message, 400)
|
22
48
|
end
|
23
49
|
|
24
50
|
def render_error_payload(error, status = 422)
|
@@ -99,6 +125,16 @@ module Spree
|
|
99
125
|
def gateway_error(exception)
|
100
126
|
render_error_payload(exception.message)
|
101
127
|
end
|
128
|
+
|
129
|
+
def error_during_processing(exception)
|
130
|
+
result = error_handler.call(exception: exception, opts: { user: spree_current_user })
|
131
|
+
|
132
|
+
render_error_payload(result.value[:message], 400)
|
133
|
+
end
|
134
|
+
|
135
|
+
def error_handler
|
136
|
+
Spree::Api::Dependencies.error_handler.constantize
|
137
|
+
end
|
102
138
|
end
|
103
139
|
end
|
104
140
|
end
|
@@ -14,30 +14,6 @@ module Spree
|
|
14
14
|
|
15
15
|
protected
|
16
16
|
|
17
|
-
def serialize_collection(collection)
|
18
|
-
collection_serializer.new(
|
19
|
-
collection,
|
20
|
-
collection_options(collection).merge(params: serializer_params)
|
21
|
-
).serializable_hash
|
22
|
-
end
|
23
|
-
|
24
|
-
def serialize_resource(resource)
|
25
|
-
resource_serializer.new(
|
26
|
-
resource,
|
27
|
-
params: serializer_params,
|
28
|
-
include: resource_includes,
|
29
|
-
fields: sparse_fields
|
30
|
-
).serializable_hash
|
31
|
-
end
|
32
|
-
|
33
|
-
def paginated_collection
|
34
|
-
collection_paginator.new(sorted_collection, params).call
|
35
|
-
end
|
36
|
-
|
37
|
-
def collection_paginator
|
38
|
-
Spree::Api::Dependencies.storefront_collection_paginator.constantize
|
39
|
-
end
|
40
|
-
|
41
17
|
def sorted_collection
|
42
18
|
collection_sorter.new(collection, params, allowed_sort_attributes).call
|
43
19
|
end
|
@@ -19,7 +19,7 @@ module Spree
|
|
19
19
|
order = spree_current_order if spree_current_order.present?
|
20
20
|
order ||= create_service.call(order_params).value
|
21
21
|
|
22
|
-
render_serialized_payload(201) {
|
22
|
+
render_serialized_payload(201) { serialize_resource(order) }
|
23
23
|
end
|
24
24
|
|
25
25
|
def add_item
|
@@ -163,7 +163,7 @@ module Spree
|
|
163
163
|
:id, :name, :url, :meta_description, :meta_keywords, :seo_title,
|
164
164
|
:mail_from_address, :customer_support_email, :default_currency,
|
165
165
|
:code, :default, :facebook, :twitter, :instagram,
|
166
|
-
:supported_currencies
|
166
|
+
:supported_currencies, :default_locale, :supported_locales
|
167
167
|
]
|
168
168
|
|
169
169
|
@@tag_attributes = [:id, :name]
|
@@ -2,5 +2,6 @@ module Spree
|
|
2
2
|
class ApiConfiguration < Preferences::Configuration
|
3
3
|
preference :requires_authentication, :boolean, default: true
|
4
4
|
preference :api_v2_content_type, :string, default: 'application/vnd.api+json'
|
5
|
+
preference :api_v2_per_page_limit, :integer, default: 100
|
5
6
|
end
|
6
7
|
end
|
@@ -16,7 +16,7 @@ module Spree
|
|
16
16
|
:storefront_cart_update_service, :storefront_cart_estimate_shipping_rates_service, :storefront_estimated_shipment_serializer,
|
17
17
|
:storefront_store_serializer, :storefront_address_serializer, :storefront_order_serializer,
|
18
18
|
:storefront_account_create_address_service, :storefront_account_update_address_service, :storefront_address_finder,
|
19
|
-
:storefront_collection_sorter
|
19
|
+
:storefront_collection_sorter, :error_handler
|
20
20
|
].freeze
|
21
21
|
|
22
22
|
attr_accessor *INJECTION_POINTS
|
@@ -86,6 +86,8 @@ module Spree
|
|
86
86
|
@storefront_find_by_variant_finder = Spree::Dependencies.line_item_by_variant_finder
|
87
87
|
@storefront_products_finder = Spree::Dependencies.products_finder
|
88
88
|
@storefront_taxon_finder = Spree::Dependencies.taxon_finder
|
89
|
+
|
90
|
+
@error_handler = 'Spree::Api::ErrorHandler'
|
89
91
|
end
|
90
92
|
end
|
91
93
|
end
|
@@ -6,7 +6,7 @@ module Spree
|
|
6
6
|
|
7
7
|
attributes :name, :url, :meta_description, :meta_keywords, :seo_title, :default_currency, :default, :supported_currencies, :facebook,
|
8
8
|
:twitter, :instagram, :default_locale, :customer_support_email, :default_country_id, :description,
|
9
|
-
:address, :contact_phone
|
9
|
+
:address, :contact_phone, :supported_locales
|
10
10
|
|
11
11
|
has_one :default_country, serializer: :country, record_type: :country, id_method_name: :default_country_id
|
12
12
|
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module Spree
|
2
|
+
module Api
|
3
|
+
class ErrorHandler
|
4
|
+
prepend ::Spree::ServiceModule::Base
|
5
|
+
|
6
|
+
def call(exception:, opts: {})
|
7
|
+
run :format_message
|
8
|
+
run :log_error
|
9
|
+
run :report_error
|
10
|
+
end
|
11
|
+
|
12
|
+
protected
|
13
|
+
|
14
|
+
def format_message(exception:, opts:)
|
15
|
+
message = if exception.respond_to?(:original_message)
|
16
|
+
exception.original_message
|
17
|
+
else
|
18
|
+
exception.message
|
19
|
+
end
|
20
|
+
|
21
|
+
success(exception: exception, message: message, opts: opts)
|
22
|
+
end
|
23
|
+
|
24
|
+
def log_error(exception:, message:, opts:)
|
25
|
+
Rails.logger.error message
|
26
|
+
Rails.logger.error "User ID: #{opts[:user]&.id}" if opts[:user]
|
27
|
+
Rails.logger.error exception.backtrace.join("\n")
|
28
|
+
|
29
|
+
success(exception: exception, message: message, opts: opts)
|
30
|
+
end
|
31
|
+
|
32
|
+
def report_error(exception:, message:, opts:)
|
33
|
+
# overwrite this method in your application to support different error handlers
|
34
|
+
# eg. Sentry, Rollbar, etc
|
35
|
+
|
36
|
+
success(exception: exception, message: message)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -3,6 +3,8 @@ Doorkeeper.configure do
|
|
3
3
|
use_refresh_token
|
4
4
|
api_only
|
5
5
|
|
6
|
+
skip_client_authentication_for_password_grant { true } if defined?(skip_client_authentication_for_password_grant)
|
7
|
+
|
6
8
|
resource_owner_authenticator { current_spree_user }
|
7
9
|
|
8
10
|
resource_owner_from_credentials do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spree_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.2.0
|
4
|
+
version: 4.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Bigg
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-02-
|
11
|
+
date: 2021-02-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jsonapi-rspec
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - '='
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 4.2.0
|
33
|
+
version: 4.2.0
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - '='
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 4.2.0
|
40
|
+
version: 4.2.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rabl
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -181,6 +181,7 @@ files:
|
|
181
181
|
- app/serializers/spree/v2/storefront/taxonomy_serializer.rb
|
182
182
|
- app/serializers/spree/v2/storefront/user_serializer.rb
|
183
183
|
- app/serializers/spree/v2/storefront/variant_serializer.rb
|
184
|
+
- app/services/spree/api/error_handler.rb
|
184
185
|
- app/views/spree/api/errors/gateway_error.rabl
|
185
186
|
- app/views/spree/api/errors/invalid_api_key.rabl
|
186
187
|
- app/views/spree/api/errors/invalid_resource.rabl
|
@@ -309,9 +310,9 @@ licenses:
|
|
309
310
|
- BSD-3-Clause
|
310
311
|
metadata:
|
311
312
|
bug_tracker_uri: https://github.com/spree/spree/issues
|
312
|
-
changelog_uri: https://github.com/spree/spree/releases/tag/v4.2.0
|
313
|
+
changelog_uri: https://github.com/spree/spree/releases/tag/v4.2.0
|
313
314
|
documentation_uri: https://guides.spreecommerce.org/
|
314
|
-
source_code_uri: https://github.com/spree/spree/tree/v4.2.0
|
315
|
+
source_code_uri: https://github.com/spree/spree/tree/v4.2.0
|
315
316
|
post_install_message:
|
316
317
|
rdoc_options: []
|
317
318
|
require_paths:
|
@@ -323,9 +324,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
323
324
|
version: 2.5.0
|
324
325
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
325
326
|
requirements:
|
326
|
-
- - "
|
327
|
+
- - ">="
|
327
328
|
- !ruby/object:Gem::Version
|
328
|
-
version:
|
329
|
+
version: '0'
|
329
330
|
requirements: []
|
330
331
|
rubygems_version: 3.1.4
|
331
332
|
signing_key:
|