Sha256: e646e8f4660724782bd6ac309f20113500c9a6eafe5e97f5bef9b6a1875700a7

Contents?: true

Size: 619 Bytes

Versions: 1

Compression:

Stored size: 619 Bytes

Contents

require 'robut/plugin'
require 'net/http'
require 'json'

class Robut::Plugin::Giphy
  module Base
    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
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
robut-giphy-0.1.0 lib/robut/plugin/giphy/base.rb