Class: OPDS::Support::Browser
- Inherits:
-
Object
- Object
- OPDS::Support::Browser
- Includes:
- Logging
- Defined in:
- lib/opds/support/browser.rb
Overview
Browser class, it will be used to access the Internet. Currently based on open-uri only
Instance Method Summary collapse
-
#body ⇒ String
Last page body.
-
#current_location ⇒ String
Current uri.
-
#discover(url) ⇒ OPDS::Support::LinkSet, false
Try to discover catalog links at the given url.
-
#go_to(uri) ⇒ Object
Navigate to the provided uri.
-
#headers ⇒ Hash
Last page HTTP headers.
-
#ok? ⇒ boolean
Last page load was ok ?.
-
#status ⇒ integer
Last page load return code.
Methods included from Logging
Instance Method Details
#body ⇒ String
Returns Last page body.
46 47 48 |
# File 'lib/opds/support/browser.rb', line 46 def body @last_response.body if @last_response end |
#current_location ⇒ String
Returns current uri.
51 52 53 |
# File 'lib/opds/support/browser.rb', line 51 def current_location @current_location end |
#discover(url) ⇒ OPDS::Support::LinkSet, false
Try to discover catalog links at the given url
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/opds/support/browser.rb', line 58 def discover(url) go_to(url) if ok? doc=Nokogiri::HTML(body) tab=OPDS::Support::LinkSet.new(self) extract_links(tab,doc,'//*[@type="application/atom+xml;type=entry;profile=opds-catalog"]') extract_links(tab,doc,'//*[@type="application/atom+xml;profile=opds-catalog"]') return false if tab.size == 0 tab else return false end end |
#go_to(uri) ⇒ Object
Navigate to the provided uri
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/opds/support/browser.rb', line 11 def go_to(uri) log("Accessing #{uri}") url=URI.parse(uri) @last_response=nil Net::HTTP.start(url.host,url.port) {|http| path="/" path=url.path unless url.path=='' req = Net::HTTP::Get.new(path) # req.basic_auth user,pass unless user.nil? @last_response = http.request(req) } @current_location=url.to_s if status/10==30 && headers['location'] log("Following redirection (code: #{status}) to #{headers['location']}") go_to(headers['location'].first) end end |
#headers ⇒ Hash
Returns Last page HTTP headers.
41 42 43 |
# File 'lib/opds/support/browser.rb', line 41 def headers @last_response.to_hash if @last_response end |
#ok? ⇒ boolean
Last page load was ok ?
31 32 33 |
# File 'lib/opds/support/browser.rb', line 31 def ok? status==200 end |
#status ⇒ integer
Returns Last page load return code.
36 37 38 |
# File 'lib/opds/support/browser.rb', line 36 def status @last_response.code.to_i if @last_response end |