rbook 0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/COPYING +340 -0
- data/LICENSE +13 -0
- data/README +16 -0
- data/Rakefile +206 -0
- data/examples/titlepage.rb +14 -0
- data/examples/www/find_all.rb +23 -0
- data/examples/www/find_cover_from_amazon.rb +12 -0
- data/examples/www/find_url_from_rainbow.rb +12 -0
- data/examples/www/list.rb +13 -0
- data/lib/rbook/bisac.rb +175 -0
- data/lib/rbook/errors.rb +7 -0
- data/lib/rbook/isbn.rb +249 -0
- data/lib/rbook/onix.rb +68 -0
- data/lib/rbook/onix/contributor.rb +60 -0
- data/lib/rbook/onix/lists.rb +2 -0
- data/lib/rbook/onix/lists/contributor_role.rb +10 -0
- data/lib/rbook/onix/lists/product_form.rb +100 -0
- data/lib/rbook/onix/message.rb +101 -0
- data/lib/rbook/onix/product.rb +188 -0
- data/lib/rbook/onix/sales_restriction.rb +51 -0
- data/lib/rbook/onix/supply_detail.rb +68 -0
- data/lib/rbook/onix/xchar.rb +98 -0
- data/lib/rbook/titlepage.rb +96 -0
- data/lib/rbook/titlepage/TitleQueryClient.rb +62 -0
- data/lib/rbook/titlepage/titlepage_driver.rb +134 -0
- data/lib/rbook/titlepage/titlepage_utils.rb +374 -0
- data/lib/rbook/www.rb +172 -0
- data/lib/rbook/www/aau_scraper.rb +76 -0
- data/lib/rbook/www/amazon_uk_scraper.rb +44 -0
- data/lib/rbook/www/base.rb +87 -0
- data/lib/rbook/www/harper_au_scraper.rb +56 -0
- data/lib/rbook/www/harper_us_scraper.rb +55 -0
- data/lib/rbook/www/hha_scraper.rb +50 -0
- data/lib/rbook/www/macmillan_scraper.rb +62 -0
- data/lib/rbook/www/orbis_scraper.rb +48 -0
- data/lib/rbook/www/oup_scraper.rb +64 -0
- data/lib/rbook/www/paulist_scraper.rb +53 -0
- data/lib/rbook/www/pearson_au_scraper.rb +52 -0
- data/lib/rbook/www/penguin_scraper.rb +45 -0
- data/lib/rbook/www/random_au_scraper.rb +90 -0
- data/lib/rbook/www/random_us_scraper.rb +59 -0
- data/lib/rbook/www/sas_scraper.rb +54 -0
- data/lib/rbook/www/unireps_scraper.rb +58 -0
- data/lib/rbook/www/wiley_us_scraper.rb +54 -0
- data/test/data/abingdon.xml +38931 -0
- data/test/data/augsburg.xml +39009 -0
- data/test/data/chalice.xml +10851 -0
- data/test/data/eerdsman.xml +36942 -0
- data/test/data/invalid_no_product.xml +9 -0
- data/test/data/not_xml.csv +1 -0
- data/test/data/single_product.xml +50 -0
- data/test/data/xml_not_onix.xml +7 -0
- data/test/mocks/titlepage_driver.rb +107 -0
- data/test/unit/bisac_test.rb +57 -0
- data/test/unit/isbn_test.rb +149 -0
- data/test/unit/onix/contributor_test.rb +50 -0
- data/test/unit/onix/message_test.rb +119 -0
- data/test/unit/onix/product_test.rb +101 -0
- data/test/unit/onix/sales_restriction_test.rb +48 -0
- data/test/unit/onix/supply_detail_test.rb +53 -0
- data/test/unit/onix/xchar_test.rb +37 -0
- data/test/unit/titlepage_test.rb +127 -0
- metadata +130 -0
@@ -0,0 +1,374 @@
|
|
1
|
+
require 'xsd/qname'
|
2
|
+
|
3
|
+
# {urn:TitleQuery}ProductIdentifier
|
4
|
+
class ProductIdentifier
|
5
|
+
@@schema_type = "ProductIdentifier"
|
6
|
+
@@schema_ns = "urn:TitleQuery"
|
7
|
+
@@schema_element = [["productIDType", ["SOAP::SOAPString", XSD::QName.new(nil, "ProductIDType")]], ["iDValue", ["SOAP::SOAPString", XSD::QName.new(nil, "IDValue")]]]
|
8
|
+
|
9
|
+
def ProductIDType
|
10
|
+
@productIDType
|
11
|
+
end
|
12
|
+
|
13
|
+
def ProductIDType=(value)
|
14
|
+
@productIDType = value
|
15
|
+
end
|
16
|
+
|
17
|
+
def IDValue
|
18
|
+
@iDValue
|
19
|
+
end
|
20
|
+
|
21
|
+
def IDValue=(value)
|
22
|
+
@iDValue = value
|
23
|
+
end
|
24
|
+
|
25
|
+
def initialize(productIDType = nil, iDValue = nil)
|
26
|
+
@productIDType = productIDType
|
27
|
+
@iDValue = iDValue
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
# {urn:TitleQuery}Title
|
32
|
+
class Title
|
33
|
+
@@schema_type = "Title"
|
34
|
+
@@schema_ns = "urn:TitleQuery"
|
35
|
+
@@schema_element = [["titleType", ["SOAP::SOAPString", XSD::QName.new(nil, "TitleType")]], ["titleText", ["SOAP::SOAPString", XSD::QName.new(nil, "TitleText")]], ["titlePrefix", ["SOAP::SOAPString", XSD::QName.new(nil, "TitlePrefix")]], ["titleWithoutPrefix", ["SOAP::SOAPString", XSD::QName.new(nil, "TitleWithoutPrefix")]], ["subtitle", ["SOAP::SOAPString", XSD::QName.new(nil, "Subtitle")]]]
|
36
|
+
|
37
|
+
def TitleType
|
38
|
+
@titleType
|
39
|
+
end
|
40
|
+
|
41
|
+
def TitleType=(value)
|
42
|
+
@titleType = value
|
43
|
+
end
|
44
|
+
|
45
|
+
def TitleText
|
46
|
+
@titleText
|
47
|
+
end
|
48
|
+
|
49
|
+
def TitleText=(value)
|
50
|
+
@titleText = value
|
51
|
+
end
|
52
|
+
|
53
|
+
def TitlePrefix
|
54
|
+
@titlePrefix
|
55
|
+
end
|
56
|
+
|
57
|
+
def TitlePrefix=(value)
|
58
|
+
@titlePrefix = value
|
59
|
+
end
|
60
|
+
|
61
|
+
def TitleWithoutPrefix
|
62
|
+
@titleWithoutPrefix
|
63
|
+
end
|
64
|
+
|
65
|
+
def TitleWithoutPrefix=(value)
|
66
|
+
@titleWithoutPrefix = value
|
67
|
+
end
|
68
|
+
|
69
|
+
def Subtitle
|
70
|
+
@subtitle
|
71
|
+
end
|
72
|
+
|
73
|
+
def Subtitle=(value)
|
74
|
+
@subtitle = value
|
75
|
+
end
|
76
|
+
|
77
|
+
def initialize(titleType = nil, titleText = nil, titlePrefix = nil, titleWithoutPrefix = nil, subtitle = nil)
|
78
|
+
@titleType = titleType
|
79
|
+
@titleText = titleText
|
80
|
+
@titlePrefix = titlePrefix
|
81
|
+
@titleWithoutPrefix = titleWithoutPrefix
|
82
|
+
@subtitle = subtitle
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
# {urn:TitleQuery}Contributor
|
87
|
+
class Contributor
|
88
|
+
@@schema_type = "Contributor"
|
89
|
+
@@schema_ns = "urn:TitleQuery"
|
90
|
+
@@schema_element = [["sequenceNumber", ["SOAP::SOAPInteger", XSD::QName.new(nil, "SequenceNumber")]], ["contributorRole", ["SOAP::SOAPString", XSD::QName.new(nil, "ContributorRole")]], ["personName", ["SOAP::SOAPString", XSD::QName.new(nil, "PersonName")]], ["personNameInverted", ["SOAP::SOAPString", XSD::QName.new(nil, "PersonNameInverted")]], ["titlesBeforeNames", ["SOAP::SOAPString", XSD::QName.new(nil, "TitlesBeforeNames")]], ["keyNames", ["SOAP::SOAPString", XSD::QName.new(nil, "KeyNames")]]]
|
91
|
+
|
92
|
+
def SequenceNumber
|
93
|
+
@sequenceNumber
|
94
|
+
end
|
95
|
+
|
96
|
+
def SequenceNumber=(value)
|
97
|
+
@sequenceNumber = value
|
98
|
+
end
|
99
|
+
|
100
|
+
def ContributorRole
|
101
|
+
@contributorRole
|
102
|
+
end
|
103
|
+
|
104
|
+
def ContributorRole=(value)
|
105
|
+
@contributorRole = value
|
106
|
+
end
|
107
|
+
|
108
|
+
def PersonName
|
109
|
+
@personName
|
110
|
+
end
|
111
|
+
|
112
|
+
def PersonName=(value)
|
113
|
+
@personName = value
|
114
|
+
end
|
115
|
+
|
116
|
+
def PersonNameInverted
|
117
|
+
@personNameInverted
|
118
|
+
end
|
119
|
+
|
120
|
+
def PersonNameInverted=(value)
|
121
|
+
@personNameInverted = value
|
122
|
+
end
|
123
|
+
|
124
|
+
def TitlesBeforeNames
|
125
|
+
@titlesBeforeNames
|
126
|
+
end
|
127
|
+
|
128
|
+
def TitlesBeforeNames=(value)
|
129
|
+
@titlesBeforeNames = value
|
130
|
+
end
|
131
|
+
|
132
|
+
def KeyNames
|
133
|
+
@keyNames
|
134
|
+
end
|
135
|
+
|
136
|
+
def KeyNames=(value)
|
137
|
+
@keyNames = value
|
138
|
+
end
|
139
|
+
|
140
|
+
def initialize(sequenceNumber = nil, contributorRole = nil, personName = nil, personNameInverted = nil, titlesBeforeNames = nil, keyNames = nil)
|
141
|
+
@sequenceNumber = sequenceNumber
|
142
|
+
@contributorRole = contributorRole
|
143
|
+
@personName = personName
|
144
|
+
@personNameInverted = personNameInverted
|
145
|
+
@titlesBeforeNames = titlesBeforeNames
|
146
|
+
@keyNames = keyNames
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
# {urn:TitleQuery}Stock
|
151
|
+
class Stock
|
152
|
+
@@schema_type = "Stock"
|
153
|
+
@@schema_ns = "urn:TitleQuery"
|
154
|
+
@@schema_element = [["onHand", ["SOAP::SOAPString", XSD::QName.new(nil, "OnHand")]], ["onOrder", ["SOAP::SOAPString", XSD::QName.new(nil, "OnOrder")]]]
|
155
|
+
|
156
|
+
def OnHand
|
157
|
+
@onHand
|
158
|
+
end
|
159
|
+
|
160
|
+
def OnHand=(value)
|
161
|
+
@onHand = value
|
162
|
+
end
|
163
|
+
|
164
|
+
def OnOrder
|
165
|
+
@onOrder
|
166
|
+
end
|
167
|
+
|
168
|
+
def OnOrder=(value)
|
169
|
+
@onOrder = value
|
170
|
+
end
|
171
|
+
|
172
|
+
def initialize(onHand = nil, onOrder = nil)
|
173
|
+
@onHand = onHand
|
174
|
+
@onOrder = onOrder
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
# {urn:TitleQuery}Price
|
179
|
+
class Price
|
180
|
+
@@schema_type = "Price"
|
181
|
+
@@schema_ns = "urn:TitleQuery"
|
182
|
+
@@schema_element = [["priceTypeCode", ["SOAP::SOAPString", XSD::QName.new(nil, "PriceTypeCode")]], ["priceAmount", ["SOAP::SOAPDecimal", XSD::QName.new(nil, "PriceAmount")]]]
|
183
|
+
|
184
|
+
def PriceTypeCode
|
185
|
+
@priceTypeCode
|
186
|
+
end
|
187
|
+
|
188
|
+
def PriceTypeCode=(value)
|
189
|
+
@priceTypeCode = value
|
190
|
+
end
|
191
|
+
|
192
|
+
def PriceAmount
|
193
|
+
@priceAmount
|
194
|
+
end
|
195
|
+
|
196
|
+
def PriceAmount=(value)
|
197
|
+
@priceAmount = value
|
198
|
+
end
|
199
|
+
|
200
|
+
def initialize(priceTypeCode = nil, priceAmount = nil)
|
201
|
+
@priceTypeCode = priceTypeCode
|
202
|
+
@priceAmount = priceAmount
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
# {urn:TitleQuery}SupplyDetail
|
207
|
+
class SupplyDetail
|
208
|
+
@@schema_type = "SupplyDetail"
|
209
|
+
@@schema_ns = "urn:TitleQuery"
|
210
|
+
@@schema_element = [["supplierName", ["SOAP::SOAPString", XSD::QName.new(nil, "SupplierName")]], ["supplierRole", ["SOAP::SOAPString", XSD::QName.new(nil, "SupplierRole")]], ["productAvailability", ["SOAP::SOAPString", XSD::QName.new(nil, "ProductAvailability")]], ["expectedShipDate", ["SOAP::SOAPString", XSD::QName.new(nil, "ExpectedShipDate")]], ["stock", ["Stock", XSD::QName.new(nil, "Stock")]], ["packQuantity", ["SOAP::SOAPInteger", XSD::QName.new(nil, "PackQuantity")]], ["price", ["Price", XSD::QName.new(nil, "Price")]]]
|
211
|
+
|
212
|
+
def SupplierName
|
213
|
+
@supplierName
|
214
|
+
end
|
215
|
+
|
216
|
+
def SupplierName=(value)
|
217
|
+
@supplierName = value
|
218
|
+
end
|
219
|
+
|
220
|
+
def SupplierRole
|
221
|
+
@supplierRole
|
222
|
+
end
|
223
|
+
|
224
|
+
def SupplierRole=(value)
|
225
|
+
@supplierRole = value
|
226
|
+
end
|
227
|
+
|
228
|
+
def ProductAvailability
|
229
|
+
@productAvailability
|
230
|
+
end
|
231
|
+
|
232
|
+
def ProductAvailability=(value)
|
233
|
+
@productAvailability = value
|
234
|
+
end
|
235
|
+
|
236
|
+
def ExpectedShipDate
|
237
|
+
@expectedShipDate
|
238
|
+
end
|
239
|
+
|
240
|
+
def ExpectedShipDate=(value)
|
241
|
+
@expectedShipDate = value
|
242
|
+
end
|
243
|
+
|
244
|
+
def Stock
|
245
|
+
@stock
|
246
|
+
end
|
247
|
+
|
248
|
+
def Stock=(value)
|
249
|
+
@stock = value
|
250
|
+
end
|
251
|
+
|
252
|
+
def PackQuantity
|
253
|
+
@packQuantity
|
254
|
+
end
|
255
|
+
|
256
|
+
def PackQuantity=(value)
|
257
|
+
@packQuantity = value
|
258
|
+
end
|
259
|
+
|
260
|
+
def Price
|
261
|
+
@price
|
262
|
+
end
|
263
|
+
|
264
|
+
def Price=(value)
|
265
|
+
@price = value
|
266
|
+
end
|
267
|
+
|
268
|
+
def initialize(supplierName = nil, supplierRole = nil, productAvailability = nil, expectedShipDate = nil, stock = nil, packQuantity = nil, price = nil)
|
269
|
+
@supplierName = supplierName
|
270
|
+
@supplierRole = supplierRole
|
271
|
+
@productAvailability = productAvailability
|
272
|
+
@expectedShipDate = expectedShipDate
|
273
|
+
@stock = stock
|
274
|
+
@packQuantity = packQuantity
|
275
|
+
@price = price
|
276
|
+
end
|
277
|
+
end
|
278
|
+
|
279
|
+
# {urn:TitleQuery}ArrayOfContributor
|
280
|
+
class ArrayOfContributor < ::Array
|
281
|
+
@@schema_type = "Contributor"
|
282
|
+
@@schema_ns = "urn:TitleQuery"
|
283
|
+
@@schema_element = [["item", ["Contributor", XSD::QName.new(nil, "item")]]]
|
284
|
+
end
|
285
|
+
|
286
|
+
# {urn:TitleQuery}ArrayOfProductIdentifier
|
287
|
+
class ArrayOfProductIdentifier < ::Array
|
288
|
+
@@schema_type = "ProductIdentifier"
|
289
|
+
@@schema_ns = "urn:TitleQuery"
|
290
|
+
@@schema_element = [["item", ["ProductIdentifier", XSD::QName.new(nil, "item")]]]
|
291
|
+
end
|
292
|
+
|
293
|
+
# {urn:TitleQuery}Product
|
294
|
+
class Product
|
295
|
+
@@schema_type = "Product"
|
296
|
+
@@schema_ns = "urn:TitleQuery"
|
297
|
+
@@schema_element = [["productIdentifiers", ["ArrayOfProductIdentifier", XSD::QName.new(nil, "ProductIdentifiers")]], ["title", ["Title", XSD::QName.new(nil, "Title")]], ["contributors", ["ArrayOfContributor", XSD::QName.new(nil, "Contributors")]], ["supplyDetail", ["SupplyDetail", XSD::QName.new(nil, "SupplyDetail")]]]
|
298
|
+
|
299
|
+
def ProductIdentifiers
|
300
|
+
@productIdentifiers
|
301
|
+
end
|
302
|
+
|
303
|
+
def ProductIdentifiers=(value)
|
304
|
+
@productIdentifiers = value
|
305
|
+
end
|
306
|
+
|
307
|
+
def Title
|
308
|
+
@title
|
309
|
+
end
|
310
|
+
|
311
|
+
def Title=(value)
|
312
|
+
@title = value
|
313
|
+
end
|
314
|
+
|
315
|
+
def Contributors
|
316
|
+
@contributors
|
317
|
+
end
|
318
|
+
|
319
|
+
def Contributors=(value)
|
320
|
+
@contributors = value
|
321
|
+
end
|
322
|
+
|
323
|
+
def SupplyDetail
|
324
|
+
@supplyDetail
|
325
|
+
end
|
326
|
+
|
327
|
+
def SupplyDetail=(value)
|
328
|
+
@supplyDetail = value
|
329
|
+
end
|
330
|
+
|
331
|
+
def initialize(productIdentifiers = nil, title = nil, contributors = nil, supplyDetail = nil)
|
332
|
+
@productIdentifiers = productIdentifiers
|
333
|
+
@title = title
|
334
|
+
@contributors = contributors
|
335
|
+
@supplyDetail = supplyDetail
|
336
|
+
end
|
337
|
+
end
|
338
|
+
|
339
|
+
# {urn:TitleQuery}SearchResults
|
340
|
+
class SearchResults
|
341
|
+
@@schema_type = "SearchResults"
|
342
|
+
@@schema_ns = "urn:TitleQuery"
|
343
|
+
@@schema_element = [["iSBN", ["SOAP::SOAPString", XSD::QName.new(nil, "ISBN")]], ["eAN", ["SOAP::SOAPString", XSD::QName.new(nil, "EAN")]], ["product", ["Product", XSD::QName.new(nil, "Product")]]]
|
344
|
+
|
345
|
+
def ISBN
|
346
|
+
@iSBN
|
347
|
+
end
|
348
|
+
|
349
|
+
def ISBN=(value)
|
350
|
+
@iSBN = value
|
351
|
+
end
|
352
|
+
|
353
|
+
def EAN
|
354
|
+
@eAN
|
355
|
+
end
|
356
|
+
|
357
|
+
def EAN=(value)
|
358
|
+
@eAN = value
|
359
|
+
end
|
360
|
+
|
361
|
+
def Product
|
362
|
+
@product
|
363
|
+
end
|
364
|
+
|
365
|
+
def Product=(value)
|
366
|
+
@product = value
|
367
|
+
end
|
368
|
+
|
369
|
+
def initialize(iSBN = nil, eAN = nil, product = nil)
|
370
|
+
@iSBN = iSBN
|
371
|
+
@eAN = eAN
|
372
|
+
@product = product
|
373
|
+
end
|
374
|
+
end
|
data/lib/rbook/www.rb
ADDED
@@ -0,0 +1,172 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__) + "/../")
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'scrapi'
|
5
|
+
|
6
|
+
require 'rbook/isbn'
|
7
|
+
require 'rbook/www/base'
|
8
|
+
|
9
|
+
# load all scraping classes
|
10
|
+
files = Dir.entries(File.dirname(__FILE__) + '/www/')
|
11
|
+
files.delete(".")
|
12
|
+
files.delete("..")
|
13
|
+
files.delete(".svn")
|
14
|
+
files.delete("base.rb")
|
15
|
+
files.each do |file|
|
16
|
+
require 'rbook/www/' + file
|
17
|
+
end
|
18
|
+
|
19
|
+
module RBook
|
20
|
+
# A set of classes to make scraping title information from various publisher websites easier.
|
21
|
+
#
|
22
|
+
# Basic usage:
|
23
|
+
# require 'rubygems'
|
24
|
+
# require 'rbook/www'
|
25
|
+
# RBook::WWW.find_info(:first, "1841492280", :penguin)
|
26
|
+
# #=> Hash
|
27
|
+
# RBook::WWW.find_info(:all, "1841492280", [:penguin, :harpercollins_au])
|
28
|
+
# #=> Array of Hashes
|
29
|
+
module WWW
|
30
|
+
|
31
|
+
# Find any information possible about the supplied isbn using the
|
32
|
+
# specified scrapers.
|
33
|
+
#
|
34
|
+
# - isbn - a valid isbn10 or isbn13
|
35
|
+
# - scrapers - a symbol or array of symbols specifying which scrapers to search with
|
36
|
+
#
|
37
|
+
# Returns the results as an array containing the results
|
38
|
+
#
|
39
|
+
# RBook::WWW.find_info(:first, "1841492280", :penguin)
|
40
|
+
# #=> Hash
|
41
|
+
# RBook::WWW.find_info(:all, "1841492280", [:penguin, :harpercollins_au])
|
42
|
+
# #=> Array of Hashes
|
43
|
+
def self.find_info(search_type, isbn, scrapers)
|
44
|
+
|
45
|
+
raise ArgumentError, 'search_type must be :first or :all' if !search_type.eql?(:first) && !search_type.eql?(:all)
|
46
|
+
raise ArgumentError, 'Supplied isbn is not valid' unless ISBN::valid_isbn?(isbn)
|
47
|
+
raise ArgumentError, 'scrapers must be a symbol or array of symbols' unless scrapers.kind_of?(Symbol) || scrapers.kind_of?(Array)
|
48
|
+
|
49
|
+
isbn = ISBN::convert_to_isbn13(isbn)
|
50
|
+
|
51
|
+
if scrapers.kind_of?(Symbol)
|
52
|
+
scrapers = [Base::find_scraper(scrapers)]
|
53
|
+
else
|
54
|
+
scrapers = Base::find_scrapers(scrapers)
|
55
|
+
end
|
56
|
+
|
57
|
+
results = []
|
58
|
+
|
59
|
+
scrapers.each do |scraper|
|
60
|
+
worker = scraper.new
|
61
|
+
result = worker.get_info(isbn)
|
62
|
+
if !result.nil? && search_type.eql(:first)
|
63
|
+
return result
|
64
|
+
elsif !result.nil?
|
65
|
+
results << result
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
if results.empty?
|
70
|
+
return nil
|
71
|
+
else
|
72
|
+
return results
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
# Find any information possible about the supplied isbn using the
|
77
|
+
# specified scrapers.
|
78
|
+
#
|
79
|
+
# - isbn - a valid isbn10 or isbn13
|
80
|
+
# - scrapers - a symbol or array of symbols specifying which scrapers to search with
|
81
|
+
#
|
82
|
+
# Returns the results as an array containing the results
|
83
|
+
#
|
84
|
+
# RBook::WWW.find_cover(:first, "1841492280", :penguin)
|
85
|
+
# #=> Hash
|
86
|
+
# RBook::WWW.find_cover(:all, "1841492280", [:penguin, :harpercollins_au])
|
87
|
+
# #=> Array of Hashes
|
88
|
+
def self.find_cover(search_type, isbn, scrapers)
|
89
|
+
|
90
|
+
raise ArgumentError, 'search_type must be :first or :all' if !search_type.eql?(:first) && !search_type.eql?(:all)
|
91
|
+
raise ArgumentError, 'Supplied isbn is not valid' unless ISBN::valid_isbn?(isbn)
|
92
|
+
raise ArgumentError, 'scrapers must be a symbol or array of symbols' unless scrapers.kind_of?(Symbol) || scrapers.kind_of?(Array)
|
93
|
+
|
94
|
+
isbn = ISBN::convert_to_isbn13(isbn)
|
95
|
+
|
96
|
+
if scrapers.kind_of?(Symbol)
|
97
|
+
scrapers = [Base::find_scraper(scrapers)]
|
98
|
+
else
|
99
|
+
scrapers = Base::find_scrapers(scrapers)
|
100
|
+
end
|
101
|
+
|
102
|
+
results = []
|
103
|
+
|
104
|
+
scrapers.each do |scraper|
|
105
|
+
worker = scraper.new
|
106
|
+
result = worker.get_cover(isbn)
|
107
|
+
if !result.nil? && search_type.eql?(:first)
|
108
|
+
return result
|
109
|
+
elsif !result.nil?
|
110
|
+
results << result
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
if results.empty?
|
115
|
+
return nil
|
116
|
+
else
|
117
|
+
return results
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
# Find any information possible about the supplied isbn using the
|
122
|
+
# specified scrapers.
|
123
|
+
#
|
124
|
+
# - isbn - a valid isbn10 or isbn13
|
125
|
+
# - scrapers - a symbol or array of symbols specifying which scrapers to search with
|
126
|
+
#
|
127
|
+
# Returns the results as an array containing the results
|
128
|
+
#
|
129
|
+
# RBook::WWW.find_url(:first, "1841492280", :penguin)
|
130
|
+
# #=> Hash
|
131
|
+
# RBook::WWW.find_url(:all, "1841492280", [:penguin, :harpercollins_au])
|
132
|
+
# #=> Array of Hashes
|
133
|
+
def self.find_url(search_type, isbn, scrapers)
|
134
|
+
|
135
|
+
raise ArgumentError, 'search_type must be :first or :all' if !search_type.eql?(:first) && !search_type.eql?(:all)
|
136
|
+
raise ArgumentError, 'Supplied isbn is not valid' unless ISBN::valid_isbn?(isbn)
|
137
|
+
raise ArgumentError, 'scrapers must be a symbol or array of symbols' unless scrapers.kind_of?(Symbol) || scrapers.kind_of?(Array)
|
138
|
+
|
139
|
+
isbn = ISBN::convert_to_isbn13(isbn)
|
140
|
+
|
141
|
+
if scrapers.kind_of?(Symbol)
|
142
|
+
scrapers = [Base::find_scraper(scrapers)]
|
143
|
+
else
|
144
|
+
scrapers = Base::find_scrapers(scrapers)
|
145
|
+
end
|
146
|
+
|
147
|
+
results = []
|
148
|
+
|
149
|
+
scrapers.each do |scraper|
|
150
|
+
worker = scraper.new
|
151
|
+
result = worker.get_url(isbn)
|
152
|
+
if !result.nil? && search_type.eql?(:first)
|
153
|
+
return result
|
154
|
+
elsif !result.nil
|
155
|
+
results << result
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
if results.empty?
|
160
|
+
return nil
|
161
|
+
else
|
162
|
+
return results
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
# returns an array of all available scrapers
|
167
|
+
def self.scrapers
|
168
|
+
Base.scrapers
|
169
|
+
end
|
170
|
+
|
171
|
+
end
|
172
|
+
end
|