Sha256: 8aa78cf1e7c36df6fe89bac60fe1eb112c973c1cbdc88cdfd3105796e4312f73

Contents?: true

Size: 821 Bytes

Versions: 1

Compression:

Stored size: 821 Bytes

Contents

require "rubygems"
require "uri"
require "net/http"
require "openssl"
require "nokogiri"

require "remote_book/base"
require "remote_book/amazon"
require "remote_book/barnes_and_noble"

module RemoteBook
  def self.get_url(url, options = {:read_timeout => 2, :open_timeout => 2})
    uri = URI.parse(url)

    http = Net::HTTP.new(uri.host, uri.port)
    http.read_timeout = options[:read_timeout]
    http.open_timeout = options[:open_timeout]
    # this return structure is pretty ugly
    begin
      res = http.start { |web|
        g = Net::HTTP::Get.new(uri.request_uri)
        web.request(g)
      }
    rescue Timeout::Error
      return {:body => "error: timeout", :status => :error}
    rescue Exception => e
      return {:body => "error: #{e}", :status => :error}
    else
      return res
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
remote_book-0.1.5 lib/remote_book.rb