2020-04-02 12:57:04 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class Api::V1::GabTrendsController < Api::BaseController
|
|
|
|
respond_to :json
|
|
|
|
|
|
|
|
skip_before_action :set_cache_headers
|
|
|
|
|
|
|
|
def index
|
2020-06-08 22:10:51 -04:00
|
|
|
type = params[:type]
|
|
|
|
if type == 'feed'
|
|
|
|
body = Redis.current.get("gabtrends")
|
|
|
|
|
|
|
|
if body.nil?
|
|
|
|
uri = URI("https://trends.gab.com/trend-feed/json")
|
|
|
|
uri.query = URI.encode_www_form({})
|
2020-04-02 12:57:04 -04:00
|
|
|
|
2020-06-08 22:10:51 -04:00
|
|
|
res = Net::HTTP.get_response(uri)
|
|
|
|
if res.is_a?(Net::HTTPSuccess)
|
|
|
|
body = res.body
|
|
|
|
Redis.current.set("gabtrends", res.body)
|
|
|
|
Redis.current.expire("gabtrends", 1.hour.seconds)
|
|
|
|
end
|
2020-04-03 19:18:26 -04:00
|
|
|
end
|
|
|
|
|
2020-06-08 22:10:51 -04:00
|
|
|
render json: body
|
|
|
|
else
|
|
|
|
raise GabSocial::NotPermittedError
|
|
|
|
end
|
2020-04-02 12:57:04 -04:00
|
|
|
end
|
2020-06-08 22:10:51 -04:00
|
|
|
|
2020-04-02 12:57:04 -04:00
|
|
|
end
|