Class: Alexandria::BookProviders::MCUProvider
- Inherits:
-
GenericProvider
- Object
- AbstractProvider
- GenericProvider
- Alexandria::BookProviders::MCUProvider
- Includes:
- Logging, GetText
- Defined in:
- lib/alexandria/book_providers/mcu.rb
Constant Summary collapse
- LANGUAGES =
{ 'es' => '1' }.freeze
- BASE_URI =
BASE_URI = “www.mcu.es/cgi-bin/BRSCGI3701?”
'http://www.mcu.es/cgi-brs/BasesHTML/isbn/BRSCGI?'
Instance Attribute Summary
Attributes inherited from AbstractProvider
Instance Method Summary collapse
-
#initialize ⇒ MCUProvider
constructor
A new instance of MCUProvider.
- #search(criterion, type) ⇒ Object
- #url(book) ⇒ Object
Methods included from Logging
Methods inherited from AbstractProvider
#<=>, abstract?, #abstract?, #action_name, #enabled, #reinitialize, #remove, #toggle_enabled, #transport, unabstract, #variable_name
Constructor Details
#initialize ⇒ MCUProvider
Returns a new instance of MCUProvider.
41 42 43 44 45 |
# File 'lib/alexandria/book_providers/mcu.rb', line 41 def initialize super('MCU', _('Spanish Culture Ministry')) # No preferences prefs.read end |
Instance Method Details
#search(criterion, type) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/alexandria/book_providers/mcu.rb', line 47 def search(criterion, type) prefs.read criterion = criterion.encode('ISO-8859-1') # still needed?? print "Doing search with MCU #{criterion}, type: #{type}\n" if $DEBUG # for DEBUGing req = BASE_URI + 'CMD=VERLST&BASE=ISBN&DOCS=1-15&CONF=AEISPA.cnf&OPDEF=AND&DOCS=1-1000&SEPARADOR=&' req += case type when SEARCH_BY_ISBN "WGEN-C=&WISB-C=#{CGI.escape(criterion)}&WAUT-C=&WTIT-C=" when SEARCH_BY_TITLE "WGEN-C=&WISB-C=&WAUT-C=&WTIT-C=#{CGI.escape(criterion)}" when SEARCH_BY_AUTHORS "WGEN-C=&WISB-C=&WAUT-C=#{CGI.escape(criterion)}&WTIT-C=" when SEARCH_BY_KEYWORD "WGEN-C=#{CGI.escape(criterion)}&WISB-C=&WAUT-C=&WTIT-C=" else raise InvalidSearchTypeError end req += '&WMAT-C=&WEDI-C=&WFEP-C=&%40T353-GE=&%40T353-LE=&WSER-C=&WLUG-C=' \ '&WDIS-C=%28DISPONIBLE+or+AGOTADO%29&WLEN-C=&WCLA-C=&WSOP-C=' products = {} print "Request page is #{req}\n" if $DEBUG # for DEBUGing transport.get(URI.parse(req)).each do |line| print "Reading line: #{line}" if $DEBUG # for DEBUGing next unless line =~ /CMD=VERDOC.*&DOCN=([^&]*)&NDOC=([^&]*)/ next if products[Regexp.last_match[1]] next unless (book = parseBook(Regexp.last_match[1], Regexp.last_match[2])) products[Regexp.last_match[1]] = book puts Regexp.last_match[1] if $DEBUG # for DEBUGing end raise NoResultsError if products.values.empty? type == SEARCH_BY_ISBN ? products.values.first : products.values end |
#url(book) ⇒ Object
87 88 89 90 91 92 93 94 95 96 |
# File 'lib/alexandria/book_providers/mcu.rb', line 87 def url(book) isbn = Library.canonicalise_isbn(book.isbn) 'http://www.mcu.es/cgi-brs/BasesHTML/isbn/BRSCGI?CMD=VERLST&BASE=ISBN&DOCS=1-15' \ "&CONF=AEISPA.cnf&OPDEF=AND&DOCS=1&SEPARADOR=&WGEN-C=&WISB-C=#{isbn}&WAUT-C=&WTIT-C=" \ '&WMAT-C=&WEDI-C=&WFEP-C=&%40T353-GE=&%40T353-LE=&WSER-C=&WLUG-C=' \ '&WDIS-C=%28DISPONIBLE+or+AGOTADO%29&WLEN-C=&WCLA-C=&WSOP-C=' rescue => ex log.warn { "Cannot create url for book #{book}; #{ex.}" } nil end |