Sha256: 8ece7c340e3859dff740da0a102cf66d1fc62285ca976f619d6a1dd67e800c38

Contents?: true

Size: 1.63 KB

Versions: 33

Compression:

Stored size: 1.63 KB

Contents

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
          <div>
            <video controls loop autoplay muted poster="#{data[:posterUrl]}" width="#{data[:width]}" height="#{data[:height]}">
              <source id="webmSource" src="#{data[:webmUrl]}" type="video/webm">
              <source id="mp4Source" src="#{data[:mp4Url]}" type="video/mp4">
              <img title="Sorry, your browser doesn't support HTML5 video." src="#{data[:posterUrl]}">
            </video><br/>
            <a href="#{data[:url]}">#{data[:name]}</a>
          </div>
        HTML
      end

      def placeholder_html
        <<-HTML
          <a href="#{data[:url]}">
            <img src="#{data[:posterUrl]}" width="#{data[:width]}" height="#{data[:height]}"><br/>
            #{data[:gfyName]}
          </a>
        HTML
      end

      private

        def match
          @match ||= @url.match(/^https?:\/\/gfycat\.com\/(?<name>.+)/)
        end

        def data
          {
            name: raw['gfyItem']['gfyName'],
            url: @url,
            posterUrl: raw['gfyItem']['posterUrl'],
            webmUrl: raw['gfyItem']['webmUrl'],
            mp4Url: raw['gfyItem']['mp4Url'],
            width: raw['gfyItem']['width'],
            height: raw['gfyItem']['height']
          }
        end

    end
  end
end

Version data entries

33 entries across 33 versions & 1 rubygems

Version Path
onebox-1.8.36 lib/onebox/engine/gfycat_onebox.rb
onebox-1.8.35 lib/onebox/engine/gfycat_onebox.rb
onebox-1.8.34 lib/onebox/engine/gfycat_onebox.rb
onebox-1.8.33 lib/onebox/engine/gfycat_onebox.rb
onebox-1.8.32 lib/onebox/engine/gfycat_onebox.rb
onebox-1.8.31 lib/onebox/engine/gfycat_onebox.rb
onebox-1.8.30 lib/onebox/engine/gfycat_onebox.rb
onebox-1.8.29 lib/onebox/engine/gfycat_onebox.rb
onebox-1.8.28 lib/onebox/engine/gfycat_onebox.rb
onebox-1.8.27 lib/onebox/engine/gfycat_onebox.rb
onebox-1.8.26 lib/onebox/engine/gfycat_onebox.rb
onebox-1.8.25 lib/onebox/engine/gfycat_onebox.rb
onebox-1.8.24 lib/onebox/engine/gfycat_onebox.rb
onebox-1.8.23 lib/onebox/engine/gfycat_onebox.rb
onebox-1.8.22 lib/onebox/engine/gfycat_onebox.rb
onebox-1.8.21 lib/onebox/engine/gfycat_onebox.rb
onebox-1.8.20 lib/onebox/engine/gfycat_onebox.rb
onebox-1.8.19 lib/onebox/engine/gfycat_onebox.rb
onebox-1.8.18 lib/onebox/engine/gfycat_onebox.rb
onebox-1.8.17 lib/onebox/engine/gfycat_onebox.rb