Module: Onebox::Engine::StandardEmbed
- Included in:
- ImgurOnebox, SlidesOnebox, SoundCloudOnebox, WhitelistedGenericOnebox, YoutubeOnebox
- Defined in:
- lib/onebox/engine/standard_embed.rb
Class Method Summary collapse
- .add_oembed_provider(regexp, endpoint) ⇒ Object
- .add_opengraph_provider(regexp) ⇒ Object
- .oembed_providers ⇒ Object
- .opengraph_providers ⇒ Object
Instance Method Summary collapse
Class Method Details
.add_oembed_provider(regexp, endpoint) ⇒ Object
13 14 15 |
# File 'lib/onebox/engine/standard_embed.rb', line 13 def self.(regexp, endpoint) [regexp] = endpoint end |
.add_opengraph_provider(regexp) ⇒ Object
17 18 19 |
# File 'lib/onebox/engine/standard_embed.rb', line 17 def self.add_opengraph_provider(regexp) opengraph_providers.push(regexp) end |
.oembed_providers ⇒ Object
5 6 7 |
# File 'lib/onebox/engine/standard_embed.rb', line 5 def self. @@oembed_providers ||= {} end |
.opengraph_providers ⇒ Object
9 10 11 |
# File 'lib/onebox/engine/standard_embed.rb', line 9 def self.opengraph_providers @@opengraph_providers ||= Array.new end |
Instance Method Details
#always_https? ⇒ Boolean
31 32 33 |
# File 'lib/onebox/engine/standard_embed.rb', line 31 def always_https? WhitelistedGenericOnebox.host_matches(uri, WhitelistedGenericOnebox.https_hosts) end |
#raw ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/onebox/engine/standard_embed.rb', line 35 def raw return @raw if @raw StandardEmbed..each do |regexp, endpoint| if url =~ regexp ("#{endpoint}?url=#{url}") return @raw if @raw end end response = Onebox::Helpers.fetch_response(url) html_doc = Nokogiri::HTML(response.body) StandardEmbed.opengraph_providers.each do |regexp| if url =~ regexp @raw = parse_open_graph(html_doc, url) return @raw if @raw end end # Determine if we should use oEmbed or OpenGraph (prefers oEmbed) = html_doc.at("//link[@type='application/json+oembed']") || html_doc.at("//link[@type='text/json+oembed']") # Do not use oEmbed for WordPress sites (https://meta.discourse.org/t/onebox-for-wordpress-4-4-sites/36765) () unless .nil? || ['href'] =~ /public-api.wordpress.com\/oembed/ || ['href'] =~ /wp-json\/oembed/ open_graph = parse_open_graph(html_doc, url) if @raw @raw[:image] = open_graph.images.first if @raw[:image].nil? && open_graph && open_graph.images return @raw end @raw = open_graph end |