Sha256: da1d5b7d4530c66174161a1aca02302291ab749c39bd094b25bdbd0ab9eb2b0e
Contents?: true
Size: 1.33 KB
Versions: 1
Compression:
Stored size: 1.33 KB
Contents
module Onebox module Engine class ImgurOnebox include Engine include StandardEmbed matches_regexp(/^https?:\/\/.*imgur\.com/) always_https def to_html imgur_data = get_imgur_data return "<video width='#{imgur_data[:"player:width"]}' height='#{imgur_data[:"player:height"]}' controls autoplay loop><source src='#{imgur_data[:"player:stream"]}' type='video/mp4'></video>" if imgur_data[:"player:stream"] return "<a href='#{url}' target='_blank'><img src='#{imgur_data[:image]}' alt='Imgur' height='#{imgur_data[:"image:height"]}' width='#{imgur_data[:"image:width"]}'></a>" if imgur_data[:image] return "<a href='#{url}' target='_blank'><img src='#{imgur_data[:"image0:src"]}' alt='Imgur'></a>" if imgur_data[:"image0:src"] return nil end private def get_imgur_data response = Onebox::Helpers.fetch_response(url) html = Nokogiri::HTML(response.body) imgur_data = {} html.css('meta').each do |m| if m.attribute('name') && m.attribute('name').to_s.match(/^twitter:/i) m_content = m.attribute('content').to_s.strip m_name = m.attribute('name').to_s.gsub('twitter:', '') imgur_data[m_name.to_sym] = m_content end end return imgur_data end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
onebox-1.5.23 | lib/onebox/engine/imgur_onebox.rb |