Bug 29686: Adapt Koha to use new fulfillment API for OverDrive

This patch modifies the checkout_download_url routine in
WebSerivce::ILS::OverDrive::Patron

We now directly hit the fulfillment endpoint with redirects disabled
and fetch the URL

The overdrive.js is modified to use a single 'Get item' button for all
checked out items and to refer to the fulfillment page

To test:
1 - Enable all OverDrive system preferences
2 - Search on opac and confirm OD results returned
3 - Checkout an item
4 - Confirm you have the new 'Get item' button on 'OverDrive account'
    tab on opac-user.pl
5 - Confirm the 'Get item' button works

NOTE:
Most items will also show the 'Get item' button in results, however,
magazines may not as each checkout has a unique 'reserve id' and the
'parent' id is not checked in our current code

Signed-off-by: Andrew Fuerste-Henry <andrew@bywatersolutions.com>

Signed-off-by: Owen Leonard <oleonard@myacpl.org>

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
This commit is contained in:
Nick Clemens 2021-12-13 13:08:28 +00:00 committed by Fridolin Somers
parent 50bb0f6e42
commit 46d3d63e46
3 changed files with 31 additions and 37 deletions

View File

@ -23,6 +23,7 @@ use Carp qw( croak );
use base qw(Koha::ExternalContent);
use WebService::ILS::OverDrive::Patron;
use C4::Context;
use LWP::UserAgent;
=head1 NAME
@ -208,6 +209,29 @@ sub set_token_in_koha_session {
);
}
=head2 checkout_download_url($item_id)
Input: id of the item to download
Returns: Fulfillment URL for reidrection
=cut
sub checkout_download_url {
my $self = shift;
my $item_id = shift or croak "Item ID not specified";
my $ua = LWP::UserAgent->new;
$ua->max_redirect(0);
my $response = $ua->get(
"https://patron.api.overdrive.com/v1/patrons/me/checkouts/".$item_id."/formats/downloadredirect",
'Authorization' => "Bearer ".$self->client->access_token,
);
my $redirect = { redirect => $response->{_headers}->{location} };
return $redirect;
}
=head1 OTHER METHODS
=head2 is_logged_in()

View File

@ -291,40 +291,12 @@ KOHA.OverDriveCirculation = new function() {
.appendTo(el);
$(el).append(" ");
if (item.format) {
var download = $('<a href="#">').appendTo(el);
decorate_button(download, __("Download") + " " + item.format);
svc_ajax('get', {action: "download-url", id: id, format: item.format}, function(data) {
download.attr("href", data.action);
});
$(el).append(" ");
}
if (item.formats) {
var lockable_formats = [];
for (var f in item.formats) {
if (f == item.format) continue;
if (item.formats[f]) {
var access = $('<a target="_blank">').appendTo(el);
decorate_button(access, __("Access online") + " " + f);
svc_ajax('get', {action: "download-url", id: id, format: f}, function(data) {
access.attr("href", data.action);
});
$(el).append(" ");
}
else {
lockable_formats.push(f);
}
}
if (lockable_formats.length > 0 && checkout_popup) {
$(el).append( ajax_button( __("Download as:"), function() {
checkout_format(el, id, lockable_formats, copies_available);
}) ).append(" ");
}
}
if (item.format) return item;
var access = $('<a target="_blank">').appendTo(el);
decorate_button(access, __("Get item") );
svc_ajax('get', {action: "download-url", id: id}, function(data) {
access.attr("href", data.action.redirect);
});
$(el).append(" ");
$(el).append( ajax_button( __("Check in"), function() {
if( confirm( __("Are you sure you want to return this item?") ) ) {

View File

@ -101,9 +101,7 @@ eval {
$action eq 'download-url' && do {
my $id = $cgi->param('id')
or response_bad_request("No 'id' specified");
my $format = $cgi->param('format')
or response_bad_request("No 'format' specified");
$data{action} = $od->checkout_download_url($id, $format, $page_url, $page_url);
$data{action} = $od->checkout_download_url($id);
last;
};