Sha256: 3e230f2f054daa8139a7eb32238d5b1577b27c434ec1fa7ae99369126c396b99

Contents?: true

Size: 1.27 KB

Versions: 7

Compression:

Stored size: 1.27 KB

Contents

# frozen_string_literal: true

module Onebox
  module Engine
    class VimeoOnebox
      include Engine
      include StandardEmbed

      matches_regexp(/^https?:\/\/(www\.)?vimeo\.com\/\d+/)
      requires_iframe_origins "https://player.vimeo.com"
      always_https

      WIDTH  ||= 640
      HEIGHT ||= 360

      def placeholder_html
        ::Onebox::Helpers.video_placeholder_html
      end

      def to_html
        video_id = oembed_data[:video_id]
        if video_id.nil?
          # for private videos
          video_id = uri.path[/\/(\d+)/, 1]
        end
        video_src = "https://player.vimeo.com/video/#{video_id}"
        video_src = video_src.gsub('autoplay=1', '').chomp("?")

        <<-HTML
          <iframe
            width="#{WIDTH}"
            height="#{HEIGHT}"
            src="#{video_src}"
            data-original-href="#{link}"
            frameborder="0"
            allowfullscreen
          ></iframe>
        HTML
      end

      private

      def oembed_data
        response = Onebox::Helpers.fetch_response("https://vimeo.com/api/oembed.json?url=#{url}")
        @oembed_data = Onebox::Helpers.symbolize_keys(::MultiJson.load(response))
      rescue
        "{}"
      end

      def og_data
        @og_data = get_opengraph
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
onebox-2.2.19 lib/onebox/engine/vimeo_onebox.rb
onebox-2.2.18 lib/onebox/engine/vimeo_onebox.rb
onebox-2.2.17 lib/onebox/engine/vimeo_onebox.rb
onebox-2.2.16 lib/onebox/engine/vimeo_onebox.rb
onebox-2.2.15 lib/onebox/engine/vimeo_onebox.rb
onebox-2.2.14 lib/onebox/engine/vimeo_onebox.rb
onebox-2.2.13 lib/onebox/engine/vimeo_onebox.rb