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 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
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
23 use HTTP::Request::Common;
30 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
31 use vars qw($user $pass $agent $image_url $link_url);
37 @EXPORT_OK = qw(&availability &content_cafe &image_url &link_url &http_jacket_link);
38 %EXPORT_TAGS = (all=>\@EXPORT_OK);
45 $user = (@_ ? shift : C4::Context->preference('BakerTaylorUsername') ) || ''; # LL17984
46 $pass = (@_ ? shift : C4::Context->preference('BakerTaylorPassword') ) || ''; # CC82349
47 $link_url = (@_ ? shift : C4::Context->preference('BakerTaylorBookstoreURL'));
48 # https://ocls.mylibrarybookstore.com/MLB/actions/searchHandler.do?nextPage=bookDetails&parentNum=10923&key=
49 $image_url = "http://contentcafe2.btol.com/buynow/Jacket.aspx?UserID=$user&Password=$pass&Product=";
50 $agent = "Koha/$VERSION [en] (Linux)";
51 #"Mozilla/4.76 [en] (Win98; U)", # if for some reason you want to go stealth, you might prefer this
55 ($user and $pass) or return undef;
56 my $isbn = (@_ ? shift : '');
57 $isbn =~ s/(p|-)//g; # sanitize
58 return $image_url . $isbn;
61 my $isbn = (@_ ? shift : '');
62 $isbn =~ s/(p|-)//g; # sanitize
63 $link_url or return undef;
64 return $link_url . $isbn;
66 sub content_cafe_url ($) {
67 ($user and $pass) or return undef;
68 my $isbn = (@_ ? shift : '');
69 $isbn =~ s/(p|-)//g; # sanitize
70 return "http://contentcafe2.btol.com/ContentCafeClient/ContentCafe.aspx?UserID=$user&Password=$pass&Options=Y&ItemKey=$isbn";
72 sub http_jacket_link ($) {
73 my $isbn = shift or return undef;
74 $isbn =~ s/(p|-)//g; # sanitize
75 my $image = availability($isbn);
76 my $alt = "Buy this book";
77 $image and $image = qq(<img class="btjacket" alt="$alt" src="$image" />);
78 my $link = &link_url($isbn);
79 unless ($link) {return $image || '';}
80 return sprintf qq(<a class="btlink" href="%s">%s</a>),$link,($image||$alt);
83 sub availability ($) {
84 my $isbn = shift or return undef;
85 ($user and $pass) or return undef;
86 $isbn =~ s/(p|-)//g; # sanitize
87 my $url = "http://contentcafe2.btol.com/ContentCafe/InventoryAvailability.asmx/CheckInventory?UserID=$user&Password=$pass&Value=$isbn";
88 $debug and warn __PACKAGE__ . " request:\n$url\n";
89 my $content = get($url);
90 $debug and print STDERR $content, "\n";
91 warn "could not retrieve $url" unless $content;
92 my $xmlsimple = XML::Simple->new();
93 my $result = $xmlsimple->XMLin($content);
94 if ($result->{Error}) {
95 warn "Error returned to " . __PACKAGE__ . " : " . $result->{Error};
97 my $avail = $result->{Availability};
98 return ($avail and $avail !~ /^false$/i) ? &image_url($isbn) : 0;
107 C4::External::BakerTaylor - Functions for retrieving content from Baker and Taylor, inventory availability and "Content Cafe".
108 The settings for this module are controlled by System Preferences:
110 These can be overridden for testing purposes using the initialize function.
114 =head1 availability($isbn);
116 =head2 $isbn is a isbn string
120 A request with failed authentication might see this back from Baker + Taylor:
122 <?xml version="1.0" encoding="utf-8"?>
123 <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">
124 <Key Type="Undefined">string</Key>
125 <Availability>false</Availability>
126 <Error>Invalid UserID</Error>
127 </InventoryAvailability>
129 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.
139 atz AT liblime DOT com