lib/onebox/preview.rb in onebox-1.1.0 vs lib/onebox/preview.rb in onebox-1.2.0

- old
+ new

@@ -1,31 +1,44 @@ module Onebox class Preview attr_reader :cache - def initialize(link, parameters = Onebox.defaults) + def initialize(link, parameters = Onebox.options) @url = link @options = parameters @cache = options.cache - @engine = Matcher.new(@url).oneboxed + @engine_class = Matcher.new(@url).oneboxed end def to_s - engine.to_html + return "" unless engine + engine.to_html || "" + rescue *Onebox::Preview.web_exceptions + "" end + def placeholder_html + return "" unless engine + engine.placeholder_html || "" + rescue *Onebox::Preview.web_exceptions + "" + end + def options OpenStruct.new(@options) end + def self.web_exceptions + [Net::HTTPServerException, OpenURI::HTTPError, Timeout::Error, Net::HTTPError, Errno::ECONNREFUSED] + end + private def engine - @engine.new(@url, cache) + return nil unless @engine_class + @engine ||= @engine_class.new(@url, cache) end class InvalidURI < StandardError - end end end -