| Class | RBook::WWW::Base |
| In: |
lib/rbook/www/base.rb
|
| Parent: | Object |
registers a new scraper with the library. classname - the class to add
# File lib/rbook/www/base.rb, line 13 def self.add_scraper(classname) @@scrapers << classname end
find a scraper matching the requested id id - a scraper id as a symbol
# File lib/rbook/www/base.rb, line 19 def self.find_scraper(id) @@scrapers.each do |scraper| return scraper if scraper::SCRAPER_ID == id end return nil end
This method can be overwritten in each scraper. It should return a hash containing the binary data and mimetype of the largest cover image it can find for the requested isbn
# File lib/rbook/www/base.rb, line 38 def get_cover(isbn) info = get_info(isbn) return nil if info.nil? return nil unless info.kind_of?(Hash) link = info[:cover_large] || info[:cover_medium] || info[:cover_thumb] return nil if link.nil? begin response = Net::HTTP.get_response URI.parse(link) if response.code != "200" raise response.code.to_s return nil else result = {} result[:data] = response.body result[:content_type] = "image/jpeg" return result end rescue return nil end end
This method can be overwritten in each scraper. It should return a hash of any information on the requested isbn it can find
# File lib/rbook/www/base.rb, line 66 def get_info(isbn) nil end
This method can be overwritten in each scraper. It should return a link to the requested isbn on the targets website
# File lib/rbook/www/base.rb, line 72 def get_link(isbn) nil end