SQL/Amazon/Tables/Books.pm untested

filter: Statementstmt 0.0% 0 / 60 Branchbran 0.0% 0 / 22 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 0.0% 0 / 5 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 92 CC 12 SCAR 47.7
CC
12
Cov
0%
insert
156.0
new
2.0
BEGIN
2.0
CRAP 117.5
1 #
2 # Copyright (c) 2005, Presicient Corp., USA
3 #
4 # Permission is granted to use this software according to the terms of the
5 # Artistic License, as specified in the Perl README file,
6 # with the exception that commercial redistribution, either
7 # electronic or via physical media, as either a standalone package,
8 # or incorporated into a third party product, requires prior
9 # written approval of the author.
10 #
11 # This software is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14 #
15 # Presicient Corp. reserves the right to provide support for this software
16 # to individual sites under a separate (possibly fee-based)
17 # agreement.
18 #
19 # History:
20 #
21 # 2005-Jan-27 D. Arnold
22 # Coded.
23 #
24 =pod
25  
26 =head4 Books (view, readonly)
27  
28 Item attribute view specific to Books
29  
30 =over 4
31  
32 =item ASIN
33  
34 =item Author
35  
36 =item Creator
37  
38 =item Title
39  
40 =item ProductGroup
41  
42 =item ListPriceAmt
43  
44 =item ListPriceCurrency
45  
46 =item ListPriceFormatted
47  
48 =item EAN
49  
50 =item Binding
51  
52 =item DeweyDecimalNumber
53  
54 =item EAN
55  
56 =item ISBN
57  
58 =item Length
59  
60 =item Width
61  
62 =item Height
63  
64 =item NumberOfItems
65  
66 =item NumberOfPages
67  
68 =item PublicationDate
69  
70 =item Publisher
71  
72 =item ReadingLevel
73  
74 =item Weight
75  
76 =back
77  
78 =cut
79  
80 package SQL::Amazon::Tables::Books;
81  
82 use DBI qw(:sql_types);
83  
84 use base qw(SQL::Amazon::Tables::Table);
85  
86 use strict;
87  
88 my %sort_params = (
89 'relevancerank', 1,
90 'salesrank', 1,
91 'reviewrank', 1,
92 'pricerank', 1,
93 'inverse-pricerank', 1,
94 'daterank', 1,
95 'titlerank', 1,
96 '-titlerank', 1,
97 );
98  
99 my %browse_nodes = (
100 'Arts & Photography', 1,
101 'Biographies & Memoirs', 2,
102 'Business & Investing', 3,
103 'Children\'s Books', 4,
104 'Comics & Graphic Novels', 4366,
105 'Computers & Internet', 5,
106 'Cooking, Food & Wine', 6,
107 'Engineering', 13643,
108 'Entertainment', 86,
109 'Gay & Lesbian', 301889,
110 'Health, Mind & Body', 10,
111 'History', 9,
112 'Home & Garden', 48,
113 'Horror', 49,
114 'Law', 10777,
115 'Literature & Fiction', 17,
116 'Medicine', 13996,
117 'Mystery & Thrillers', 18,
118 'Nonfiction', 53,
119 'Outdoors & Nature', 290060,
120 'Parenting & Families', 20,
121 'Professional & Technical', 173507,
122 'Reference', 21,
123 'Religion & Spirituality', 22,
124 'Romance', 23,
125 'Science', 75,
126 'Science Fiction & Fantasy', 25,
127 'Sports', 26,
128 'Teens', 28,
129 'Travel', 27,
130 );
131  
132 our %metadata = (
133 'NAME', [
134 qw/ASIN Authors Creator Title ProductGroup ListPriceAmt ListPriceCurrency
135 ListPriceFormatted
136 EAN Binding DeweyDecimalNumber ISBN NumberOfItems
137 NumberOfPages PublicationDate Publisher ReadingLevel DetailPageURL SalesRank
138 SmallImageURL SmallImageHeight SmallImageWidth MediumImageURL
139 MediumImageHeight MediumImageWidth LargeImageURL
140 LargeImageHeight LargeImageWidth OfferCount TotalNew
141 LowestNewPriceAmt LowestNewPriceCurrency
142 LowestNewPriceFormatted TotalUsed LowestUsedPriceAmt
143 LowestUsedPriceCurrency LowestUsedPriceFormatted
144 TotalCollectible
145 LowestCollectiblePriceAmt
146 LowestCollectiblePriceCurrency
147 LowestCollectiblePriceFormatted
148  
149 TotalRefurbished
150 LowestRefurbishedPriceAmt
151 LowestRefurbishedPriceCurrency
152 LowestRefurbishedPriceFormatted
153  
154 VariationCount VariationLowPriceAmt VariationLowPriceCurrency
155 VariationLowPriceFormatted VariationHighPriceAmt
156 VariationHighPriceCurrency VariationHighPriceFormatted
157 VariationLowSalePriceAmt VariationLowSalePriceCurrency
158 VariationLowSalePriceFormatted VariationHighSalePriceAmt
159 VariationHighSalePriceCurrency VariationHighSalePriceFormatted
160 SingleMerchantID AverageRating TotalCustomerReviews
161 TotalOffers/
162 ],
163 'TYPE', [
164 SQL_VARCHAR,
165 SQL_VARCHAR,
166 SQL_VARCHAR,
167 SQL_VARCHAR,
168 SQL_VARCHAR,
169 SQL_DECIMAL,
170 SQL_VARCHAR,
171 SQL_VARCHAR,
172 SQL_VARCHAR,
173 SQL_VARCHAR,
174 SQL_VARCHAR,
175 SQL_VARCHAR,
176 SQL_INTEGER,
177 SQL_INTEGER,
178 SQL_DATE,
179 SQL_VARCHAR,
180 SQL_VARCHAR,
181 SQL_VARCHAR,
182 SQL_INTEGER,
183 SQL_VARCHAR,
184 SQL_INTEGER,
185 SQL_INTEGER,
186 SQL_VARCHAR,
187 SQL_INTEGER,
188 SQL_INTEGER,
189 SQL_VARCHAR,
190 SQL_INTEGER,
191 SQL_INTEGER,
192 SQL_INTEGER,
193 SQL_INTEGER,
194 SQL_DECIMAL,
195 SQL_VARCHAR,
196 SQL_VARCHAR,
197 SQL_INTEGER,
198 SQL_DECIMAL,
199 SQL_VARCHAR,
200 SQL_VARCHAR,
201  
202 SQL_INTEGER,
203 SQL_DECIMAL,
204 SQL_VARCHAR,
205 SQL_VARCHAR,
206  
207 SQL_INTEGER,
208 SQL_DECIMAL,
209 SQL_VARCHAR,
210 SQL_VARCHAR,
211  
212 SQL_INTEGER,
213 SQL_DECIMAL,
214 SQL_VARCHAR,
215 SQL_VARCHAR,
216 SQL_DECIMAL,
217 SQL_VARCHAR,
218 SQL_VARCHAR,
219 SQL_DECIMAL,
220 SQL_VARCHAR,
221 SQL_VARCHAR,
222 SQL_DECIMAL,
223 SQL_VARCHAR,
224 SQL_VARCHAR,
225 SQL_VARCHAR,
226 SQL_DECIMAL,
227 SQL_INTEGER,
228 SQL_INTEGER,
229 ],
230 'PRECISION', [
231 32,
232 256,# Authors
233 256,# Creator
234 256,# Title
235 256,# ProductGroup
236 15,
237 10,
238 32,
239 32,
240 32,
241 32,
242 32,
243 10,
244 10,
245 10,
246 256,# Publisher
247 32,
248 256,# DetailPageURL
249 10,
250 256,# SmallImageURL
251 10,
252 10,
253 256,# MediumImageURL
254 10,
255 10,
256 256,# LargeImageURL
257 10,
258 10,
259 10,
260 10,
261 15,
262 10,
263 32,
264 10,
265 15,
266 10,
267 32,
268  
269 10,
270 15,
271 10,
272 32,
273  
274 10,
275 15,
276 10,
277 32,
278  
279 10,
280 15,
281 10,
282 32,
283 15,
284 10,
285 32,
286 15,
287 10,
288 32,
289 15,
290 10,
291 32,
292 32,
293 15,
294 10,
295 10,
296 ],
297 'SCALE', [
298 undef,
299 undef,
300 undef,
301 undef,
302 undef,
303 2,
304 undef,
305 undef,
306 undef,
307 undef,
308 undef,
309 undef,
310 undef,
311 undef,
312 undef,
313 undef,
314 undef,
315 undef,
316 undef,
317 undef,
318 undef,
319 undef,
320 undef,
321 undef,
322 undef,
323 undef,
324 undef,
325 undef,
326 undef,
327 undef,
328 2,
329 undef,
330 undef,
331 undef,
332 2,
333 undef,
334 undef,
335 undef,
336 2,
337 undef,
338 undef,
339  
340 undef,
341 2,
342 undef,
343 undef,
344 undef,
345 2,
346 undef,
347 undef,
348 2,
349 undef,
350 undef,
351 2,
352 undef,
353 undef,
354 2,
355 undef,
356 undef,
357 undef,
358 2,
359 undef,
360 undef,
361 ],
362 'NULLABLE', [
363 undef,
364 1,
365 1,
366 1,
367 1,
368 1,
369 1,
370 1,
371 1,
372 1,
373 1,
374 1,
375 1,
376 1,
377 1,
378 1,
379 1,
380 1,
381 1,
382 1,
383 1,
384 1,
385 1,
386 1,
387 1,
388 1,
389 1,
390 1,
391 1,
392 1,
393 1,
394 1,
395 1,
396 1,
397 1,
398 1,
399 1,
400 1,
401 1,
402 1,
403 1,
404 1,
405 1,
406 1,
407 1,
408 1,
409 1,
410 1,
411 1,
412 1,
413 1,
414 1,
415 1,
416 1,
417 1,
418 1,
419 1,
420 1,
421 1,
422 1,
423 1,
424 1,
425 ]
426 );
427  
428 sub new {
429 my $class = shift;
430 my $obj = $class->SUPER::new(\%metadata);
431 return $obj;
432 }
433 sub insert {
434 my ($obj, $item, $asin, $reqid) = @_;
435 my $names = $obj->{NAME};
436 my $types = $obj->{TYPE};
437 my @row = ();
438 my $colnums = $obj->{col_nums};
439 $row[$colnums->{ASIN}] = $item->{ASIN};
440 $row[$colnums->{DetailPageURL}] = $item->{DetailPageURL};
441 $row[$colnums->{SalesRank}] = $item->{SalesRank};
442 foreach ('SmallImage', 'MediumImage', 'LargeImage') {
443 $row[$colnums->{$_ . 'URL'}] = $item->{$_}{URL},
444 $row[$colnums->{$_ . 'Height'}] = $item->{$_}{Height},
445 $row[$colnums->{$_ . 'Width'}] = $item->{$_}{Width}
446 if $item->{$_};
447 }
448  
449 my $attrs = $item->{OfferSummary};
450 if ($attrs) {
451 $row[$colnums->{TotalCollectible}] = $attrs->{TotalCollectible};
452 $row[$colnums->{TotalNew}] = $attrs->{TotalNew};
453 $row[$colnums->{TotalUsed}] = $attrs->{TotalUsed};
454 $row[$colnums->{TotalRefurbished}] = $attrs->{TotalRefurbished};
455 foreach ('LowestNewPrice', 'LowestUsedPrice',
456 'LowestCollectiblePrice', 'LowestRefurbishedPrice') {
457  
458 $row[$colnums->{$_ . 'Amt'}] = $obj->format_money($attrs->{$_}{Amount}),
459 $row[$colnums->{$_ . 'Currency'}] = $attrs->{$_}{CurrencyCode},
460 $row[$colnums->{$_ . 'Formatted'}] = $attrs->{$_}{FormattedPrice}
461 if $attrs->{$_};
462 }
463 }
464 $attrs = $item->{ItemAttributes};
465 if ($attrs) {
466 $row[$colnums->{Authors}] = ref $attrs->{Author} ?
467 join('; ', @{$attrs->{Author}}) :
468 $attrs->{Author}
469 if $attrs->{Author};
470 $row[$colnums->{Binding}] = $attrs->{Binding};
471 $row[$colnums->{EAN}] = $attrs->{EAN};
472 $row[$colnums->{ISBN}] = $attrs->{ISBN};
473 $row[$colnums->{NumberOfItems}] = $attrs->{NumberOfItems} || 1;
474 $row[$colnums->{NumberOfPages}] = $attrs->{NumberOfPages};
475 $row[$colnums->{PublicationDate}] =
476 $obj->format_date($attrs->{PublicationDate})
477 if $attrs->{PublicationDate};
478 $row[$colnums->{Publisher}] = $attrs->{Publisher};
479 $row[$colnums->{Title}] = $attrs->{Title};
480 $row[$colnums->{ProductGroup}] = $attrs->{ProductGroup};
481 if ($attrs->{ListPrice}) {
482 $row[$colnums->{ListPriceAmt}] =
483 $obj->format_money($attrs->{ListPrice}{Amount})
484 if $attrs->{ListPrice}{Amount};
485 $row[$colnums->{ListPriceCurrency}] =
486 $attrs->{ListPrice}{CurrencyCode};
487 $row[$colnums->{ListPriceFormatted}] =
488 $attrs->{ListPrice}{FormattedPrice};
489 }
490 }
491  
492 $attrs = $item->{Offers};
493 $row[$colnums->{TotalOffers}] = $attrs->{TotalOffers}
494 if $attrs;
495 $attrs = $item->{CustomerReviews};
496 $row[$colnums->{TotalCustomerReviews}] = $attrs->{TotalReviews},
497 $row[$colnums->{AverageRating}] = $attrs->{AverageRating}
498 if $attrs;
499
500 return $obj->SUPER::save_row(\@row, $item, $reqid);
501 }
502  
503 1;