Sha256: f6e6dba25eaad4a15b655852f48a7d93f77d896b48c8b3cf6b5bed3d2d43a664

Contents?: true

Size: 901 Bytes

Versions: 15

Compression:

Stored size: 901 Bytes

Contents

module Onebox
  class Preview
    attr_reader :cache

    def initialize(link, parameters = Onebox.options)
      @url = link
      @options = parameters
      @cache = options.cache
      @engine_class = Matcher.new(@url).oneboxed
    end

    def to_s
      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
      return nil unless @engine_class
      @engine ||= @engine_class.new(@url, cache)
    end

    class InvalidURI < StandardError
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
onebox-1.3.4 lib/onebox/preview.rb
onebox-1.3.3 lib/onebox/preview.rb
onebox-1.3.2 lib/onebox/preview.rb
onebox-1.3.1 lib/onebox/preview.rb
onebox-1.3.0 lib/onebox/preview.rb
onebox-1.2.9 lib/onebox/preview.rb
onebox-1.2.8 lib/onebox/preview.rb
onebox-1.2.7 lib/onebox/preview.rb
onebox-1.2.6 lib/onebox/preview.rb
onebox-1.2.5 lib/onebox/preview.rb
onebox-1.2.4 lib/onebox/preview.rb
onebox-1.2.3 lib/onebox/preview.rb
onebox-1.2.2 lib/onebox/preview.rb
onebox-1.2.1 lib/onebox/preview.rb
onebox-1.2.0 lib/onebox/preview.rb