class Giphytranslate::Giphy

Public Class Methods

new(tagName, markup, tokens) click to toggle source
Calls superclass method
# File lib/giphytranslate.rb, line 10
def initialize(tagName, markup, tokens)
  super
    @string = markup

end

Public Instance Methods

render(context) click to toggle source
# File lib/giphytranslate.rb, line 16
def render(context)

  uri = URI("http://api.giphy.com/v1/gifs/translate?api_key=#{@@public_api}&s=#{@string}")
  response = Net::HTTP.get(uri)
  json_response = JSON.parse(response)
  json_raw = json_response['data']
  @image_height = json_raw['image_height']
  @image_width = json_raw['image_width']
  @image = json_raw['image_original_url']

  "<img src=\"#{@image}\" height=\"#{@image_height}\" width=\"#{@image_width}\" alt=\"#{@string}\">"


end