Class: SimpleImagesDownloader::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/simple_images_downloader/client.rb

Overview

Client class Responsible for opening the URI and handling errors

Examples:

SimpleImagesDownloader::Client.new.open(uri)

Instance Method Summary collapse

Constructor Details

#initialize(options = Configuration::REQUEST_OPTIONS) ⇒ Client

Returns a new instance of Client.



13
14
15
# File 'lib/simple_images_downloader/client.rb', line 13

def initialize(options = Configuration::REQUEST_OPTIONS)
  @options = options
end

Instance Method Details

#open(uri) ⇒ StringIO

Returns StringIO object.

Parameters:

  • uri (URI)

    URI object

Returns:

  • (StringIO)

    StringIO object



19
20
21
22
23
24
25
# File 'lib/simple_images_downloader/client.rb', line 19

def open(uri)
  uri.open(@options)
rescue OpenURI::HTTPRedirect
  raise Errors::RedirectError, uri
rescue OpenURI::HTTPError
  raise Errors::ConnectionError, uri
end