spree_api 5.1.0.beta3 → 5.1.0.beta4

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 372516f7b98eecd75dbb03724a3bc7472b9d09745502f5cf8980aff4bf511847
4
- data.tar.gz: 0e0f426db7f21e2efdec616e922e63efc5da81867117e64020be18ec5933b900
3
+ metadata.gz: 18576a5979e028efde302e65a1fec8f6695ecbf4d0a93d94c98872614880ca98
4
+ data.tar.gz: 4625d7f902a5806987ddcc368afeeda68ff41a9bbb1b7813f1287606c49bfccd
5
5
  SHA512:
6
- metadata.gz: e775c684859f3dde910518f1acd5ed7545215c2ee8ad5562a1085197c1a9c1ab064875fc4fe9827d56881622523be8f93d467a1c4d97d8ee315dd6efa8b80560
7
- data.tar.gz: 270e2536eef094252293a2888e75347e15446e6c405261cd6b8c57d3d24712e8361d9ce99a7d50622a9af8d384cf02bb0f29fcdd23ca19f7eff7ba02ecf4cd91
6
+ metadata.gz: 03bff840b60ec12ec91fed698ac45e5265852aedfbf638a1010ca6f59b9217e625ff010347dabd768b00d27caffd750b942eb6985b5c323562dc7dabe4f7ed1f
7
+ data.tar.gz: c5970c9e510bf18a09410424a2b10bbf9879e30d8031196df60a503a6d1434f199fb6bbfeae47b30f4d7a3c87bb4c72875542ffbc774d08aef37b0eef113cda1
@@ -20,6 +20,8 @@ module Spree
20
20
  rescue_from ArgumentError, with: :error_during_processing
21
21
  rescue_from ActionDispatch::Http::Parameters::ParseError, with: :error_during_processing
22
22
 
23
+ # Returns the content type for the API
24
+ # @return [String] The content type, eg 'application/vnd.api+json'
23
25
  def content_type
24
26
  Spree::Api::Config[:api_v2_content_type]
25
27
  end
@@ -42,18 +44,28 @@ module Spree
42
44
  ).serializable_hash
43
45
  end
44
46
 
47
+ # Returns a paginated collection
48
+ # @return [Array] The paginated collection
45
49
  def paginated_collection
46
50
  @paginated_collection ||= collection_paginator.new(sorted_collection, params).call
47
51
  end
48
52
 
53
+ # Returns the collection paginator
54
+ # @return [Class] The collection paginator class, default is Spree::Shared::Paginate
49
55
  def collection_paginator
50
56
  Spree::Api::Dependencies.storefront_collection_paginator.constantize
51
57
  end
52
58
 
59
+ # Renders a serialized payload with the given status code
60
+ # @param status [Integer] HTTP status code to return, eg 200, 201, 204
61
+ # @yield [Hash] The serialized data to render
53
62
  def render_serialized_payload(status = 200)
54
63
  render json: yield, status: status, content_type: content_type
55
64
  end
56
65
 
66
+ # Renders a serialized error payload with the given status code
67
+ # @param status [Integer] HTTP status code to return
68
+ # @yield [Hash] The serialized data to render
57
69
  def render_error_payload(error, status = 422)
58
70
  json = if error.is_a?(ActiveModel::Errors)
59
71
  { error: error.full_messages.to_sentence, errors: error.messages }
@@ -66,6 +78,9 @@ module Spree
66
78
  render json: json, status: status, content_type: content_type
67
79
  end
68
80
 
81
+ # Renders a serialized result payload with the given status code
82
+ # @param result [Object] The result to render
83
+ # @param ok_status [Integer] HTTP status code to return if the result is successful, eg 200, 201, 204
69
84
  def render_result(result, ok_status = 200)
70
85
  if result.success?
71
86
  render_serialized_payload(ok_status) { serialize_resource(result.value) }
@@ -74,6 +89,8 @@ module Spree
74
89
  end
75
90
  end
76
91
 
92
+ # Returns the current Spree user
93
+ # @return [Spree.user_class] The current Spree user
77
94
  def spree_current_user
78
95
  return nil unless doorkeeper_token
79
96
  return @spree_current_user if defined?(@spree_current_user)
@@ -86,10 +103,17 @@ module Spree
86
103
 
87
104
  alias try_spree_current_user spree_current_user # for compatibility with spree_legacy_frontend
88
105
 
106
+ # Authorizes the current Spree user for the given action and subject
107
+ # @param action [Symbol] The action to authorize
108
+ # @param subject [Object] The subject to authorize
109
+ # @param args [Array] Additional arguments to pass to the authorize! method
110
+ # @return [void]
89
111
  def spree_authorize!(action, subject, *args)
90
112
  authorize!(action, subject, *args)
91
113
  end
92
114
 
115
+ # Raises an AccessDenied error if the current Spree user is nil
116
+ # @raise [CanCan::AccessDenied] If the current Spree user is nil
93
117
  def require_spree_current_user
94
118
  raise CanCan::AccessDenied if spree_current_user.nil?
