Sha256: 667bfb8af9563c1c5c965171ade4aba032f07a90de3b6e5a3cb9a1079d4be8b6
Contents?: true
Size: 1.41 KB
Versions: 1
Compression:
Stored size: 1.41 KB
Contents
module Onebox module Engine class ImgurOnebox include Engine include StandardEmbed matches_regexp(/^https?:\/\/(www\.)?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'><source src='#{imgur_data[:"player:stream"].gsub('mp4', 'webm')}' type='video/webm'></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.24 | lib/onebox/engine/imgur_onebox.rb |