module Onebox module Engine class GfycatOnebox include Engine include JSON matches_regexp(/^https?:\/\/gfycat\.com\//) always_https def self.priority # This engine should have priority over WhitelistedGenericOnebox. 1 end def url "https://gfycat.com/cajax/get/#{match[:name]}" end def to_html <<-HTML HTML end def placeholder_html <<-HTML
#{data[:gfyName]}
HTML end private def match @match ||= @url.match(/^https?:\/\/gfycat\.com\/(gifs\/detail\/)?(?.+)/) end def data total_tags = [raw['gfyItem']['tags'], raw['gfyItem']['userTags']].flatten.compact tag_links = total_tags.map { |t| "##{t}" }.join(' ') if total_tags autoplay = raw['gfyItem']['webmSize'].to_i < 10485760 ? 'autoplay' : '' { name: raw['gfyItem']['gfyName'], title: raw['gfyItem']['title'] || 'No Title', author: raw['gfyItem']['userName'], tags: tag_links, url: @url, posterUrl: raw['gfyItem']['posterUrl'], webmUrl: raw['gfyItem']['webmUrl'], mp4Url: raw['gfyItem']['mp4Url'], width: raw['gfyItem']['width'], height: raw['gfyItem']['height'], autoplay: autoplay } end end end end