harpiya_api 4.3.0.alpha

Sign up to get free protection for your applications and to get access to all the features.
Files changed (249) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +17 -0
  3. data/Gemfile +5 -0
  4. data/LICENSE +26 -0
  5. data/Rakefile +29 -0
  6. data/app/assets/javascripts/harpiya/api/main.js +36 -0
  7. data/app/assets/javascripts/harpiya/api/storefront/cart.js +49 -0
  8. data/app/controllers/concerns/harpiya/api/v2/storefront/order_concern.rb +52 -0
  9. data/app/controllers/harpiya/api/base_controller.rb +171 -0
  10. data/app/controllers/harpiya/api/errors_controller.rb +9 -0
  11. data/app/controllers/harpiya/api/v1/addresses_controller.rb +46 -0
  12. data/app/controllers/harpiya/api/v1/checkouts_controller.rb +106 -0
  13. data/app/controllers/harpiya/api/v1/classifications_controller.rb +20 -0
  14. data/app/controllers/harpiya/api/v1/countries_controller.rb +22 -0
  15. data/app/controllers/harpiya/api/v1/credit_cards_controller.rb +26 -0
  16. data/app/controllers/harpiya/api/v1/customer_returns_controller.rb +25 -0
  17. data/app/controllers/harpiya/api/v1/images_controller.rb +58 -0
  18. data/app/controllers/harpiya/api/v1/inventory_units_controller.rb +54 -0
  19. data/app/controllers/harpiya/api/v1/line_items_controller.rb +70 -0
  20. data/app/controllers/harpiya/api/v1/option_types_controller.rb +60 -0
  21. data/app/controllers/harpiya/api/v1/option_values_controller.rb +62 -0
  22. data/app/controllers/harpiya/api/v1/orders_controller.rb +156 -0
  23. data/app/controllers/harpiya/api/v1/payments_controller.rb +82 -0
  24. data/app/controllers/harpiya/api/v1/product_properties_controller.rb +73 -0
  25. data/app/controllers/harpiya/api/v1/products_controller.rb +131 -0
  26. data/app/controllers/harpiya/api/v1/promotions_controller.rb +30 -0
  27. data/app/controllers/harpiya/api/v1/properties_controller.rb +70 -0
  28. data/app/controllers/harpiya/api/v1/reimbursements_controller.rb +25 -0
  29. data/app/controllers/harpiya/api/v1/return_authorizations_controller.rb +70 -0
  30. data/app/controllers/harpiya/api/v1/shipments_controller.rb +196 -0
  31. data/app/controllers/harpiya/api/v1/states_controller.rb +36 -0
  32. data/app/controllers/harpiya/api/v1/stock_items_controller.rb +82 -0
  33. data/app/controllers/harpiya/api/v1/stock_locations_controller.rb +53 -0
  34. data/app/controllers/harpiya/api/v1/stock_movements_controller.rb +45 -0
  35. data/app/controllers/harpiya/api/v1/stores_controller.rb +56 -0
  36. data/app/controllers/harpiya/api/v1/taxonomies_controller.rb +67 -0
  37. data/app/controllers/harpiya/api/v1/taxons_controller.rb +100 -0
  38. data/app/controllers/harpiya/api/v1/users_controller.rb +97 -0
  39. data/app/controllers/harpiya/api/v1/variants_controller.rb +81 -0
  40. data/app/controllers/harpiya/api/v1/zones_controller.rb +55 -0
  41. data/app/controllers/harpiya/api/v2/base_controller.rb +167 -0
  42. data/app/controllers/harpiya/api/v2/platform/addresses_controller.rb +19 -0
  43. data/app/controllers/harpiya/api/v2/platform/countries_controller.rb +19 -0
  44. data/app/controllers/harpiya/api/v2/platform/menu_items_controller.rb +35 -0
  45. data/app/controllers/harpiya/api/v2/platform/menus_controller.rb +19 -0
  46. data/app/controllers/harpiya/api/v2/platform/option_types_controller.rb +15 -0
  47. data/app/controllers/harpiya/api/v2/platform/option_values_controller.rb +19 -0
  48. data/app/controllers/harpiya/api/v2/platform/products_controller.rb +27 -0
  49. data/app/controllers/harpiya/api/v2/platform/resource_controller.rb +102 -0
  50. data/app/controllers/harpiya/api/v2/platform/taxons_controller.rb +27 -0
  51. data/app/controllers/harpiya/api/v2/platform/users_controller.rb +23 -0
  52. data/app/controllers/harpiya/api/v2/resource_controller.rb +59 -0
  53. data/app/controllers/harpiya/api/v2/storefront/account/addresses_controller.rb +75 -0
  54. data/app/controllers/harpiya/api/v2/storefront/account/credit_cards_controller.rb +39 -0
  55. data/app/controllers/harpiya/api/v2/storefront/account/orders_controller.rb +46 -0
  56. data/app/controllers/harpiya/api/v2/storefront/account_controller.rb +52 -0
  57. data/app/controllers/harpiya/api/v2/storefront/cart_controller.rb +195 -0
  58. data/app/controllers/harpiya/api/v2/storefront/checkout_controller.rb +136 -0
  59. data/app/controllers/harpiya/api/v2/storefront/countries_controller.rb +50 -0
  60. data/app/controllers/harpiya/api/v2/storefront/menus_controller.rb +42 -0
  61. data/app/controllers/harpiya/api/v2/storefront/order_status_controller.rb +34 -0
  62. data/app/controllers/harpiya/api/v2/storefront/products_controller.rb +55 -0
  63. data/app/controllers/harpiya/api/v2/storefront/stores_controller.rb +23 -0
  64. data/app/controllers/harpiya/api/v2/storefront/taxons_controller.rb +47 -0
  65. data/app/helpers/harpiya/api/api_helpers.rb +190 -0
  66. data/app/helpers/harpiya/api/v2/collection_options_helpers.rb +46 -0
  67. data/app/helpers/harpiya/api/v2/display_money_helper.rb +43 -0
  68. data/app/models/concerns/harpiya/user_api_authentication.rb +19 -0
  69. data/app/models/concerns/harpiya/user_api_methods.rb +7 -0
  70. data/app/models/harpiya/api_configuration.rb +8 -0
  71. data/app/models/harpiya/api_dependencies.rb +98 -0
  72. data/app/serializers/concerns/harpiya/api/v2/resource_serializer_concern.rb +16 -0
  73. data/app/serializers/harpiya/api/v2/base_serializer.rb +32 -0
  74. data/app/serializers/harpiya/api/v2/platform/address_serializer.rb +15 -0
  75. data/app/serializers/harpiya/api/v2/platform/base_serializer.rb +10 -0
  76. data/app/serializers/harpiya/api/v2/platform/country_serializer.rb +13 -0
  77. data/app/serializers/harpiya/api/v2/platform/image_serializer.rb +11 -0
  78. data/app/serializers/harpiya/api/v2/platform/menu_item_serializer.rb +22 -0
  79. data/app/serializers/harpiya/api/v2/platform/menu_serializer.rb +14 -0
  80. data/app/serializers/harpiya/api/v2/platform/option_type_serializer.rb +13 -0
  81. data/app/serializers/harpiya/api/v2/platform/option_value_serializer.rb +13 -0
  82. data/app/serializers/harpiya/api/v2/platform/product_property_serializer.rb +11 -0
  83. data/app/serializers/harpiya/api/v2/platform/product_serializer.rb +28 -0
  84. data/app/serializers/harpiya/api/v2/platform/state_serializer.rb +13 -0
  85. data/app/serializers/harpiya/api/v2/platform/store_serializer.rb +14 -0
  86. data/app/serializers/harpiya/api/v2/platform/taxon_image_serializer.rb +11 -0
  87. data/app/serializers/harpiya/api/v2/platform/taxon_serializer.rb +37 -0
  88. data/app/serializers/harpiya/api/v2/platform/taxonomy_serializer.rb +11 -0
  89. data/app/serializers/harpiya/api/v2/platform/user_serializer.rb +21 -0
  90. data/app/serializers/harpiya/api/v2/platform/variant_serializer.rb +15 -0
  91. data/app/serializers/harpiya/v2/storefront/address_serializer.rb +20 -0
  92. data/app/serializers/harpiya/v2/storefront/base_serializer.rb +10 -0
  93. data/app/serializers/harpiya/v2/storefront/cart_serializer.rb +36 -0
  94. data/app/serializers/harpiya/v2/storefront/country_serializer.rb +24 -0
  95. data/app/serializers/harpiya/v2/storefront/credit_card_serializer.rb +13 -0
  96. data/app/serializers/harpiya/v2/storefront/estimated_shipping_rate_serializer.rb +29 -0
  97. data/app/serializers/harpiya/v2/storefront/image_serializer.rb +11 -0
  98. data/app/serializers/harpiya/v2/storefront/line_item_serializer.rb +19 -0
  99. data/app/serializers/harpiya/v2/storefront/menu_item_serializer.rb +38 -0
  100. data/app/serializers/harpiya/v2/storefront/menu_serializer.rb +14 -0
  101. data/app/serializers/harpiya/v2/storefront/option_type_serializer.rb +13 -0
  102. data/app/serializers/harpiya/v2/storefront/option_value_serializer.rb +13 -0
  103. data/app/serializers/harpiya/v2/storefront/payment_method_serializer.rb +11 -0
  104. data/app/serializers/harpiya/v2/storefront/payment_serializer.rb +15 -0
  105. data/app/serializers/harpiya/v2/storefront/product_property_serializer.rb +19 -0
  106. data/app/serializers/harpiya/v2/storefront/product_serializer.rb +67 -0
  107. data/app/serializers/harpiya/v2/storefront/promotion_serializer.rb +12 -0
  108. data/app/serializers/harpiya/v2/storefront/shipment_serializer.rb +20 -0
  109. data/app/serializers/harpiya/v2/storefront/shipping_rate_serializer.rb +16 -0
  110. data/app/serializers/harpiya/v2/storefront/state_serializer.rb +11 -0
  111. data/app/serializers/harpiya/v2/storefront/stock_location_serializer.rb +11 -0
  112. data/app/serializers/harpiya/v2/storefront/store_credit_category_serializer.rb +11 -0
  113. data/app/serializers/harpiya/v2/storefront/store_credit_event_serializer.rb +15 -0
  114. data/app/serializers/harpiya/v2/storefront/store_credit_serializer.rb +17 -0
  115. data/app/serializers/harpiya/v2/storefront/store_credit_type_serializer.rb +11 -0
  116. data/app/serializers/harpiya/v2/storefront/store_serializer.rb +23 -0
  117. data/app/serializers/harpiya/v2/storefront/taxon_image_serializer.rb +11 -0
  118. data/app/serializers/harpiya/v2/storefront/taxon_serializer.rb +36 -0
  119. data/app/serializers/harpiya/v2/storefront/taxonomy_serializer.rb +11 -0
  120. data/app/serializers/harpiya/v2/storefront/user_serializer.rb +31 -0
  121. data/app/serializers/harpiya/v2/storefront/variant_serializer.rb +49 -0
  122. data/app/services/harpiya/api/error_handler.rb +40 -0
  123. data/app/views/harpiya/api/errors/gateway_error.rabl +2 -0
  124. data/app/views/harpiya/api/errors/invalid_api_key.rabl +2 -0
  125. data/app/views/harpiya/api/errors/invalid_resource.rabl +3 -0
  126. data/app/views/harpiya/api/errors/must_specify_api_key.rabl +2 -0
  127. data/app/views/harpiya/api/errors/not_found.rabl +2 -0
  128. data/app/views/harpiya/api/errors/unauthorized.rabl +2 -0
  129. data/app/views/harpiya/api/v1/addresses/show.rabl +10 -0
  130. data/app/views/harpiya/api/v1/adjustments/show.rabl +4 -0
  131. data/app/views/harpiya/api/v1/countries/index.rabl +7 -0
  132. data/app/views/harpiya/api/v1/countries/show.rabl +5 -0
  133. data/app/views/harpiya/api/v1/credit_cards/index.rabl +7 -0
  134. data/app/views/harpiya/api/v1/credit_cards/show.rabl +3 -0
  135. data/app/views/harpiya/api/v1/customer_returns/index.rabl +7 -0
  136. data/app/views/harpiya/api/v1/images/index.rabl +4 -0
  137. data/app/views/harpiya/api/v1/images/new.rabl +3 -0
  138. data/app/views/harpiya/api/v1/images/show.rabl +6 -0
  139. data/app/views/harpiya/api/v1/inventory_units/show.rabl +2 -0
  140. data/app/views/harpiya/api/v1/line_items/new.rabl +3 -0
  141. data/app/views/harpiya/api/v1/line_items/show.rabl +14 -0
  142. data/app/views/harpiya/api/v1/option_types/index.rabl +3 -0
  143. data/app/views/harpiya/api/v1/option_types/new.rabl +3 -0
  144. data/app/views/harpiya/api/v1/option_types/show.rabl +5 -0
  145. data/app/views/harpiya/api/v1/option_values/index.rabl +3 -0
  146. data/app/views/harpiya/api/v1/option_values/new.rabl +3 -0
  147. data/app/views/harpiya/api/v1/option_values/show.rabl +2 -0
  148. data/app/views/harpiya/api/v1/orders/address.rabl +0 -0
  149. data/app/views/harpiya/api/v1/orders/canceled.rabl +0 -0
  150. data/app/views/harpiya/api/v1/orders/cart.rabl +0 -0
  151. data/app/views/harpiya/api/v1/orders/complete.rabl +0 -0
  152. data/app/views/harpiya/api/v1/orders/could_not_apply_coupon.rabl +2 -0
  153. data/app/views/harpiya/api/v1/orders/could_not_transition.rabl +3 -0
  154. data/app/views/harpiya/api/v1/orders/index.rabl +7 -0
  155. data/app/views/harpiya/api/v1/orders/insufficient_quantity.rabl +2 -0
  156. data/app/views/harpiya/api/v1/orders/invalid_shipping_method.rabl +2 -0
  157. data/app/views/harpiya/api/v1/orders/mine.rabl +9 -0
  158. data/app/views/harpiya/api/v1/orders/order.rabl +10 -0
  159. data/app/views/harpiya/api/v1/orders/payment.rabl +3 -0
  160. data/app/views/harpiya/api/v1/orders/show.rabl +51 -0
  161. data/app/views/harpiya/api/v1/payments/credit_over_limit.rabl +2 -0
  162. data/app/views/harpiya/api/v1/payments/index.rabl +7 -0
  163. data/app/views/harpiya/api/v1/payments/new.rabl +5 -0
  164. data/app/views/harpiya/api/v1/payments/show.rabl +2 -0
  165. data/app/views/harpiya/api/v1/payments/update_forbidden.rabl +2 -0
  166. data/app/views/harpiya/api/v1/product_properties/index.rabl +7 -0
  167. data/app/views/harpiya/api/v1/product_properties/new.rabl +2 -0
  168. data/app/views/harpiya/api/v1/product_properties/show.rabl +2 -0
  169. data/app/views/harpiya/api/v1/products/index.rabl +9 -0
  170. data/app/views/harpiya/api/v1/products/new.rabl +3 -0
  171. data/app/views/harpiya/api/v1/products/product.rabl +1 -0
  172. data/app/views/harpiya/api/v1/products/show.rabl +36 -0
  173. data/app/views/harpiya/api/v1/promotions/handler.rabl +5 -0
  174. data/app/views/harpiya/api/v1/promotions/show.rabl +2 -0
  175. data/app/views/harpiya/api/v1/properties/index.rabl +7 -0
  176. data/app/views/harpiya/api/v1/properties/new.rabl +2 -0
  177. data/app/views/harpiya/api/v1/properties/show.rabl +2 -0
  178. data/app/views/harpiya/api/v1/reimbursements/index.rabl +7 -0
  179. data/app/views/harpiya/api/v1/return_authorizations/index.rabl +7 -0
  180. data/app/views/harpiya/api/v1/return_authorizations/new.rabl +3 -0
  181. data/app/views/harpiya/api/v1/return_authorizations/show.rabl +2 -0
  182. data/app/views/harpiya/api/v1/shared/stock_location_required.rabl +2 -0
  183. data/app/views/harpiya/api/v1/shipments/big.rabl +48 -0
  184. data/app/views/harpiya/api/v1/shipments/cannot_ready_shipment.rabl +2 -0
  185. data/app/views/harpiya/api/v1/shipments/mine.rabl +9 -0
  186. data/app/views/harpiya/api/v1/shipments/show.rabl +32 -0
  187. data/app/views/harpiya/api/v1/shipments/small.rabl +37 -0
  188. data/app/views/harpiya/api/v1/shipping_rates/show.rabl +2 -0
  189. data/app/views/harpiya/api/v1/states/index.rabl +12 -0
  190. data/app/views/harpiya/api/v1/states/show.rabl +2 -0
  191. data/app/views/harpiya/api/v1/stock_items/index.rabl +7 -0
  192. data/app/views/harpiya/api/v1/stock_items/show.rabl +5 -0
  193. data/app/views/harpiya/api/v1/stock_locations/index.rabl +7 -0
  194. data/app/views/harpiya/api/v1/stock_locations/show.rabl +8 -0
  195. data/app/views/harpiya/api/v1/stock_movements/index.rabl +7 -0
  196. data/app/views/harpiya/api/v1/stock_movements/show.rabl +5 -0
  197. data/app/views/harpiya/api/v1/stores/index.rabl +4 -0
  198. data/app/views/harpiya/api/v1/stores/show.rabl +2 -0
  199. data/app/views/harpiya/api/v1/tags/index.rabl +9 -0
  200. data/app/views/harpiya/api/v1/taxonomies/index.rabl +7 -0
  201. data/app/views/harpiya/api/v1/taxonomies/jstree.rabl +7 -0
  202. data/app/views/harpiya/api/v1/taxonomies/nested.rabl +11 -0
  203. data/app/views/harpiya/api/v1/taxonomies/new.rabl +3 -0
  204. data/app/views/harpiya/api/v1/taxonomies/show.rabl +15 -0
  205. data/app/views/harpiya/api/v1/taxons/index.rabl +10 -0
  206. data/app/views/harpiya/api/v1/taxons/jstree.rabl +7 -0
  207. data/app/views/harpiya/api/v1/taxons/new.rabl +3 -0
  208. data/app/views/harpiya/api/v1/taxons/show.rabl +6 -0
  209. data/app/views/harpiya/api/v1/taxons/taxons.rabl +5 -0
  210. data/app/views/harpiya/api/v1/users/index.rabl +7 -0
  211. data/app/views/harpiya/api/v1/users/new.rabl +3 -0
  212. data/app/views/harpiya/api/v1/users/show.rabl +11 -0
  213. data/app/views/harpiya/api/v1/variants/big.rabl +14 -0
  214. data/app/views/harpiya/api/v1/variants/index.rabl +9 -0
  215. data/app/views/harpiya/api/v1/variants/new.rabl +2 -0
  216. data/app/views/harpiya/api/v1/variants/show.rabl +3 -0
  217. data/app/views/harpiya/api/v1/variants/small.rabl +18 -0
  218. data/app/views/harpiya/api/v1/zones/index.rabl +7 -0
  219. data/app/views/harpiya/api/v1/zones/show.rabl +6 -0
  220. data/config/initializers/doorkeeper.rb +48 -0
  221. data/config/initializers/json_api_mime_types.rb +8 -0
  222. data/config/initializers/rabl.rb +9 -0
  223. data/config/initializers/user_class_extensions.rb +7 -0
  224. data/config/locales/en.yml +36 -0
  225. data/config/routes.rb +295 -0
  226. data/db/migrate/20100107141738_add_api_key_to_harpiya_users.rb +7 -0
  227. data/db/migrate/20120411123334_resize_api_key_field.rb +7 -0
  228. data/db/migrate/20120530054546_rename_api_key_to_harpiya_api_key.rb +7 -0
  229. data/db/migrate/20131017162334_add_index_to_user_harpiya_api_key.rb +7 -0
  230. data/db/migrate/20180320110726_create_doorkeeper_tables.rb +69 -0
  231. data/docs/oauth/index.yml +140 -0
  232. data/docs/v2/platform/index.yaml +599 -0
  233. data/docs/v2/storefront/index.yaml +5585 -0
  234. data/harpiya_api.gemspec +36 -0
  235. data/lib/harpiya/api.rb +11 -0
  236. data/lib/harpiya/api/controller_setup.rb +19 -0
  237. data/lib/harpiya/api/engine.rb +30 -0
  238. data/lib/harpiya/api/responders.rb +11 -0
  239. data/lib/harpiya/api/responders/rabl_template.rb +28 -0
  240. data/lib/harpiya/api/testing_support/caching.rb +10 -0
  241. data/lib/harpiya/api/testing_support/helpers.rb +44 -0
  242. data/lib/harpiya/api/testing_support/setup.rb +16 -0
  243. data/lib/harpiya/api/testing_support/v2/base.rb +13 -0
  244. data/lib/harpiya/api/testing_support/v2/current_order.rb +79 -0
  245. data/lib/harpiya/api/testing_support/v2/platform_contexts.rb +213 -0
  246. data/lib/harpiya_api.rb +4 -0
  247. data/script/rails +9 -0
  248. data/spec/fixtures/thinking-cat.jpg +0 -0
  249. metadata +418 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 409c86a0349c916e9e9c52be9bd722c36448dddd00ce047f803420f3e63d4ba8
