solidus_api 2.3.1 → 2.4.0.beta1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of solidus_api might be problematic. Click here for more details.

Files changed (234) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/spree/api/base_controller.rb +9 -12
  3. data/app/controllers/spree/api/checkouts_controller.rb +3 -5
  4. data/app/controllers/spree/api/orders_controller.rb +2 -12
  5. data/app/controllers/spree/api/payments_controller.rb +0 -1
  6. data/app/controllers/spree/api/resource_controller.rb +2 -0
  7. data/app/controllers/spree/api/shipments_controller.rb +17 -6
  8. data/app/controllers/spree/api/stock_items_controller.rb +6 -0
  9. data/app/helpers/spree/api/api_helpers.rb +3 -4
  10. data/app/views/.rubocop.yml +4 -0
  11. data/app/views/spree/api/address_books/show.json.jbuilder +11 -0
  12. data/app/views/spree/api/addresses/_address.json.jbuilder +17 -0
  13. data/app/views/spree/api/addresses/show.json.jbuilder +1 -0
  14. data/app/views/spree/api/adjustments/_adjustment.json.jbuilder +4 -0
  15. data/app/views/spree/api/config/money.json.jbuilder +1 -0
  16. data/app/views/spree/api/config/show.json.jbuilder +2 -0
  17. data/app/views/spree/api/countries/index.json.jbuilder +2 -0
  18. data/app/views/spree/api/countries/show.json.jbuilder +4 -0
  19. data/app/views/spree/api/credit_cards/_credit_card.json.jbuilder +10 -0
  20. data/app/views/spree/api/credit_cards/index.json.jbuilder +4 -0
  21. data/app/views/spree/api/credit_cards/show.json.jbuilder +1 -0
  22. data/app/views/spree/api/errors/delete_restriction.json.jbuilder +1 -0
  23. data/app/views/spree/api/errors/gateway_error.json.jbuilder +1 -0
  24. data/app/views/spree/api/errors/invalid_api_key.json.jbuilder +1 -0
  25. data/app/views/spree/api/errors/invalid_resource.json.jbuilder +2 -0
  26. data/app/views/spree/api/errors/must_specify_api_key.json.jbuilder +1 -0
  27. data/app/views/spree/api/errors/not_found.json.jbuilder +1 -0
  28. data/app/views/spree/api/errors/unauthorized.json.jbuilder +1 -0
  29. data/app/views/spree/api/errors/variant_not_in_stock_transfer.json.jbuilder +1 -0
  30. data/app/views/spree/api/images/_image.json.jbuilder +5 -0
  31. data/app/views/spree/api/images/index.json.jbuilder +3 -0
  32. data/app/views/spree/api/images/show.json.jbuilder +1 -0
  33. data/app/views/spree/api/inventory_units/show.json.jbuilder +1 -0
  34. data/app/views/spree/api/line_items/_line_item.json.jbuilder +16 -0
  35. data/app/views/spree/api/line_items/new.json.jbuilder +2 -0
  36. data/app/views/spree/api/line_items/show.json.jbuilder +1 -0
  37. data/app/views/spree/api/option_types/_option_type.json.jbuilder +4 -0
  38. data/app/views/spree/api/option_types/index.json.jbuilder +3 -0
  39. data/app/views/spree/api/option_types/show.json.jbuilder +1 -0
  40. data/app/views/spree/api/option_values/_option_value.json.jbuilder +1 -0
  41. data/app/views/spree/api/option_values/index.json.jbuilder +3 -0
  42. data/app/views/spree/api/option_values/show.json.jbuilder +1 -0
  43. data/app/views/spree/api/orders/_big.json.jbuilder +49 -0
  44. data/app/views/spree/api/orders/_order.json.jbuilder +10 -0
  45. data/app/views/spree/api/orders/could_not_apply_coupon.json.jbuilder +1 -0
  46. data/app/views/spree/api/orders/could_not_transition.json.jbuilder +2 -0
  47. data/app/views/spree/api/orders/expected_total_mismatch.json.jbuilder +1 -0
  48. data/app/views/spree/api/orders/index.json.jbuilder +4 -0
  49. data/app/views/spree/api/orders/invalid_shipping_method.json.jbuilder +1 -0
  50. data/app/views/spree/api/orders/mine.json.jbuilder +4 -0
  51. data/app/views/spree/api/orders/show.json.jbuilder +1 -0
  52. data/app/views/spree/api/payments/credit_over_limit.json.jbuilder +1 -0
  53. data/app/views/spree/api/payments/index.json.jbuilder +2 -0
  54. data/app/views/spree/api/payments/new.json.jbuilder +4 -0
  55. data/app/views/spree/api/payments/show.json.jbuilder +1 -0
  56. data/app/views/spree/api/payments/update_forbidden.json.jbuilder +1 -0
  57. data/app/views/spree/api/product_properties/index.json.jbuilder +4 -0
  58. data/app/views/spree/api/product_properties/new.json.jbuilder +2 -0
  59. data/app/views/spree/api/product_properties/show.json.jbuilder +1 -0
  60. data/app/views/spree/api/products/_product.json.jbuilder +34 -0
  61. data/app/views/spree/api/products/index.json.jbuilder +4 -0
  62. data/app/views/spree/api/products/new.json.jbuilder +2 -0
  63. data/app/views/spree/api/products/show.json.jbuilder +1 -0
  64. data/app/views/spree/api/promotions/handler.json.jbuilder +4 -0
  65. data/app/views/spree/api/promotions/show.json.jbuilder +1 -0
  66. data/app/views/spree/api/properties/index.json.jbuilder +4 -0
  67. data/app/views/spree/api/properties/new.json.jbuilder +2 -0
  68. data/app/views/spree/api/properties/show.json.jbuilder +1 -0
  69. data/app/views/spree/api/return_authorizations/index.json.jbuilder +4 -0
  70. data/app/views/spree/api/return_authorizations/new.json.jbuilder +2 -0
  71. data/app/views/spree/api/return_authorizations/show.json.jbuilder +1 -0
  72. data/app/views/spree/api/shared/_pagination.json.jbuilder +5 -0
  73. data/app/views/spree/api/shipments/_big.json.jbuilder +51 -0
  74. data/app/views/spree/api/shipments/_small.json.jbuilder +32 -0
  75. data/app/views/spree/api/shipments/cannot_ready_shipment.json.jbuilder +1 -0
  76. data/app/views/spree/api/shipments/mine.json.jbuilder +4 -0
  77. data/app/views/spree/api/shipments/show.json.jbuilder +31 -0
  78. data/app/views/spree/api/shipping_rates/_shipping_rate.json.jbuilder +2 -0
  79. data/app/views/spree/api/states/index.json.jbuilder +5 -0
  80. data/app/views/spree/api/states/show.json.jbuilder +1 -0
  81. data/app/views/spree/api/stock_items/_stock_item.json.jbuilder +4 -0
  82. data/app/views/spree/api/stock_items/index.json.jbuilder +4 -0
  83. data/app/views/spree/api/stock_items/show.json.jbuilder +1 -0
  84. data/app/views/spree/api/stock_locations/_stock_location.json.jbuilder +15 -0
  85. data/app/views/spree/api/stock_locations/index.json.jbuilder +4 -0
  86. data/app/views/spree/api/stock_locations/show.json.jbuilder +1 -0
  87. data/app/views/spree/api/stock_movements/_stock_movement.json.jbuilder +4 -0
  88. data/app/views/spree/api/stock_movements/index.json.jbuilder +4 -0
  89. data/app/views/spree/api/stock_movements/show.json.jbuilder +1 -0
  90. data/app/views/spree/api/stock_transfers/receive.json.jbuilder +4 -0
  91. data/app/views/spree/api/store_credit_events/mine.json.jbuilder +5 -0
  92. data/app/views/spree/api/stores/index.json.jbuilder +1 -0
  93. data/app/views/spree/api/stores/show.json.jbuilder +1 -0
  94. data/app/views/spree/api/taxonomies/_nested.json.jbuilder +8 -0
  95. data/app/views/spree/api/taxonomies/_taxonomy.json.jbuilder +11 -0
  96. data/app/views/spree/api/taxonomies/index.json.jbuilder +4 -0
  97. data/app/views/spree/api/taxonomies/jstree.json.jbuilder +6 -0
  98. data/app/views/spree/api/taxonomies/new.json.jbuilder +2 -0
  99. data/app/views/spree/api/taxonomies/show.json.jbuilder +1 -0
  100. data/app/views/spree/api/taxons/_taxon.json.jbuilder +2 -0
  101. data/app/views/spree/api/taxons/_taxons.json.jbuilder +4 -0
  102. data/app/views/spree/api/taxons/index.json.jbuilder +7 -0
  103. data/app/views/spree/api/taxons/jstree.json.jbuilder +8 -0
  104. data/app/views/spree/api/taxons/new.json.jbuilder +2 -0
  105. data/app/views/spree/api/taxons/show.json.jbuilder +1 -0
  106. data/app/views/spree/api/transfer_items/_transfer_item.json.jbuilder +5 -0
  107. data/app/views/spree/api/transfer_items/show.json.jbuilder +1 -0
  108. data/app/views/spree/api/users/_user.json.jbuilder +15 -0
  109. data/app/views/spree/api/users/index.json.jbuilder +4 -0
  110. data/app/views/spree/api/users/new.json.jbuilder +2 -0
  111. data/app/views/spree/api/users/show.json.jbuilder +1 -0
  112. data/app/views/spree/api/variants/_big.json.jbuilder +13 -0
  113. data/app/views/spree/api/variants/_small.json.jbuilder +16 -0
  114. data/app/views/spree/api/variants/index.json.jbuilder +4 -0
  115. data/app/views/spree/api/variants/new.json.jbuilder +2 -0
  116. data/app/views/spree/api/variants/show.json.jbuilder +1 -0
  117. data/app/views/spree/api/zones/_zone.json.jbuilder +4 -0
  118. data/app/views/spree/api/zones/index.json.jbuilder +4 -0
  119. data/app/views/spree/api/zones/show.json.jbuilder +1 -0
  120. data/config/locales/en.yml +1 -0
  121. data/lib/spree/api/engine.rb +0 -14
  122. data/lib/spree/api.rb +1 -1
  123. data/lib/spree_api.rb +1 -0
  124. data/solidus_api.gemspec +3 -1
  125. data/spec/controllers/spree/api/base_controller_spec.rb +0 -56
  126. data/spec/requests/spree/api/checkouts_controller_spec.rb +8 -13
  127. data/spec/requests/spree/api/orders_controller_spec.rb +7 -60
  128. data/spec/requests/spree/api/payments_controller_spec.rb +0 -11
  129. data/spec/requests/spree/api/shipments_controller_spec.rb +16 -1
  130. data/spec/requests/spree/api/states_controller_spec.rb +1 -0
  131. data/spec/requests/spree/api/taxons_controller_spec.rb +25 -0
  132. data/spec/requests/spree/api/users_controller_spec.rb +1 -1
  133. data/spec/support/be_paginated_matcher.rb +7 -0
  134. data/spec/test_views/spree/api/widgets/_widget.json.jbuilder +1 -0
  135. data/spec/test_views/spree/api/widgets/index.json.jbuilder +7 -0
  136. data/spec/test_views/spree/api/widgets/new.json.jbuilder +1 -0
  137. data/spec/test_views/spree/api/widgets/show.json.jbuilder +1 -0
  138. metadata +166 -111
  139. data/app/views/spree/api/address_books/show.v1.rabl +0 -7
  140. data/app/views/spree/api/addresses/show.v1.rabl +0 -10
  141. data/app/views/spree/api/adjustments/show.v1.rabl +0 -4
  142. data/app/views/spree/api/config/money.v1.rabl +0 -2
  143. data/app/views/spree/api/config/show.v1.rabl +0 -3
  144. data/app/views/spree/api/countries/index.v1.rabl +0 -7
  145. data/app/views/spree/api/countries/show.v1.rabl +0 -5
  146. data/app/views/spree/api/credit_cards/index.v1.rabl +0 -7
  147. data/app/views/spree/api/credit_cards/show.v1.rabl +0 -7
  148. data/app/views/spree/api/errors/gateway_error.v1.rabl +0 -2
  149. data/app/views/spree/api/errors/invalid_api_key.v1.rabl +0 -2
  150. data/app/views/spree/api/errors/invalid_resource.v1.rabl +0 -3
  151. data/app/views/spree/api/errors/must_specify_api_key.v1.rabl +0 -2
  152. data/app/views/spree/api/errors/not_found.v1.rabl +0 -2
  153. data/app/views/spree/api/errors/unauthorized.v1.rabl +0 -2
  154. data/app/views/spree/api/errors/variant_not_in_stock_transfer.v1.rabl +0 -2
  155. data/app/views/spree/api/images/index.v1.rabl +0 -4
  156. data/app/views/spree/api/images/show.v1.rabl +0 -6
  157. data/app/views/spree/api/inventory_units/show.rabl +0 -2
  158. data/app/views/spree/api/line_items/new.v1.rabl +0 -3
  159. data/app/views/spree/api/line_items/show.v1.rabl +0 -15
  160. data/app/views/spree/api/option_types/index.v1.rabl +0 -3
  161. data/app/views/spree/api/option_types/show.v1.rabl +0 -5
  162. data/app/views/spree/api/option_values/index.v1.rabl +0 -3
  163. data/app/views/spree/api/option_values/show.v1.rabl +0 -2
  164. data/app/views/spree/api/orders/could_not_apply_coupon.v1.rabl +0 -2
  165. data/app/views/spree/api/orders/could_not_transition.v1.rabl +0 -3
  166. data/app/views/spree/api/orders/expected_total_mismatch.v1.rabl +0 -2
  167. data/app/views/spree/api/orders/index.v1.rabl +0 -7
  168. data/app/views/spree/api/orders/invalid_shipping_method.v1.rabl +0 -2
  169. data/app/views/spree/api/orders/mine.v1.rabl +0 -9
  170. data/app/views/spree/api/orders/order.v1.rabl +0 -9
  171. data/app/views/spree/api/orders/show.v1.rabl +0 -53
  172. data/app/views/spree/api/payments/credit_over_limit.v1.rabl +0 -2
  173. data/app/views/spree/api/payments/index.v1.rabl +0 -7
  174. data/app/views/spree/api/payments/new.v1.rabl +0 -5
  175. data/app/views/spree/api/payments/show.v1.rabl +0 -2
  176. data/app/views/spree/api/payments/update_forbidden.v1.rabl +0 -2
  177. data/app/views/spree/api/product_properties/index.v1.rabl +0 -7
  178. data/app/views/spree/api/product_properties/new.v1.rabl +0 -2
  179. data/app/views/spree/api/product_properties/show.v1.rabl +0 -2
  180. data/app/views/spree/api/products/index.v1.rabl +0 -9
  181. data/app/views/spree/api/products/new.v1.rabl +0 -3
  182. data/app/views/spree/api/products/product.v1.rabl +0 -1
  183. data/app/views/spree/api/products/show.v1.rabl +0 -42
  184. data/app/views/spree/api/promotions/handler.v1.rabl +0 -5
  185. data/app/views/spree/api/promotions/show.v1.rabl +0 -2
  186. data/app/views/spree/api/properties/index.v1.rabl +0 -7
  187. data/app/views/spree/api/properties/new.v1.rabl +0 -2
  188. data/app/views/spree/api/properties/show.v1.rabl +0 -2
  189. data/app/views/spree/api/return_authorizations/index.v1.rabl +0 -7
  190. data/app/views/spree/api/return_authorizations/new.v1.rabl +0 -3
  191. data/app/views/spree/api/return_authorizations/show.v1.rabl +0 -2
  192. data/app/views/spree/api/shipments/big.v1.rabl +0 -55
  193. data/app/views/spree/api/shipments/cannot_ready_shipment.v1.rabl +0 -2
  194. data/app/views/spree/api/shipments/mine.v1.rabl +0 -9
  195. data/app/views/spree/api/shipments/show.v1.rabl +0 -32
  196. data/app/views/spree/api/shipments/small.v1.rabl +0 -37
  197. data/app/views/spree/api/shipping_rates/show.v1.rabl +0 -2
  198. data/app/views/spree/api/states/index.v1.rabl +0 -14
  199. data/app/views/spree/api/states/show.v1.rabl +0 -2
  200. data/app/views/spree/api/stock_items/index.v1.rabl +0 -7
  201. data/app/views/spree/api/stock_items/show.v1.rabl +0 -5
  202. data/app/views/spree/api/stock_locations/index.v1.rabl +0 -7
  203. data/app/views/spree/api/stock_locations/show.v1.rabl +0 -8
  204. data/app/views/spree/api/stock_movements/index.v1.rabl +0 -7
  205. data/app/views/spree/api/stock_movements/show.v1.rabl +0 -5
  206. data/app/views/spree/api/stock_transfers/receive.v1.rabl +0 -5
  207. data/app/views/spree/api/store_credit_events/mine.v1.rabl +0 -10
  208. data/app/views/spree/api/stores/index.v1.rabl +0 -4
  209. data/app/views/spree/api/stores/show.v1.rabl +0 -2
  210. data/app/views/spree/api/taxonomies/index.v1.rabl +0 -7
  211. data/app/views/spree/api/taxonomies/jstree.rabl +0 -8
  212. data/app/views/spree/api/taxonomies/nested.v1.rabl +0 -11
  213. data/app/views/spree/api/taxonomies/new.v1.rabl +0 -3
  214. data/app/views/spree/api/taxonomies/show.v1.rabl +0 -15
  215. data/app/views/spree/api/taxons/index.v1.rabl +0 -12
  216. data/app/views/spree/api/taxons/jstree.rabl +0 -8
  217. data/app/views/spree/api/taxons/new.v1.rabl +0 -3
  218. data/app/views/spree/api/taxons/show.v1.rabl +0 -6
  219. data/app/views/spree/api/taxons/taxons.v1.rabl +0 -5
  220. data/app/views/spree/api/transfer_items/show.v1.rabl +0 -6
  221. data/app/views/spree/api/users/index.v1.rabl +0 -7
  222. data/app/views/spree/api/users/new.v1.rabl +0 -3
  223. data/app/views/spree/api/users/show.v1.rabl +0 -10
  224. data/app/views/spree/api/variants/big.v1.rabl +0 -20
  225. data/app/views/spree/api/variants/index.v1.rabl +0 -9
  226. data/app/views/spree/api/variants/new.v1.rabl +0 -2
  227. data/app/views/spree/api/variants/show.v1.rabl +0 -3
  228. data/app/views/spree/api/variants/small.v1.rabl +0 -17
  229. data/app/views/spree/api/zones/index.v1.rabl +0 -7
  230. data/app/views/spree/api/zones/show.v1.rabl +0 -6
  231. data/config/initializers/rails5_rabl_hacks.rb +0 -12
  232. data/spec/test_views/spree/api/widgets/index.v1.rabl +0 -7
  233. data/spec/test_views/spree/api/widgets/new.v1.rabl +0 -2
  234. data/spec/test_views/spree/api/widgets/show.v1.rabl +0 -2
