From d79133c72d6291d4a2fc0c07239a6159a9e144f2 Mon Sep 17 00:00:00 2001 From: mgabdev <> Date: Thu, 2 Apr 2020 00:07:47 -0400 Subject: [PATCH] Progress --- app/controllers/api/v1/gifs_controller.rb | 16 ++++++++++++++++ app/javascript/gabsocial/actions/tenor.js | 7 +++---- config/routes.rb | 1 + 3 files changed, 20 insertions(+), 4 deletions(-) create mode 100644 app/controllers/api/v1/gifs_controller.rb diff --git a/app/controllers/api/v1/gifs_controller.rb b/app/controllers/api/v1/gifs_controller.rb new file mode 100644 index 00000000..23963fe3 --- /dev/null +++ b/app/controllers/api/v1/gifs_controller.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +class Api::V1::GifsController < Api::BaseController + respond_to :json + + skip_before_action :set_cache_headers + + def index + uri = URI('https://api.tenor.com/v1/categories') + params = { :key => "QHFJ0C5EWGBH" } + uri.query = URI.encode_www_form(params) + + res = Net::HTTP.get_response(uri) + render json: res.body if res.is_a?(Net::HTTPSuccess) + end +end diff --git a/app/javascript/gabsocial/actions/tenor.js b/app/javascript/gabsocial/actions/tenor.js index fff6ede3..49563c66 100644 --- a/app/javascript/gabsocial/actions/tenor.js +++ b/app/javascript/gabsocial/actions/tenor.js @@ -1,4 +1,4 @@ -import axios from 'axios' +import api from '../api'; import { me, tenorkey } from '../initial_state' export const GIFS_CLEAR_RESULTS = 'GIFS_CLEAR_RESULTS' @@ -14,13 +14,12 @@ export const GIF_CATEGORIES_FETCH_SUCCESS = 'GIF_CATEGORIES_FETCH_SUCCESS' export const GIF_CATEGORIES_FETCH_FAIL = 'GIF_CATEGORIES_FETCH_FAIL' export const fetchGifCategories = () => { - return function (dispatch) { + return function (dispatch, getState) { if (!me) return dispatch(fetchGifCategoriesRequest()) - axios.get(`https://api.tenor.com/v1/categories?media_filter=minimal&limit=30&key=${tenorkey}`) - .then((response) => { + api(getState).get('/api/v1/gifs').then(response => { console.log("fetchGifCategoriesSuccess:", response) dispatch(fetchGifCategoriesSuccess(response.data.tags)) }).catch(function (error) { diff --git a/config/routes.rb b/config/routes.rb index 1af7757a..172e5e35 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -328,6 +328,7 @@ Rails.application.routes.draw do resources :streaming, only: [:index] resources :custom_emojis, only: [:index] + resources :gifs, only: [:index] resources :suggestions, only: [:index, :destroy] resources :scheduled_statuses, only: [:index, :show, :update, :destroy] resources :preferences, only: [:index]