lib/onebox/engine/standard_embed.rb in onebox-1.6.9 vs lib/onebox/engine/standard_embed.rb in onebox-1.7.0
- old
+ new
@@ -20,10 +20,12 @@
# Some oembed providers (like meetup.com) don't provide links to themselves
add_oembed_provider(/www\.meetup\.com\//, 'http://api.meetup.com/oembed')
# In order to support Private Videos
add_oembed_provider(/vimeo\.com\//, 'https://vimeo.com/api/oembed.json')
+ # NYT requires login so use oembed only
+ add_oembed_provider(/nytimes\.com\//, 'https://www.nytimes.com/svc/oembed/json/')
def always_https?
WhitelistedGenericOnebox.host_matches(uri, WhitelistedGenericOnebox.https_hosts) || super
end
@@ -44,13 +46,11 @@
end
protected
def html_doc
- return @html_doc if @html_doc
- response = Onebox::Helpers.fetch_response(url)
- @html_doc = Nokogiri::HTML(response.body)
+ @html_doc ||= Nokogiri::HTML(Onebox::Helpers.fetch_response(url).body) rescue nil
end
def get_oembed
oembed_url = nil
@@ -77,15 +77,17 @@
# never use oembed from WordPress 4.4 (it's broken)
oe.delete(:html) if oe[:html] && oe[:html]["wp-embedded-content"]
oe
- rescue Errno::ECONNREFUSED, Net::HTTPError, MultiJson::LoadError
+ rescue Errno::ECONNREFUSED, Net::HTTPError, Net::HTTPFatalError, MultiJson::LoadError
{}
end
def get_opengraph
+ return {} unless html_doc
+
og = {}
html_doc.css('meta').each do |m|
if (m["property"] && m["property"][/^og:(.+)$/i]) || (m["name"] && m["name"][/^og:(.+)$/i])
value = (m["content"] || m["value"]).to_s
@@ -101,9 +103,11 @@
og
end
def get_twitter
+ return {} unless html_doc
+
twitter = {}
html_doc.css('meta').each do |m|
if (m["property"] && m["property"][/^twitter:(.+)$/i]) || (m["name"] && m["name"][/^twitter:(.+)$/i])
value = (m["content"] || m["value"]).to_s