@@ -0,0 +1,51 @@
1
+ json.cache! [I18n.locale, shipment] do
2
+ json.(shipment, *shipment_attributes)
3
+ json.selected_shipping_rate do
4
+ if shipment.selected_shipping_rate
5
+ json.partial!("spree/api/shipping_rates/shipping_rate", shipping_rate: shipment.selected_shipping_rate)
6
+ else
7
+ json.nil!
8
+ end
9
+ end
10
+ json.inventory_units(shipment.inventory_units) do |inventory_unit|
11
+ json.(inventory_unit, *inventory_unit_attributes)
12
+ json.variant do
13
+ json.partial!("spree/api/variants/small", variant: inventory_unit.variant)
14
+ json.(inventory_unit.variant, :product_id)
15
+ json.images(inventory_unit.variant.images) do |image|
16
+ json.partial!("spree/api/images/image", image: image)
17
+ end
18
+ end
19
+ json.line_item do
20
+ json.(inventory_unit.line_item, *line_item_attributes)
21
+ json.single_display_amount(inventory_unit.line_item.single_display_amount.to_s)
22
+ json.display_amount(inventory_unit.line_item.display_amount.to_s)
23
+ json.total(inventory_unit.line_item.total)
24
+ end
25
+ end
26
+ json.order do
27
+ json.partial!("spree/api/orders/order", order: shipment.order)
28
+ json.bill_address do
29
+ if shipment.order.billing_address
30
+ json.partial!("spree/api/addresses/address", address: shipment.order.billing_address)
31
+ else
32
+ json.nil!
33
+ end
34
+ end
35
+ json.ship_address do
36
+ json.partial!("spree/api/addresses/address", address: shipment.order.shipping_address)
37
+ end
38
+ json.adjustments(shipment.order.adjustments) do |adjustment|
39
+ json.partial!("spree/api/adjustments/adjustment", adjustment: adjustment)
40
+ end
41
+ json.payments(shipment.order.payments) do |payment|
42
+ json.(payment, :id, :amount, :display_amount, :state)
43
+ json.source do
44
+ attrs = [:id]
45
+ (attrs << :cc_type) if payment.source.respond_to?(:cc_type)
46
+ json.(payment.source, *attrs)
47
+ end
48
+ json.payment_method { json.(payment.payment_method, :id, :name) }
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,32 @@
1
+ json.cache! [I18n.locale, shipment] do
2
+ json.(shipment, *shipment_attributes)
3
+ json.order_id(shipment.order.number)
4
+ json.stock_location_name(shipment.stock_location.name)
5
+ json.shipping_rates(shipment.shipping_rates) do |shipping_rate|
6
+ json.partial!("spree/api/shipping_rates/shipping_rate", shipping_rate: shipping_rate)
7
+ end
8
+ json.selected_shipping_rate do
9
+ if shipment.selected_shipping_rate
10
+ json.partial!("spree/api/shipping_rates/shipping_rate", shipping_rate: shipment.selected_shipping_rate)
11
+ else
12
+ json.nil!
13
+ end
14
+ end
15
+ json.shipping_methods(shipment.shipping_methods) do |shipping_method|
16
+ json.(shipping_method, :id, :code, :name)
17
+ json.zones(shipping_method.zones) do |zone|
18
+ json.(zone, :id, :name, :description)
19
+ end
20
+ json.shipping_categories(shipping_method.shipping_categories) do |shipping_category|
21
+ json.(shipping_category, :id, :name)
22
+ end
23
+ end
24
+ json.manifest(shipment.manifest) do |manifest_item|
25
+ json.variant_id manifest_item.variant.id
26
+ json.quantity(manifest_item.quantity)
27
+ json.states(manifest_item.states)
28
+ end
29
+ json.adjustments(shipment.adjustments) do |adjustment|
30
+ json.partial!("spree/api/adjustments/adjustment", adjustment: adjustment)
31
+ end
32
+ end
@@ -0,0 +1 @@
1
+ json.error(I18n.t(:cannot_ready, scope: "spree.api.shipment"))
@@ -0,0 +1,4 @@
1
+ json.partial! 'spree/api/shared/pagination', pagination: @shipments
2
+ json.shipments(@shipments) do |shipment|
3
+ json.partial!("spree/api/shipments/big", shipment: shipment)
4
+ end
@@ -0,0 +1,31 @@
1
+ json.cache! [I18n.locale, @shipment] do
2
+ json.(@shipment, *shipment_attributes)
3
+ json.order_id(@shipment.order.number)
4
+ json.stock_location_name(@shipment.stock_location.name)
5
+ json.shipping_rates(@shipment.shipping_rates) do |shipping_rate|
6
+ json.partial!("spree/api/shipping_rates/shipping_rate", shipping_rate: shipping_rate)
7
+ end
8
+ json.selected_shipping_rate do
9
+ if @shipment.selected_shipping_rate
10
+ json.partial!("spree/api/shipping_rates/shipping_rate", shipping_rate: @shipment.selected_shipping_rate)
11
+ else
12
+ json.nil!
13
+ end
14
+ end
15
+ json.shipping_methods(@shipment.shipping_methods) do |shipping_method|
16
+ json.(shipping_method, :id, :name)
17
+ json.zones(shipping_method.zones) do |zone|
18
+ json.(zone, :id, :name, :description)
19
+ end
20
+ json.shipping_categories(shipping_method.shipping_categories) do |shipping_category|
21
+ json.(shipping_category, :id, :name)
22
+ end
23
+ end
24
+ json.manifest(@shipment.manifest) do |manifest_item|
25
+ json.variant do
26
+ json.partial!("spree/api/variants/small", variant: manifest_item.variant)
27
+ end
28
+ json.quantity(manifest_item.quantity)
29
+ json.states(manifest_item.states)
30
+ end
31
+ end
@@ -0,0 +1,2 @@
1
+ json.(shipping_rate, :id, :name, :cost, :selected, :shipping_method_id, :shipping_method_code)
2
+ json.display_cost(shipping_rate.display_cost.to_s)
@@ -0,0 +1,5 @@
1
+ json.states_required(@country.states_required) if @country
2
+ json.states(@states) { |state| json.(state, *state_attributes) }
3
+ if @states.respond_to?(:total_pages)
4
+ json.partial! 'spree/api/shared/pagination', pagination: @states
5
+ end
@@ -0,0 +1 @@
1
+ json.(@state, *state_attributes)
@@ -0,0 +1,4 @@
1
+ json.(stock_item, *stock_item_attributes)
2
+ json.variant do
3
+ json.partial!("spree/api/variants/small", variant: stock_item.variant)
4
+ end
@@ -0,0 +1,4 @@
1
+ json.stock_items(@stock_items) do |stock_item|
2
+ json.partial!("spree/api/stock_items/stock_item", stock_item: stock_item)
3
+ end
4
+ json.partial! 'spree/api/shared/pagination', pagination: @stock_items
@@ -0,0 +1 @@
1
+ json.partial!("spree/api/stock_items/stock_item", stock_item: @stock_item)
@@ -0,0 +1,15 @@
1
+ json.(stock_location, *stock_location_attributes)
2
+ json.country do
3
+ if stock_location.country
4
+ json.(stock_location.country, *country_attributes)
5
+ else
6
+ json.nil!
7
+ end
8
+ end
9
+ json.state do
10
+ if stock_location.state
11
+ json.(stock_location.state, *state_attributes)
12
+ else
13
+ json.nil!
14
+ end
15
+ end
@@ -0,0 +1,4 @@
1
+ json.stock_locations(@stock_locations) do |stock_location|
2
+ json.partial!("spree/api/stock_locations/stock_location", stock_location: stock_location)
3
+ end
4
+ json.partial! 'spree/api/shared/pagination', pagination: @stock_locations
@@ -0,0 +1 @@
1
+ json.partial!("spree/api/stock_locations/stock_location", stock_location: @stock_location)
@@ -0,0 +1,4 @@
1
+ json.(stock_movement, *stock_movement_attributes)
2
+ json.stock_item do
3
+ json.partial!("spree/api/stock_items/stock_item", stock_item: stock_movement.stock_item)
4
+ end
@@ -0,0 +1,4 @@
1
+ json.stock_movements(@stock_movements) do |stock_movement|
2
+ json.partial!("spree/api/stock_movements/stock_movement", stock_movement: stock_movement)
3
+ end
4
+ json.partial! 'spree/api/shared/pagination', pagination: @stock_movements
@@ -0,0 +1 @@
1
+ json.partial!("spree/api/stock_movements/stock_movement", stock_movement: @stock_movement)
@@ -0,0 +1,4 @@
1
+ json.(@stock_transfer, *stock_transfer_attributes)
2
+ json.received_item do
3
+ json.partial!("spree/api/transfer_items/transfer_item", transfer_item: @transfer_item)
4
+ end
@@ -0,0 +1,5 @@
1
+ json.store_credit_events(@store_credit_events) do |store_credit_event|
2
+ json.(store_credit_event, *store_credit_history_attributes)
3
+ json.order_number(store_credit_event.order.try(:number))
4
+ end
5
+ json.partial! 'spree/api/shared/pagination', pagination: @store_credit_events
@@ -0,0 +1 @@
1
+ json.stores(@stores) { |store| json.(store, *store_attributes) }
@@ -0,0 +1 @@
1
+ json.(@store, *store_attributes)
@@ -0,0 +1,8 @@
1
+ json.(taxonomy, *taxonomy_attributes)
2
+ json.root do
3
+ json.(taxonomy.root, *taxon_attributes)
4
+ json.taxons(taxonomy.root.children) do |taxon|
5
+ json.(taxon, *taxon_attributes)
6
+ json.partial!("spree/api/taxons/taxons", taxon: taxon)
7
+ end
8
+ end
@@ -0,0 +1,11 @@
1
+ if params[:set] == "nested"
2
+ json.partial!("spree/api/taxonomies/nested", taxonomy: taxonomy)
3
+ else
4
+ json.(taxonomy, *taxonomy_attributes)
5
+ json.root do
6
+ json.(taxonomy.root, *taxon_attributes)
7
+ json.taxons(taxonomy.root.children) do |taxon|
8
+ json.(taxon, *taxon_attributes)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,4 @@
1
+ json.taxonomies(@taxonomies) do |taxonomy|
2
+ json.partial!("spree/api/taxonomies/taxonomy", taxonomy: taxonomy)
3
+ end
4
+ json.partial! 'spree/api/shared/pagination', pagination: @taxonomies
@@ -0,0 +1,6 @@
1
+ json.data @taxonomy.root.name
2
+ json.attr do
3
+ json.id @taxonomy.root.id
4
+ json.name @taxonomy.root.name
5
+ end
6
+ json.state "closed"
@@ -0,0 +1,2 @@
1
+ json.attributes([*taxonomy_attributes])
2
+ json.required_attributes(required_fields_for(Spree::Taxonomy))
@@ -0,0 +1 @@
1
+ json.partial!("spree/api/taxonomies/taxonomy", taxonomy: @taxonomy)
@@ -0,0 +1,2 @@
1
+ json.(taxon, *taxon_attributes)
2
+ json.taxons(taxon.children) { |taxon| json.(taxon, *taxon_attributes) }
@@ -0,0 +1,4 @@
1
+ json.taxons(taxon.children) do |taxon|
2
+ json.(taxon, *taxon_attributes)
3
+ json.partial!("spree/api/taxons/taxons", taxon: taxon)
4
+ end
@@ -0,0 +1,7 @@
1
+ json.partial! 'spree/api/shared/pagination', pagination: @taxons
2
+ json.taxons(@taxons) do |taxon|
3
+ json.(taxon, *taxon_attributes)
4
+ unless params[:without_children]
5
+ json.partial!("spree/api/taxons/taxons", taxon: taxon)
6
+ end
7
+ end
@@ -0,0 +1,8 @@
1
+ json.array!(@taxon.children) do |taxon|
2
+ json.data taxon.name
3
+ json.attr do
4
+ json.id taxon.id
5
+ json.name taxon.name
6
+ end
7
+ json.state "closed"
8
+ end
@@ -0,0 +1,2 @@
1
+ json.attributes([*taxon_attributes])
2
+ json.required_attributes(required_fields_for(Spree::Taxon))
@@ -0,0 +1 @@
1
+ json.partial!("spree/api/taxons/taxon", taxon: @taxon)
@@ -0,0 +1,5 @@
1
+ json.(transfer_item, *transfer_item_attributes)
2
+ json.variant do
3
+ json.partial!("spree/api/variants/small", variant: transfer_item.variant)
4
+ json.(transfer_item.variant, *transfer_item_variant_attributes)
5
+ end
@@ -0,0 +1 @@
1
+ json.partial!("spree/api/transfer_items/transfer_item", transfer_item: @transfer_item)
@@ -0,0 +1,15 @@
1
+ json.(user, *user_attributes)
2
+ json.bill_address do
3
+ if user.bill_address
4
+ json.partial!("spree/api/addresses/address", address: user.bill_address)
5
+ else
6
+ json.nil!
7
+ end
8
+ end
9
+ json.ship_address do
10
+ if user.ship_address
11
+ json.partial!("spree/api/addresses/address", address: user.ship_address)
12
+ else
13
+ json.nil!
14
+ end
15
+ end
@@ -0,0 +1,4 @@
1
+ json.users(@users) do |user|
2
+ json.partial!("spree/api/users/user", user: user)
3
+ end
4
+ json.partial! 'spree/api/shared/pagination', pagination: @users
@@ -0,0 +1,2 @@
1
+ json.attributes([*user_attributes])
2
+ json.required_attributes(required_fields_for(Spree.user_class))
@@ -0,0 +1 @@
1
+ json.partial!("spree/api/users/user", user: @user)
@@ -0,0 +1,13 @@
1
+ json.cache! [I18n.locale, Spree::StockLocation.accessible_by(current_ability), variant] do
2
+ json.(variant, *variant_attributes)
3
+ json.partial!("spree/api/variants/small", variant: variant)
4
+ json.total_on_hand(variant.total_on_hand)
5
+ json.variant_properties(variant.variant_properties) do |variant_property|
6
+ json.(variant_property, *variant_property_attributes)
7
+ end
8
+ json.stock_items(variant.stock_items.accessible_by(current_ability)) do |stock_item|
9
+ json.(stock_item, :id, :count_on_hand, :stock_location_id, :backorderable)
10
+ json.available stock_item.available?
11
+ json.stock_location_name(stock_item.stock_location.name)
12
+ end
13
+ end
@@ -0,0 +1,16 @@
1
+ json.cache! [I18n.locale, variant] do
2
+ json.(variant, *variant_attributes)
3
+ json.display_price(variant.display_price.to_s)
4
+ json.options_text(variant.options_text)
5
+ json.track_inventory(variant.should_track_inventory?)
6
+ json.in_stock(variant.in_stock?)
7
+ json.is_backorderable(variant.is_backorderable?)
8
+ json.total_on_hand(variant.total_on_hand)
9
+ json.is_destroyed(variant.destroyed?)
10
+ json.option_values(variant.option_values) do |option_value|
11
+ json.(option_value, *option_value_attributes)
12
+ end
13
+ json.images(variant.images) do |image|
14
+ json.partial!("spree/api/images/image", image: image)
15
+ end
16
+ end
@@ -0,0 +1,4 @@
1
+ json.partial! 'spree/api/shared/pagination', pagination: @variants
2
+ json.variants(@variants) do |variant|
3
+ json.partial!("spree/api/variants/big", variant: variant)
4
+ end
@@ -0,0 +1,2 @@
1
+ json.attributes([*variant_attributes])
2
+ json.required_attributes([])
@@ -0,0 +1 @@
1
+ json.partial!("spree/api/variants/big", variant: @variant)
@@ -0,0 +1,4 @@
1
+ json.(zone, :id, :name, :description)
2
+ json.zone_members(zone.zone_members) do |zone_member|
3
+ json.(zone_member, :id, :name, :zoneable_type, :zoneable_id)
4
+ end
@@ -0,0 +1,4 @@
1
+ json.zones(@zones) do |zone|
2
+ json.partial!("spree/api/zones/zone", zone: zone)
3
+ end
4
+ json.partial! 'spree/api/shared/pagination', pagination: @zones
@@ -0,0 +1 @@
1
+ json.partial!("spree/api/zones/zone", zone: @zone)
@@ -7,6 +7,7 @@ en:
7
7
  invalid_resource: "Invalid resource. Please fix errors and try again."
