gab-social/app/controllers/api/v1/shop_controller.rb
mgabdev 095e646661 Added ShopPanel to home sidebar
• Added:
- ShopPanel to home sidebar
- DIssenter shop redux, api route/controller
2020-07-01 21:33:10 -04:00

34 lines
819 B
Ruby

# frozen_string_literal: true
class Api::V1::ShopController < Api::BaseController
before_action :require_user!
respond_to :json
skip_before_action :set_cache_headers
def index
type = params[:type]
if type == 'featured_products'
body = Redis.current.get("gabstore:featuredproducts")
if body.nil?
uri = URI("https://shop.dissenter.com/product/group/json")
uri.query = URI.encode_www_form({})
res = Net::HTTP.get_response(uri)
if res.is_a?(Net::HTTPSuccess)
body = res.body
Redis.current.set("gabstore:featuredproducts", res.body)
Redis.current.expire("gabstore:featuredproducts", 15.minutes.seconds)
end
end
render json: body
else
raise GabSocial::NotPermittedError
end
end
end