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.
Files changed (205) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/concerns/spree/api/v2/caching.rb +7 -3
  3. data/app/controllers/concerns/spree/api/v2/coupon_codes_helper.rb +29 -0
  4. data/app/controllers/concerns/spree/api/v2/number_resource.rb +11 -0
  5. data/app/controllers/concerns/spree/api/v2/platform/nested_set_reposition_concern.rb +37 -0
  6. data/app/controllers/concerns/spree/api/v2/platform/promotion_calculator_params.rb +17 -0
  7. data/app/controllers/concerns/spree/api/v2/platform/promotion_rule_params.rb +16 -0
  8. data/app/controllers/concerns/spree/api/v2/storefront/metadata_controller_concern.rb +18 -0
  9. data/app/controllers/spree/api/v1/checkouts_controller.rb +1 -1
  10. data/app/controllers/spree/api/v2/base_controller.rb +7 -5
  11. data/app/controllers/spree/api/v2/platform/adjustments_controller.rb +19 -0
  12. data/app/controllers/spree/api/v2/platform/classifications_controller.rb +1 -22
  13. data/app/controllers/spree/api/v2/platform/cms_pages_controller.rb +4 -0
  14. data/app/controllers/spree/api/v2/platform/cms_sections_controller.rb +13 -18
  15. data/app/controllers/spree/api/v2/platform/digital_links_controller.rb +25 -0
  16. data/app/controllers/spree/api/v2/platform/digitals_controller.rb +19 -0
  17. data/app/controllers/spree/api/v2/platform/line_items_controller.rb +59 -0
  18. data/app/controllers/spree/api/v2/platform/menu_items_controller.rb +5 -19
  19. data/app/controllers/spree/api/v2/platform/menus_controller.rb +0 -4
  20. data/app/controllers/spree/api/v2/platform/orders_controller.rb +163 -0
  21. data/app/controllers/spree/api/v2/platform/payment_methods_controller.rb +27 -0
  22. data/app/controllers/spree/api/v2/platform/payments_controller.rb +17 -0
  23. data/app/controllers/spree/api/v2/platform/promotion_actions_controller.rb +30 -0
  24. data/app/controllers/spree/api/v2/platform/promotion_categories_controller.rb +19 -0
  25. data/app/controllers/spree/api/v2/platform/promotion_rules_controller.rb +25 -0
  26. data/app/controllers/spree/api/v2/platform/promotions_controller.rb +31 -0
  27. data/app/controllers/spree/api/v2/platform/resource_controller.rb +47 -16
  28. data/app/controllers/spree/api/v2/platform/roles_controller.rb +15 -0
  29. data/app/controllers/spree/api/v2/platform/shipments_controller.rb +143 -0
  30. data/app/controllers/spree/api/v2/platform/shipping_categories_controller.rb +15 -0
  31. data/app/controllers/spree/api/v2/platform/shipping_methods_controller.rb +24 -0
  32. data/app/controllers/spree/api/v2/platform/states_controller.rb +19 -0
  33. data/app/controllers/spree/api/v2/platform/stock_items_controller.rb +19 -0
  34. data/app/controllers/spree/api/v2/platform/stock_locations_controller.rb +19 -0
  35. data/app/controllers/spree/api/v2/platform/store_credit_categories_controller.rb +15 -0
  36. data/app/controllers/spree/api/v2/platform/store_credit_types_controller.rb +15 -0
  37. data/app/controllers/spree/api/v2/platform/store_credits_controller.rb +19 -0
  38. data/app/controllers/spree/api/v2/platform/tax_categories_controller.rb +19 -0
  39. data/app/controllers/spree/api/v2/platform/tax_rates_controller.rb +23 -0
  40. data/app/controllers/spree/api/v2/platform/taxonomies_controller.rb +19 -0
  41. data/app/controllers/spree/api/v2/platform/taxons_controller.rb +25 -0
  42. data/app/controllers/spree/api/v2/platform/users_controller.rb +4 -0
  43. data/app/controllers/spree/api/v2/platform/variants_controller.rb +19 -0
  44. data/app/controllers/spree/api/v2/platform/webhooks/events_controller.rb +21 -0
  45. data/app/controllers/spree/api/v2/platform/webhooks/subscribers_controller.rb +21 -0
  46. data/app/controllers/spree/api/v2/platform/wished_items_controller.rb +19 -0
  47. data/app/controllers/spree/api/v2/platform/wishlists_controller.rb +19 -0
  48. data/app/controllers/spree/api/v2/platform/zones_controller.rb +19 -0
  49. data/app/controllers/spree/api/v2/resource_controller.rb +3 -3
  50. data/app/controllers/spree/api/v2/storefront/account/addresses_controller.rb +5 -3
  51. data/app/controllers/spree/api/v2/storefront/account/credit_cards_controller.rb +4 -1
  52. data/app/controllers/spree/api/v2/storefront/cart_controller.rb +57 -29
  53. data/app/controllers/spree/api/v2/storefront/checkout_controller.rb +24 -0
  54. data/app/controllers/spree/api/v2/storefront/digitals_controller.rb +54 -0
  55. data/app/controllers/spree/api/v2/storefront/products_controller.rb +8 -0
  56. data/app/controllers/spree/api/v2/storefront/wishlists_controller.rb +171 -0
  57. data/app/helpers/spree/api/v2/collection_options_helpers.rb +1 -1
  58. data/app/jobs/spree/webhooks/subscribers/make_request_job.rb +17 -0
  59. data/app/models/concerns/spree/webhooks/has_webhooks.rb +58 -0
  60. data/app/models/spree/api/webhooks/order_decorator.rb +43 -0
  61. data/app/models/spree/api/webhooks/payment_decorator.rb +26 -0
  62. data/app/models/spree/api/webhooks/product_decorator.rb +27 -0
  63. data/app/models/spree/api/webhooks/shipment_decorator.rb +21 -0
  64. data/app/models/spree/api/webhooks/stock_item_decorator.rb +43 -0
  65. data/app/models/spree/api/webhooks/stock_movement_decorator.rb +52 -0
  66. data/app/models/spree/api/webhooks/variant_decorator.rb +26 -0
  67. data/app/models/spree/oauth_access_grant.rb +7 -0
  68. data/app/models/spree/oauth_access_token.rb +7 -0
  69. data/app/models/spree/oauth_application.rb +15 -0
  70. data/app/models/spree/webhooks/base.rb +11 -0
  71. data/app/models/spree/webhooks/event.rb +12 -0
  72. data/app/models/spree/webhooks/subscriber.rb +57 -0
  73. data/app/presenters/spree/api/products/filters_presenter.rb +39 -0
  74. data/app/serializers/concerns/spree/api/v2/resource_serializer_concern.rb +19 -1
  75. data/app/serializers/spree/api/v2/base_serializer.rb +11 -4
  76. data/app/serializers/spree/api/v2/platform/address_serializer.rb +1 -1
  77. data/app/serializers/spree/api/v2/platform/adjustment_serializer.rb +20 -0
  78. data/app/serializers/spree/api/v2/platform/asset_serializer.rb +13 -0
  79. data/app/serializers/spree/api/v2/platform/calculator_serializer.rb +17 -0
  80. data/app/serializers/spree/api/v2/platform/classification_serializer.rb +1 -1
  81. data/app/serializers/spree/api/v2/platform/cms_page_serializer.rb +1 -1
  82. data/app/serializers/spree/api/v2/platform/cms_section_serializer.rb +8 -1
  83. data/app/serializers/spree/api/v2/platform/country_serializer.rb +1 -1
  84. data/app/serializers/spree/api/v2/platform/credit_card_serializer.rb +14 -0
  85. data/app/serializers/spree/api/v2/platform/customer_return_serializer.rb +17 -0
  86. data/app/serializers/spree/api/v2/platform/digital_link_serializer.rb +16 -0
  87. data/app/serializers/spree/api/v2/platform/digital_serializer.rb +30 -0
  88. data/app/serializers/spree/api/v2/platform/feature_page_serializer.rb +11 -0
  89. data/app/serializers/spree/api/v2/platform/homepage_serializer.rb +11 -0
  90. data/app/serializers/spree/api/v2/platform/inventory_unit_serializer.rb +19 -0
  91. data/app/serializers/spree/api/v2/platform/line_item_serializer.rb +19 -0
  92. data/app/serializers/spree/api/v2/platform/log_entry_serializer.rb +13 -0
  93. data/app/serializers/spree/api/v2/platform/menu_item_serializer.rb +1 -1
  94. data/app/serializers/spree/api/v2/platform/menu_serializer.rb +1 -1
  95. data/app/serializers/spree/api/v2/platform/option_type_serializer.rb +1 -1
  96. data/app/serializers/spree/api/v2/platform/option_value_serializer.rb +1 -1
  97. data/app/serializers/spree/api/v2/platform/order_promotion_serializer.rb +14 -0
  98. data/app/serializers/spree/api/v2/platform/order_serializer.rb +31 -0
  99. data/app/serializers/spree/api/v2/platform/payment_capture_event_serializer.rb +13 -0
  100. data/app/serializers/spree/api/v2/platform/payment_method_serializer.rb +18 -0
  101. data/app/serializers/spree/api/v2/platform/payment_serializer.rb +21 -0
  102. data/app/serializers/spree/api/v2/platform/price_serializer.rb +19 -0
  103. data/app/serializers/spree/api/v2/platform/product_property_serializer.rb +1 -1
  104. data/app/serializers/spree/api/v2/platform/product_serializer.rb +7 -3
  105. data/app/serializers/spree/api/v2/platform/promotion_action_line_item_serializer.rb +14 -0
  106. data/app/serializers/spree/api/v2/platform/promotion_action_serializer.rb +19 -0
  107. data/app/serializers/spree/api/v2/platform/promotion_category_serializer.rb +13 -0
  108. data/app/serializers/spree/api/v2/platform/promotion_rule_serializer.rb +21 -0
  109. data/app/serializers/spree/api/v2/platform/promotion_serializer.rb +17 -0
  110. data/app/serializers/spree/api/v2/platform/property_serializer.rb +11 -0
  111. data/app/serializers/spree/api/v2/platform/prototype_serializer.rb +15 -0
  112. data/app/serializers/spree/api/v2/platform/refund_reason_serializer.rb +11 -0
  113. data/app/serializers/spree/api/v2/platform/refund_serializer.rb +16 -0
  114. data/app/serializers/spree/api/v2/platform/reimbursement_credit_serializer.rb +10 -0
  115. data/app/serializers/spree/api/v2/platform/reimbursement_serializer.rb +18 -0
  116. data/app/serializers/spree/api/v2/platform/reimbursement_type_serializer.rb +11 -0
  117. data/app/serializers/spree/api/v2/platform/return_authorization_reason_serializer.rb +11 -0
  118. data/app/serializers/spree/api/v2/platform/return_authorization_serializer.rb +17 -0
  119. data/app/serializers/spree/api/v2/platform/return_item_serializer.rb +16 -0
  120. data/app/serializers/spree/api/v2/platform/role_serializer.rb +11 -0
  121. data/app/serializers/spree/api/v2/platform/shipment_serializer.rb +22 -0
  122. data/app/serializers/spree/api/v2/platform/shipping_category_serializer.rb +11 -0
  123. data/app/serializers/spree/api/v2/platform/shipping_method_serializer.rb +16 -0
  124. data/app/serializers/spree/api/v2/platform/shipping_rate_serializer.rb +15 -0
  125. data/app/serializers/spree/api/v2/platform/standard_page_serializer.rb +11 -0
  126. data/app/serializers/spree/api/v2/platform/state_change_serializer.rb +13 -0
  127. data/app/serializers/spree/api/v2/platform/state_serializer.rb +1 -1
  128. data/app/serializers/spree/api/v2/platform/stock_item_serializer.rb +1 -3
  129. data/app/serializers/spree/api/v2/platform/stock_location_serializer.rb +2 -4
  130. data/app/serializers/spree/api/v2/platform/stock_movement_serializer.rb +11 -0
  131. data/app/serializers/spree/api/v2/platform/stock_transfer_serializer.rb +15 -0
  132. data/app/serializers/spree/api/v2/platform/store_credit_category_serializer.rb +12 -0
  133. data/app/serializers/spree/api/v2/platform/store_credit_event_serializer.rb +14 -0
  134. data/app/serializers/spree/api/v2/platform/store_credit_serializer.rb +18 -0
  135. data/app/serializers/spree/api/v2/platform/store_credit_type_serializer.rb +12 -0
  136. data/app/serializers/spree/api/v2/platform/store_serializer.rb +1 -1
  137. data/app/serializers/spree/api/v2/platform/tax_category_serializer.rb +2 -2
  138. data/app/serializers/spree/api/v2/platform/tax_rate_serializer.rb +14 -0
  139. data/app/serializers/spree/api/v2/platform/taxon_serializer.rb +1 -1
  140. data/app/serializers/spree/api/v2/platform/taxonomy_serializer.rb +1 -1
  141. data/app/serializers/spree/api/v2/platform/user_serializer.rb +1 -1
  142. data/app/serializers/spree/api/v2/platform/variant_serializer.rb +3 -2
  143. data/app/serializers/spree/api/v2/platform/webhooks/event_serializer.rb +15 -0
  144. data/app/serializers/spree/api/v2/platform/webhooks/subscriber_serializer.rb +13 -0
  145. data/app/serializers/spree/api/v2/platform/wished_item_serializer.rb +29 -0
  146. data/app/serializers/spree/api/v2/platform/wishlist_serializer.rb +19 -0
  147. data/app/serializers/spree/api/v2/platform/zone_member_serializer.rb +13 -0
  148. data/app/serializers/spree/api/v2/platform/zone_serializer.rb +13 -0
  149. data/app/serializers/spree/v2/storefront/address_serializer.rb +1 -1
  150. data/app/serializers/spree/v2/storefront/cart_serializer.rb +1 -1
  151. data/app/serializers/spree/v2/storefront/cms_section_serializer.rb +5 -1
  152. data/app/serializers/spree/v2/storefront/credit_card_serializer.rb +1 -1
  153. data/app/serializers/spree/v2/storefront/digital_link_serializer.rb +11 -0
  154. data/app/serializers/spree/v2/storefront/estimated_shipping_rate_serializer.rb +2 -2
  155. data/app/serializers/spree/v2/storefront/line_item_serializer.rb +2 -1
  156. data/app/serializers/spree/v2/storefront/option_type_serializer.rb +1 -1
  157. data/app/serializers/spree/v2/storefront/option_value_serializer.rb +1 -1
  158. data/app/serializers/spree/v2/storefront/payment_method_serializer.rb +1 -1
  159. data/app/serializers/spree/v2/storefront/payment_serializer.rb +1 -1
  160. data/app/serializers/spree/v2/storefront/product_serializer.rb +2 -2
  161. data/app/serializers/spree/v2/storefront/promotion_serializer.rb +1 -1
  162. data/app/serializers/spree/v2/storefront/shipment_serializer.rb +2 -1
  163. data/app/serializers/spree/v2/storefront/store_credit_serializer.rb +1 -1
  164. data/app/serializers/spree/v2/storefront/store_serializer.rb +1 -1
  165. data/app/serializers/spree/v2/storefront/taxon_serializer.rb +1 -1
  166. data/app/serializers/spree/v2/storefront/taxonomy_serializer.rb +1 -1
  167. data/app/serializers/spree/v2/storefront/user_serializer.rb +1 -1
  168. data/app/serializers/spree/v2/storefront/variant_serializer.rb +1 -1
  169. data/app/serializers/spree/v2/storefront/wished_item_serializer.rb +29 -0
  170. data/app/serializers/spree/v2/storefront/wishlist_serializer.rb +17 -0
  171. data/app/services/spree/webhooks/subscribers/handle_request.rb +73 -0
  172. data/app/services/spree/webhooks/subscribers/make_request.rb +82 -0
  173. data/app/services/spree/webhooks/subscribers/queue_requests.rb +17 -0
  174. data/app/services/spree/webhooks.rb +13 -0
  175. data/config/i18n-tasks.yml +40 -0
  176. data/config/initializers/doorkeeper.rb +12 -12
  177. data/config/initializers/rabl.rb +2 -2
  178. data/config/locales/en.yml +29 -27
  179. data/config/routes.rb +85 -59
  180. data/db/migrate/20210902162826_create_spree_webhooks_tables.rb +16 -0
  181. data/db/migrate/20210919183228_enable_polymorphic_resource_owner.rb +21 -0
  182. data/db/migrate/20211025162826_create_spree_webhooks_events.rb +14 -0
  183. data/docs/oauth/index.yml +126 -33
  184. data/docs/v2/platform/index.yaml +19182 -1717
  185. data/docs/v2/storefront/index.yaml +14823 -14588
  186. data/{app/models/spree → lib/spree/api}/api_dependencies.rb +60 -5
  187. data/lib/spree/api/engine.rb +24 -1
  188. data/lib/spree/api/testing_support/factories/oauth_application_factory.rb +6 -0
  189. data/lib/spree/api/testing_support/factories/webhook_event_factory.rb +27 -0
  190. data/lib/spree/api/testing_support/factories/webhook_subscriber_factory.rb +13 -0
  191. data/lib/spree/api/testing_support/factories.rb +3 -0
  192. data/lib/spree/api/testing_support/helpers.rb +1 -1
  193. data/lib/spree/api/testing_support/jobs.rb +18 -0
  194. data/lib/spree/api/testing_support/matchers/webhooks.rb +67 -0
  195. data/lib/spree/api/testing_support/serializers.rb +25 -0
  196. data/lib/spree/api/testing_support/spree_webhooks.rb +9 -0
  197. data/lib/spree/api/testing_support/v2/base.rb +1 -1
  198. data/lib/spree/api/testing_support/v2/current_order.rb +34 -1
  199. data/lib/spree/api/testing_support/v2/platform_contexts.rb +109 -50
  200. data/lib/spree/api/testing_support/v2/serializers_params.rb +3 -1
  201. data/lib/spree/api.rb +1 -0
  202. data/spec/fixtures/files/icon_256x256.jpg +0 -0
  203. data/spree_api.gemspec +16 -15
  204. metadata +176 -28
  205. data/app/controllers/spree/api/errors_controller.rb +0 -9
