spree_api 4.1.5 → 4.2.0.beta

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: 8c9821451801f101e2515e3595c057cdf95ea6afca35c7c7ac28fa23587d36b9
4
- data.tar.gz: 367c6e377dc344d7d139171254a407c00659a7a5c82d992eb76edfc871954eca
3
+ metadata.gz: 3d7a31de48e37ea579244e2c62fb47e2891f5663b095aa8f49de99ecc24abc1e
4
+ data.tar.gz: 6d5470cb5181210801f5210f46b1e0fc7a3d704b8cd930f372a0544b5861713b
5
5
  SHA512:
6
- metadata.gz: 564695676cf6b20217140d99f075f1c05e10c6bedd3464f2cc748db844f029b39a0cb4709496c3986b8311d5351d9667986bea4a40ce50202a61be6933342041
7
- data.tar.gz: 1bbb9f8afb20b960831cfe1e8c720c12ca72c7206a85fced08e54038ef81ffa5d437fd62e2f2df2d9cca99f486d0934114c82d8a8836bd065d1ee8b97238c2ef
6
+ metadata.gz: 0b79cb583334e0813cde900718b6062a3601761aba2093159846a383c684219735ebf6861056a24376701d072e766eb74b2a280ef9dacf0f4993f67237dc6c01
7
+ data.tar.gz: 2429b6091f2e256743136cef85b42a65cfd53f9daadc6b1a5f3945c0fba1b9a1f882491edc85f0cf8a22cd7a7ee8dbed30c174f53e3d139b7d62eda8fe91c4a4
@@ -34,6 +34,10 @@ module Spree
34
34
  )
35
35
  end
36
36
 
37
+ def supported_currencies
38
+ current_store.supported_currencies_list
39
+ end
40
+
37
41
  def serialize_order(order)
38
42
  resource_serializer.new(order.reload, include: resource_includes, fields: sparse_fields).serializable_hash
39
43
  end
@@ -2,9 +2,7 @@ require_dependency 'spree/api/controller_setup'
2
2
 
3
3
  module Spree
4
4
  module Api
5
- class BaseController < ActionController::Base
6
- protect_from_forgery unless: -> { request.format.json? || request.format.xml? }
7
-
5
+ class BaseController < ActionController::API
8
6
  include Spree::Api::ControllerSetup
9
7
  include Spree::Core::ControllerHelpers::Store
10
8
  include Spree::Core::ControllerHelpers::StrongParameters
@@ -1,6 +1,6 @@
1
1
  module Spree
2
2
  module Api
3
- class ErrorsController < ActionController::Base
3
+ class ErrorsController < ActionController::API
4
4
  def render_404
5
5
  render 'spree/api/errors/not_found', status: 404
6
6
  end
@@ -74,7 +74,12 @@ module Spree
74
74
 
75
75
  def taxonomy
76
76
  if params[:taxonomy_id].present?
77
- @taxonomy ||= Spree::Taxonomy.accessible_by(current_ability, :show).find(params[:taxonomy_id])
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
78
83
  end
79
84
  end
80
85
 
@@ -5,22 +5,48 @@ module Spree
5
5
  rescue_from Spree::Core::DestroyWithOrdersError, with: :error_during_processing
6
6
 
7
7
  def index
8
- @users = Spree.user_class.accessible_by(current_ability, :show)
8
+ users
9
9
 
10
10
  if params[:ids]