8
8
  resource_not_found: "The resource you were looking for could not be found."
9
9
  gateway_error: "There was a problem with the payment gateway: %{text}"
10
+ delete_restriction_error: "Cannot delete record."
10
11
  access: "API Access"
11
12
  key: "Key"
12
13
  clear_key: "Clear key"
@@ -6,16 +6,6 @@ module Spree
6
6
  isolate_namespace Spree
7
7
  engine_name 'spree_api'
8
8
 
9
- Rabl.configure do |config|
10
- config.include_json_root = false
11
- config.include_child_root = false
12
-
13
- # Motivation here it make it call as_json when rendering timestamps
14
- # and therefore display miliseconds. Otherwise it would fall to
15
- # JSON.dump which doesn't display the miliseconds
16
- config.json_engine = ActiveSupport::JSON
17
- end
18
-
19
9
  initializer "spree.api.environment", before: :load_config_initializers do |_app|
20
10
  Spree::Api::Config = Spree::ApiConfiguration.new
21
11
  end
@@ -29,10 +19,6 @@ module Spree
29
19
  config.extraction_strategy = :http_header
30
20
  end
31
21
  end
32
-
33
- def self.root
34
- @root ||= Pathname.new(File.expand_path('../../../../', __FILE__))
35
- end
36
22
  end
