Sha256: 2f768b46d28eb2e6aef0b959e74edf7e8a1389a4cfda66f20f7e2a65c96b8348

Contents?: true

Size: 1.13 KB

Versions: 12

Compression:

Stored size: 1.13 KB

Contents

require 'htmlentities'

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

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

      def data
        og = get_opengraph
        title = og[:title].split(":")[0].strip.gsub(" on Instagram", "")
        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_link] = og[:url]
        end

        result
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
onebox-1.8.76 lib/onebox/engine/instagram_onebox.rb
onebox-1.8.75 lib/onebox/engine/instagram_onebox.rb
onebox-1.8.74 lib/onebox/engine/instagram_onebox.rb
onebox-1.8.73 lib/onebox/engine/instagram_onebox.rb
onebox-1.8.72 lib/onebox/engine/instagram_onebox.rb
onebox-1.8.71 lib/onebox/engine/instagram_onebox.rb
onebox-1.8.70 lib/onebox/engine/instagram_onebox.rb
onebox-1.8.69 lib/onebox/engine/instagram_onebox.rb
onebox-1.8.68 lib/onebox/engine/instagram_onebox.rb
onebox-1.8.67 lib/onebox/engine/instagram_onebox.rb
onebox-1.8.66 lib/onebox/engine/instagram_onebox.rb
onebox-1.8.65 lib/onebox/engine/instagram_onebox.rb