spree_api_v1 4.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (158) hide show
  1. checksums.yaml +7 -0
  2. data/.circleci/config.yml +189 -0
  3. data/.gitignore +23 -0
  4. data/.rspec +3 -0
  5. data/.rubocop.yml +24 -0
  6. data/CHANGELOG.md +3 -0
  7. data/CODE_OF_CONDUCT.md +22 -0
  8. data/Gemfile +59 -0
  9. data/LICENSE +26 -0
  10. data/README.md +62 -0
  11. data/Rakefile +15 -0
  12. data/app/controllers/spree/api/v1/addresses_controller.rb +46 -0
  13. data/app/controllers/spree/api/v1/base_controller.rb +174 -0
  14. data/app/controllers/spree/api/v1/checkouts_controller.rb +106 -0
  15. data/app/controllers/spree/api/v1/classifications_controller.rb +21 -0
  16. data/app/controllers/spree/api/v1/countries_controller.rb +22 -0
  17. data/app/controllers/spree/api/v1/credit_cards_controller.rb +26 -0
  18. data/app/controllers/spree/api/v1/customer_returns_controller.rb +25 -0
  19. data/app/controllers/spree/api/v1/images_controller.rb +58 -0
  20. data/app/controllers/spree/api/v1/inventory_units_controller.rb +54 -0
  21. data/app/controllers/spree/api/v1/line_items_controller.rb +70 -0
  22. data/app/controllers/spree/api/v1/option_types_controller.rb +60 -0
  23. data/app/controllers/spree/api/v1/option_values_controller.rb +62 -0
  24. data/app/controllers/spree/api/v1/orders_controller.rb +160 -0
  25. data/app/controllers/spree/api/v1/payments_controller.rb +82 -0
  26. data/app/controllers/spree/api/v1/product_properties_controller.rb +73 -0
  27. data/app/controllers/spree/api/v1/products_controller.rb +131 -0
  28. data/app/controllers/spree/api/v1/promotions_controller.rb +30 -0
  29. data/app/controllers/spree/api/v1/properties_controller.rb +70 -0
  30. data/app/controllers/spree/api/v1/reimbursements_controller.rb +25 -0
  31. data/app/controllers/spree/api/v1/return_authorizations_controller.rb +70 -0
  32. data/app/controllers/spree/api/v1/shipments_controller.rb +196 -0
  33. data/app/controllers/spree/api/v1/states_controller.rb +36 -0
  34. data/app/controllers/spree/api/v1/stock_items_controller.rb +82 -0
  35. data/app/controllers/spree/api/v1/stock_locations_controller.rb +53 -0
  36. data/app/controllers/spree/api/v1/stock_movements_controller.rb +45 -0
  37. data/app/controllers/spree/api/v1/stores_controller.rb +56 -0
  38. data/app/controllers/spree/api/v1/taxonomies_controller.rb +67 -0
  39. data/app/controllers/spree/api/v1/taxons_controller.rb +100 -0
  40. data/app/controllers/spree/api/v1/users_controller.rb +97 -0
  41. data/app/controllers/spree/api/v1/variants_controller.rb +81 -0
  42. data/app/controllers/spree/api/v1/zones_controller.rb +55 -0
  43. data/app/helpers/spree/api/api_helpers.rb +190 -0
  44. data/app/models/spree/api_v1_configuration.rb +5 -0
  45. data/app/views/spree/api/errors/gateway_error.rabl +2 -0
  46. data/app/views/spree/api/errors/invalid_api_key.rabl +2 -0
  47. data/app/views/spree/api/errors/invalid_resource.rabl +3 -0
  48. data/app/views/spree/api/errors/must_specify_api_key.rabl +2 -0
  49. data/app/views/spree/api/errors/not_found.rabl +2 -0
  50. data/app/views/spree/api/errors/unauthorized.rabl +2 -0
  51. data/app/views/spree/api/v1/addresses/show.rabl +10 -0
  52. data/app/views/spree/api/v1/adjustments/show.rabl +4 -0
  53. data/app/views/spree/api/v1/countries/index.rabl +7 -0
  54. data/app/views/spree/api/v1/countries/show.rabl +5 -0
  55. data/app/views/spree/api/v1/credit_cards/index.rabl +7 -0
  56. data/app/views/spree/api/v1/credit_cards/show.rabl +3 -0
  57. data/app/views/spree/api/v1/customer_returns/index.rabl +7 -0
  58. data/app/views/spree/api/v1/images/index.rabl +4 -0
  59. data/app/views/spree/api/v1/images/new.rabl +3 -0
  60. data/app/views/spree/api/v1/images/show.rabl +6 -0
  61. data/app/views/spree/api/v1/inventory_units/show.rabl +2 -0
  62. data/app/views/spree/api/v1/line_items/new.rabl +3 -0
  63. data/app/views/spree/api/v1/line_items/show.rabl +14 -0
  64. data/app/views/spree/api/v1/option_types/index.rabl +3 -0
  65. data/app/views/spree/api/v1/option_types/new.rabl +3 -0
  66. data/app/views/spree/api/v1/option_types/show.rabl +5 -0
  67. data/app/views/spree/api/v1/option_values/index.rabl +3 -0
  68. data/app/views/spree/api/v1/option_values/new.rabl +3 -0
  69. data/app/views/spree/api/v1/option_values/show.rabl +2 -0
  70. data/app/views/spree/api/v1/orders/address.rabl +0 -0
  71. data/app/views/spree/api/v1/orders/canceled.rabl +0 -0
  72. data/app/views/spree/api/v1/orders/cart.rabl +0 -0
  73. data/app/views/spree/api/v1/orders/complete.rabl +0 -0
  74. data/app/views/spree/api/v1/orders/could_not_apply_coupon.rabl +2 -0
  75. data/app/views/spree/api/v1/orders/could_not_transition.rabl +3 -0
  76. data/app/views/spree/api/v1/orders/index.rabl +7 -0
  77. data/app/views/spree/api/v1/orders/insufficient_quantity.rabl +2 -0
  78. data/app/views/spree/api/v1/orders/invalid_shipping_method.rabl +2 -0
  79. data/app/views/spree/api/v1/orders/mine.rabl +9 -0
  80. data/app/views/spree/api/v1/orders/order.rabl +10 -0
  81. data/app/views/spree/api/v1/orders/payment.rabl +3 -0
  82. data/app/views/spree/api/v1/orders/show.rabl +51 -0
  83. data/app/views/spree/api/v1/payments/credit_over_limit.rabl +2 -0
  84. data/app/views/spree/api/v1/payments/index.rabl +7 -0
  85. data/app/views/spree/api/v1/payments/new.rabl +5 -0
  86. data/app/views/spree/api/v1/payments/show.rabl +2 -0
  87. data/app/views/spree/api/v1/payments/update_forbidden.rabl +2 -0
  88. data/app/views/spree/api/v1/product_properties/index.rabl +7 -0
  89. data/app/views/spree/api/v1/product_properties/new.rabl +2 -0
  90. data/app/views/spree/api/v1/product_properties/show.rabl +2 -0
  91. data/app/views/spree/api/v1/products/index.rabl +9 -0
  92. data/app/views/spree/api/v1/products/new.rabl +3 -0
  93. data/app/views/spree/api/v1/products/product.rabl +1 -0
  94. data/app/views/spree/api/v1/products/show.rabl +36 -0
  95. data/app/views/spree/api/v1/promotions/handler.rabl +5 -0
  96. data/app/views/spree/api/v1/promotions/show.rabl +2 -0
  97. data/app/views/spree/api/v1/properties/index.rabl +7 -0
  98. data/app/views/spree/api/v1/properties/new.rabl +2 -0
  99. data/app/views/spree/api/v1/properties/show.rabl +2 -0
  100. data/app/views/spree/api/v1/reimbursements/index.rabl +7 -0
  101. data/app/views/spree/api/v1/return_authorizations/index.rabl +7 -0
  102. data/app/views/spree/api/v1/return_authorizations/new.rabl +3 -0
  103. data/app/views/spree/api/v1/return_authorizations/show.rabl +2 -0
  104. data/app/views/spree/api/v1/shared/stock_location_required.rabl +2 -0
  105. data/app/views/spree/api/v1/shipments/big.rabl +48 -0
  106. data/app/views/spree/api/v1/shipments/cannot_ready_shipment.rabl +2 -0
  107. data/app/views/spree/api/v1/shipments/mine.rabl +9 -0
  108. data/app/views/spree/api/v1/shipments/show.rabl +32 -0
  109. data/app/views/spree/api/v1/shipments/small.rabl +37 -0
  110. data/app/views/spree/api/v1/shipping_rates/show.rabl +2 -0
  111. data/app/views/spree/api/v1/states/index.rabl +12 -0
  112. data/app/views/spree/api/v1/states/show.rabl +2 -0
  113. data/app/views/spree/api/v1/stock_items/index.rabl +7 -0
  114. data/app/views/spree/api/v1/stock_items/show.rabl +5 -0
  115. data/app/views/spree/api/v1/stock_locations/index.rabl +7 -0
  116. data/app/views/spree/api/v1/stock_locations/show.rabl +8 -0
  117. data/app/views/spree/api/v1/stock_movements/index.rabl +7 -0
  118. data/app/views/spree/api/v1/stock_movements/show.rabl +5 -0
  119. data/app/views/spree/api/v1/stores/index.rabl +4 -0
  120. data/app/views/spree/api/v1/stores/show.rabl +2 -0
  121. data/app/views/spree/api/v1/tags/index.rabl +9 -0
  122. data/app/views/spree/api/v1/taxonomies/index.rabl +7 -0
  123. data/app/views/spree/api/v1/taxonomies/jstree.rabl +7 -0
  124. data/app/views/spree/api/v1/taxonomies/nested.rabl +11 -0
  125. data/app/views/spree/api/v1/taxonomies/new.rabl +3 -0
  126. data/app/views/spree/api/v1/taxonomies/show.rabl +15 -0
  127. data/app/views/spree/api/v1/taxons/index.rabl +10 -0
  128. data/app/views/spree/api/v1/taxons/jstree.rabl +7 -0
  129. data/app/views/spree/api/v1/taxons/new.rabl +3 -0
  130. data/app/views/spree/api/v1/taxons/show.rabl +6 -0
  131. data/app/views/spree/api/v1/taxons/taxons.rabl +5 -0
  132. data/app/views/spree/api/v1/users/index.rabl +7 -0
  133. data/app/views/spree/api/v1/users/new.rabl +3 -0
  134. data/app/views/spree/api/v1/users/show.rabl +11 -0
  135. data/app/views/spree/api/v1/variants/big.rabl +14 -0
  136. data/app/views/spree/api/v1/variants/index.rabl +9 -0
  137. data/app/views/spree/api/v1/variants/new.rabl +2 -0
  138. data/app/views/spree/api/v1/variants/show.rabl +3 -0
  139. data/app/views/spree/api/v1/variants/small.rabl +18 -0
  140. data/app/views/spree/api/v1/zones/index.rabl +7 -0
  141. data/app/views/spree/api/v1/zones/show.rabl +6 -0
  142. data/config/initializers/rabl.rb +9 -0
  143. data/config/routes.rb +123 -0
  144. data/lib/spree/api_v1/controller_setup.rb +19 -0
  145. data/lib/spree/api_v1/engine.rb +27 -0
  146. data/lib/spree/api_v1/factories.rb +6 -0
  147. data/lib/spree/api_v1/responders/rabl_template.rb +28 -0
  148. data/lib/spree/api_v1/responders.rb +11 -0
  149. data/lib/spree/api_v1/testing_support/helpers.rb +44 -0
  150. data/lib/spree/api_v1/testing_support/setup.rb +16 -0
  151. data/lib/spree/api_v1/version.rb +9 -0
  152. data/lib/spree/api_v1.rb +9 -0
  153. data/lib/spree_api_v1.rb +3 -0
  154. data/script/rails +9 -0
  155. data/spec/fixtures/files/icon_256x256.jpg +0 -0
  156. data/spec/fixtures/thinking-cat.jpg +0 -0
  157. data/spree_api_v1.gemspec +26 -0
  158. metadata +261 -0
