The Amazon module allows libraries to deliver amazon content to the opac
[koha.git] / C4 / Amazon.pm
1
2 package C4::Amazon;
3 # Copyright 2004-2005 Joshua Ferraro (jmf at kados dot org)
4 #
5 # This file is part of Koha.
6 #
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
10 # version.
11 #
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License along with
17 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
18 # Suite 330, Boston, MA  02111-1307 USA
19 #
20 # This module dynamically pulls amazon content into Koha.  It does not
21 # store the data in Koha's database.  You'll need to get a developer's key
22 # as well as an associate's tag to use it.
23 # FIXME: need to write up more docs.
24 #
25
26 use strict;
27 require Exporter;
28
29 use vars qw($VERSION @ISA @EXPORT);
30
31 $VERSION = 0.01;
32
33 @ISA = qw(Exporter);
34
35 @EXPORT = qw(
36   &get_amazon_details
37 );
38
39 sub get_amazon_details {
40
41 my ( $isbn ) = @_;
42
43 # insert your dev key here
44 my $dev_key='';
45
46 # insert your associates tag here
47 my $af_tag='';
48
49 my $asin=$isbn;
50
51 # old way from command line: shift @ARGV or die "Usage:perl amazon_http.ol <asin>\n";
52
53 #my $url = "http://xml.amazon.com/onca/xml3?t=" . $af_tag .
54 #       "&dev-t=" . $dev_key .
55 #       "&type=heavy&f=xml&" .
56 #       "AsinSearch=" . $asin;
57 my $url = "http://xml.amazon.com/onca/xml3?t=$dev_key&dev-t=$af_tag&type=heavy&f=xml&AsinSearch=" . $asin;
58
59 #Here's an example asin for the book "Cryptonomicon"
60 #0596005423";
61
62 use XML::Simple;
63 use LWP::Simple;
64 my $content = get($url);
65 die "could not regrieve $url" unless $content;
66
67 my $xmlsimple = XML::Simple->new();
68 my $response = $xmlsimple->XMLin($content,
69   forcearray => [ qw(Details Product AvgCustomerRating CustomerReview) ],
70 );
71 return $response;
72 #foreach my $result (@{$response->{Details}}){
73 #       my $product_description = $result->{ProductDescription};
74 #       my $image = $result->{ImageUrlMedium};
75 #       my $price = $result->{ListPrice};
76 #       my $reviews = $result->{
77 #       return $result;
78 #}
79 }