Class: ImageInfo::RequestHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/image_info/request_handler.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(image) ⇒ RequestHandler

Returns a new instance of RequestHandler.



7
8
9
10
# File 'lib/image_info/request_handler.rb', line 7

def initialize(image)
  @image = image
  @buffer = StringIO.new
end

Instance Attribute Details

#bufferObject (readonly)

Returns the value of attribute buffer.



5
6
7
# File 'lib/image_info/request_handler.rb', line 5

def buffer
  @buffer
end

#imageObject (readonly)

Returns the value of attribute image.



5
6
7
# File 'lib/image_info/request_handler.rb', line 5

def image
  @image
end

Instance Method Details

#buildObject



12
13
14
15
16
17
18
19
20
# File 'lib/image_info/request_handler.rb', line 12

def build
  ::Typhoeus::Request.new(image.uri.to_s, followlocation: true, accept_encoding: :gzip).tap do |request|
    request.on_body do |chunk|
      buffer.write(chunk)
      buffer.rewind
      :abort if max_image_size_reached? || found_image_info?
    end
  end
end