37
23
  end
38
24
  end
data/lib/spree/api.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  require 'spree/core'
2
2
 
3
- require 'rabl'
3
+ require 'responders'
4
4
 
5
5
  module Spree
6
6
  module Api
data/lib/spree_api.rb CHANGED
@@ -1,3 +1,4 @@
1
1
  require 'spree/api'
2
2
  require 'spree/api/responders'
3
3
  require 'versioncake'
4
+ require 'jbuilder'
data/solidus_api.gemspec CHANGED
@@ -21,6 +21,8 @@ Gem::Specification.new do |gem|
21
21
  gem.required_rubygems_version = '>= 1.8.23'
22
22
 
23
23
  gem.add_dependency 'solidus_core', gem.version
24
- gem.add_dependency 'rabl', '0.13.0' # FIXME: update for proper rails 5 support
25
24
  gem.add_dependency 'versioncake', '~> 3.0'
25
+ gem.add_dependency 'responders'
26
+ gem.add_dependency 'jbuilder', '~> 2.6'
27
+ gem.add_dependency 'kaminari', '>= 0.17', '< 2.0'
26
28
  end
@@ -62,66 +62,10 @@ describe Spree::Api::BaseController, type: :controller do
62
62
  end
63
63
  end
64
64
 
65
- it 'chatches StandardError' do
66
- expect(subject).to receive(:authenticate_user).and_return(true)
67
- expect(subject).to receive(:load_user_roles).and_return(true)
68
- expect(subject).to receive(:index).and_raise("no joy")
69
- get :index, params: { token: "fake_key" }
70
- expect(json_response).to eq({ "exception" => "no joy" })
71
- expect(response.content_type).to eq("application/json")
72
- end
73
-
74
- it 'raises Exception' do
75
- expect(subject).to receive(:authenticate_user).and_return(true)
76
- expect(subject).to receive(:load_user_roles).and_return(true)
77
- expect(subject).to receive(:index).and_raise(Exception.new("no joy"))
78
- expect {
79
- get :index, params: { token: "fake_key" }
80
- }.to raise_error(Exception, "no joy")
81
- end
82
-
83
65
  it "lets a subclass override the product associations that are eager-loaded" do
