module Robut::Plugin::Giphy::Base

Public Instance Methods

giphy_uri(gif) click to toggle source
# File lib/robut/plugin/giphy/base.rb, line 7
def giphy_uri(gif)
  uri = "http://api.giphy.com/v1/gifs/random?api_key=#{CGI::escape(Robut::Plugin::Giphy.api_key)}&tag=#{CGI::escape(gif)}&rating=#{CGI::escape(Robut::Plugin::Giphy.rating)}"

  response = Net::HTTP.get_response(URI.parse(uri))
  raise "Giphy didn't like it" unless response.code.to_i == 200

  result = JSON.parse(response.body)
  if result['data'] && result['data'].include?('image_url')
    result['data']['image_url']
  else
    nil
  end
end