harpiya_api 4.3.0.alpha
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +5 -0
- data/LICENSE +26 -0
- data/Rakefile +29 -0
- data/app/assets/javascripts/harpiya/api/main.js +36 -0
- data/app/assets/javascripts/harpiya/api/storefront/cart.js +49 -0
- data/app/controllers/concerns/harpiya/api/v2/storefront/order_concern.rb +52 -0
- data/app/controllers/harpiya/api/base_controller.rb +171 -0
- data/app/controllers/harpiya/api/errors_controller.rb +9 -0
- data/app/controllers/harpiya/api/v1/addresses_controller.rb +46 -0
- data/app/controllers/harpiya/api/v1/checkouts_controller.rb +106 -0
- data/app/controllers/harpiya/api/v1/classifications_controller.rb +20 -0
- data/app/controllers/harpiya/api/v1/countries_controller.rb +22 -0
- data/app/controllers/harpiya/api/v1/credit_cards_controller.rb +26 -0
- data/app/controllers/harpiya/api/v1/customer_returns_controller.rb +25 -0
- data/app/controllers/harpiya/api/v1/images_controller.rb +58 -0
- data/app/controllers/harpiya/api/v1/inventory_units_controller.rb +54 -0
- data/app/controllers/harpiya/api/v1/line_items_controller.rb +70 -0
- data/app/controllers/harpiya/api/v1/option_types_controller.rb +60 -0
- data/app/controllers/harpiya/api/v1/option_values_controller.rb +62 -0
- data/app/controllers/harpiya/api/v1/orders_controller.rb +156 -0
- data/app/controllers/harpiya/api/v1/payments_controller.rb +82 -0
- data/app/controllers/harpiya/api/v1/product_properties_controller.rb +73 -0
- data/app/controllers/harpiya/api/v1/products_controller.rb +131 -0
- data/app/controllers/harpiya/api/v1/promotions_controller.rb +30 -0
- data/app/controllers/harpiya/api/v1/properties_controller.rb +70 -0
- data/app/controllers/harpiya/api/v1/reimbursements_controller.rb +25 -0
- data/app/controllers/harpiya/api/v1/return_authorizations_controller.rb +70 -0
- data/app/controllers/harpiya/api/v1/shipments_controller.rb +196 -0
- data/app/controllers/harpiya/api/v1/states_controller.rb +36 -0
- data/app/controllers/harpiya/api/v1/stock_items_controller.rb +82 -0
- data/app/controllers/harpiya/api/v1/stock_locations_controller.rb +53 -0
- data/app/controllers/harpiya/api/v1/stock_movements_controller.rb +45 -0
- data/app/controllers/harpiya/api/v1/stores_controller.rb +56 -0
- data/app/controllers/harpiya/api/v1/taxonomies_controller.rb +67 -0
- data/app/controllers/harpiya/api/v1/taxons_controller.rb +100 -0
- data/app/controllers/harpiya/api/v1/users_controller.rb +97 -0
- data/app/controllers/harpiya/api/v1/variants_controller.rb +81 -0
- data/app/controllers/harpiya/api/v1/zones_controller.rb +55 -0
- data/app/controllers/harpiya/api/v2/base_controller.rb +167 -0
- data/app/controllers/harpiya/api/v2/platform/addresses_controller.rb +19 -0
- data/app/controllers/harpiya/api/v2/platform/countries_controller.rb +19 -0
- data/app/controllers/harpiya/api/v2/platform/menu_items_controller.rb +35 -0
- data/app/controllers/harpiya/api/v2/platform/menus_controller.rb +19 -0
- data/app/controllers/harpiya/api/v2/platform/option_types_controller.rb +15 -0
- data/app/controllers/harpiya/api/v2/platform/option_values_controller.rb +19 -0
- data/app/controllers/harpiya/api/v2/platform/products_controller.rb +27 -0
- data/app/controllers/harpiya/api/v2/platform/resource_controller.rb +102 -0
- data/app/controllers/harpiya/api/v2/platform/taxons_controller.rb +27 -0
- data/app/controllers/harpiya/api/v2/platform/users_controller.rb +23 -0
- data/app/controllers/harpiya/api/v2/resource_controller.rb +59 -0
- data/app/controllers/harpiya/api/v2/storefront/account/addresses_controller.rb +75 -0
- data/app/controllers/harpiya/api/v2/storefront/account/credit_cards_controller.rb +39 -0
- data/app/controllers/harpiya/api/v2/storefront/account/orders_controller.rb +46 -0
- data/app/controllers/harpiya/api/v2/storefront/account_controller.rb +52 -0
- data/app/controllers/harpiya/api/v2/storefront/cart_controller.rb +195 -0
- data/app/controllers/harpiya/api/v2/storefront/checkout_controller.rb +136 -0
- data/app/controllers/harpiya/api/v2/storefront/countries_controller.rb +50 -0
- data/app/controllers/harpiya/api/v2/storefront/menus_controller.rb +42 -0
- data/app/controllers/harpiya/api/v2/storefront/order_status_controller.rb +34 -0
- data/app/controllers/harpiya/api/v2/storefront/products_controller.rb +55 -0
- data/app/controllers/harpiya/api/v2/storefront/stores_controller.rb +23 -0
- data/app/controllers/harpiya/api/v2/storefront/taxons_controller.rb +47 -0
- data/app/helpers/harpiya/api/api_helpers.rb +190 -0
- data/app/helpers/harpiya/api/v2/collection_options_helpers.rb +46 -0
- data/app/helpers/harpiya/api/v2/display_money_helper.rb +43 -0
- data/app/models/concerns/harpiya/user_api_authentication.rb +19 -0
- data/app/models/concerns/harpiya/user_api_methods.rb +7 -0
- data/app/models/harpiya/api_configuration.rb +8 -0
- data/app/models/harpiya/api_dependencies.rb +98 -0
- data/app/serializers/concerns/harpiya/api/v2/resource_serializer_concern.rb +16 -0
- data/app/serializers/harpiya/api/v2/base_serializer.rb +32 -0
- data/app/serializers/harpiya/api/v2/platform/address_serializer.rb +15 -0
- data/app/serializers/harpiya/api/v2/platform/base_serializer.rb +10 -0
- data/app/serializers/harpiya/api/v2/platform/country_serializer.rb +13 -0
- data/app/serializers/harpiya/api/v2/platform/image_serializer.rb +11 -0
- data/app/serializers/harpiya/api/v2/platform/menu_item_serializer.rb +22 -0
- data/app/serializers/harpiya/api/v2/platform/menu_serializer.rb +14 -0
- data/app/serializers/harpiya/api/v2/platform/option_type_serializer.rb +13 -0
- data/app/serializers/harpiya/api/v2/platform/option_value_serializer.rb +13 -0
- data/app/serializers/harpiya/api/v2/platform/product_property_serializer.rb +11 -0
- data/app/serializers/harpiya/api/v2/platform/product_serializer.rb +28 -0
- data/app/serializers/harpiya/api/v2/platform/state_serializer.rb +13 -0
- data/app/serializers/harpiya/api/v2/platform/store_serializer.rb +14 -0
- data/app/serializers/harpiya/api/v2/platform/taxon_image_serializer.rb +11 -0
- data/app/serializers/harpiya/api/v2/platform/taxon_serializer.rb +37 -0
- data/app/serializers/harpiya/api/v2/platform/taxonomy_serializer.rb +11 -0
- data/app/serializers/harpiya/api/v2/platform/user_serializer.rb +21 -0
- data/app/serializers/harpiya/api/v2/platform/variant_serializer.rb +15 -0
- data/app/serializers/harpiya/v2/storefront/address_serializer.rb +20 -0
- data/app/serializers/harpiya/v2/storefront/base_serializer.rb +10 -0
- data/app/serializers/harpiya/v2/storefront/cart_serializer.rb +36 -0
- data/app/serializers/harpiya/v2/storefront/country_serializer.rb +24 -0
- data/app/serializers/harpiya/v2/storefront/credit_card_serializer.rb +13 -0
- data/app/serializers/harpiya/v2/storefront/estimated_shipping_rate_serializer.rb +29 -0
- data/app/serializers/harpiya/v2/storefront/image_serializer.rb +11 -0
- data/app/serializers/harpiya/v2/storefront/line_item_serializer.rb +19 -0
- data/app/serializers/harpiya/v2/storefront/menu_item_serializer.rb +38 -0
- data/app/serializers/harpiya/v2/storefront/menu_serializer.rb +14 -0
- data/app/serializers/harpiya/v2/storefront/option_type_serializer.rb +13 -0
- data/app/serializers/harpiya/v2/storefront/option_value_serializer.rb +13 -0
- data/app/serializers/harpiya/v2/storefront/payment_method_serializer.rb +11 -0
- data/app/serializers/harpiya/v2/storefront/payment_serializer.rb +15 -0
- data/app/serializers/harpiya/v2/storefront/product_property_serializer.rb +19 -0
- data/app/serializers/harpiya/v2/storefront/product_serializer.rb +67 -0
- data/app/serializers/harpiya/v2/storefront/promotion_serializer.rb +12 -0
- data/app/serializers/harpiya/v2/storefront/shipment_serializer.rb +20 -0
- data/app/serializers/harpiya/v2/storefront/shipping_rate_serializer.rb +16 -0
- data/app/serializers/harpiya/v2/storefront/state_serializer.rb +11 -0
- data/app/serializers/harpiya/v2/storefront/stock_location_serializer.rb +11 -0
- data/app/serializers/harpiya/v2/storefront/store_credit_category_serializer.rb +11 -0
- data/app/serializers/harpiya/v2/storefront/store_credit_event_serializer.rb +15 -0
- data/app/serializers/harpiya/v2/storefront/store_credit_serializer.rb +17 -0
- data/app/serializers/harpiya/v2/storefront/store_credit_type_serializer.rb +11 -0
- data/app/serializers/harpiya/v2/storefront/store_serializer.rb +23 -0
- data/app/serializers/harpiya/v2/storefront/taxon_image_serializer.rb +11 -0
- data/app/serializers/harpiya/v2/storefront/taxon_serializer.rb +36 -0
- data/app/serializers/harpiya/v2/storefront/taxonomy_serializer.rb +11 -0
- data/app/serializers/harpiya/v2/storefront/user_serializer.rb +31 -0
- data/app/serializers/harpiya/v2/storefront/variant_serializer.rb +49 -0
- data/app/services/harpiya/api/error_handler.rb +40 -0
- data/app/views/harpiya/api/errors/gateway_error.rabl +2 -0
- data/app/views/harpiya/api/errors/invalid_api_key.rabl +2 -0
- data/app/views/harpiya/api/errors/invalid_resource.rabl +3 -0
- data/app/views/harpiya/api/errors/must_specify_api_key.rabl +2 -0
- data/app/views/harpiya/api/errors/not_found.rabl +2 -0
- data/app/views/harpiya/api/errors/unauthorized.rabl +2 -0
- data/app/views/harpiya/api/v1/addresses/show.rabl +10 -0
- data/app/views/harpiya/api/v1/adjustments/show.rabl +4 -0
- data/app/views/harpiya/api/v1/countries/index.rabl +7 -0
- data/app/views/harpiya/api/v1/countries/show.rabl +5 -0
- data/app/views/harpiya/api/v1/credit_cards/index.rabl +7 -0
- data/app/views/harpiya/api/v1/credit_cards/show.rabl +3 -0
- data/app/views/harpiya/api/v1/customer_returns/index.rabl +7 -0
- data/app/views/harpiya/api/v1/images/index.rabl +4 -0
- data/app/views/harpiya/api/v1/images/new.rabl +3 -0
- data/app/views/harpiya/api/v1/images/show.rabl +6 -0
- data/app/views/harpiya/api/v1/inventory_units/show.rabl +2 -0
- data/app/views/harpiya/api/v1/line_items/new.rabl +3 -0
- data/app/views/harpiya/api/v1/line_items/show.rabl +14 -0
- data/app/views/harpiya/api/v1/option_types/index.rabl +3 -0
- data/app/views/harpiya/api/v1/option_types/new.rabl +3 -0
- data/app/views/harpiya/api/v1/option_types/show.rabl +5 -0
- data/app/views/harpiya/api/v1/option_values/index.rabl +3 -0
- data/app/views/harpiya/api/v1/option_values/new.rabl +3 -0
- data/app/views/harpiya/api/v1/option_values/show.rabl +2 -0
- data/app/views/harpiya/api/v1/orders/address.rabl +0 -0
- data/app/views/harpiya/api/v1/orders/canceled.rabl +0 -0
- data/app/views/harpiya/api/v1/orders/cart.rabl +0 -0
- data/app/views/harpiya/api/v1/orders/complete.rabl +0 -0
- data/app/views/harpiya/api/v1/orders/could_not_apply_coupon.rabl +2 -0
- data/app/views/harpiya/api/v1/orders/could_not_transition.rabl +3 -0
- data/app/views/harpiya/api/v1/orders/index.rabl +7 -0
- data/app/views/harpiya/api/v1/orders/insufficient_quantity.rabl +2 -0
- data/app/views/harpiya/api/v1/orders/invalid_shipping_method.rabl +2 -0
- data/app/views/harpiya/api/v1/orders/mine.rabl +9 -0
- data/app/views/harpiya/api/v1/orders/order.rabl +10 -0
- data/app/views/harpiya/api/v1/orders/payment.rabl +3 -0
- data/app/views/harpiya/api/v1/orders/show.rabl +51 -0
- data/app/views/harpiya/api/v1/payments/credit_over_limit.rabl +2 -0
- data/app/views/harpiya/api/v1/payments/index.rabl +7 -0
- data/app/views/harpiya/api/v1/payments/new.rabl +5 -0
- data/app/views/harpiya/api/v1/payments/show.rabl +2 -0
- data/app/views/harpiya/api/v1/payments/update_forbidden.rabl +2 -0
- data/app/views/harpiya/api/v1/product_properties/index.rabl +7 -0
- data/app/views/harpiya/api/v1/product_properties/new.rabl +2 -0
- data/app/views/harpiya/api/v1/product_properties/show.rabl +2 -0
- data/app/views/harpiya/api/v1/products/index.rabl +9 -0
- data/app/views/harpiya/api/v1/products/new.rabl +3 -0
- data/app/views/harpiya/api/v1/products/product.rabl +1 -0
- data/app/views/harpiya/api/v1/products/show.rabl +36 -0
- data/app/views/harpiya/api/v1/promotions/handler.rabl +5 -0
- data/app/views/harpiya/api/v1/promotions/show.rabl +2 -0
- data/app/views/harpiya/api/v1/properties/index.rabl +7 -0
- data/app/views/harpiya/api/v1/properties/new.rabl +2 -0
- data/app/views/harpiya/api/v1/properties/show.rabl +2 -0
- data/app/views/harpiya/api/v1/reimbursements/index.rabl +7 -0
- data/app/views/harpiya/api/v1/return_authorizations/index.rabl +7 -0
- data/app/views/harpiya/api/v1/return_authorizations/new.rabl +3 -0
- data/app/views/harpiya/api/v1/return_authorizations/show.rabl +2 -0
- data/app/views/harpiya/api/v1/shared/stock_location_required.rabl +2 -0
- data/app/views/harpiya/api/v1/shipments/big.rabl +48 -0
- data/app/views/harpiya/api/v1/shipments/cannot_ready_shipment.rabl +2 -0
- data/app/views/harpiya/api/v1/shipments/mine.rabl +9 -0
- data/app/views/harpiya/api/v1/shipments/show.rabl +32 -0
- data/app/views/harpiya/api/v1/shipments/small.rabl +37 -0
- data/app/views/harpiya/api/v1/shipping_rates/show.rabl +2 -0
- data/app/views/harpiya/api/v1/states/index.rabl +12 -0
- data/app/views/harpiya/api/v1/states/show.rabl +2 -0
- data/app/views/harpiya/api/v1/stock_items/index.rabl +7 -0
- data/app/views/harpiya/api/v1/stock_items/show.rabl +5 -0
- data/app/views/harpiya/api/v1/stock_locations/index.rabl +7 -0
- data/app/views/harpiya/api/v1/stock_locations/show.rabl +8 -0
- data/app/views/harpiya/api/v1/stock_movements/index.rabl +7 -0
- data/app/views/harpiya/api/v1/stock_movements/show.rabl +5 -0
- data/app/views/harpiya/api/v1/stores/index.rabl +4 -0
- data/app/views/harpiya/api/v1/stores/show.rabl +2 -0
- data/app/views/harpiya/api/v1/tags/index.rabl +9 -0
- data/app/views/harpiya/api/v1/taxonomies/index.rabl +7 -0
- data/app/views/harpiya/api/v1/taxonomies/jstree.rabl +7 -0
- data/app/views/harpiya/api/v1/taxonomies/nested.rabl +11 -0
- data/app/views/harpiya/api/v1/taxonomies/new.rabl +3 -0
- data/app/views/harpiya/api/v1/taxonomies/show.rabl +15 -0
- data/app/views/harpiya/api/v1/taxons/index.rabl +10 -0
- data/app/views/harpiya/api/v1/taxons/jstree.rabl +7 -0
- data/app/views/harpiya/api/v1/taxons/new.rabl +3 -0
- data/app/views/harpiya/api/v1/taxons/show.rabl +6 -0
- data/app/views/harpiya/api/v1/taxons/taxons.rabl +5 -0
- data/app/views/harpiya/api/v1/users/index.rabl +7 -0
- data/app/views/harpiya/api/v1/users/new.rabl +3 -0
- data/app/views/harpiya/api/v1/users/show.rabl +11 -0
- data/app/views/harpiya/api/v1/variants/big.rabl +14 -0
- data/app/views/harpiya/api/v1/variants/index.rabl +9 -0
- data/app/views/harpiya/api/v1/variants/new.rabl +2 -0
- data/app/views/harpiya/api/v1/variants/show.rabl +3 -0
- data/app/views/harpiya/api/v1/variants/small.rabl +18 -0
- data/app/views/harpiya/api/v1/zones/index.rabl +7 -0
- data/app/views/harpiya/api/v1/zones/show.rabl +6 -0
- data/config/initializers/doorkeeper.rb +48 -0
- data/config/initializers/json_api_mime_types.rb +8 -0
- data/config/initializers/rabl.rb +9 -0
- data/config/initializers/user_class_extensions.rb +7 -0
- data/config/locales/en.yml +36 -0
- data/config/routes.rb +295 -0
- data/db/migrate/20100107141738_add_api_key_to_harpiya_users.rb +7 -0
- data/db/migrate/20120411123334_resize_api_key_field.rb +7 -0
- data/db/migrate/20120530054546_rename_api_key_to_harpiya_api_key.rb +7 -0
- data/db/migrate/20131017162334_add_index_to_user_harpiya_api_key.rb +7 -0
- data/db/migrate/20180320110726_create_doorkeeper_tables.rb +69 -0
- data/docs/oauth/index.yml +140 -0
- data/docs/v2/platform/index.yaml +599 -0
- data/docs/v2/storefront/index.yaml +5585 -0
- data/harpiya_api.gemspec +36 -0
- data/lib/harpiya/api.rb +11 -0
- data/lib/harpiya/api/controller_setup.rb +19 -0
- data/lib/harpiya/api/engine.rb +30 -0
- data/lib/harpiya/api/responders.rb +11 -0
- data/lib/harpiya/api/responders/rabl_template.rb +28 -0
- data/lib/harpiya/api/testing_support/caching.rb +10 -0
- data/lib/harpiya/api/testing_support/helpers.rb +44 -0
- data/lib/harpiya/api/testing_support/setup.rb +16 -0
- data/lib/harpiya/api/testing_support/v2/base.rb +13 -0
- data/lib/harpiya/api/testing_support/v2/current_order.rb +79 -0
- data/lib/harpiya/api/testing_support/v2/platform_contexts.rb +213 -0
- data/lib/harpiya_api.rb +4 -0
- data/script/rails +9 -0
- data/spec/fixtures/thinking-cat.jpg +0 -0
- metadata +418 -0
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
module Harpiya
|
|
2
|
+
module Api
|
|
3
|
+
module V1
|
|
4
|
+
class ZonesController < Harpiya::Api::BaseController
|
|
5
|
+
def create
|
|
6
|
+
authorize! :create, Zone
|
|
7
|
+
@zone = Harpiya::Zone.new(zone_params)
|
|
8
|
+
if @zone.save
|
|
9
|
+
respond_with(@zone, status: 201, default_template: :show)
|
|
10
|
+
else
|
|
11
|
+
invalid_resource!(@zone)
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def destroy
|
|
16
|
+
authorize! :destroy, zone
|
|
17
|
+
zone.destroy
|
|
18
|
+
respond_with(zone, status: 204)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def index
|
|
22
|
+
@zones = Zone.accessible_by(current_ability).order('name ASC').ransack(params[:q]).result.page(params[:page]).per(params[:per_page])
|
|
23
|
+
respond_with(@zones)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def show
|
|
27
|
+
respond_with(zone)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def update
|
|
31
|
+
authorize! :update, zone
|
|
32
|
+
if zone.update(zone_params)
|
|
33
|
+
respond_with(zone, status: 200, default_template: :show)
|
|
34
|
+
else
|
|
35
|
+
invalid_resource!(zone)
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
private
|
|
40
|
+
|
|
41
|
+
def zone_params
|
|
42
|
+
attrs = params.require(:zone).permit!
|
|
43
|
+
if attrs[:zone_members]
|
|
44
|
+
attrs[:zone_members_attributes] = attrs.delete(:zone_members)
|
|
45
|
+
end
|
|
46
|
+
attrs
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def zone
|
|
50
|
+
@zone ||= Harpiya::Zone.accessible_by(current_ability, :show).find(params[:id])
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
module Harpiya
|
|
2
|
+
module Api
|
|
3
|
+
module V2
|
|
4
|
+
class BaseController < ActionController::API
|
|
5
|
+
include CanCan::ControllerAdditions
|
|
6
|
+
include Harpiya::Core::ControllerHelpers::StrongParameters
|
|
7
|
+
include Harpiya::Core::ControllerHelpers::Store
|
|
8
|
+
include Harpiya::Core::ControllerHelpers::Locale
|
|
9
|
+
include Harpiya::Core::ControllerHelpers::Currency
|
|
10
|
+
|
|
11
|
+
rescue_from ActiveRecord::RecordNotFound, with: :record_not_found
|
|
12
|
+
rescue_from CanCan::AccessDenied, with: :access_denied
|
|
13
|
+
rescue_from Doorkeeper::Errors::DoorkeeperError, with: :access_denied_401
|
|
14
|
+
rescue_from Harpiya::Core::GatewayError, with: :gateway_error
|
|
15
|
+
rescue_from ActionController::ParameterMissing, with: :error_during_processing
|
|
16
|
+
if defined?(JSONAPI::Serializer::UnsupportedIncludeError)
|
|
17
|
+
rescue_from JSONAPI::Serializer::UnsupportedIncludeError, with: :error_during_processing
|
|
18
|
+
end
|
|
19
|
+
rescue_from ArgumentError, with: :error_during_processing
|
|
20
|
+
|
|
21
|
+
def content_type
|
|
22
|
+
Harpiya::Api::Config[:api_v2_content_type]
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
protected
|
|
26
|
+
|
|
27
|
+
def serialize_collection(collection)
|
|
28
|
+
collection_serializer.new(
|
|
29
|
+
collection,
|
|
30
|
+
collection_options(collection).merge(params: serializer_params)
|
|
31
|
+
).serializable_hash
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def serialize_resource(resource)
|
|
35
|
+
resource_serializer.new(
|
|
36
|
+
resource,
|
|
37
|
+
params: serializer_params,
|
|
38
|
+
include: resource_includes,
|
|
39
|
+
fields: sparse_fields
|
|
40
|
+
).serializable_hash
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def paginated_collection
|
|
44
|
+
@paginated_collection ||= collection_paginator.new(sorted_collection, params).call
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def collection_paginator
|
|
48
|
+
Harpiya::Api::Dependencies.storefront_collection_paginator.constantize
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def render_serialized_payload(status = 200)
|
|
52
|
+
render json: yield, status: status, content_type: content_type
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def render_error_payload(error, status = 422)
|
|
56
|
+
json = if error.is_a?(ActiveModel::Errors)
|
|
57
|
+
{ error: error.full_messages.to_sentence, errors: error.messages }
|
|
58
|
+
elsif error.is_a?(Struct)
|
|
59
|
+
{ error: error.to_s, errors: error.to_h }
|
|
60
|
+
else
|
|
61
|
+
{ error: error }
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
render json: json, status: status, content_type: content_type
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def render_result(result)
|
|
68
|
+
if result.success?
|
|
69
|
+
render_serialized_payload { serialize_resource(result.value) }
|
|
70
|
+
else
|
|
71
|
+
render_error_payload(result.error)
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def harpiya_current_user
|
|
76
|
+
return nil unless doorkeeper_token
|
|
77
|
+
return @harpiya_current_user if @harpiya_current_user
|
|
78
|
+
|
|
79
|
+
doorkeeper_authorize!
|
|
80
|
+
|
|
81
|
+
@harpiya_current_user ||= Harpiya.user_class.find_by(id: doorkeeper_token.resource_owner_id)
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def harpiya_authorize!(action, subject, *args)
|
|
85
|
+
authorize!(action, subject, *args)
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def require_harpiya_current_user
|
|
89
|
+
raise CanCan::AccessDenied if harpiya_current_user.nil?
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
# Needs to be overriden so that we use Harpiya's Ability rather than anyone else's.
|
|
93
|
+
def current_ability
|
|
94
|
+
@current_ability ||= Harpiya::Dependencies.ability_class.constantize.new(harpiya_current_user)
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
def request_includes
|
|
98
|
+
# if API user want's to receive only the bare-minimum
|
|
99
|
+
# the API will return only the main resource without any included
|
|
100
|
+
if params[:include]&.blank?
|
|
101
|
+
[]
|
|
102
|
+
elsif params[:include].present?
|
|
103
|
+
params[:include].split(',')
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
def resource_includes
|
|
108
|
+
(request_includes || default_resource_includes).map(&:intern)
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
# overwrite this method in your controllers to set JSON API default include value
|
|
112
|
+
# https://jsonapi.org/format/#fetching-includes
|
|
113
|
+
# eg.:
|
|
114
|
+
# %w[images variants]
|
|
115
|
+
# ['variant.images', 'line_items']
|
|
116
|
+
def default_resource_includes
|
|
117
|
+
[]
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
def sparse_fields
|
|
121
|
+
return unless params[:fields]&.respond_to?(:each)
|
|
122
|
+
|
|
123
|
+
fields = {}
|
|
124
|
+
params[:fields].
|
|
125
|
+
select { |_, v| v.is_a?(String) }.
|
|
126
|
+
each { |type, values| fields[type.intern] = values.split(',').map(&:intern) }
|
|
127
|
+
fields.presence
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
def serializer_params
|
|
131
|
+
{
|
|
132
|
+
currency: current_currency,
|
|
133
|
+
locale: current_locale,
|
|
134
|
+
store: current_store,
|
|
135
|
+
user: harpiya_current_user
|
|
136
|
+
}
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
def record_not_found
|
|
140
|
+
render_error_payload(I18n.t(:resource_not_found, scope: 'harpiya.api'), 404)
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
def access_denied(exception)
|
|
144
|
+
render_error_payload(exception.message, 403)
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
def access_denied_401(exception)
|
|
148
|
+
render_error_payload(exception.message, 401)
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
def gateway_error(exception)
|
|
152
|
+
render_error_payload(exception.message)
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
def error_during_processing(exception)
|
|
156
|
+
result = error_handler.call(exception: exception, opts: { user: harpiya_current_user })
|
|
157
|
+
|
|
158
|
+
render_error_payload(result.value[:message], 400)
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
def error_handler
|
|
162
|
+
Harpiya::Api::Dependencies.error_handler.constantize
|
|
163
|
+
end
|
|
164
|
+
end
|
|
165
|
+
end
|
|
166
|
+
end
|
|
167
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
module Harpiya
|
|
2
|
+
module Api
|
|
3
|
+
module V2
|
|
4
|
+
module Platform
|
|
5
|
+
class AddressesController < ResourceController
|
|
6
|
+
private
|
|
7
|
+
|
|
8
|
+
def model_class
|
|
9
|
+
Harpiya::Address
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def scope_includes
|
|
13
|
+
[:country, :state, :user]
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
module Harpiya
|
|
2
|
+
module Api
|
|
3
|
+
module V2
|
|
4
|
+
module Platform
|
|
5
|
+
class CountriesController < ResourceController
|
|
6
|
+
private
|
|
7
|
+
|
|
8
|
+
def model_class
|
|
9
|
+
Harpiya::Country
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def scope_includes
|
|
13
|
+
[:states, :zones]
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
module Harpiya
|
|
2
|
+
module Api
|
|
3
|
+
module V2
|
|
4
|
+
module Platform
|
|
5
|
+
class MenuItemsController < ResourceController
|
|
6
|
+
before_action -> { doorkeeper_authorize! :write, :admin }, only: WRITE_ACTIONS << :reposition
|
|
7
|
+
|
|
8
|
+
def reposition
|
|
9
|
+
harpiya_authorize! :update, @moved_item if harpiya_current_user.present?
|
|
10
|
+
|
|
11
|
+
@moved_item = scope.find(params[:moved_item_id])
|
|
12
|
+
@new_parent = scope.find(params[:new_parent_id])
|
|
13
|
+
new_index = params[:new_position_idx].to_i
|
|
14
|
+
|
|
15
|
+
if @moved_item && @new_parent && new_index
|
|
16
|
+
@moved_item.move_to_child_with_index(@new_parent, new_index)
|
|
17
|
+
else
|
|
18
|
+
head :bad_request
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
if @moved_item.save
|
|
22
|
+
head :no_content
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
private
|
|
27
|
+
|
|
28
|
+
def model_class
|
|
29
|
+
Harpiya::MenuItem
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
module Harpiya
|
|
2
|
+
module Api
|
|
3
|
+
module V2
|
|
4
|
+
module Platform
|
|
5
|
+
class OptionValuesController < ResourceController
|
|
6
|
+
private
|
|
7
|
+
|
|
8
|
+
def model_class
|
|
9
|
+
Harpiya::OptionValue
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def scope_includes
|
|
13
|
+
[:option_type]
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
module Harpiya
|
|
2
|
+
module Api
|
|
3
|
+
module V2
|
|
4
|
+
module Platform
|
|
5
|
+
class ProductsController < ResourceController
|
|
6
|
+
private
|
|
7
|
+
|
|
8
|
+
def model_class
|
|
9
|
+
Harpiya::Product
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def scope_includes
|
|
13
|
+
{
|
|
14
|
+
master: :default_price,
|
|
15
|
+
variants: [],
|
|
16
|
+
variant_images: [],
|
|
17
|
+
taxons: [],
|
|
18
|
+
product_properties: :property,
|
|
19
|
+
option_types: :option_values,
|
|
20
|
+
variants_including_master: %i[default_price option_values]
|
|
21
|
+
}
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
module Harpiya
|
|
2
|
+
module Api
|
|
3
|
+
module V2
|
|
4
|
+
module Platform
|
|
5
|
+
class ResourceController < ::Harpiya::Api::V2::ResourceController
|
|
6
|
+
READ_ACTIONS = %i[show index]
|
|
7
|
+
WRITE_ACTIONS = %i[create update destroy]
|
|
8
|
+
|
|
9
|
+
# doorkeeper scopes usage: https://github.com/doorkeeper-gem/doorkeeper/wiki/Using-Scopes
|
|
10
|
+
before_action -> { doorkeeper_authorize! :read, :admin }, only: READ_ACTIONS
|
|
11
|
+
before_action -> { doorkeeper_authorize! :write, :admin }, only: WRITE_ACTIONS
|
|
12
|
+
|
|
13
|
+
# optional authorization if using a user token instead of app token
|
|
14
|
+
before_action :authorize_harpiya_user, only: WRITE_ACTIONS
|
|
15
|
+
|
|
16
|
+
# index and show acrtions are defined in Harpiya::Api::V2::ResourceController
|
|
17
|
+
|
|
18
|
+
def create
|
|
19
|
+
resource = model_class.new(permitted_resource_params)
|
|
20
|
+
|
|
21
|
+
if resource.save
|
|
22
|
+
render_serialized_payload(201) { serialize_resource(resource) }
|
|
23
|
+
else
|
|
24
|
+
render_error_payload(resource.errors)
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def update
|
|
29
|
+
if resource.update(permitted_resource_params)
|
|
30
|
+
render_serialized_payload { serialize_resource(resource) }
|
|
31
|
+
else
|
|
32
|
+
render_error_payload(resource.errors)
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def destroy
|
|
37
|
+
if resource.destroy
|
|
38
|
+
head 204
|
|
39
|
+
else
|
|
40
|
+
render_error_payload(resource.errors)
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
protected
|
|
45
|
+
|
|
46
|
+
def resource_serializer
|
|
47
|
+
"Harpiya::Api::V2::Platform::#{model_class.to_s.demodulize}Serializer".constantize
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def collection_serializer
|
|
51
|
+
resource_serializer
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
# overwiting to utilize ransack gem for filtering
|
|
55
|
+
# https://github.com/activerecord-hackery/ransack#search-matchers
|
|
56
|
+
def collection
|
|
57
|
+
@collection ||= scope.ransack(params[:filter]).result
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
# overwriting to skip cancancan check if API is consumed by an application
|
|
61
|
+
def scope
|
|
62
|
+
return super if harpiya_current_user.present?
|
|
63
|
+
|
|
64
|
+
model_class.includes(scope_includes)
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
# We're overwriting this method because the original one calls `dookreeper_authorize`
|
|
68
|
+
# which breaks our application authorizations defined on top of this controller
|
|
69
|
+
def harpiya_current_user
|
|
70
|
+
return nil unless doorkeeper_token
|
|
71
|
+
return nil if doorkeeper_token.resource_owner_id.nil?
|
|
72
|
+
return @harpiya_current_user if @harpiya_current_user
|
|
73
|
+
|
|
74
|
+
@harpiya_current_user ||= Harpiya.user_class.find_by(id: doorkeeper_token.resource_owner_id)
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def access_denied(exception)
|
|
78
|
+
access_denied_401(exception)
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
# if using a user oAuth token we need to check CanCanCan abilities
|
|
82
|
+
# defined in https://github.com/harpiya/harpiya/blob/master/core/app/models/harpiya/ability.rb
|
|
83
|
+
def authorize_harpiya_user
|
|
84
|
+
return if harpiya_current_user.nil?
|
|
85
|
+
|
|
86
|
+
if action_name == 'create'
|
|
87
|
+
harpiya_authorize! :create, model_class
|
|
88
|
+
else
|
|
89
|
+
harpiya_authorize! action_name, resource
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def permitted_resource_params
|
|
94
|
+
model_param_name = model_class.to_s.demodulize.underscore
|
|
95
|
+
|
|
96
|
+
params.require(model_param_name).permit(Harpiya::PermittedAttributes.send("#{model_param_name}_attributes"))
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
end
|