4
+ data.tar.gz: f968607c6a8a35226467cd989bb6857cfc2dc3aa369d6c181af1294a67222bf9
5
+ SHA512:
6
+ metadata.gz: 3a1e701ab0f0b8a0b2e71592d0b89439f50a5ca48f37b68980376a1a02035bf1f8d501f23eb519cecb96c71d48acef70e39105bb7968c3d187a18f0d2eec4bea
7
+ data.tar.gz: bf6958a28183d38407b2f9482f25b41077888c5ae8b50e8cd24c17e6806b3f9f2830d5e17276e3098caf90638bd967a4a26a64222865eec03570c7e346477d69
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ eval_gemfile('../common_harpiya_dependencies.rb')
2
+
3
+ gem 'harpiya_core', path: '../core'
4
+
5
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,26 @@
1
+ Copyright (c) 2007-2015, Harpiya Commerce, Inc. and other contributors
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without modification,
5
+ are permitted provided that the following conditions are met:
6
+
7
+ * Redistributions of source code must retain the above copyright notice,
8
+ this list of conditions and the following disclaimer.
9
+ * Redistributions in binary form must reproduce the above copyright notice,
10
+ this list of conditions and the following disclaimer in the documentation
11
+ and/or other materials provided with the distribution.
12
+ * Neither the name Harpiya nor the names of its contributors may be used to
13
+ endorse or promote products derived from this software without specific
14
+ prior written permission.
15
+
16
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
20
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
23
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
24
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
25
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/Rakefile ADDED
@@ -0,0 +1,29 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'rake/testtask'
4
+ require 'rspec/core/rake_task'
5
+ require 'harpiya/testing_support/common_rake'
6
+
7
+ RSpec::Core::RakeTask.new
8
+
9
+ task default: :spec
10
+
11
+ desc "Generates a dummy app for testing"
12
+ task :test_app do
13
+ ENV['LIB_NAME'] = 'harpiya/api'
14
+ Rake::Task['common:test_app'].invoke
15
+ end
16
+
17
+ namespace :rswag do
18
+ namespace :specs do
19
+ desc 'Generate Swagger JSON files from integration specs'
20
+ RSpec::Core::RakeTask.new('swaggerize') do |t|
21
+ t.pattern = ENV.fetch(
22
+ 'PATTERN',
23
+ 'spec/integration/**/*_spec.rb'
24
+ )
25
+
26
+ t.rspec_opts = ['--format Rswag::Specs::SwaggerFormatter', '--order defined']
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,36 @@
1
+ //= require harpiya
2
+
3
+ var HarpiyaAPI = {
4
+ oauthToken: null, // user Bearer token to authorize operations for the given user
5
+ orderToken: null // order token to authorize operations on current order (cart)
6
+ }
7
+
8
+ HarpiyaAPI.Storefront = {}
9
+ HarpiyaAPI.Platform = {}
10
+
11
+ // API routes
12
+ Harpiya.routes.api_v2_storefront_cart_create = Harpiya.pathFor('api/v2/storefront/cart')
13
+ Harpiya.routes.api_v2_storefront_cart_add_item = Harpiya.pathFor('api/v2/storefront/cart/add_item')
14
+ Harpiya.routes.api_v2_storefront_cart_apply_coupon_code = Harpiya.pathFor('api/v2/storefront/cart/apply_coupon_code')
15
+
16
+ // helpers
17
+ HarpiyaAPI.handle500error = function () {
18
+ alert('Internal Server Error')
19
+ }
20
+
21
+ HarpiyaAPI.prepareHeaders = function (headers) {
22
+ if (typeof headers === 'undefined') {
23
+ headers = {}
24
+ }
25
+
26
+ // if signed in we need to pass the Bearer authorization token
27
+ // so backend will recognize that actions are authorized in scope of this user
28
+ if (HarpiyaAPI.oauthToken) {
29
+ headers['Authorization'] = 'Bearer ' + HarpiyaAPI.oauthToken
30
+ }
31
+
32
+ // default headers, required for POST/PATCH/DELETE requests
33
+ headers['Accept'] = 'application/json'
34
+ headers['Content-Type'] = 'application/json'
35
+ return headers
36
+ }
@@ -0,0 +1,49 @@
1
+ //= require harpiya/api/main
2
+
3
+ HarpiyaAPI.Storefront.createCart = function (successCallback, failureCallback) {
4
+ fetch(Harpiya.routes.api_v2_storefront_cart_create, {
5
+ method: 'POST',
6
+ headers: HarpiyaAPI.prepareHeaders()
7
+ }).then(function (response) {
8
+ switch (response.status) {
9
+ case 422:
10
+ response.json().then(function (json) { failureCallback(json.error) })
11
+ break
12
+ case 500:
13
+ HarpiyaAPI.handle500error()
14
+ break
15
+ case 201:
16
+ response.json().then(function (json) {
17
+ HarpiyaAPI.orderToken = json.data.attributes.token
18
+ successCallback()
19
+ })
20
+ break
21
+ }
22
+ })
23
+ }
24
+
25
+ HarpiyaAPI.Storefront.addToCart = function (variantId, quantity, options, successCallback, failureCallback) {
26
+ fetch(Harpiya.routes.api_v2_storefront_cart_add_item, {
27
+ method: 'POST',
28
+ headers: HarpiyaAPI.prepareHeaders({ 'X-Harpiya-Order-Token': HarpiyaAPI.orderToken }),
29
+ body: JSON.stringify({
30
+ variant_id: variantId,
31
+ quantity: quantity,
32
+ options: options
33
+ })
34
+ }).then(function (response) {
35
+ switch (response.status) {
36
+ case 422:
37
+ response.json().then(function (json) { failureCallback(json.error) })
38
+ break
39
+ case 500:
40
+ HarpiyaAPI.handle500error()
41
+ break
42
+ case 200:
43
+ response.json().then(function (json) {
44
+ successCallback(json.data)
45
+ })
46
+ break
47
+ }
48
+ })
49
+ }
@@ -0,0 +1,52 @@
1
+ module Harpiya
2
+ module Api
3
+ module V2
4
+ module Storefront
5
+ module OrderConcern
6
+ private
7
+
8
+ def render_order(result)
9
+ if result.success?
10
+ render_serialized_payload { serialized_current_order }
11
+ else
12
+ render_error_payload(result.error)
13
+ end
14
+ end
15
+
16
+ def ensure_order
17
+ raise ActiveRecord::RecordNotFound if harpiya_current_order.nil?
18
+ end
19
+
20
+ def order_token
21
+ request.headers['X-Harpiya-Order-Token'] || params[:order_token]
22
+ end
23
+
24
+ def harpiya_current_order
25
+ @harpiya_current_order ||= find_harpiya_current_order
26
+ end
27
+
28
+ def find_harpiya_current_order
29
+ Harpiya::Api::Dependencies.storefront_current_order_finder.constantize.new.execute(
30
+ store: current_store,
31
+ user: harpiya_current_user,
32
+ token: order_token,
33
+ currency: current_currency
34
+ )
35
+ end
36
+
37
+ def serialized_current_order
38
+ serialize_resource(harpiya_current_order)
39
+ end
40
+
41
+ def serialize_order(order)
42
+ ActiveSupport::Deprecation.warn(<<-DEPRECATION, caller)
43
+ `OrderConcern#serialize_order` is deprecated and will be removed in Harpiya 5.0.
44
+ Please use `serializer_resource` method
45
+ DEPRECATION
46
+ serialize_resource(order)
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,171 @@
1
+ require_dependency 'harpiya/api/controller_setup'
2
+
3
+ module Harpiya
4
+ module Api
5
+ class BaseController < ActionController::API
6
+ include Harpiya::Api::ControllerSetup
7
+ include Harpiya::Core::ControllerHelpers::Store
8
+ include Harpiya::Core::ControllerHelpers::StrongParameters
9
+ include Harpiya::Core::ControllerHelpers::Locale
10
+ include Harpiya::Core::ControllerHelpers::Currency
11
+
12
+ attr_accessor :current_api_user
13
+
14
+ before_action :set_content_type
15
+ before_action :load_user
16
+ before_action :authorize_for_order, if: proc { order_token.present? }
17
+ before_action :authenticate_user
18
+ before_action :load_user_roles
19
+
20
+ rescue_from ActionController::ParameterMissing, with: :error_during_processing
21
+ rescue_from ActiveRecord::RecordInvalid, with: :error_during_processing
22
+ rescue_from ActiveRecord::RecordNotFound, with: :not_found
23
+ rescue_from CanCan::AccessDenied, with: :unauthorized
24
+ rescue_from Harpiya::Core::GatewayError, with: :gateway_error
25
+
26
+ helper Harpiya::Api::ApiHelpers
27
+
28
+ # users should be able to set price when importing orders via api
29
+ def permitted_line_item_attributes
30
+ if @current_user_roles.include?('admin')
31
+ super + [:price, :variant_id, :sku]
32
+ else
33
+ super
34
+ end
35
+ end
36
+
37
+ def content_type
38
+ case params[:format]
39
+ when 'json'
40
+ 'application/json; charset=utf-8'
41
+ when 'xml'
42
+ 'text/xml; charset=utf-8'
43
+ end
44
+ end
45
+
46
+ private
47
+
48
+ def set_content_type
49
+ headers['Content-Type'] = content_type
50
+ end
51
+
52
+ def load_user
53
+ @current_api_user = Harpiya.user_class.find_by(harpiya_api_key: api_key.to_s)
54
+ end
55
+
56
+ def authenticate_user
57
+ return if @current_api_user
58
+
59
+ if requires_authentication? && api_key.blank? && order_token.blank?
60
+ must_specify_api_key and return
61
+ elsif order_token.blank? && (requires_authentication? || api_key.present?)
62
+ invalid_api_key and return
63
+ else
64
+ # An anonymous user
65
+ @current_api_user = Harpiya.user_class.new
66
+ end
67
+ end
68
+
69
+ def invalid_api_key
70
+ render 'harpiya/api/errors/invalid_api_key', status: 401
71
+ end
72
+
73
+ def must_specify_api_key
74
+ render 'harpiya/api/errors/must_specify_api_key', status: 401
75
+ end
76
+
77
+ def load_user_roles
78
+ @current_user_roles = @current_api_user ? @current_api_user.harpiya_roles.pluck(:name) : []
79
+ end
80
+
81
+ def unauthorized
82
+ render 'harpiya/api/errors/unauthorized', status: 401 and return
83
+ end
84
+
85
+ def error_during_processing(exception)
86
+ message = if exception.respond_to?(:original_message)
87
+ exception.original_message
88
+ else
89
+ exception.message
90
+ end
91
+
92
+ Rails.logger.error message
93
+ Rails.logger.error exception.backtrace.join("\n")
94
+
95
+ unprocessable_entity(message)
96
+ end
97
+
98
+ def unprocessable_entity(message)
99
+ render plain: { exception: message }.to_json, status: 422
100
+ end
101
+
102
+ def gateway_error(exception)
103
+ @order.errors.add(:base, exception.message)
104
+ invalid_resource!(@order)
105
+ end
106
+
107
+ def requires_authentication?
108
+ Harpiya::Api::Config[:requires_authentication]
109
+ end
110
+
111
+ def not_found
112
+ render 'harpiya/api/errors/not_found', status: 404 and return
113
+ end
114
+
115
+ def current_ability
116
+ Harpiya::Dependencies.ability_class.constantize.new(current_api_user)
117
+ end
118
+
119
+ def invalid_resource!(resource)
120
+ @resource = resource
121
+ render 'harpiya/api/errors/invalid_resource', status: 422
122
+ end
123
+
124
+ def api_key
125
+ request.headers['X-Harpiya-Token'] || params[:token]
126
+ end
127
+ helper_method :api_key
128
+
129
+ def order_token
130
+ request.headers['X-Harpiya-Order-Token'] || params[:order_token]
131
+ end
132
+
133
+ def find_product(id)
134
+ @product = product_scope.friendly.distinct(false).find(id.to_s)
135
+ rescue ActiveRecord::RecordNotFound
136
+ @product = product_scope.find_by(id: id)
137
+ not_found unless @product
138
+ end
139
+
140
+ def product_scope
141
+ if @current_user_roles.include?('admin')
142
+ scope = Product.with_deleted.accessible_by(current_ability, :show).includes(*product_includes)
143
+
144
+ scope = scope.not_deleted unless params[:show_deleted]
145
+ scope = scope.not_discontinued unless params[:show_discontinued]
146
+ else
147
+ scope = Product.accessible_by(current_ability, :show).active.includes(*product_includes)
148
+ end
149
+
150
+ scope
151
+ end
152
+
153
+ def variants_associations
154
+ [{ option_values: :option_type }, :default_price, :images]
155
+ end
156
+
157
+ def product_includes
158
+ [:option_types, :taxons, product_properties: :property, variants: variants_associations, master: variants_associations]
159
+ end
160
+
161
+ def order_id
162
+ params[:order_id] || params[:checkout_id] || params[:order_number]
163
+ end
164
+
165
+ def authorize_for_order
166
+ @order = Harpiya::Order.find_by(number: order_id)
167
+ authorize! :show, @order, order_token
168
+ end
169
+ end
170
+ end
171
+ end
@@ -0,0 +1,9 @@
1
+ module Harpiya
2
+ module Api
3
+ class ErrorsController < ActionController::API
4
+ def render_404
5
+ render 'harpiya/api/errors/not_found', status: 404
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,46 @@
1
+ module Harpiya
2
+ module Api
3
+ module V1
4
+ class AddressesController < Harpiya::Api::BaseController
5
+ before_action :find_order
6
+
7
+ def show
8
+ authorize! :show, @order, order_token
9
+ @address = find_address
10
+ respond_with(@address)
11
+ end
12
+
13
+ def update
14
+ authorize! :update, @order, order_token
15
+ @address = find_address
16
+
17
+ if @address.update(address_params)
18
+ respond_with(@address, default_template: :show)
19
+ else
20
+ invalid_resource!(@address)
21
+ end
22
+ end
23
+
24
+ private
25
+
26
+ def address_params
27
+ params.require(:address).permit(permitted_address_attributes)
28
+ end
29
+
30
+ def find_order
31
+ @order = Harpiya::Order.find_by!(number: order_id)
32
+ end
33
+
34
+ def find_address
35
+ if @order.bill_address_id == params[:id].to_i
36
+ @order.bill_address
37
+ elsif @order.ship_address_id == params[:id].to_i
38
+ @order.ship_address
39
+ else
40
+ raise CanCan::AccessDenied
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end