Class: Alexandria::BookProviders::DeaStoreProvider

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

Constant Summary collapse

SITE =
'http://www.deastore.com'
BASE_SEARCH_URL =

type/term

"#{SITE}/search/italian_books/0/%s/%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

#initializeDeaStoreProvider

Returns a new instance of DeaStoreProvider.



39
40
41
42
43
# File 'lib/alexandria/book_providers/deastore.rb', line 39

def initialize
  super('DeaStore', 'DeaStore (Italy)')
  prefs.read
  @agent = nil
end

Instance Method Details

#agentObject



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

def agent
  unless @agent
    @agent = Alexandria::WWWAgent.new
    @agent.language = :it
  end
  @agent
end

#get_book_from_search_result(result) ⇒ Object



53
54
55
56
57
58
59
60
# File 'lib/alexandria/book_providers/deastore.rb', line 53

def get_book_from_search_result(result)
  log.debug { "Fetching book from #{result[:url]}" }
  html_data = agent.get(result[:url])
  # File.open("rsltflarn#{Time.now().usec()}.html", 'wb') do |f|
  #  f.write(html_data.body)
  # end
  parse_result_data(html_data.body)
end

#search(criterion, type) ⇒ Object

Raises:



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/alexandria/book_providers/deastore.rb', line 62

def search(criterion, type)
  begin
    criterion = criterion.encode('ISO-8859-1') # still needed??
  rescue Encoding::UndefinedConversionError
    log.info { "Cannot search for non-ISO-8859-1 terms at DeaStore : #{criterion}" }
    raise NoResultsError
  end
  html_data = agent.get(create_search_uri(type, criterion))
  # File.open("flarn#{Time.now().usec()}.html", 'wb') do |f|
  #  f.write(html_data.body)
  # end
  results = parse_search_result_data(html_data.body)
  raise NoResultsError if results.empty?

  if type == SEARCH_BY_ISBN
    get_book_from_search_result(results.first)
  else
    results.map { |result| get_book_from_search_result(result) }
  end
end

#url(_book) ⇒ Object

it isn’t possible to create a URL for a book given only the ISBN…



84
85
86
# File 'lib/alexandria/book_providers/deastore.rb', line 84

def url(_book)
  nil
end