Class: Jekyll::Giphy
- Inherits:
-
Liquid::Tag
- Object
- Liquid::Tag
- Jekyll::Giphy
- Defined in:
- lib/jekyll-giphy.rb
Constant Summary collapse
- @@public_api =
"dc6zaTOxFJmzC"
Instance Method Summary collapse
-
#initialize(tagName, markup, tokens) ⇒ Giphy
constructor
A new instance of Giphy.
- #render(context) ⇒ Object
Constructor Details
#initialize(tagName, markup, tokens) ⇒ Giphy
Returns a new instance of Giphy.
9 10 11 12 13 |
# File 'lib/jekyll-giphy.rb', line 9 def initialize(tagName, markup, tokens) super @tag = markup end |
Instance Method Details
#render(context) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/jekyll-giphy.rb', line 15 def render(context) uri = URI("http://api.giphy.com/v1/gifs/random?api_key=#{@@public_api}&tag=#{@tag}") 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=\"#{@tag}\">" end |