11
- @users = @users.where(id: params[:ids])
12
- elsif params[:q]
13
- users_with_ship_address = @users.with_address(params[:q][:ship_address_firstname_start])
14
- users_with_bill_address = @users.with_address(params[:q][:ship_address_firstname_start], :bill_address)
15
-
16
- users_with_addresses_ids = (users_with_ship_address.ids + users_with_bill_address.ids).compact.uniq
17
- @users = @users.with_email_or_addresses_ids(params[:q][:email_start], users_with_addresses_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
18
16
  end
19
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
20
43
  @users = @users.page(params[:page]).per(params[:per_page])
44
+ end
45
+
46
+ def prepare_index_response
47
+ paginate_users
21
48
  expires_in 15.minutes, public: true
22
49
  headers['Surrogate-Control'] = "max-age=#{15.minutes}"
23
- respond_with(@users)
24
50
  end
25
51
 
26
52
  def show
@@ -7,6 +7,7 @@ module Spree
7
7
  include Spree::Core::ControllerHelpers::Store
8
8
  rescue_from ActiveRecord::RecordNotFound, with: :record_not_found
9
9
  rescue_from CanCan::AccessDenied, with: :access_denied
10
+ rescue_from Spree::Core::GatewayError, with: :gateway_error
10
11
 
11
12
  def content_type
12
13
  Spree::Api::Config[:api_v2_content_type]
@@ -108,6 +109,10 @@ module Spree
108
109
  def access_denied(exception)
109
110
  render_error_payload(exception.message, 403)
110
111
  end
112
+
113
+ def gateway_error(exception)
114
+ render_error_payload(exception.message)
115
+ end
111
116
  end
112
117
  end
113
118
  end
@@ -65,7 +65,11 @@ module Spree
65
65
  def shipping_rates
66
66
  result = shipping_rates_service.call(order: spree_current_order)
67
67
 
68
- render_serialized_payload { serialize_shipping_rates(result.value) }
68
+ if result.success?
69
+ render_serialized_payload { serialize_shipping_rates(result.value) }
70
+ else
71
+ render_error_payload(result.error)
72
+ end
69
73
  end
70
74
 
71
75
  def payment_methods
@@ -161,8 +161,9 @@ module Spree
161
161
 
162
162
  @@store_attributes = [
163
163
  :id, :name, :url, :meta_description, :meta_keywords, :seo_title,
164
- :mail_from_address, :default_currency, :code, :default,
165
- :facebook, :twitter, :instagram
164
+ :mail_from_address, :customer_support_email, :default_currency,
165
+ :code, :default, :facebook, :twitter, :instagram,
166
+ :supported_currencies
166
167
  ]
167
168
 
168
169
  @@tag_attributes = [:id, :name]
@@ -20,12 +20,14 @@ module Spree
20
20
 
21
21
  belongs_to :user
22
22
  belongs_to :billing_address,
23
- id_method_name: :bill_address_id,
24
- serializer: :address
23
+ id_method_name: :bill_address_id,
24
+ serializer: :address,
25
+ record_type: :address
25
26
 
26
27
  belongs_to :shipping_address,
27
- id_method_name: :ship_address_id,
28
- serializer: :address
28
+ id_method_name: :ship_address_id,
29
+ serializer: :address,
30
+ record_type: :address
29
31
  end
30
32
  end
31
33
  end
@@ -5,8 +5,8 @@ module Spree
5
5
  set_type :product
6
6
 
7
7
  attributes :name, :description, :price, :currency, :display_price,
8
- :available_on, :slug, :meta_description, :meta_keywords,
9
- :updated_at
8
+ :compare_at_price, :display_compare_at_price, :available_on,
9
+ :slug, :meta_description, :meta_keywords, :updated_at
10
10
 
11
11
  attribute :purchasable, &:purchasable?
12
12
  attribute :in_stock, &:in_stock?
@@ -4,7 +4,7 @@ module Spree
4
4
  class TaxonSerializer < BaseSerializer
5
5
  set_type :taxon
6
6
 
7
- attributes :name, :pretty_name, :permalink, :seo_title, :meta_title, :meta_description,
7
+ attributes :name, :pretty_name, :permalink, :seo_title, :description, :meta_title, :meta_description,
8
8
  :meta_keywords, :left, :right, :position, :depth, :updated_at
9
9
 
10
10
  attribute :is_root, &:root?
@@ -4,8 +4,8 @@ module Spree
4
4
  class VariantSerializer < BaseSerializer
5
5
  set_type :variant
6
6
 
7
- attributes :name, :sku, :price, :currency, :display_price, :weight, :height,
8
- :width, :depth, :is_master, :options_text, :slug, :description
7
+ attributes :sku, :price, :currency, :display_price, :weight, :height,
8
+ :width, :depth, :is_master, :options_text
9
9
 
10
10
  attribute :purchasable, &:purchasable?
11
11
  attribute :in_stock, &:in_stock?
@@ -6,6 +6,10 @@ attributes *product_attributes
6
6
  node(:display_price) { |p| p.display_price.to_s }
7
7
  node(:has_variants, &:has_variants?)
8
8
  node(:taxon_ids, &:taxon_ids)
9
+ node(:display_current_currency_price) do |product|
10
+ price = product.price_in(current_currency)
11
+ Spree::Money.new(price.amount, currency: current_currency).to_s
12
+ end
9
13
 
10
14
  child master: :master do
11
15
  extends 'spree/api/v1/variants/small'
@@ -49,7 +49,88 @@ paths:
49
49
  $ref: '#/components/responses/403Forbidden'
50
50
  security:
51
51
  - bearerAuth: []
52
-
52
+ post:
53
+ description: >-
54
+ Creates a new account
55
+
56
+ This endpoint requires [Spree Auth Devise](https://github.com/spree/spree_auth_devise) gem installed
57
+ tags:
58
+ - Account
59
+ operationId: 'Account Creation'
60
+ requestBody:
61
+ required: true
62
+ content:
63
+ application/vnd.api+json:
64
+ schema:
65
+ type: object
66
+ properties:
67
+ user:
68
+ type: object
69
+ properties:
70
+ email:
71
+ type: string
72
+ example: 'john@snow.org'
73
+ password:
74
+ type: string
75
+ example: 'spree123'
76
+ password_confirmation:
77
+ type: string
78
+ example: 'spree123'
79
+ responses:
80
+ '200':
81
+ description: ok
82
+ content:
83
+ application/vnd.api+json:
84
+ schema:
85
+ $ref: '#/components/schemas/Account'
86
+ '422':
87
+ description: Validation errors
88
+ content:
89
+ application/vnd.api+json:
90
+ schema:
91
+ $ref: '#/components/schemas/Error'
92
+ patch:
93
+ description: >-
94
+ Updates user account
95
+
96
+ This endpoint requires [Spree Auth Devise](https://github.com/spree/spree_auth_devise) gem installed
97
+ tags:
98
+ - Account
99
+ operationId: 'Account Updates'
100
+ requestBody:
101
+ required: true
102
+ content:
103
+ application/vnd.api+json:
104
+ schema:
105
+ type: object
106
+ properties:
107
+ user:
108
+ type: object
109
+ properties:
110
+ email:
111
+ type: string
112
+ example: 'john@snow.org'
113
+ password:
114
+ type: string
115
+ example: 'spree123'
116
+ password_confirmation:
117
+ type: string
118
+ example: 'spree123'
119
+ responses:
120
+ '200':
121
+ description: ok
122
+ content:
123
+ application/vnd.api+json:
124
+ schema:
125
+ $ref: '#/components/schemas/Account'
126
+ '422':
127
+ description: Validation errors
128
+ content:
129
+ application/vnd.api+json:
130
+ schema:
131
+ $ref: '#/components/schemas/Error'
132
+ security:
133
+ - bearerAuth: []
53
134
  '/account/credit_cards':
54
135
  get:
55
136
  description: >-
@@ -774,7 +855,7 @@ paths:
774
855
  description: >-
775
856
  Returns a list of available Shipping Rates for Checkout.
776
857
  Shipping Rates are grouped against Shipments.
777
- Each checkout cna have multiple Shipments eg. some products are available
858
+ Each checkout can have multiple Shipments eg. some products are available
778
859
  in stock and will be send out instantly and some needs to be backordered.
779
860
  tags:
780
861
  - Checkout
@@ -2003,10 +2084,6 @@ components:
2003
2084
  VariantAttributes:
2004
2085
  type: object
2005
2086
  properties:
2006
- name:
2007
- type: string
2008
- example: 'Example product'
2009
- description: 'Product name'
2010
2087
  sku:
2011
2088
  type: string
2012
2089
  example: 'SKU-1001'
@@ -2038,14 +2115,6 @@ components:
2038
2115
  options_text:
2039
2116
  type: string
2040
2117
  example: 'Size: small, Color: red'
2041
- slug:
2042
- type: string
2043
- example: 'example-product'
2044
- description: 'Product slug'
2045
- description:
2046
- type: string
2047
- example: 'Example description'
2048
- description: 'Product description'
2049
2118
  purchasable:
2050
2119
  type: boolean
2051
2120
  example: true
@@ -6,7 +6,6 @@ module Spree
6
6
  def self.included(klass)
7
7
  klass.class_eval do
8
8
  include CanCan::ControllerAdditions
9
- include Spree::Core::ControllerHelpers::Auth
10
9
 
11
10
  prepend_view_path Rails.root + 'app/views'
12
11
  append_view_path File.expand_path('../../../app/views', File.dirname(__FILE__))
@@ -2,20 +2,27 @@
2
2
  require_relative '../core/lib/spree/core/version.rb'
3
3
 
4
4
  Gem::Specification.new do |s|
5
+ s.name = "spree_api"
6
+ s.version = Spree.version
5
7
  s.authors = ["Ryan Bigg"]
6
8
  s.email = ["ryan@spreecommerce.com"]
7
- s.description = %q{Spree's API}
8
9
  s.summary = %q{Spree's API}
9
- s.homepage = 'http://spreecommerce.org'
10
+ s.description = %q{Spree's API}
11
+ s.homepage = 'https://spreecommerce.org'
10
12
  s.license = 'BSD-3-Clause'
11
13
 
14
+ s.metadata = {
15
+ "bug_tracker_uri" => "https://github.com/spree/spree/issues",
16
+ "changelog_uri" => "https://github.com/spree/spree/releases/tag/v#{s.version}",
17
+ "documentation_uri" => "https://guides.spreecommerce.org/",
18
+ "source_code_uri" => "https://github.com/spree/spree/tree/v#{s.version}",
19
+ }
20
+
12
21
  s.required_ruby_version = '>= 2.5.0'
13
22
 
14
23
  s.files = `git ls-files`.split($\).reject { |f| f.match(/^spec/) && !f.match(/^spec\/fixtures/) }
15
24
  s.executables = s.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
16
- s.name = "spree_api"
17
25
  s.require_paths = ["lib"]
18
- s.version = Spree.version
19
26
 
20
27
  s.add_development_dependency 'jsonapi-rspec'
21
28
 
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.1.5
4
+ version: 4.2.0.beta
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Bigg
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-04-14 00:00:00.000000000 Z
11
+ date: 2020-09-07 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.1.5
33
+ version: 4.2.0.beta
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.1.5
40
+ version: 4.2.0.beta
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rabl
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -297,10 +297,14 @@ files:
297
297
  - script/rails
298
298
  - spec/fixtures/thinking-cat.jpg
299
299
  - spree_api.gemspec
300
- homepage: http://spreecommerce.org
300
+ homepage: https://spreecommerce.org
301
301
  licenses:
302
302
  - BSD-3-Clause
303
- metadata: {}
303
+ metadata:
304
+ bug_tracker_uri: https://github.com/spree/spree/issues
305
+ changelog_uri: https://github.com/spree/spree/releases/tag/v4.2.0.beta
306
+ documentation_uri: https://guides.spreecommerce.org/
307
+ source_code_uri: https://github.com/spree/spree/tree/v4.2.0.beta
304
308
  post_install_message:
305
309
  rdoc_options: []
306
310
  require_paths:
@@ -312,9 +316,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
312
316
  version: 2.5.0
313
317
  required_rubygems_version: !ruby/object:Gem::Requirement
314
318
  requirements:
315
- - - ">="
319
+ - - ">"
316
320
  - !ruby/object:Gem::Version
317
- version: '0'
321
+ version: 1.3.1
318
322
  requirements: []
319
323
  rubygems_version: 3.1.2
320
324
  signing_key: