@@ -, +, @@ OverDrive tab on opac-user.pl --- 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(-) --- a/Koha/ExternalContent/OverDrive.pm +++ a/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() --- a/koha-tmpl/opac-tmpl/bootstrap/js/overdrive.js +++ a/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 = $('').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 = $('').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 = $('').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?") ) ) { --- a/opac/svc/overdrive +++ a/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; }; --