gab-social/app/controllers/api/v1/gifs_controller.rb

34 lines
822 B
Ruby
Raw Normal View History

2020-04-02 05:07:47 +01:00
# frozen_string_literal: true
class Api::V1::GifsController < Api::BaseController
2020-04-17 06:35:46 +01:00
before_action :require_user!
2020-04-02 05:07:47 +01:00
respond_to :json
skip_before_action :set_cache_headers
2020-04-17 06:35:46 +01:00
def categories
2020-04-02 05:07:47 +01:00
uri = URI('https://api.tenor.com/v1/categories')
2020-05-02 07:25:55 +01:00
theOptions = { :key => "TENOR_KEY" }
2020-04-17 06:35:46 +01:00
uri.query = URI.encode_www_form(theOptions)
res = Net::HTTP.get_response(uri)
render json: res.body if res.is_a?(Net::HTTPSuccess)
end
def search
uri = URI('https://api.tenor.com/v1/search')
theOptions = {
2020-05-02 07:25:55 +01:00
:key => "TENOR_KEY",
2020-04-17 06:35:46 +01:00
:media_filter => "minimal",
:limit => 30,
:q => params[:search],
:pos => params[:next] || 0
}
uri.query = URI.encode_www_form(theOptions)
2020-04-02 05:07:47 +01:00
res = Net::HTTP.get_response(uri)
render json: res.body if res.is_a?(Net::HTTPSuccess)
end
end