1 package C4::External::BakerTaylor;
3 # Copyright (C) 2008 LibLime
4 # <jmf at liblime dot com>
6 # This file is part of Koha.
8 # Koha is free software; you can redistribute it and/or modify it
9 # under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 3 of the License, or
11 # (at your option) any later version.
13 # Koha is distributed in the hope that it will be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with Koha; if not, see <http://www.gnu.org/licenses>.
22 use LWP::Simple qw( get );
28 use vars qw(%EXPORT_TAGS $VERSION);
29 our (@ISA, @EXPORT_OK);
34 $VERSION = 3.07.00.049;
35 @EXPORT_OK = qw(availability content_cafe_url image_url link_url http_jacket_link);
38 # These variables are plack safe: they are initialized each time
39 my ( $user, $pass, $agent, $image_url, $link_url );
42 $user = (@_ ? shift : C4::Context->preference('BakerTaylorUsername') ) || ''; # LL17984
43 $pass = (@_ ? shift : C4::Context->preference('BakerTaylorPassword') ) || ''; # CC82349
44 $link_url = (@_ ? shift : C4::Context->preference('BakerTaylorBookstoreURL'));
45 $image_url = "https://contentcafe2.btol.com/ContentCafe/Jacket.aspx?UserID=$user&Password=$pass&Options=Y&Return=T&Type=S&Value=";
46 $agent = "Koha/$VERSION [en] (Linux)";
47 #"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;
60 my $isbn = (@_ ? shift : '');
61 $isbn =~ s/(p|-)//g; # sanitize
63 return $link_url . $isbn;
66 sub content_cafe_url {
68 ($user and $pass) or return;
69 my $isbn = (@_ ? shift : '');
70 $isbn =~ s/(p|-)//g; # sanitize
71 return "https://contentcafe2.btol.com/ContentCafeClient/ContentCafe.aspx?UserID=$user&Password=$pass&Options=Y&ItemKey=$isbn";
74 sub http_jacket_link {
76 my $isbn = shift or return;
77 $isbn =~ s/(p|-)//g; # sanitize
78 my $image = availability($isbn);
79 my $alt = "Buy this book";
80 $image and $image = qq(<img class="btjacket" alt="$alt" src="$image" />);
81 my $link = &link_url($isbn);
82 unless ($link) {return $image || '';}
83 return sprintf qq(<a class="btlink" href="%s">%s</a>),$link,($image||$alt);
88 my $isbn = shift or return;
89 ($user and $pass) or return;
90 $isbn =~ s/(p|-)//g; # sanitize
91 my $url = "https://contentcafe2.btol.com/ContentCafe/InventoryAvailability.asmx/CheckInventory?UserID=$user&Password=$pass&Value=$isbn";
92 my $content = get($url);
93 warn "could not retrieve $url" unless $content;
94 my $xmlsimple = XML::Simple->new();
95 my $result = $xmlsimple->XMLin($content);
96 if ($result->{Error}) {
97 warn "Error returned to " . __PACKAGE__ . " : " . $result->{Error};
99 my $avail = $result->{Availability};
100 return ($avail and $avail !~ /^false$/i) ? &image_url($isbn) : 0;
109 C4::External::BakerTaylor
113 Functions for retrieving content from Baker and Taylor, inventory availability and "Content Cafe".
115 The settings for this module are controlled by System Preferences:
117 These can be overridden for testing purposes using the initialize function.
121 =head2 availability($isbn);
123 $isbn is a isbn string
127 A request with failed authentication might see this back from Baker + Taylor:
129 <?xml version="1.0" encoding="utf-8"?>
130 <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">
131 <Key Type="Undefined">string</Key>
132 <Availability>false</Availability>
133 <Error>Invalid UserID</Error>
134 </InventoryAvailability>
136 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.
145 atz AT liblime DOT com