spree_api 4.3.0.rc3 → 4.4.0.rc2
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/caching.rb +7 -3
- data/app/controllers/concerns/spree/api/v2/coupon_codes_helper.rb +29 -0
- data/app/controllers/concerns/spree/api/v2/number_resource.rb +11 -0
- data/app/controllers/concerns/spree/api/v2/platform/nested_set_reposition_concern.rb +37 -0
- data/app/controllers/concerns/spree/api/v2/platform/promotion_calculator_params.rb +17 -0
- data/app/controllers/concerns/spree/api/v2/platform/promotion_rule_params.rb +16 -0
- data/app/controllers/concerns/spree/api/v2/storefront/metadata_controller_concern.rb +18 -0
- data/app/controllers/spree/api/v1/checkouts_controller.rb +1 -1
- data/app/controllers/spree/api/v2/base_controller.rb +7 -5
- data/app/controllers/spree/api/v2/platform/adjustments_controller.rb +19 -0
- data/app/controllers/spree/api/v2/platform/classifications_controller.rb +1 -22
- data/app/controllers/spree/api/v2/platform/cms_pages_controller.rb +4 -0
- data/app/controllers/spree/api/v2/platform/cms_sections_controller.rb +13 -18
- data/app/controllers/spree/api/v2/platform/digital_links_controller.rb +25 -0
- data/app/controllers/spree/api/v2/platform/digitals_controller.rb +19 -0
- data/app/controllers/spree/api/v2/platform/line_items_controller.rb +59 -0
- data/app/controllers/spree/api/v2/platform/menu_items_controller.rb +5 -19
- data/app/controllers/spree/api/v2/platform/menus_controller.rb +0 -4
- data/app/controllers/spree/api/v2/platform/orders_controller.rb +163 -0
- data/app/controllers/spree/api/v2/platform/payment_methods_controller.rb +27 -0
- data/app/controllers/spree/api/v2/platform/payments_controller.rb +17 -0
- data/app/controllers/spree/api/v2/platform/promotion_actions_controller.rb +30 -0
- data/app/controllers/spree/api/v2/platform/promotion_categories_controller.rb +19 -0
- data/app/controllers/spree/api/v2/platform/promotion_rules_controller.rb +25 -0
- data/app/controllers/spree/api/v2/platform/promotions_controller.rb +31 -0
- data/app/controllers/spree/api/v2/platform/resource_controller.rb +47 -16
- data/app/controllers/spree/api/v2/platform/roles_controller.rb +15 -0
- data/app/controllers/spree/api/v2/platform/shipments_controller.rb +143 -0
- data/app/controllers/spree/api/v2/platform/shipping_categories_controller.rb +15 -0
- data/app/controllers/spree/api/v2/platform/shipping_methods_controller.rb +24 -0
- data/app/controllers/spree/api/v2/platform/states_controller.rb +19 -0
- data/app/controllers/spree/api/v2/platform/stock_items_controller.rb +19 -0
- data/app/controllers/spree/api/v2/platform/stock_locations_controller.rb +19 -0
- data/app/controllers/spree/api/v2/platform/store_credit_categories_controller.rb +15 -0
- data/app/controllers/spree/api/v2/platform/store_credit_types_controller.rb +15 -0
- data/app/controllers/spree/api/v2/platform/store_credits_controller.rb +19 -0
- data/app/controllers/spree/api/v2/platform/tax_categories_controller.rb +19 -0
- data/app/controllers/spree/api/v2/platform/tax_rates_controller.rb +23 -0
- data/app/controllers/spree/api/v2/platform/taxonomies_controller.rb +19 -0
- data/app/controllers/spree/api/v2/platform/taxons_controller.rb +25 -0
- data/app/controllers/spree/api/v2/platform/users_controller.rb +4 -0
- data/app/controllers/spree/api/v2/platform/variants_controller.rb +19 -0
- data/app/controllers/spree/api/v2/platform/webhooks/events_controller.rb +21 -0
- data/app/controllers/spree/api/v2/platform/webhooks/subscribers_controller.rb +21 -0
- data/app/controllers/spree/api/v2/platform/wished_items_controller.rb +19 -0
- data/app/controllers/spree/api/v2/platform/wishlists_controller.rb +19 -0
- data/app/controllers/spree/api/v2/platform/zones_controller.rb +19 -0
- data/app/controllers/spree/api/v2/resource_controller.rb +3 -3
- data/app/controllers/spree/api/v2/storefront/account/addresses_controller.rb +5 -3
- data/app/controllers/spree/api/v2/storefront/account/credit_cards_controller.rb +4 -1
- data/app/controllers/spree/api/v2/storefront/cart_controller.rb +57 -29
- data/app/controllers/spree/api/v2/storefront/checkout_controller.rb +24 -0
- data/app/controllers/spree/api/v2/storefront/digitals_controller.rb +54 -0
- data/app/controllers/spree/api/v2/storefront/products_controller.rb +8 -0
- data/app/controllers/spree/api/v2/storefront/wishlists_controller.rb +171 -0
- data/app/helpers/spree/api/v2/collection_options_helpers.rb +1 -1
- data/app/jobs/spree/webhooks/subscribers/make_request_job.rb +17 -0
- data/app/models/concerns/spree/webhooks/has_webhooks.rb +58 -0
- data/app/models/spree/api/webhooks/order_decorator.rb +43 -0
- data/app/models/spree/api/webhooks/payment_decorator.rb +26 -0
- data/app/models/spree/api/webhooks/product_decorator.rb +27 -0
- data/app/models/spree/api/webhooks/shipment_decorator.rb +21 -0
- data/app/models/spree/api/webhooks/stock_item_decorator.rb +43 -0
- data/app/models/spree/api/webhooks/stock_movement_decorator.rb +52 -0
- data/app/models/spree/api/webhooks/variant_decorator.rb +26 -0
- data/app/models/spree/oauth_access_grant.rb +7 -0
- data/app/models/spree/oauth_access_token.rb +7 -0
- data/app/models/spree/oauth_application.rb +15 -0
- data/app/models/spree/webhooks/base.rb +11 -0
- data/app/models/spree/webhooks/event.rb +12 -0
- data/app/models/spree/webhooks/subscriber.rb +57 -0
- data/app/presenters/spree/api/products/filters_presenter.rb +39 -0
- data/app/serializers/concerns/spree/api/v2/resource_serializer_concern.rb +19 -1
- data/app/serializers/spree/api/v2/base_serializer.rb +11 -4
- data/app/serializers/spree/api/v2/platform/address_serializer.rb +1 -1
- data/app/serializers/spree/api/v2/platform/adjustment_serializer.rb +20 -0
- data/app/serializers/spree/api/v2/platform/asset_serializer.rb +13 -0
- data/app/serializers/spree/api/v2/platform/calculator_serializer.rb +17 -0
- data/app/serializers/spree/api/v2/platform/classification_serializer.rb +1 -1
- data/app/serializers/spree/api/v2/platform/cms_page_serializer.rb +1 -1
- data/app/serializers/spree/api/v2/platform/cms_section_serializer.rb +8 -1
- data/app/serializers/spree/api/v2/platform/country_serializer.rb +1 -1
- data/app/serializers/spree/api/v2/platform/credit_card_serializer.rb +14 -0
- data/app/serializers/spree/api/v2/platform/customer_return_serializer.rb +17 -0
- data/app/serializers/spree/api/v2/platform/digital_link_serializer.rb +16 -0
- data/app/serializers/spree/api/v2/platform/digital_serializer.rb +30 -0
- data/app/serializers/spree/api/v2/platform/feature_page_serializer.rb +11 -0
- data/app/serializers/spree/api/v2/platform/homepage_serializer.rb +11 -0
- data/app/serializers/spree/api/v2/platform/inventory_unit_serializer.rb +19 -0
- data/app/serializers/spree/api/v2/platform/line_item_serializer.rb +19 -0
- data/app/serializers/spree/api/v2/platform/log_entry_serializer.rb +13 -0
- data/app/serializers/spree/api/v2/platform/menu_item_serializer.rb +1 -1
- data/app/serializers/spree/api/v2/platform/menu_serializer.rb +1 -1
- data/app/serializers/spree/api/v2/platform/option_type_serializer.rb +1 -1
- data/app/serializers/spree/api/v2/platform/option_value_serializer.rb +1 -1
- data/app/serializers/spree/api/v2/platform/order_promotion_serializer.rb +14 -0
- data/app/serializers/spree/api/v2/platform/order_serializer.rb +31 -0
- data/app/serializers/spree/api/v2/platform/payment_capture_event_serializer.rb +13 -0
- data/app/serializers/spree/api/v2/platform/payment_method_serializer.rb +18 -0
- data/app/serializers/spree/api/v2/platform/payment_serializer.rb +21 -0
- data/app/serializers/spree/api/v2/platform/price_serializer.rb +19 -0
- data/app/serializers/spree/api/v2/platform/product_property_serializer.rb +1 -1
- data/app/serializers/spree/api/v2/platform/product_serializer.rb +7 -3
- data/app/serializers/spree/api/v2/platform/promotion_action_line_item_serializer.rb +14 -0
- data/app/serializers/spree/api/v2/platform/promotion_action_serializer.rb +19 -0
- data/app/serializers/spree/api/v2/platform/promotion_category_serializer.rb +13 -0
- data/app/serializers/spree/api/v2/platform/promotion_rule_serializer.rb +21 -0
- data/app/serializers/spree/api/v2/platform/promotion_serializer.rb +17 -0
- data/app/serializers/spree/api/v2/platform/property_serializer.rb +11 -0
- data/app/serializers/spree/api/v2/platform/prototype_serializer.rb +15 -0
- data/app/serializers/spree/api/v2/platform/refund_reason_serializer.rb +11 -0
- data/app/serializers/spree/api/v2/platform/refund_serializer.rb +16 -0
- data/app/serializers/spree/api/v2/platform/reimbursement_credit_serializer.rb +10 -0
- data/app/serializers/spree/api/v2/platform/reimbursement_serializer.rb +18 -0
- data/app/serializers/spree/api/v2/platform/reimbursement_type_serializer.rb +11 -0
- data/app/serializers/spree/api/v2/platform/return_authorization_reason_serializer.rb +11 -0
- data/app/serializers/spree/api/v2/platform/return_authorization_serializer.rb +17 -0
- data/app/serializers/spree/api/v2/platform/return_item_serializer.rb +16 -0
- data/app/serializers/spree/api/v2/platform/role_serializer.rb +11 -0
- data/app/serializers/spree/api/v2/platform/shipment_serializer.rb +22 -0
- data/app/serializers/spree/api/v2/platform/shipping_category_serializer.rb +11 -0
- data/app/serializers/spree/api/v2/platform/shipping_method_serializer.rb +16 -0
- data/app/serializers/spree/api/v2/platform/shipping_rate_serializer.rb +15 -0
- data/app/serializers/spree/api/v2/platform/standard_page_serializer.rb +11 -0
- data/app/serializers/spree/api/v2/platform/state_change_serializer.rb +13 -0
- data/app/serializers/spree/api/v2/platform/state_serializer.rb +1 -1
- data/app/serializers/spree/api/v2/platform/stock_item_serializer.rb +1 -3
- data/app/serializers/spree/api/v2/platform/stock_location_serializer.rb +2 -4
- data/app/serializers/spree/api/v2/platform/stock_movement_serializer.rb +11 -0
- data/app/serializers/spree/api/v2/platform/stock_transfer_serializer.rb +15 -0
- data/app/serializers/spree/api/v2/platform/store_credit_category_serializer.rb +12 -0
- data/app/serializers/spree/api/v2/platform/store_credit_event_serializer.rb +14 -0
- data/app/serializers/spree/api/v2/platform/store_credit_serializer.rb +18 -0
- data/app/serializers/spree/api/v2/platform/store_credit_type_serializer.rb +12 -0
- data/app/serializers/spree/api/v2/platform/store_serializer.rb +1 -1
- data/app/serializers/spree/api/v2/platform/tax_category_serializer.rb +2 -2
- data/app/serializers/spree/api/v2/platform/tax_rate_serializer.rb +14 -0
- data/app/serializers/spree/api/v2/platform/taxon_serializer.rb +1 -1
- data/app/serializers/spree/api/v2/platform/taxonomy_serializer.rb +1 -1
- data/app/serializers/spree/api/v2/platform/user_serializer.rb +1 -1
- data/app/serializers/spree/api/v2/platform/variant_serializer.rb +3 -2
- data/app/serializers/spree/api/v2/platform/webhooks/event_serializer.rb +15 -0
- data/app/serializers/spree/api/v2/platform/webhooks/subscriber_serializer.rb +13 -0
- data/app/serializers/spree/api/v2/platform/wished_item_serializer.rb +29 -0
- data/app/serializers/spree/api/v2/platform/wishlist_serializer.rb +19 -0
- data/app/serializers/spree/api/v2/platform/zone_member_serializer.rb +13 -0
- data/app/serializers/spree/api/v2/platform/zone_serializer.rb +13 -0
- data/app/serializers/spree/v2/storefront/address_serializer.rb +1 -1
- data/app/serializers/spree/v2/storefront/cart_serializer.rb +1 -1
- data/app/serializers/spree/v2/storefront/cms_section_serializer.rb +5 -1
- data/app/serializers/spree/v2/storefront/credit_card_serializer.rb +1 -1
- data/app/serializers/spree/v2/storefront/digital_link_serializer.rb +11 -0
- data/app/serializers/spree/v2/storefront/estimated_shipping_rate_serializer.rb +2 -2
- data/app/serializers/spree/v2/storefront/line_item_serializer.rb +2 -1
- data/app/serializers/spree/v2/storefront/option_type_serializer.rb +1 -1
- data/app/serializers/spree/v2/storefront/option_value_serializer.rb +1 -1
- data/app/serializers/spree/v2/storefront/payment_method_serializer.rb +1 -1
- data/app/serializers/spree/v2/storefront/payment_serializer.rb +1 -1
- data/app/serializers/spree/v2/storefront/product_serializer.rb +2 -2
- data/app/serializers/spree/v2/storefront/promotion_serializer.rb +1 -1
- data/app/serializers/spree/v2/storefront/shipment_serializer.rb +2 -1
- data/app/serializers/spree/v2/storefront/store_credit_serializer.rb +1 -1
- data/app/serializers/spree/v2/storefront/store_serializer.rb +1 -1
- data/app/serializers/spree/v2/storefront/taxon_serializer.rb +1 -1
- data/app/serializers/spree/v2/storefront/taxonomy_serializer.rb +1 -1
- data/app/serializers/spree/v2/storefront/user_serializer.rb +1 -1
- data/app/serializers/spree/v2/storefront/variant_serializer.rb +1 -1
- data/app/serializers/spree/v2/storefront/wished_item_serializer.rb +29 -0
- data/app/serializers/spree/v2/storefront/wishlist_serializer.rb +17 -0
- data/app/services/spree/webhooks/subscribers/handle_request.rb +73 -0
- data/app/services/spree/webhooks/subscribers/make_request.rb +82 -0
- data/app/services/spree/webhooks/subscribers/queue_requests.rb +17 -0
- data/app/services/spree/webhooks.rb +13 -0
- data/config/i18n-tasks.yml +40 -0
- data/config/initializers/doorkeeper.rb +12 -12
- data/config/initializers/rabl.rb +2 -2
- data/config/locales/en.yml +29 -27
- data/config/routes.rb +85 -59
- data/db/migrate/20210902162826_create_spree_webhooks_tables.rb +16 -0
- data/db/migrate/20210919183228_enable_polymorphic_resource_owner.rb +21 -0
- data/db/migrate/20211025162826_create_spree_webhooks_events.rb +14 -0
- data/docs/oauth/index.yml +126 -33
- data/docs/v2/platform/index.yaml +19182 -1717
- data/docs/v2/storefront/index.yaml +14823 -14588
- data/{app/models/spree → lib/spree/api}/api_dependencies.rb +60 -5
- data/lib/spree/api/engine.rb +24 -1
- data/lib/spree/api/testing_support/factories/oauth_application_factory.rb +6 -0
- data/lib/spree/api/testing_support/factories/webhook_event_factory.rb +27 -0
- data/lib/spree/api/testing_support/factories/webhook_subscriber_factory.rb +13 -0
- data/lib/spree/api/testing_support/factories.rb +3 -0
- data/lib/spree/api/testing_support/helpers.rb +1 -1
- data/lib/spree/api/testing_support/jobs.rb +18 -0
- data/lib/spree/api/testing_support/matchers/webhooks.rb +67 -0
- data/lib/spree/api/testing_support/serializers.rb +25 -0
- data/lib/spree/api/testing_support/spree_webhooks.rb +9 -0
- data/lib/spree/api/testing_support/v2/base.rb +1 -1
- data/lib/spree/api/testing_support/v2/current_order.rb +34 -1
- data/lib/spree/api/testing_support/v2/platform_contexts.rb +109 -50
- data/lib/spree/api/testing_support/v2/serializers_params.rb +3 -1
- data/lib/spree/api.rb +1 -0
- data/spec/fixtures/files/icon_256x256.jpg +0 -0
- data/spree_api.gemspec +16 -15
- metadata +176 -28
- data/app/controllers/spree/api/errors_controller.rb +0 -9
@@ -1,36 +1,48 @@
|
|
1
1
|
class String
|
2
2
|
def articleize
|
3
|
-
|
3
|
+
if split.first == 'User'
|
4
|
+
"a #{self}"
|
5
|
+
else
|
6
|
+
%w(a e i o u).include?(self[0].downcase) ? "an #{self}" : "a #{self}"
|
7
|
+
end
|
4
8
|
end
|
5
9
|
end
|
6
10
|
|
7
11
|
shared_context 'Platform API v2' do
|
8
12
|
let(:store) { Spree::Store.default }
|
9
|
-
let(:admin_app) {
|
10
|
-
let(:read_app) {
|
13
|
+
let(:admin_app) { Spree::OauthApplication.find_or_create_by!(name: 'Admin Panel', scopes: 'admin', redirect_uri: '') }
|
14
|
+
let(:read_app) { Spree::OauthApplication.find_or_create_by!(name: 'Read App', scopes: 'read', redirect_uri: '') }
|
11
15
|
let(:oauth_token) do
|
12
|
-
|
16
|
+
Spree::OauthAccessToken.create!(
|
13
17
|
application_id: admin_app.id,
|
14
18
|
scopes: admin_app.scopes
|
15
19
|
)
|
16
20
|
end
|
17
21
|
let(:read_oauth_token) do
|
18
|
-
|
22
|
+
Spree::OauthAccessToken.create!(
|
19
23
|
application_id: read_app.id,
|
20
24
|
scopes: read_app.scopes
|
21
25
|
)
|
22
26
|
end
|
23
27
|
let(:user_oauth_token) do
|
24
|
-
|
25
|
-
|
28
|
+
Spree::OauthAccessToken.create!(
|
29
|
+
resource_owner: user,
|
26
30
|
application_id: admin_app.id,
|
27
31
|
scopes: admin_app.scopes
|
28
32
|
)
|
29
33
|
end
|
34
|
+
let(:user_oauth_token_without_app) do
|
35
|
+
Spree::OauthAccessToken.create!(
|
36
|
+
resource_owner: user,
|
37
|
+
scopes: 'admin'
|
38
|
+
)
|
39
|
+
end
|
40
|
+
|
30
41
|
|
31
42
|
let(:valid_authorization) { "Bearer #{oauth_token.token}" }
|
32
43
|
let(:valid_read_authorization) { "Bearer #{read_oauth_token.token}" }
|
33
44
|
let(:valid_user_authorization) { "Bearer #{user_oauth_token.token}" }
|
45
|
+
let(:valid_user_authorization_without_app) { "Bearer #{user_oauth_token_without_app.token}" }
|
34
46
|
let(:bogus_authorization) { "Bearer #{::Base64.strict_encode64('bogus:bogus')}" }
|
35
47
|
|
36
48
|
let(:Authorization) { valid_authorization }
|
@@ -53,9 +65,14 @@ def json_api_include_parameter(example = '')
|
|
53
65
|
parameter name: :include, in: :query, type: :string, description: JSON_API_INCLUDES_DESCRIPTION, example: example
|
54
66
|
end
|
55
67
|
|
56
|
-
def json_api_filter_parameter(
|
57
|
-
|
58
|
-
|
68
|
+
def json_api_filter_parameter(examples = [])
|
69
|
+
examples.each do |api_filter|
|
70
|
+
name = api_filter[:name].to_sym
|
71
|
+
example = api_filter[:example]
|
72
|
+
let(name) { nil }
|
73
|
+
|
74
|
+
parameter name: name, in: :query, type: :string, description: JSON_API_FILTER_DESCRIPTION, example: example
|
75
|
+
end
|
59
76
|
end
|
60
77
|
|
61
78
|
shared_examples 'authentication failed' do
|
@@ -95,21 +112,21 @@ shared_examples 'records returned' do
|
|
95
112
|
end
|
96
113
|
|
97
114
|
shared_examples 'record created' do
|
98
|
-
response '201', '
|
115
|
+
response '201', 'Record created' do
|
99
116
|
schema '$ref' => '#/components/schemas/resource'
|
100
117
|
run_test!
|
101
118
|
end
|
102
119
|
end
|
103
120
|
|
104
121
|
shared_examples 'record updated' do
|
105
|
-
response '200', '
|
122
|
+
response '200', 'Record updated' do
|
106
123
|
schema '$ref' => '#/components/schemas/resource'
|
107
124
|
run_test!
|
108
125
|
end
|
109
126
|
end
|
110
127
|
|
111
128
|
shared_examples 'invalid request' do |param_name|
|
112
|
-
response '422', '
|
129
|
+
response '422', 'Invalid request' do
|
113
130
|
let(param_name) { invalid_param_value }
|
114
131
|
schema '$ref' => '#/components/schemas/validation_errors'
|
115
132
|
run_test!
|
@@ -117,13 +134,17 @@ shared_examples 'invalid request' do |param_name|
|
|
117
134
|
end
|
118
135
|
|
119
136
|
# index action
|
120
|
-
shared_examples 'GET records list' do |resource_name,
|
121
|
-
|
122
|
-
|
137
|
+
shared_examples 'GET records list' do |resource_name, **options|
|
138
|
+
endpoint_name = options[:custom_endpoint_name] || resource_name
|
139
|
+
|
140
|
+
get "Return a list of #{endpoint_name.pluralize}" do
|
141
|
+
tags endpoint_name.pluralize
|
123
142
|
security [ bearer_auth: [] ]
|
143
|
+
description "Returns a list of #{endpoint_name.pluralize}"
|
144
|
+
operationId "#{resource_name.parameterize.pluralize.to_sym}-list"
|
124
145
|
include_context 'jsonapi pagination'
|
125
|
-
json_api_include_parameter(include_example)
|
126
|
-
json_api_filter_parameter(
|
146
|
+
json_api_include_parameter(options[:include_example]) unless options[:include_example].nil?
|
147
|
+
json_api_filter_parameter(options[:filter_examples]) unless options[:filter_examples].nil?
|
127
148
|
|
128
149
|
before { records_list }
|
129
150
|
|
@@ -133,12 +154,16 @@ shared_examples 'GET records list' do |resource_name, include_example, filter_ex
|
|
133
154
|
end
|
134
155
|
|
135
156
|
# show
|
136
|
-
shared_examples 'GET record' do |resource_name,
|
137
|
-
|
138
|
-
|
157
|
+
shared_examples 'GET record' do |resource_name, **options|
|
158
|
+
endpoint_name = options[:custom_endpoint_name] || resource_name
|
159
|
+
|
160
|
+
get "Return #{endpoint_name.articleize}" do
|
161
|
+
tags endpoint_name.pluralize
|
139
162
|
security [ bearer_auth: [] ]
|
163
|
+
description "Returns #{endpoint_name.articleize}"
|
164
|
+
operationId "show-#{resource_name.parameterize.to_sym}"
|
140
165
|
parameter name: :id, in: :path, type: :string
|
141
|
-
json_api_include_parameter(include_example)
|
166
|
+
json_api_include_parameter(options[:include_example]) unless options[:include_example].nil?
|
142
167
|
|
143
168
|
it_behaves_like 'record found'
|
144
169
|
it_behaves_like 'record not found'
|
@@ -147,49 +172,83 @@ shared_examples 'GET record' do |resource_name, include_example|
|
|
147
172
|
end
|
148
173
|
|
149
174
|
# create
|
150
|
-
shared_examples 'POST create record' do |resource_name,
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
175
|
+
shared_examples 'POST create record' do |resource_name, **options|
|
176
|
+
custom_create_params = options[:custom_create_params] || nil
|
177
|
+
endpoint_name = options[:custom_endpoint_name] || resource_name
|
178
|
+
param_name = resource_name.parameterize(separator: '_').to_sym
|
179
|
+
consumes_kind = options[:consumes_kind] || 'application/json'
|
180
|
+
request_data_type = case consumes_kind
|
181
|
+
when 'multipart/form-data'
|
182
|
+
:formData
|
183
|
+
else
|
184
|
+
:body
|
185
|
+
end
|
186
|
+
|
187
|
+
post "Create #{endpoint_name.articleize}" do
|
188
|
+
tags endpoint_name.pluralize
|
189
|
+
consumes consumes_kind
|
156
190
|
security [ bearer_auth: [] ]
|
157
|
-
|
158
|
-
|
191
|
+
description "Creates #{endpoint_name.articleize}"
|
192
|
+
operationId "create-#{resource_name.parameterize.to_sym}"
|
193
|
+
if custom_create_params
|
194
|
+
parameter name: param_name, in: request_data_type, schema: custom_create_params
|
195
|
+
else
|
196
|
+
parameter name: param_name, in: request_data_type, schema: { '$ref' => "#/components/schemas/create_#{param_name}_params" }
|
197
|
+
end
|
198
|
+
json_api_include_parameter(options[:include_example]) unless options[:include_example].nil?
|
159
199
|
|
160
200
|
let(param_name) { valid_create_param_value }
|
161
201
|
|
162
202
|
it_behaves_like 'record created'
|
163
|
-
it_behaves_like 'invalid request', param_name
|
203
|
+
it_behaves_like 'invalid request', param_name unless options[:skip_invalid_params] == true
|
164
204
|
end
|
165
205
|
end
|
166
206
|
|
167
207
|
# update
|
168
|
-
shared_examples '
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
208
|
+
shared_examples 'PATCH update record' do |resource_name, **options|
|
209
|
+
custom_update_params = options[:custom_update_params] || nil
|
210
|
+
endpoint_name = options[:custom_endpoint_name] || resource_name
|
211
|
+
param_name = resource_name.parameterize(separator: '_').to_sym
|
212
|
+
consumes_kind = options[:consumes_kind] || 'application/json'
|
213
|
+
request_data_type = case consumes_kind
|
214
|
+
when 'multipart/form-data'
|
215
|
+
:formData
|
216
|
+
else
|
217
|
+
:body
|
218
|
+
end
|
219
|
+
|
220
|
+
patch "Update #{endpoint_name.articleize}" do
|
221
|
+
tags endpoint_name.pluralize
|
173
222
|
security [ bearer_auth: [] ]
|
174
|
-
|
223
|
+
description "Updates #{endpoint_name.articleize}"
|
224
|
+
operationId "update-#{resource_name.parameterize.to_sym}"
|
225
|
+
consumes consumes_kind
|
175
226
|
parameter name: :id, in: :path, type: :string
|
176
|
-
|
177
|
-
|
227
|
+
if custom_update_params
|
228
|
+
parameter name: param_name, in: request_data_type, schema: custom_update_params
|
229
|
+
else
|
230
|
+
parameter name: param_name, in: request_data_type, schema: { '$ref' => "#/components/schemas/update_#{param_name}_params" }
|
231
|
+
end
|
232
|
+
json_api_include_parameter(options[:include_example]) unless options[:include_example].nil?
|
178
233
|
|
179
234
|
let(param_name) { valid_update_param_value }
|
180
235
|
|
181
236
|
it_behaves_like 'record updated'
|
182
|
-
it_behaves_like 'invalid request', param_name
|
237
|
+
it_behaves_like 'invalid request', param_name unless options[:skip_invalid_params] == true
|
183
238
|
it_behaves_like 'record not found'
|
184
239
|
it_behaves_like 'authentication failed'
|
185
240
|
end
|
186
241
|
end
|
187
242
|
|
188
243
|
# destroy
|
189
|
-
shared_examples 'DELETE record' do |resource_name|
|
190
|
-
|
191
|
-
|
244
|
+
shared_examples 'DELETE record' do |resource_name, **options|
|
245
|
+
endpoint_name = options[:custom_endpoint_name] || resource_name
|
246
|
+
|
247
|
+
delete "Delete #{endpoint_name.articleize}" do
|
248
|
+
tags endpoint_name.pluralize
|
192
249
|
security [ bearer_auth: [] ]
|
250
|
+
description "Deletes #{endpoint_name.articleize}"
|
251
|
+
operationId "delete-#{resource_name.parameterize.to_sym}"
|
193
252
|
parameter name: :id, in: :path, type: :string
|
194
253
|
|
195
254
|
it_behaves_like 'record deleted'
|
@@ -198,17 +257,17 @@ shared_examples 'DELETE record' do |resource_name|
|
|
198
257
|
end
|
199
258
|
end
|
200
259
|
|
201
|
-
shared_examples 'CRUD examples' do |resource_name,
|
202
|
-
resource_path = resource_name.
|
260
|
+
shared_examples 'CRUD examples' do |resource_name, **options|
|
261
|
+
resource_path = resource_name.parameterize(separator: '_').pluralize
|
203
262
|
|
204
263
|
path "/api/v2/platform/#{resource_path}" do
|
205
|
-
include_examples 'GET records list', resource_name,
|
206
|
-
include_examples 'POST create record', resource_name,
|
264
|
+
include_examples 'GET records list', resource_name, options
|
265
|
+
include_examples 'POST create record', resource_name, options
|
207
266
|
end
|
208
267
|
|
209
268
|
path "/api/v2/platform/#{resource_path}/{id}" do
|
210
|
-
include_examples 'GET record', resource_name,
|
211
|
-
include_examples '
|
212
|
-
include_examples 'DELETE record', resource_name
|
269
|
+
include_examples 'GET record', resource_name, options
|
270
|
+
include_examples 'PATCH update record', resource_name, options
|
271
|
+
include_examples 'DELETE record', resource_name, options
|
213
272
|
end
|
214
273
|
end
|
@@ -2,13 +2,15 @@ shared_context 'API v2 serializers params' do
|
|
2
2
|
let(:store) { Spree::Store.default || create(:store, default: true) }
|
3
3
|
let(:currency) { store.default_currency }
|
4
4
|
let(:locale) { store.default_locale }
|
5
|
+
let(:zone) { Spree::Zone.default_tax || create(:zone, default_tax: true) }
|
5
6
|
|
6
7
|
let(:serializer_params) do
|
7
8
|
{
|
8
9
|
store: store,
|
9
10
|
currency: currency,
|
10
11
|
user: nil,
|
11
|
-
locale: locale
|
12
|
+
locale: locale,
|
13
|
+
price_options: { tax_zone: zone }
|
12
14
|
}
|
13
15
|
end
|
14
16
|
end
|
data/lib/spree/api.rb
CHANGED
Binary file
|
data/spree_api.gemspec
CHANGED
@@ -1,36 +1,37 @@
|
|
1
|
-
|
2
|
-
require_relative '../core/lib/spree/core/version.rb'
|
1
|
+
require_relative '../core/lib/spree/core/version'
|
3
2
|
|
4
3
|
Gem::Specification.new do |s|
|
5
|
-
s.name =
|
4
|
+
s.name = 'spree_api'
|
6
5
|
s.version = Spree.version
|
7
|
-
s.authors = [
|
8
|
-
s.email = [
|
6
|
+
s.authors = ['Ryan Bigg']
|
7
|
+
s.email = ['ryan@spreecommerce.com']
|
9
8
|
s.summary = %q{Spree's API}
|
10
9
|
s.description = %q{Spree's API}
|
11
10
|
s.homepage = 'https://spreecommerce.org'
|
12
11
|
s.license = 'BSD-3-Clause'
|
13
12
|
|
14
13
|
s.metadata = {
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
14
|
+
'bug_tracker_uri' => 'https://github.com/spree/spree/issues',
|
15
|
+
'changelog_uri' => "https://github.com/spree/spree/releases/tag/v#{s.version}",
|
16
|
+
'documentation_uri' => 'https://dev-docs.spreecommerce.org/',
|
17
|
+
'source_code_uri' => "https://github.com/spree/spree/tree/v#{s.version}",
|
19
18
|
}
|
20
19
|
|
21
20
|
s.required_ruby_version = '>= 2.5'
|
22
21
|
|
23
22
|
s.files = `git ls-files`.split($\).reject { |f| f.match(/^spec/) && !f.match(/^spec\/fixtures/) }
|
24
|
-
s.executables = s.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
25
|
-
s.require_paths = [
|
23
|
+
s.executables = s.files.grep(%r{^bin/}).map { |f| File.basename(f) }
|
24
|
+
s.require_paths = ['lib']
|
26
25
|
|
26
|
+
s.add_development_dependency 'i18n-tasks'
|
27
27
|
s.add_development_dependency 'jsonapi-rspec'
|
28
|
-
s.add_development_dependency 'rswag-specs'
|
29
28
|
s.add_development_dependency 'multi_json'
|
29
|
+
s.add_development_dependency 'rswag-specs'
|
30
30
|
|
31
|
-
s.add_dependency '
|
32
|
-
s.add_dependency '
|
31
|
+
s.add_dependency 'bcrypt', '~> 3.1'
|
32
|
+
s.add_dependency 'doorkeeper', '~> 5.3'
|
33
33
|
s.add_dependency 'jsonapi-serializer', '~> 2.1'
|
34
|
-
s.add_dependency '
|
34
|
+
s.add_dependency 'rabl', '~> 0.14', '>= 0.14.2'
|
35
35
|
s.add_dependency 'responders'
|
36
|
+
s.add_dependency 'spree_core', s.version
|
36
37
|
end
|