Class: LinkThumbnailer::Processor

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/link_thumbnailer/processor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeProcessor

Returns a new instance of Processor.



13
14
15
16
17
18
# File 'lib/link_thumbnailer/processor.rb', line 13

def initialize
  @config = ::LinkThumbnailer.page.config
  @http   = ::Net::HTTP::Persistent.new

  super(config)
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



11
12
13
# File 'lib/link_thumbnailer/processor.rb', line 11

def config
  @config
end

#httpObject (readonly)

Returns the value of attribute http.



11
12
13
# File 'lib/link_thumbnailer/processor.rb', line 11

def http
  @http
end

#redirect_countObject (readonly)

Returns the value of attribute redirect_count.



11
12
13
# File 'lib/link_thumbnailer/processor.rb', line 11

def redirect_count
  @redirect_count
end

#urlObject

Returns the value of attribute url.



10
11
12
# File 'lib/link_thumbnailer/processor.rb', line 10

def url
  @url
end

Instance Method Details

#call(url = '', redirect_count = 0, headers = {}) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/link_thumbnailer/processor.rb', line 26

def call(url = '', redirect_count = 0, headers = {})
  self.url        = url
  @redirect_count = redirect_count

  raise ::LinkThumbnailer::RedirectLimit if too_many_redirections?

  with_valid_url do
    set_http_headers(headers)
    set_http_options
    perform_request
  end
rescue ::Net::HTTPExceptions, ::SocketError, ::Timeout::Error, ::Net::HTTP::Persistent::Error => e
  raise ::LinkThumbnailer::HTTPError.new(e.message)
end

#start(url) ⇒ Object



20
21
22
23
24
# File 'lib/link_thumbnailer/processor.rb', line 20

def start(url)
  result = call(url)
  shutdown
  result
end