Sha256: 233472d7c2d2f998a4dc98313bceb5d614da8f0157b5debde497542235104522
Contents?: true
Size: 1.3 KB
Versions: 1
Compression:
Stored size: 1.3 KB
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}/", "/") description = oembed.title type = if description =~ /^Photos by/ "album" elsif description =~ /^Video by/ "video" else "photo" end title = if type == "album" "[Album] @#{oembed.author_name}" else "@#{oembed.author_name}" end result = { link: permalink, title: title, image: "#{permalink}/media/?size=l", description: Onebox::Helpers.truncate(description, 250) } result[:video_link] = permalink if type == "video" result 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-1.9.28.2 | lib/onebox/engine/instagram_onebox.rb |