Bugzilla – Attachment 128628 Details for
Bug 29686
Adapt OverDrive for new fulfillment API
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 29686: Adapt Koha to use new fulfillment API for OverDrive
Bug-29686-Adapt-Koha-to-use-new-fulfillment-API-fo.patch (text/plain), 5.58 KB, created by
Owen Leonard
on 2021-12-16 15:13:57 UTC
(
hide
)
Description:
Bug 29686: Adapt Koha to use new fulfillment API for OverDrive
Filename:
MIME Type:
Creator:
Owen Leonard
Created:
2021-12-16 15:13:57 UTC
Size:
5.58 KB
patch
obsolete
>From 0f5e015b94029a879610a43913c0c3a78aa901a6 Mon Sep 17 00:00:00 2001 >From: Nick Clemens <nick@bywatersolutions.com> >Date: Mon, 13 Dec 2021 13:08:28 +0000 >Subject: [PATCH] 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> >--- > Koha/ExternalContent/OverDrive.pm | 24 +++++++++++ > koha-tmpl/opac-tmpl/bootstrap/js/overdrive.js | 40 +++---------------- > opac/svc/overdrive | 4 +- > 3 files changed, 31 insertions(+), 37 deletions(-) > >diff --git a/Koha/ExternalContent/OverDrive.pm b/Koha/ExternalContent/OverDrive.pm >index 6247dfee6e..6c6ccf1ae8 100644 >--- a/Koha/ExternalContent/OverDrive.pm >+++ b/Koha/ExternalContent/OverDrive.pm >@@ -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() >diff --git a/koha-tmpl/opac-tmpl/bootstrap/js/overdrive.js b/koha-tmpl/opac-tmpl/bootstrap/js/overdrive.js >index f71fd13fae..0d95baf27d 100644 >--- a/koha-tmpl/opac-tmpl/bootstrap/js/overdrive.js >+++ b/koha-tmpl/opac-tmpl/bootstrap/js/overdrive.js >@@ -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?") ) ) { >diff --git a/opac/svc/overdrive b/opac/svc/overdrive >index 8945fc386d..3266e5765d 100755 >--- a/opac/svc/overdrive >+++ b/opac/svc/overdrive >@@ -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; > }; > >-- >2.20.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 29686
:
128457
|
128481
|
128514
|
128628
|
129233