From ae0132663c89d16f7a4db3bbcdd39a5d454ec6c5 Mon Sep 17 00:00:00 2001 From: mgabdev <> Date: Fri, 6 Nov 2020 23:23:18 -0600 Subject: [PATCH] Added test params in GabTrendsController for local, dev envs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit • Added: - test params in GabTrendsController for local, dev envs --- .../api/v1/gab_trends_controller.rb | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/app/controllers/api/v1/gab_trends_controller.rb b/app/controllers/api/v1/gab_trends_controller.rb index 825b09d9..7ce7d5a3 100644 --- a/app/controllers/api/v1/gab_trends_controller.rb +++ b/app/controllers/api/v1/gab_trends_controller.rb @@ -43,6 +43,42 @@ class Api::V1::GabTrendsController < Api::BaseController else render json: body end + elsif type == 'news' + body = Redis.current.get("gabtrends:news") + + if body.nil? || body.empty? + Request.new(:get, "https://news.gab.com/feed/json").perform do |res| + Rails.logger.debug "GabTrendsController: #{type} endpoint res code: #{res.code.to_s}" + if res.code == 200 + body = res.body_with_limit + Redis.current.set("gabtrends:news", body) + Redis.current.expire("gabtrends:news", 1.minute.seconds) + render json: body + else + render json: nil + end + end + else + render json: body + end + elsif type == 'rss' + body = Redis.current.get("gabtrends:feeds") + + if body.nil? || body.empty? + Request.new(:get, "https://trends.gab.com/feed/5f97577c9b4a496b7e810354?fmt=json").perform do |res| + Rails.logger.debug "GabTrendsController: #{type} endpoint res code: #{res.code.to_s}" + if res.code == 200 + body = res.body_with_limit + Redis.current.set("gabtrends:news", body) + Redis.current.expire("gabtrends:news", 1.minute.seconds) + render json: body + else + render json: nil + end + end + else + render json: body + end else raise GabSocial::NotPermittedError end