Class: Alexandria::BookProviders::AdLibrisProvider

Inherits:
WebsiteBasedProvider show all
Includes:
Logging
Defined in:
lib/alexandria/book_providers/adlibris.rb

Constant Summary collapse

SITE =
'http://www.adlibris.com/se/'
BASE_SEARCH_URL =
"#{SITE}searchresult.aspx?search=advanced&%s=%s" \
'&fromproduct=False'
PRODUCT_URL =

type/term

"#{SITE}product.aspx?isbn=%s"

Instance Attribute Summary

Attributes inherited from AbstractProvider

#fullname, #name, #prefs

Instance Method Summary collapse

Methods included from Logging

included, #log

Methods inherited from WebsiteBasedProvider

#html_to_doc, #text_of

Methods inherited from AbstractProvider

#<=>, abstract?, #abstract?, #action_name, #enabled, #reinitialize, #remove, #toggle_enabled, #transport, unabstract, #variable_name

Constructor Details

#initializeAdLibrisProvider

Returns a new instance of AdLibrisProvider.



45
46
47
48
49
# File 'lib/alexandria/book_providers/adlibris.rb', line 45

def initialize
  super('AdLibris', 'AdLibris (Sweden)')
  prefs.read
  # @ent = HTMLEntities.new
end

Instance Method Details

#search(criterion, type) ⇒ Object

search (copied from new WorldCat search)



52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/alexandria/book_providers/adlibris.rb', line 52

def search(criterion, type)
  req = create_search_uri(type, criterion)
  log.info { "Fetching #{req} " }
  html_data = transport.get_response(URI.parse(req))

  if type == SEARCH_BY_ISBN
    parse_result_data(html_data.body)
  else
    results = parse_search_result_data(html_data.body)
    raise NoResultsError if results.empty?

    results.map { |result| get_book_from_search_result(result) }
  end
end

#url(book) ⇒ Object

url



68
69
70
71
72
73
# File 'lib/alexandria/book_providers/adlibris.rb', line 68

def url(book)
  create_search_uri(SEARCH_BY_ISBN, book.isbn)
rescue => ex
  log.warn { "Cannot create url for book #{book}; #{ex.message}" }
  nil
end