Class: Alexandria::BookProviders::SicilianoProvider

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

Constant Summary collapse

SITE =
"http://www.siciliano.com.br"
BASE_SEARCH_URL =

The string interpolations in this URL are the search term and search type, respectively.

"#{SITE}/pesquisaweb/pesquisaweb.dll/pesquisa?" \
"&FIL_ID=102" \
"&PALAVRASN1=%s" \
"&FILTRON1=%s" \
"&ESTRUTN1=0301&ORDEMN2=E"

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

#initializeSicilianoProvider

Returns a new instance of SicilianoProvider.



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

def initialize
  super("Siciliano", "Livraria Siciliano (Brasil)")
  # no preferences for the moment
  prefs.read
end

Instance Method Details

#get_book_from_search_result(result) ⇒ Object



53
54
55
56
57
# File 'lib/alexandria/book_providers/siciliano.rb', line 53

def get_book_from_search_result(result)
  log.info { "Fetching book from #{result[:url]}" }
  html_data = transport.get(URI.parse(result[:url]))
  parse_result_data(html_data, result)
end

#search(criterion, type) ⇒ Object



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

def search(criterion, type)
  criterion = criterion.encode("ISO-8859-1") # still needed??
  trying_again = false
  begin
    req = create_search_uri(type, criterion, trying_again)
    log.debug { "#{name} #{trying_again ? 'retrying ' : ''}request = #{req}" }
    data = transport.get(URI.parse(req))
    results = parse_search_result_data(data)
    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
  rescue NoResultsError => ex
    if (type == SEARCH_BY_ISBN) && (trying_again == false)
      trying_again = true
      retry
    end

    raise ex
  end
end

#url(_book) ⇒ Object

the new Siciliano website no longer has direct links to books by their ISBN (the permalink now seems to be based on the product id)



86
87
88
# File 'lib/alexandria/book_providers/siciliano.rb', line 86

def url(_book)
  nil
end