Module: RemoteBook
- Defined in:
- lib/remote_book.rb,
lib/remote_book/base.rb,
lib/remote_book/amazon.rb,
lib/remote_book/version.rb,
lib/remote_book/barnes_and_noble.rb
Defined Under Namespace
Classes: Amazon, AmazonError, BarnesAndNoble, BarnesAndNobleError, Base, RemoteBookError
Constant Summary collapse
- VERSION =
File.read(File.dirname(__FILE__) + "/../../VERSION").chomp
Class Method Summary collapse
Class Method Details
.get_url(url, options = {:read_timeout => 2, :open_timeout => 2}) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/remote_book.rb', line 12 def self.get_url(url, = {:read_timeout => 2, :open_timeout => 2}) uri = URI.parse(url) http = Net::HTTP.new(uri.host, uri.port) http.read_timeout = [:read_timeout] http.open_timeout = [: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 |