1 package C4::External::BakerTaylor;
2 # Copyright (C) 2008 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
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
23 use HTTP::Request::Common;
30 use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $VERSION);
31 use vars qw($user $pass $agent $image_url $link_url);
37 $VERSION = 3.07.00.049;
38 @EXPORT_OK = qw(&availability &content_cafe &image_url &link_url &http_jacket_link);
39 %EXPORT_TAGS = (all=>\@EXPORT_OK);
43 $user = (@_ ? shift : C4::Context->preference('BakerTaylorUsername') ) || ''; # LL17984
44 $pass = (@_ ? shift : C4::Context->preference('BakerTaylorPassword') ) || ''; # CC82349
45 $link_url = (@_ ? shift : C4::Context->preference('BakerTaylorBookstoreURL'));
46 $image_url = "http://contentcafe2.btol.com/ContentCafe/Jacket.aspx?UserID=$user&Password=$pass&Options=Y&Return=T&Type=S&Value=";
47 $agent = "Koha/$VERSION [en] (Linux)";
48 #"Mozilla/4.76 [en] (Win98; U)", # if for some reason you want to go stealth, you might prefer this
52 ($user and $pass) or return;
53 my $isbn = (@_ ? shift : '');
54 $isbn =~ s/(p|-)//g; # sanitize
55 return $image_url . $isbn;
58 my $isbn = (@_ ? shift : '');
59 $isbn =~ s/(p|-)//g; # sanitize
61 return $link_url . $isbn;
63 sub content_cafe_url {
64 ($user and $pass) or return;
65 my $isbn = (@_ ? shift : '');
66 $isbn =~ s/(p|-)//g; # sanitize
67 return "http://contentcafe2.btol.com/ContentCafeClient/ContentCafe.aspx?UserID=$user&Password=$pass&Options=Y&ItemKey=$isbn";
69 sub http_jacket_link {
70 my $isbn = shift or return;
71 $isbn =~ s/(p|-)//g; # sanitize
72 my $image = availability($isbn);
73 my $alt = "Buy this book";
74 $image and $image = qq(<img class="btjacket" alt="$alt" src="$image" />);
75 my $link = &link_url($isbn);
76 unless ($link) {return $image || '';}
77 return sprintf qq(<a class="btlink" href="%s">%s</a>),$link,($image||$alt);
81 my $isbn = shift or return;
82 ($user and $pass) or return;
83 $isbn =~ s/(p|-)//g; # sanitize
84 my $url = "http://contentcafe2.btol.com/ContentCafe/InventoryAvailability.asmx/CheckInventory?UserID=$user&Password=$pass&Value=$isbn";
85 $debug and warn __PACKAGE__ . " request:\n$url\n";
86 my $content = get($url);
87 $debug and print STDERR $content, "\n";
88 warn "could not retrieve $url" unless $content;
89 my $xmlsimple = XML::Simple->new();
90 my $result = $xmlsimple->XMLin($content);
91 if ($result->{Error}) {
92 warn "Error returned to " . __PACKAGE__ . " : " . $result->{Error};
94 my $avail = $result->{Availability};
95 return ($avail and $avail !~ /^false$/i) ? &image_url($isbn) : 0;
104 C4::External::BakerTaylor
108 Functions for retrieving content from Baker and Taylor, inventory availability and "Content Cafe".
110 The settings for this module are controlled by System Preferences:
112 These can be overridden for testing purposes using the initialize function.
116 =head2 availability($isbn);
118 $isbn is a isbn string
122 A request with failed authentication might see this back from Baker + Taylor:
124 <?xml version="1.0" encoding="utf-8"?>
125 <InventoryAvailability xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" DateTime="2008-03-07T22:01:25.6520429-05:00" xmlns="http://ContentCafe2.btol.com">
126 <Key Type="Undefined">string</Key>
127 <Availability>false</Availability>
128 <Error>Invalid UserID</Error>
129 </InventoryAvailability>
131 Such response will trigger a warning for each request (potentially many). Point being, do not leave this module configured with incorrect username and password in production.
140 atz AT liblime DOT com