84
66
  expect(controller.respond_to?(:product_includes, true)).to be
85
67
  end
86
68
 
87
- describe '#error_during_processing' do
88
- controller(FakesController) do
89
- # GET /foo
90
- # Simulates a failed API call.
91
- def foo
92
- raise StandardError
93
- end
94
- end
95
-
96
- # What would be placed in config/initializers/spree.rb
97
- Spree::Api::BaseController.error_notifier = proc do |e, controller|
98
- MockHoneybadger.notify_or_ignore(e, rack_env: controller.request.env)
99
- end
100
-
101
- ##
102
- # Fake HB alert class
103
- class MockHoneybadger
104
- # https://github.com/honeybadger-io/honeybadger-ruby/blob/master/lib/honeybadger.rb#L136
105
- def self.notify_or_ignore(_exception, _opts = {})
106
- end
107
- end
108
-
109
- before do
110
- user = double(email: "spree@example.com")
111
- allow(user).to receive_message_chain :spree_roles, pluck: []
112
- allow(Spree.user_class).to receive_messages find_by: user
113
- @routes = ActionDispatch::Routing::RouteSet.new.tap do |r|
114
- r.draw { get 'foo' => 'fakes#foo' }
115
- end
116
- end
117
-
118
- it 'should notify notify_error_during_processing' do
119
- expect(MockHoneybadger).to receive(:notify_or_ignore).once.with(kind_of(Exception), rack_env: kind_of(Hash))
120
- get :foo, params: { token: 123 }
121
- expect(response.status).to eq(422)
122
- end
123
- end
124
-
125
69
  context 'insufficient stock' do