@@ -0,0 +1,48 @@
1
+ object @shipment
2
+ cache @shipment
3
+ attributes *shipment_attributes
4
+
5
+ child selected_shipping_rate: :selected_shipping_rate do
6
+ extends 'spree/api/v1/shipping_rates/show'
7
+ end
8
+
9
+ child inventory_units: :inventory_units do
10
+ object @inventory_unit
11
+ attributes *inventory_unit_attributes
12
+
13
+ child :variant do
14
+ extends 'spree/api/v1/variants/small'
15
+ attributes :product_id
16
+ child(images: :images) { extends 'spree/api/v1/images/show' }
17
+ end
18
+
19
+ child :line_item do
20
+ attributes *line_item_attributes
21
+ node(:single_display_amount) { |li| li.single_display_amount.to_s }
22
+ node(:display_amount) { |li| li.display_amount.to_s }
23
+ node(:total, &:total)
24
+ end
25
+ end
26
+
27
+ child order: :order do
28
+ extends 'spree/api/v1/orders/order'
29
+
30
+ child billing_address: :bill_address do
31
+ extends 'spree/api/v1/addresses/show'
32
+ end
33
+
34
+ child shipping_address: :ship_address do
35
+ extends 'spree/api/v1/addresses/show'
36
+ end
37
+
38
+ child adjustments: :adjustments do
39
+ extends 'spree/api/v1/adjustments/show'
40
+ end
41
+
42
+ child payments: :payments do
43
+ attributes :id, :amount, :display_amount, :state
44
+ child payment_method: :payment_method do
45
+ attributes :id, :name
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,2 @@
1
+ object false
2
+ node(:error) { I18n.t(:cannot_ready, scope: 'spree.api.shipment') }
@@ -0,0 +1,9 @@
1
+ object false
2
+
3
+ node(:count) { @shipments.count }
4
+ node(:current_page) { params[:page].try(:to_i) || 1 }
5
+ node(:pages) { @shipments.total_pages }
6
+
7
+ child(@shipments => :shipments) do
8
+ extends 'spree/api/v1/shipments/big'
9
+ end
@@ -0,0 +1,32 @@
1
+ object @shipment
2
+ cache [I18n.locale, root_object]
3
+ attributes *shipment_attributes
4
+ node(:order_id) { |shipment| shipment.order.number }
5
+ node(:stock_location_name) { |shipment| shipment.stock_location.name }
6
+
7
+ child shipping_rates: :shipping_rates do
8
+ extends 'spree/api/v1/shipping_rates/show'
9
+ end
10
+
11
+ child selected_shipping_rate: :selected_shipping_rate do
12
+ extends 'spree/api/v1/shipping_rates/show'
13
+ end
14
+
15
+ child shipping_methods: :shipping_methods do
16
+ attributes :id, :name, :tracking_url
17
+ child zones: :zones do
18
+ attributes :id, :name, :description
19
+ end
20
+
21
+ child shipping_categories: :shipping_categories do
22
+ attributes :id, :name
23
+ end
24
+ end
25
+
26
+ child manifest: :manifest do
27
+ child variant: :variant do
28
+ extends 'spree/api/v1/variants/small'
29
+ end
30
+ node(:quantity, &:quantity)
31
+ node(:states, &:states)
32
+ end
@@ -0,0 +1,37 @@
1
+ object @shipment
2
+ cache [I18n.locale, 'small_shipment', root_object]
3
+
4
+ attributes *shipment_attributes
5
+ node(:order_id) { |shipment| shipment.order.number }
6
+ node(:stock_location_name) { |shipment| shipment.stock_location.name }
7
+
8
+ child shipping_rates: :shipping_rates do
9
+ extends 'spree/api/v1/shipping_rates/show'
10
+ end
11
+
12
+ child selected_shipping_rate: :selected_shipping_rate do
13
+ extends 'spree/api/v1/shipping_rates/show'
14
+ end
15
+
16
+ child shipping_methods: :shipping_methods do
17
+ attributes :id, :code, :name
18
+ child zones: :zones do
19
+ attributes :id, :name, :description
20
+ end
21
+
22
+ child shipping_categories: :shipping_categories do
23
+ attributes :id, :name
24
+ end
25
+ end
26
+
27
+ child manifest: :manifest do
28
+ glue(:variant) do
29
+ attribute id: :variant_id
30
+ end
31
+ node(:quantity, &:quantity)
32
+ node(:states, &:states)
33
+ end
34
+
35
+ child adjustments: :adjustments do
36
+ extends 'spree/api/v1/adjustments/show'
37
+ end
@@ -0,0 +1,2 @@
1
+ attributes :id, :name, :cost, :selected, :shipping_method_id, :shipping_method_code
2
+ node(:display_cost) { |sr| sr.display_cost.to_s }
@@ -0,0 +1,12 @@
1
+ object false
2
+ node(:states_required) { @country.states_required } if @country
3
+
4
+ child(@states => :states) do
5
+ attributes *state_attributes
6
+ end
7
+
8
+ if @states.respond_to?(:total_pages)
9
+ node(:count) { @states.count }
10
+ node(:current_page) { params[:page].try(:to_i) || 1 }
11
+ node(:pages) { @states.total_pages }
12
+ end
@@ -0,0 +1,2 @@
1
+ object @state
2
+ attributes *state_attributes
@@ -0,0 +1,7 @@
1
+ object false
2
+ child(@stock_items => :stock_items) do
3
+ extends 'spree/api/v1/stock_items/show'
4
+ end
5
+ node(:count) { @stock_items.count }
6
+ node(:current_page) { params[:page].try(:to_i) || 1 }
7
+ node(:pages) { @stock_items.total_pages }
@@ -0,0 +1,5 @@
1
+ object @stock_item
2
+ attributes *stock_item_attributes
3
+ child(:variant) do
4
+ extends 'spree/api/v1/variants/small'
5
+ end
@@ -0,0 +1,7 @@
1
+ object false
2
+ child(@stock_locations => :stock_locations) do
3
+ extends 'spree/api/v1/stock_locations/show'
4
+ end
5
+ node(:count) { @stock_locations.count }
6
+ node(:current_page) { params[:page].try(:to_i) || 1 }
7
+ node(:pages) { @stock_locations.total_pages }
@@ -0,0 +1,8 @@
1
+ object @stock_location
2
+ attributes *stock_location_attributes
3
+ child(:country) do |_address|
4
+ attributes *country_attributes
5
+ end
6
+ child(:state) do |_address|
7
+ attributes *state_attributes
8
+ end
@@ -0,0 +1,7 @@
1
+ object false
2
+ child(@stock_movements => :stock_movements) do
3
+ extends 'spree/api/v1/stock_movements/show'
4
+ end
5
+ node(:count) { @stock_movements.count }
6
+ node(:current_page) { params[:page].try(:to_i) || 1 }
7
+ node(:pages) { @stock_movements.total_pages }
@@ -0,0 +1,5 @@
1
+ object @stock_movement
2
+ attributes *stock_movement_attributes
3
+ child :stock_item do
4
+ extends 'spree/api/v1/stock_items/show'
5
+ end
@@ -0,0 +1,4 @@
1
+ object false
2
+ child(@stores => :stores) do
3
+ attributes *store_attributes
4
+ end
@@ -0,0 +1,2 @@
1
+ object @store
2
+ attributes *store_attributes
@@ -0,0 +1,9 @@
1
+ object false
2
+ node(:count) { @tags.count }
3
+ node(:total_count) { @tags.total_count }
4
+ node(:current_page) { params[:page] ? params[:page].to_i : 1 }
5
+ node(:per_page) { params[:per_page] || Kaminari.config.default_per_page }
6
+ node(:pages) { @tags.total_pages }
7
+ child(@tags => :tags) do
8
+ attributes :name, :id
9
+ end
@@ -0,0 +1,7 @@
1
+ object false
2
+ child(@taxonomies => :taxonomies) do
3
+ extends 'spree/api/v1/taxonomies/show'
4
+ end
5
+ node(:count) { @taxonomies.count }
6
+ node(:current_page) { params[:page].try(:to_i) || 1 }
7
+ node(:pages) { @taxonomies.total_pages }
@@ -0,0 +1,7 @@
1
+ object false
2
+ node(:data) { @taxonomy.root.name }
3
+ node(:attr) do
4
+ { id: @taxonomy.root.id,
5
+ name: @taxonomy.root.name }
6
+ end
7
+ node(:state) { 'closed' }
@@ -0,0 +1,11 @@
1
+ attributes *taxonomy_attributes
2
+
3
+ child root: :root do
4
+ attributes *taxon_attributes
5
+
6
+ child children: :taxons do
7
+ attributes *taxon_attributes
8
+
9
+ extends 'spree/api/v1/taxons/taxons'
10
+ end
11
+ end
@@ -0,0 +1,3 @@
1
+ object false
2
+ node(:attributes) { [*taxonomy_attributes] }
3
+ node(:required_attributes) { required_fields_for(Spree::Taxonomy) }
@@ -0,0 +1,15 @@
1
+ object @taxonomy
2
+
3
+ if params[:set] == 'nested'
4
+ extends 'spree/api/v1/taxonomies/nested'
5
+ else
6
+ attributes *taxonomy_attributes
7
+
8
+ child root: :root do
9
+ attributes *taxon_attributes
10
+
11
+ child children: :taxons do
12
+ attributes *taxon_attributes
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,10 @@
1
+ object false
2
+ node(:count) { @taxons.count }
3
+ node(:total_count) { @taxons.total_count }
4
+ node(:current_page) { params[:page] ? params[:page].to_i : 1 }
5
+ node(:per_page) { params[:per_page].try(:to_i) || Kaminari.config.default_per_page }
6
+ node(:pages) { @taxons.total_pages }
7
+ child @taxons => :taxons do
8
+ attributes *taxon_attributes
9
+ extends 'spree/api/v1/taxons/taxons' unless params[:without_children]
10
+ end
@@ -0,0 +1,7 @@
1
+ collection @taxon.children, object_root: false
2
+ node(:data, &:name)
3
+ node(:attr) do |taxon|
4
+ { id: taxon.id,
5
+ name: taxon.name }
6
+ end
7
+ node(:state) { 'closed' }
@@ -0,0 +1,3 @@
1
+ object false
2
+ node(:attributes) { [*taxon_attributes] }
3
+ node(:required_attributes) { required_fields_for(Spree::Taxon) }
@@ -0,0 +1,6 @@
1
+ object @taxon
2
+ attributes *taxon_attributes
3
+
4
+ child children: :taxons do
5
+ attributes *taxon_attributes
6
+ end
@@ -0,0 +1,5 @@
1
+ attributes *taxon_attributes
2
+
3
+ node :taxons do |t|
4
+ t.children.map { |c| partial('spree/api/v1/taxons/taxons', object: c) }
5
+ end
@@ -0,0 +1,7 @@
1
+ object false
2
+ child(@users => :users) do
3
+ extends 'spree/api/v1/users/show'
4
+ end
5
+ node(:count) { @users.count }
6
+ node(:current_page) { params[:page].try(:to_i) || 1 }
7
+ node(:pages) { @users.total_pages }
@@ -0,0 +1,3 @@
1
+ object false
2
+ node(:attributes) { [*user_attributes] }
3
+ node(:required_attributes) { required_fields_for(Spree.user_class) }
@@ -0,0 +1,11 @@
1
+ object @user
2
+ cache [I18n.locale, root_object]
3
+
4
+ attributes *user_attributes
5
+ child(bill_address: :bill_address) do
6
+ extends 'spree/api/v1/addresses/show'
7
+ end
8
+
9
+ child(ship_address: :ship_address) do
10
+ extends 'spree/api/v1/addresses/show'
11
+ end
@@ -0,0 +1,14 @@
1
+ object @variant
2
+
3
+ cache [I18n.locale, @current_user_roles.include?('admin'), 'big_variant', root_object]
4
+
5
+ extends 'spree/api/v1/variants/small'
6
+
7
+ child(stock_items: :stock_items) do
8
+ attributes :id, :count_on_hand, :stock_location_id, :backorderable
9
+ attribute available?: :available
10
+
11
+ glue(:stock_location) do
12
+ attribute name: :stock_location_name
13
+ end
14
+ end
@@ -0,0 +1,9 @@
1
+ object false
2
+ node(:count) { @variants.count }
3
+ node(:total_count) { @variants.total_count }
4
+ node(:current_page) { params[:page] ? params[:page].to_i : 1 }
5
+ node(:pages) { @variants.total_pages }
6
+
7
+ child(@variants => :variants) do
8
+ extends 'spree/api/v1/variants/big'
9
+ end
@@ -0,0 +1,2 @@
1
+ node(:attributes) { [*variant_attributes] }
2
+ node(:required_attributes) { [] }
@@ -0,0 +1,3 @@
1
+ object @variant
2
+ cache [I18n.locale, @current_user_roles.include?('admin'), 'show', root_object]
3
+ extends 'spree/api/v1/variants/big'
@@ -0,0 +1,18 @@
1
+ cache [I18n.locale, @current_user_roles.include?('admin'), 'small_variant', root_object]
2
+
3
+ attributes *variant_attributes
4
+
5
+ node(:display_price) { |p| p.display_price.to_s }
6
+ node(:options_text, &:options_text)
7
+ node(:track_inventory, &:should_track_inventory?)
8
+ node(:in_stock, &:in_stock?)
9
+ node(:is_backorderable, &:is_backorderable?)
10
+ node(:is_orderable) { |v| v.is_backorderable? || v.in_stock? }
11
+ node(:total_on_hand, &:total_on_hand)
12
+ node(:is_destroyed, &:destroyed?)
13
+
14
+ child option_values: :option_values do
15
+ attributes *option_value_attributes
16
+ end
17
+
18
+ child(images: :images) { extends 'spree/api/v1/images/show' }
@@ -0,0 +1,7 @@
1
+ object false
2
+ child(@zones => :zones) do
3
+ extends 'spree/api/v1/zones/show'
4
+ end
5
+ node(:count) { @zones.count }
6
+ node(:current_page) { params[:page].try(:to_i) || 1 }
7
+ node(:pages) { @zones.total_pages }
@@ -0,0 +1,6 @@
1
+ object @zone
2
+ attributes :id, :name, :description
3
+
4
+ child zone_members: :zone_members do
5
+ attributes :id, :name, :zoneable_type, :zoneable_id
6
+ end
@@ -0,0 +1,9 @@
1
+ Rabl.configure do |config|
2
+ config.include_json_root = false
3
+ config.include_child_root = false
4
+
5
+ # Motivation here it make it call as_json when rendering timestamps
6
+ # and therefore display milliseconds. Otherwise it would fall to
7
+ # JSON.dump which doesn't display the milliseconds
8
+ config.json_engine = ActiveSupport::JSON
9
+ end
data/config/routes.rb ADDED
@@ -0,0 +1,123 @@
1
+ Spree::Core::Engine.add_routes do
2
+ namespace :api, defaults: { format: 'json' } do
3
+ namespace :v1 do
4
+ resources :promotions, only: [:show]
5
+
6
+ resources :customer_returns, only: [:index]
7
+ resources :reimbursements, only: [:index]
8
+
9
+ resources :products do
10
+ resources :images
11
+ resources :variants
12
+ resources :product_properties
13
+ end
14
+
15
+ concern :order_routes do
16
+ member do
17
+ put :approve
18
+ put :cancel
19
+ put :empty
20
+ put :apply_coupon_code
21
+ end
22
+
23
+ resources :line_items
24
+ resources :payments do
25
+ member do
26
+ put :authorize
27
+ put :capture
28
+ put :purchase
29
+ put :void
30
+ put :credit
31
+ end
32
+ end
33
+
34
+ resources :addresses, only: [:show, :update]
35
+
36
+ resources :return_authorizations do
37
+ member do
38
+ put :add
39
+ put :cancel
40
+ put :receive
41
+ end
42
+ end
43
+ end
44
+
45
+ resources :checkouts, only: [:update], concerns: :order_routes do
46
+ member do
47
+ put :next
48
+ put :advance
49
+ end
50
+ end
51
+
52
+ resources :variants do
53
+ resources :images
54
+ end
55
+
56
+ resources :option_types do
57
+ resources :option_values
58
+ end
59
+ resources :option_values
60
+
61
+ resources :option_values, only: :index
62
+
63
+ get '/orders/mine', to: 'orders#mine', as: 'my_orders'
64
+ get '/orders/current', to: 'orders#current', as: 'current_order'
65
+
66
+ resources :orders, concerns: :order_routes do
67
+ put :remove_coupon_code, on: :member
68
+ end
69
+
70
+ resources :zones
71
+ resources :countries, only: [:index, :show] do
72
+ resources :states, only: [:index, :show]
73
+ end
74
+
75
+ resources :shipments, only: [:create, :update] do
76
+ collection do
77
+ post 'transfer_to_location'
78
+ post 'transfer_to_shipment'
79
+ get :mine
80
+ end
81
+
82
+ member do
83
+ put :ready
84
+ put :ship
85
+ put :add
86
+ put :remove
87
+ end
88
+ end
89
+ resources :states, only: [:index, :show]
90
+
91
+ resources :taxonomies do
92
+ member do
93
+ get :jstree
94
+ end
95
+ resources :taxons do
96
+ member do
97
+ get :jstree
98
+ end
99
+ end
100
+ end
101
+
102
+ resources :taxons, only: [:index]
103
+
104
+ resources :inventory_units, only: [:show, :update]
105
+
106
+ resources :users do
107
+ resources :credit_cards, only: [:index]
108
+ end
109
+
110
+ resources :properties
111
+ resources :stock_locations do
112
+ resources :stock_movements
113
+ resources :stock_items
114
+ end
115
+
116
+ resources :stock_items, only: [:index, :update, :destroy]
117
+ resources :stores
118
+
119
+ put '/classifications', to: 'classifications#update', as: :classifications
120
+ get '/taxons/products', to: 'taxons#products', as: :taxon_products
121
+ end
122
+ end
123
+ end
@@ -0,0 +1,19 @@
1
+ require 'spree/api_v1/responders'
2
+
3
+ module Spree
4
+ module ApiV1
5
+ module ControllerSetup
6
+ def self.included(klass)
7
+ klass.class_eval do
8
+ include CanCan::ControllerAdditions
9
+
10
+ prepend_view_path Rails.root + 'app/views'
11
+ append_view_path File.expand_path('../../../app/views', File.dirname(__FILE__))
12
+
13
+ self.responder = Spree::ApiV1::Responders::AppResponder
14
+ respond_to :json
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,27 @@
1
+ require 'rails/engine'
2
+
3
+ module Spree
4
+ module ApiV1
5
+ class Engine < Rails::Engine
6
+ isolate_namespace Spree
7
+ engine_name 'spree_api_v1'
8
+
9
+ # use rspec for tests
10
+ config.generators do |g|
11
+ g.test_framework :rspec
12
+ end
13
+
14
+ config.after_initialize do |_app|
15
+ Spree::ApiV1::Config = Spree::ApiV1Configuration.new
16
+ end
17
+
18
+ def self.activate
19
+ Dir.glob(File.join(File.dirname(__FILE__), '../../app/**/*_decorator*.rb')) do |c|
20
+ Rails.configuration.cache_classes ? require(c) : load(c)
21
+ end
22
+ end
23
+
24
+ config.to_prepare(&method(:activate).to_proc)
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,6 @@
1
+ FactoryBot.define do
2
+ # Define your Spree extensions Factories within this file to enable applications, and other extensions to use and override them.
3
+ #
4
+ # Example adding this to your spec_helper will load these Factories for use:
5
+ # require 'spree_api_v1/factories'
6
+ end
@@ -0,0 +1,28 @@
1
+ module Spree
2
+ module ApiV1
3
+ module Responders
4
+ module RablTemplate
5
+ def to_format
6
+ if template
7
+ render template, status: options[:status] || 200
8
+ else
9
+ super
10
+ end
11
+ rescue ActionView::MissingTemplate => e
12
+ api_behavior
13
+ end
14
+
15
+ def template
16
+ options[:default_template]
17
+ end
18
+
19
+ def api_behavior
20
+ if controller.params[:action] == 'destroy'
21
+ # Render a blank template
22
+ super
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,11 @@
1
+ require 'spree/api_v1/responders/rabl_template'
2
+
3
+ module Spree
4
+ module ApiV1
5
+ module Responders
6
+ class AppResponder < ActionController::Responder
7
+ include RablTemplate
8
+ end
9
+ end
10
+ end
11
+ end