Class: Onebox::Engine::InstagramOnebox

Inherits:
Object
  • Object
show all
Includes:
Onebox::Engine, StandardEmbed, LayoutSupport
Defined in:
lib/onebox/engine/instagram_onebox.rb

Instance Attribute Summary

Attributes included from Onebox::Engine

#errors, #options, #timeout, #uri, #url

Instance Method Summary collapse

Methods included from LayoutSupport

#layout, max_text

Methods included from StandardEmbed

add_oembed_provider, add_opengraph_provider, #always_https?, oembed_providers, opengraph_providers, #raw

Methods included from Onebox::Engine

all_iframe_origins, engines, included, #initialize, origins_to_regexes

Instance Method Details

#clean_urlObject



16
17
18
19
20
21
22
23
# File 'lib/onebox/engine/instagram_onebox.rb', line 16

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

#dataObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/onebox/engine/instagram_onebox.rb', line 25

def data
  @data ||=
    begin
      oembed = get_oembed
      if oembed.data.empty?
        raise "No oEmbed data found. Ensure 'facebook_app_access_token' is valid"
      end

      {
        link: clean_url.gsub("/#{oembed.author_name}/", "/") + "/embed",
        title: "@#{oembed.author_name}",
        image: oembed.thumbnail_url,
        image_width: oembed.data[:thumbnail_width],
        image_height: oembed.data[:thumbnail_height],
        description: Onebox::Helpers.truncate(oembed.title, 250),
      }
    end
end

#placeholder_htmlObject



44
45
46
# File 'lib/onebox/engine/instagram_onebox.rb', line 44

def placeholder_html
  ::Onebox::Helpers.image_placeholder_html
end

#to_htmlObject



48
49
50
51
52
53
54
55
56
57
# File 'lib/onebox/engine/instagram_onebox.rb', line 48

def to_html
  <<-HTML
    <iframe
      src="#{data[:link]}"
      width="#{data[:image_width]}"
      height="#{data[:image_height].to_i + 98}"
      frameborder="0"
    ></iframe>
  HTML
end