Sha256: 93e7afba743520cf894b22888246020af037e3afaf665ab191fac07e6c3d83a5

Contents?: true

Size: 894 Bytes

Versions: 11

Compression:

Stored size: 894 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
        oembed = get_oembed
        permalink = clean_url.gsub("/#{oembed.author_name}/", "/")

        { link: permalink,
          title: "@#{oembed.author_name}",
          image: "#{permalink}/media/?size=l",
          description: Onebox::Helpers.truncate(oembed.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

11 entries across 11 versions & 1 rubygems

Version Path
onebox-2.1.3 lib/onebox/engine/instagram_onebox.rb
onebox-2.1.2 lib/onebox/engine/instagram_onebox.rb
onebox-2.1.1 lib/onebox/engine/instagram_onebox.rb
onebox-2.1.0 lib/onebox/engine/instagram_onebox.rb
onebox-2.0.2 lib/onebox/engine/instagram_onebox.rb
onebox-2.0.1 lib/onebox/engine/instagram_onebox.rb
onebox-2.0.0 lib/onebox/engine/instagram_onebox.rb
onebox-1.9.30 lib/onebox/engine/instagram_onebox.rb
onebox-1.9.29 lib/onebox/engine/instagram_onebox.rb
onebox-1.9.28.4 lib/onebox/engine/instagram_onebox.rb
onebox-1.9.28.3 lib/onebox/engine/instagram_onebox.rb