rel_3_0 moved to HEAD
[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 # To use this module you need to do three things:
26 # 1. get a dev key and associate tag from Amazon
27 # 2. uncomment the Amazon stuff in opac-detail.pl
28 # 3. add the template variables to opac-detail.tmpl
29 #    here's what's available: 
30 #    ProductDescription
31 #    ImageUrlMedium
32 #    ListPrice
33 #    url
34 #    loop SimilarProducts (Product)
35 #    loop Reviews (rating, Summary)
36 #
37 use XML::Simple;
38 use LWP::Simple;
39 use strict;
40 require Exporter;
41
42 use vars qw($VERSION @ISA @EXPORT);
43
44 $VERSION = 0.02;
45 =head1 NAME
46
47 C4::Amazon - Functions for retrieving Amazon.com content in Koha
48
49 =head1 FUNCTIONS
50
51 This module provides facilities for retrieving Amazon.com content in Koha
52
53 =cut
54
55 @ISA = qw(Exporter);
56
57 @EXPORT = qw(
58   &get_amazon_details
59 );
60
61 =head1 get_amazon_details($isbn);
62
63 =head2 $isbn is a isbn string
64
65 =cut
66
67 sub get_amazon_details {
68
69 my ( $isbn ) = @_;
70
71 # insert your dev key here
72         $isbn =~ s/(p|-)//g;
73
74 # insert your associates tag here
75         my $dev_key=C4::Context->preference('AmazonDevKey');
76
77         #grab the associates tag: mine is '0ZRY7YASKJS280T7YB02'
78         my $af_tag=C4::Context->preference('AmazonAssocTag');
79
80 my $asin=$isbn;
81
82 # old way from command line: shift @ARGV or die "Usage:perl amazon_http.ol <asin>\n";
83
84 #my $url = "http://xml.amazon.com/onca/xml3?t=" . $af_tag .
85 #       "&dev-t=" . $dev_key .
86 #       "&type=heavy&f=xml&" .
87 #       "AsinSearch=" . $asin;
88         my $url = "http://xml.amazon.com/onca/xml3?t=$af_tag&dev-t=$dev_key&type=heavy&f=xml&AsinSearch=" . $asin;
89 my $content = get($url);
90         warn "could not retrieve $url" unless $content;
91 my $xmlsimple = XML::Simple->new();
92 my $response = $xmlsimple->XMLin($content,
93   forcearray => [ qw(Details Product AvgCustomerRating CustomerReview) ],
94 );
95 return $response;
96 }
97
98 =head1 NOTES
99
100 =head1 AUTHOR
101
102 Joshua Ferraro <jmf@liblime.com>
103 =cut