Sha256: f0121e015d448425a02a20dc781ff075fb722af1523b6f96e99a0e6b43623014

Contents?: true

Size: 1.26 KB

Versions: 4

Compression:

Stored size: 1.26 KB

Contents

require 'htmlentities'

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

      matches_regexp(/^https?:\/\/(?:www\.)?(?:instagram\.com|instagr\.am)/)
      always_https

      def data
        og = get_opengraph
        title = og[:title].split(":")[0].strip
        html_entities = HTMLEntities.new

        json_data = html_doc.xpath('//script[contains(text(),"window._sharedData")]').text.to_s
        title = "[Album] #{title}" if json_data =~ /"edge_sidecar_to_children"/

        result = { link: og[:url],
                   title: html_entities.decode(Onebox::Helpers.truncate(title, 80)),
                   description: html_entities.decode(Sanitize.fragment(Onebox::Helpers.truncate(og[:description].strip, 250)))
                  }

        if !Onebox::Helpers.blank?(og[:image])
          result[:image] = ::Onebox::Helpers.normalize_url_for_output(og[:image])
        end

        if !Onebox::Helpers.blank?(og[:video_secure_url])
          result[:video_width] = og[:video_width]
          result[:video_height] = og[:video_height]
          result[:video_secure_url] = ::Onebox::Helpers.normalize_url_for_output(og[:video_secure_url])
        end

        result
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
onebox-1.8.46 lib/onebox/engine/instagram_onebox.rb
onebox-1.8.45 lib/onebox/engine/instagram_onebox.rb
onebox-1.8.44 lib/onebox/engine/instagram_onebox.rb
onebox-1.8.43 lib/onebox/engine/instagram_onebox.rb