# returns the HTTP response object from the URL fetch
sub fetch_response {
- my( $self, $page, $key ) = @_;
+ my( $self, $page, $raw_key ) = @_;
my $uname = $self->userid;
+ my $key = $self->normalize_key($raw_key);
+ return 0 if $key eq 0;
+ my $url = $self->base_url . "$key.01.$page";
+ return $AC->get_url($url);
+}
+
+sub normalize_key {
+ my( $self, $key ) = @_;
+
# Some sites have entered Amazon IDs in 020 $a, thus we cannot
# simply pass all incoming keys to Business::ISBN for normalization
if (length($key) > 10) {
}
# Amazon prefers ISBN10
- $isbn = $isbn->as_isbn10 if $isbn->type eq 'ISBN13';
+ $isbn = $isbn->as_isbn10 if $isbn->prefix eq '978';
$key = $isbn->as_string([]);
}
-
- my $url = $self->base_url . "$key.01.$page";
- return $AC->get_url($url);
+ return $key;
}
-
1;
#!perl -T
-use Test::More tests => 5;
+use Test::More tests => 9;
BEGIN {
use_ok( 'OpenILS::WWW::AddedContent' );
use_ok( 'OpenILS::WWW::AddedContent::ContentCafe' );
use_ok( 'OpenILS::WWW::AddedContent::OpenLibrary' );
use_ok( 'OpenILS::WWW::AddedContent::Syndetic' );
+
+my $amazon = OpenILS::WWW::AddedContent::Amazon;
+is($amazon->normalize_key('9791186178140'), '9791186178140', 'Amazon Added Content can handle 979 ISBNs');
+is($amazon->normalize_key('9780735220171'), '0735220174', 'Amazon Added Content converts ISBN-13s to ISBN-10s');
+is($amazon->normalize_key('0735220174'), '0735220174', 'Amazon Added Content leaves ISBN-10s as they are');
+is($amazon->normalize_key('978-0735220171'), '0735220174', 'Amazon Added Content removes hyphens from ISBNs');
--- /dev/null
+BEGIN;
+
+SELECT plan(4);
+
+SELECT is(
+ (SELECT public.translate_isbn1013('9791186178140')),
+ '9791186178140 ',
+ 'public.translate_isbn1013 can handle 979 ISBNs'
+);
+
+SELECT is(
+ (SELECT public.translate_isbn1013('9780735220171')),
+ '9780735220171 0735220174 ',
+ 'public.translate_isbn1013 can translate 978 ISBNs to ISBN10s'
+);
+
+SELECT is(
+ (SELECT public.translate_isbn1013('0735220174')),
+ '0735220174 9780735220171 ',
+ 'public.translate_isbn1013 can translate ISBN10s to ISBN13s'
+);
+
+SELECT is(
+ (SELECT public.translate_isbn1013('979-1186178140')),
+ '9791186178140 ',
+ 'public.translate_isbn1013 can remove hyphens'
+);
+
+
+ROLLBACK;