# loop SimilarProducts (Product)
# loop Reviews (rating, Summary)
#
+use XML::Simple;
+use LWP::Simple;
use strict;
require Exporter;
use vars qw($VERSION @ISA @EXPORT);
-$VERSION = 0.01;
+$VERSION = 0.02;
+=head1 NAME
+
+C4::Amazon - Functions for retrieving Amazon.com content in Koha
+
+=head1 FUNCTIONS
+
+This module provides facilities for retrieving Amazon.com content in Koha
+
+=cut
@ISA = qw(Exporter);
&get_amazon_details
);
+=head1 get_amazon_details($isbn);
+
+=head2 $isbn is a isbn string
+
+=cut
+
sub get_amazon_details {
my ( $isbn ) = @_;
# insert your dev key here
-my $dev_key='neulibrary-20';
-$isbn=substr($isbn,0,9);
+ $isbn =~ s/(p|-)//g;
+
# insert your associates tag here
-my $af_tag='0YGCZ5GV9ZNGGS7THDG2';
+ my $dev_key=C4::Context->preference('AmazonDevKey');
+
+ #grab the associates tag: mine is '0ZRY7YASKJS280T7YB02'
+ my $af_tag=C4::Context->preference('AmazonAssocTag');
my $asin=$isbn;
# "&dev-t=" . $dev_key .
# "&type=heavy&f=xml&" .
# "AsinSearch=" . $asin;
-my $url = "http://xml.amazon.com/onca/xml3?t=$dev_key&dev-t=$af_tag&type=heavy&f=xml&AsinSearch=" . $asin;
-
-#Here's an example asin for the book "Cryptonomicon"
-#0596005423";
-
-use XML::Simple;
-use LWP::Simple;
+ my $url = "http://xml.amazon.com/onca/xml3?t=$af_tag&dev-t=$dev_key&type=heavy&f=xml&AsinSearch=" . $asin;
my $content = get($url);
-if ($content){
-
+ warn "could not retrieve $url" unless $content;
my $xmlsimple = XML::Simple->new();
my $response = $xmlsimple->XMLin($content,
- forcearray => [ qw(Details Product AvgCustomerRating CustomerReview ) ],
+ forcearray => [ qw(Details Product AvgCustomerRating CustomerReview) ],
);
return $response;
-#foreach my $result (@{$response->{Details}}){
-# my $product_description = $result->{ProductDescription};
-# my $image = $result->{ImageUrlMedium};
-# my $price = $result->{ListPrice};
-# my $reviews = $result->{
-# return $result;
-#}
}
-}
\ No newline at end of file
+
+=head1 NOTES
+
+=head1 AUTHOR
+
+Joshua Ferraro <jmf@liblime.com>
+=cut