95
119
  end
@@ -100,10 +124,13 @@ module Spree
100
124
  end
101
125
 
102
126
  # this method can be extended in extensions or developer applications
127
+ # @return [Hash] The ability options
103
128
  def ability_options
104
129
  { store: current_store }
105
130
  end
106
131
 
132
+ # Returns the requested includes
133
+ # @return [Array] The requested includes
107
134
  def request_includes
108
135
  # if API user wants to receive only the bare-minimum
109
136
  # the API will return only the main resource without any included
@@ -114,6 +141,8 @@ module Spree
114
141
  end
115
142
  end
116
143
 
144
+ # Returns the resource includes, useful to avoid N+1 queries
145
+ # @return [Array] The resource includes, eg [:images, :variants]
117
146
  def resource_includes
118
147
  (request_includes || default_resource_includes).map(&:intern)
119
148
  end
@@ -127,6 +156,8 @@ module Spree
127
156
  []
128
157
  end
129
158
 
159
+ # Returns the JSON API sparse fields
160
+ # @return [Hash] The sparse fields, eg { product: [:name, :description] }
130
161
  def sparse_fields
131
162
  return unless params[:fields]&.respond_to?(:each)
132
163
 
@@ -137,6 +168,9 @@ module Spree
137
168
  fields.presence
138
169
  end
139
170
 
171
+ # Returns the serializer global params
172
+ # all of these params are passed down to the serializer
173
+ # @return [Hash] The serializer params
140
174
  def serializer_params
141
175
  {
142
176
  currency: current_currency,
@@ -149,28 +183,43 @@ module Spree
149
183
  }
150
184
  end
151
185
 
186
+ # Renders a 404 error payload
187
+ # @param exception [Exception] The exception to render
188
+ # @return [void]
152
189
  def record_not_found(exception)
153
190
  Rails.error.report(exception, context: { user_id: spree_current_user&.id }, source: 'spree.api')
154
191
 
155
192
  render_error_payload(I18n.t(:resource_not_found, scope: 'spree.api'), 404)
156
193
  end
157
194
 
195
+ # Renders a 403 error payload
196
+ # @param exception [Exception] The exception to render
197
+ # @return [void]
158
198
  def access_denied(exception)
159
199
  Rails.error.report(exception, context: { user_id: spree_current_user&.id }, source: 'spree.api')
160
200
 
161
201
  render_error_payload(exception.message, 403)
162
202
  end
163
203
 
204
+ # Renders a 401 error payload
205
+ # @param exception [Exception] The exception to render
206
+ # @return [void]
164
207
  def access_denied_401(exception)
165
208
  render_error_payload(exception.message, 401)
166
209
  end
167
210
 
211
+ # Renders a 500 error payload when a payment gateway error occurs
212
+ # @param exception [Exception] The exception to render
213
+ # @return [void]
168
214
  def gateway_error(exception)
169
215
  Rails.error.report(exception, context: { user_id: spree_current_user&.id }, source: 'spree.api')
170
216
 
171
217
  render_error_payload(exception.message)
172
218
  end
173
219
 
220
+ # Renders a 400 error payload when an error occurs during parameter parsing
221
+ # @param exception [Exception] The exception to render
222
+ # @return [void]
174
223
  def error_during_processing(exception)
175
224
  Rails.error.report(exception, context: { user_id: spree_current_user&.id }, source: 'spree.api')
176
225
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spree_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.1.0.beta3
4
+ version: 5.1.0.beta4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Bigg
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2025-05-29 00:00:00.000000000 Z
13
+ date: 2025-06-04 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: jsonapi-rspec
@@ -102,14 +102,14 @@ dependencies:
102
102
  requirements:
103
103
  - - '='
104
104
  - !ruby/object:Gem::Version
105
- version: 5.1.0.beta3
105
+ version: 5.1.0.beta4
106
106
  type: :runtime
107
107
  prerelease: false
108
108
  version_requirements: !ruby/object:Gem::Requirement
109
109
  requirements:
110
110
  - - '='
111
111
  - !ruby/object:Gem::Version
112
- version: 5.1.0.beta3
112
+ version: 5.1.0.beta4
113
113
  description: Spree's API
114
114
  email:
115
115
  - hello@spreecommerce.org
@@ -364,9 +364,9 @@ licenses:
364
364
  - BSD-3-Clause
365
365
  metadata:
366
366
  bug_tracker_uri: https://github.com/spree/spree/issues
367
- changelog_uri: https://github.com/spree/spree/releases/tag/v5.1.0.beta3
367
+ changelog_uri: https://github.com/spree/spree/releases/tag/v5.1.0.beta4
368
368
  documentation_uri: https://docs.spreecommerce.org/
369
- source_code_uri: https://github.com/spree/spree/tree/v5.1.0.beta3
369
+ source_code_uri: https://github.com/spree/spree/tree/v5.1.0.beta4
370
370
  post_install_message:
371
371
  rdoc_options: []
372
372
  require_paths: