Class: Alexandria::BookProviders::ProxisProvider
Constant Summary
collapse
- SITE =
Proxis essentially has three book databases, NL, FR and EN. Currently, this provider only searches the NL database, since it adds most to Alexandria (Amazon already has French and English titles).
'http://www.proxis.nl'
- BASE_SEARCH_URL =
"#{SITE}/NLNL/Search/IndexGSA.aspx?search=%s" \
'&shop=100001NL&SelRubricLevel1Id=100001NL'
- ISBN_REDIRECT_BASE_URL =
"#{SITE}/NLNL/Search/Index.aspx?search=%s" \
'&shop=100001NL&SelRubricLevel1Id=100001NL'
Instance Attribute Summary
#fullname, #name, #prefs
Instance Method Summary
collapse
Methods included from Logging
included, #log
#html_to_doc
#<=>, abstract?, #abstract?, #action_name, #enabled, #reinitialize, #remove, #toggle_enabled, #transport, unabstract, #variable_name
Constructor Details
Returns a new instance of ProxisProvider.
45
46
47
48
49
50
|
# File 'lib/alexandria/book_providers/proxis.rb', line 45
def initialize
super('Proxis', 'Proxis (Belgium)')
prefs.read
end
|
Instance Method Details
#create_search_uri(search_type, search_term) ⇒ Object
66
67
68
69
70
71
72
|
# File 'lib/alexandria/book_providers/proxis.rb', line 66
def create_search_uri(search_type, search_term)
if search_type == SEARCH_BY_ISBN
BASE_SEARCH_URL % Library.canonicalise_ean(search_term)
else
BASE_SEARCH_URL % CGI.escape(search_term)
end
end
|
123
124
125
126
127
|
# File 'lib/alexandria/book_providers/proxis.rb', line 123
def (th)
tr = th.parent
td = tr.at('td')
text_of(td) if td
end
|
#get_book_from_search_result(result) ⇒ Object
74
75
76
77
78
|
# File 'lib/alexandria/book_providers/proxis.rb', line 74
def get_book_from_search_result(result)
log.debug { "Fetching book from #{result[:lookup_url]}" }
html_data = transport.get_response(URI.parse(result[:lookup_url]))
parse_result_data(html_data.body)
end
|
#parse_result_data(html) ⇒ Object
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
|
# File 'lib/alexandria/book_providers/proxis.rb', line 129
def parse_result_data(html)
doc = html_to_doc(html)
book_data = {}
book_data[:authors] = []
if ( = doc.search('div.detailBlock h3'))
= .first.search('span')
title = text_of(.first)
title = Regexp.last_match[1].strip if title =~ /(.+)-$/
book_data[:title] = title
end
= doc.search('table.productInfoTable th')
isbns = []
unless .empty?
.each do |th|
isbns << (th) if th.inner_text =~ /(ISBN|EAN)/
end
book_data[:isbn] = Library.canonicalise_ean(isbns.first)
end
unless .empty?
.each do |th|
= th.inner_text
if =~ /Type/
book_data[:binding] = (th)
elsif =~ /Verschijningsdatum/
date = (th)
date =~ /\/([\d]{4})/
book_data[:publish_year] = Regexp.last_match[1].to_i
elsif =~ /Auteur/
book_data[:authors] << (th)
elsif =~ /Uitgever/
book_data[:publisher] = (th)
end
end
end
image_url = nil
if (cover_img = doc.at("img[@id$='imgProduct']"))
image_url = if cover_img['src'] =~ /^http/
cover_img['src']
else
"#{SITE}/#{cover_img['src']}" end
image_url = nil if image_url =~ /ProductNoCover/
end
book = Book.new(book_data[:title], book_data[:authors],
book_data[:isbn], book_data[:publisher],
book_data[:publish_year], book_data[:binding])
[book, image_url]
end
|
#parse_search_result_data(html) ⇒ Object
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
# File 'lib/alexandria/book_providers/proxis.rb', line 103
def parse_search_result_data(html)
doc = html_to_doc(html)
book_search_results = []
items = doc.search('table.searchResult tr')
items.each do |item|
result = {}
title_link = item % 'h5 a'
if title_link
result[:title] = text_of(title_link)
result[:lookup_url] = title_link['href']
result[:lookup_url] = "#{SITE}#{result[:lookup_url]}" unless result[:lookup_url] =~ /^http/
end
book_search_results << result
end
book_search_results
end
|
#search(criterion, type) ⇒ Object
52
53
54
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/alexandria/book_providers/proxis.rb', line 52
def search(criterion, type)
req = create_search_uri(type, criterion)
puts req if $DEBUG
html_data = transport.get_response(URI.parse(req))
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
|
#text_of(node) ⇒ Object
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
# File 'lib/alexandria/book_providers/proxis.rb', line 85
def text_of(node)
if node.nil?
nil
else
if node.text?
node.to_html
elsif node.elem?
if node.children.nil?
nil
else
node_text = node.children.map { |n| text_of(n) }.join
node_text.strip.squeeze(' ')
end
end
end
end
|