Sha256: 57ab4f3ee7245f6eda2b0556257d85090dd927992da5b1576121a4cf4c082f79

Contents?: true

Size: 948 Bytes

Versions: 1

Compression:

Stored size: 948 Bytes

Contents

# frozen_string_literal: true

module Onebox
  module Engine
    class InstagramOnebox
      include Engine
      include StandardEmbed
      include LayoutSupport

      matches_regexp(/^https?:\/\/(?:www\.)?(?:instagram\.com|instagr\.am)\/?(?:.*)\/p\/[a-zA-Z\d_-]+/)
      always_https

      def clean_url
        url.scan(/^https?:\/\/(?:www\.)?(?:instagram\.com|instagr\.am)\/?(?:.*)\/p\/[a-zA-Z\d_-]+/).flatten.first
      end

      def data
        og = get_opengraph
        author_name = og.description.match(/\(@(\w+)\) on Instagram/)[1]
        permalink = clean_url.gsub("/#{author_name}/", "/")

        { link: permalink,
          title: "@#{author_name}",
          image: "#{permalink}/media/?size=l",
          description: Onebox::Helpers.truncate(og.title, 250)
        }
      end

      protected

      def get_oembed_url
        oembed_url = "https://api.instagram.com/oembed/?url=#{clean_url}"
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
onebox-2.1.4 lib/onebox/engine/instagram_onebox.rb