126
70
  before do
127
71
  expect(subject).to receive(:authenticate_user).and_return(true)
@@ -154,19 +154,6 @@ module Spree
154
154
  expect(response.status).to eq(200)
155
155
  end
156
156
 
157
- context "with disallowed payment method" do
158
- it "returns not found" do
159
- order.update_column(:state, "payment")
160
- allow_any_instance_of(Spree::PaymentMethod::BogusCreditCard).to receive(:source_required?).and_return(false)
161
- @payment_method.update!(available_to_users: false)
162
- expect {
163
- put spree.api_checkout_path(order.to_param), params: { order_token: order.guest_token, order: { payments_attributes: [{ payment_method_id: @payment_method.id }] } }
164
- }.not_to change { Spree::Payment.count }
165
- expect(response.status).to eq(404)
166
- end
167
- end
168
-
169
-
170
157
  it "returns errors when source is required and missing" do
171
158
  order.update_column(:state, "payment")
172
159
  put spree.api_checkout_path(order.to_param), params: { order_token: order.guest_token, order: { payments_attributes: [{ payment_method_id: @payment_method.id }] } }
@@ -362,6 +349,14 @@ module Spree
362
349
  expect(PromotionHandler::Coupon).to receive(:new).with(order).and_call_original
363
350
  expect_any_instance_of(PromotionHandler::Coupon).to receive(:apply).and_return({ coupon_applied?: true })
364
351
  put spree.api_checkout_path(order.to_param), params: { order_token: order.guest_token, order: { coupon_code: "foobar" } }
352
+ expect(response.status).to eq(200)
353
+ end
354
+
355
+ it "renders error failing to apply coupon" do
356
+ order.update_column(:state, "payment")
357
+ put spree.api_checkout_path(order.to_param), params: { order_token: order.guest_token, order: { coupon_code: "foobar" } }
358
+ expect(response.status).to eq(422)
359
+ expect(json_response).to eq({ "error" => "The coupon code you entered doesn't exist. Please try again." })
365
360
  end
366
361
  end
367
362