setting $dbh->{AutoCommit} = 0, and adding a new --commit arg.
[koha.git] / C4 / Amazon.pm
blob19a92f6ce025e0c0bfa10a9f6aa2de684279e1eb
1 package C4::Amazon;
2 # Copyright (C) 2006 LibLime
3 # <jmf at liblime dot com>
5 # This file is part of Koha.
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.
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.
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
20 use XML::Simple;
21 use LWP::Simple;
22 use LWP::UserAgent;
23 use HTTP::Request::Common;
25 use strict;
27 use vars qw($VERSION @ISA @EXPORT);
29 BEGIN {
30 require Exporter;
31 $VERSION = 0.03;
32 @ISA = qw(Exporter);
33 @EXPORT = qw(
34 &get_amazon_details
35 &check_search_inside
39 =head1 NAME
41 C4::Amazon - Functions for retrieving Amazon.com content in Koha
43 =head1 FUNCTIONS
45 This module provides facilities for retrieving Amazon.com content in Koha
47 =head1 get_amazon_details($isbn);
49 =head2 $isbn is a isbn string
51 =cut
53 sub get_amazon_details {
54 my ( $isbn ) = @_;
56 #get rid of MARC cataloger's nonsense
57 $isbn =~ s/(p|-)//g;
59 # grab the developer's key: mine is 'ektostoukadou-20'
60 my $dev_key=C4::Context->preference('AmazonDevKey');
62 #grab the associates tag: mine is '0ZRY7YASKJS280T7YB02'
63 my $af_tag=C4::Context->preference('AmazonAssocTag');
65 my $asin=$isbn;
66 my $url = "http://xml.amazon.com/onca/xml3?t=$af_tag&dev-t=$dev_key&type=heavy&f=xml&AsinSearch=" . $asin;
67 my $content = get($url);
68 #warn $content;
69 warn "could not retrieve $url" unless $content;
70 my $xmlsimple = XML::Simple->new();
71 my $response = $xmlsimple->XMLin($content,
72 forcearray => [ qw(Details Product AvgCustomerRating CustomerReview) ],
74 return $response;
77 sub check_search_inside {
78 my $isbn = shift;
79 my $ua = LWP::UserAgent->new(
80 agent => "Mozilla/4.76 [en] (Win98; U)",
81 keep_alive => 1,
82 env_proxy => 1,
84 my $available = 1;
85 my $uri = "http://www.amazon.com/gp/reader/$isbn/ref=sib_dp_pt/002-7879865-0184864#reader-link";
86 my $req = HTTP::Request->new(GET => $uri);
87 $req->header (
88 'Accept' => 'image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, image/png, */*',
89 'Accept-Charset' => 'iso-8859-1,*,utf-8',
90 'Accept-Language' => 'en-US' );
91 my $res = $ua->request($req);
92 my $content = $res->content();
93 if ($content =~ m/This book is temporarily unavailable/) {
94 undef $available;
96 return $available;
100 __END__
102 =head1 NOTES
104 =head1 AUTHOR
106 Joshua Ferraro <jmf@liblime.com>
108 =cut