@@ -1,36 +1,48 @@
1
1
  class String
2
2
  def articleize
3
- %w(a e i o u).include?(self[0].downcase) ? "an #{self}" : "a #{self}"
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) { Doorkeeper::Application.find_or_create_by!(name: 'Admin Panel', scopes: 'admin', redirect_uri: '') }
10
- let(:read_app) { Doorkeeper::Application.find_or_create_by!(name: 'Read App', scopes: 'read', redirect_uri: '') }
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
- Doorkeeper::AccessToken.create!(
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
- Doorkeeper::AccessToken.create!(
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
- Doorkeeper::AccessToken.create!(
25
- resource_owner_id: user.id,
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(example = '')
57
- let(:filter) { nil }
58
- parameter name: :filter, in: :query, type: :string, description: JSON_API_FILTER_DESCRIPTION, example: example
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', 'record created' do
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', 'record updated' do
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', 'invalid request' do
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, include_example, filter_example|
121
- get "Returns a list of #{resource_name.pluralize}" do
122
- tags resource_name.pluralize
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(filter_example)
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, include_example|
137
- get "Returns #{resource_name.articleize}" do
138
- tags resource_name.pluralize
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, include_example|
151
- param_name = resource_name.tableize.to_sym
152
-
153
- post "Creates #{resource_name.articleize}" do
154
- tags resource_name.pluralize
155
- consumes 'application/json'
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
- parameter name: param_name, in: :body, schema: { '$ref' => "#/components/schemas/#{param_name}_params" }
158
- json_api_include_parameter(include_example)
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 'PUT update record' do |resource_name, include_example|
169
- param_name = resource_name.tableize.to_sym
170
-
171
- put "Updates #{resource_name.articleize}" do
172
- tags resource_name.pluralize
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
- consumes 'application/json'
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
- parameter name: param_name, in: :body, schema: { '$ref' => "#/components/schemas/#{param_name}_params" }
177
- json_api_include_parameter(include_example)
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
- delete "Deletes #{resource_name.articleize}" do
191
- tags resource_name.pluralize
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, include_example, filter_example|
202
- resource_path = resource_name.tableize.pluralize
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, include_example, filter_example
206
- include_examples 'POST create record', resource_name, include_example
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, include_example
211
- include_examples 'PUT update record', resource_name, include_example
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
@@ -8,4 +8,5 @@ module Spree
8
8
  end
9
9
  end
10
10
 
11
+ require 'spree/api/api_dependencies'
11
12
  require 'spree/api/engine'
data/spree_api.gemspec CHANGED
@@ -1,36 +1,37 @@
1
- # -*- encoding: utf-8 -*-
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 = "spree_api"
4
+ s.name = 'spree_api'
6
5
  s.version = Spree.version
7
- s.authors = ["Ryan Bigg"]
8
- s.email = ["ryan@spreecommerce.com"]
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
- "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://dev-docs.spreecommerce.org/",
18
- "source_code_uri" => "https://github.com/spree/spree/tree/v#{s.version}",
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 = ["lib"]
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 'spree_core', s.version
32
- s.add_dependency 'rabl', '~> 0.14', '>= 0.14.2'
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 'doorkeeper', '~> 5.2', '>= 5.2.1'
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