View | Details | Raw Unified | Return to bug 29686
Collapse All | Expand All

(-)a/Koha/ExternalContent/OverDrive.pm (+24 lines)
Lines 23-28 use Carp qw( croak ); Link Here
23
use base qw(Koha::ExternalContent);
23
use base qw(Koha::ExternalContent);
24
use WebService::ILS::OverDrive::Patron;
24
use WebService::ILS::OverDrive::Patron;
25
use C4::Context;
25
use C4::Context;
26
use LWP::UserAgent;
26
27
27
=head1 NAME
28
=head1 NAME
28
29
Lines 208-213 sub set_token_in_koha_session { Link Here
208
    );
209
    );
209
}
210
}
210
211
212
=head2 checkout_download_url($item_id)
213
214
  Input: id of the item to download
215
216
  Returns: Fulfillment URL for reidrection
217
218
=cut
219
220
sub checkout_download_url {
221
    my $self = shift;
222
    my $item_id = shift or croak "Item ID not specified";
223
224
    my $ua = LWP::UserAgent->new;
225
    $ua->max_redirect(0);
226
    my $response = $ua->get(
227
        "https://patron.api.overdrive.com/v1/patrons/me/checkouts/".$item_id."/formats/downloadredirect",
228
        'Authorization' => "Bearer ".$self->client->access_token,
229
        );
230
231
    my $redirect = { redirect => $response->{_headers}->{location} };
232
    return $redirect;
233
}
234
211
=head1 OTHER METHODS
235
=head1 OTHER METHODS
212
236
213
=head2 is_logged_in()
237
=head2 is_logged_in()
(-)a/koha-tmpl/opac-tmpl/bootstrap/js/overdrive.js (-34 / +6 lines)
Lines 291-330 KOHA.OverDriveCirculation = new function() { Link Here
291
                    .appendTo(el);
291
                    .appendTo(el);
292
                $(el).append(" ");
292
                $(el).append(" ");
293
293
294
                if (item.format) {
294
                var access = $('<a target="_blank">').appendTo(el);
295
                    var download = $('<a href="#">').appendTo(el);
295
                decorate_button(access, __("Get item") );
296
                    decorate_button(download, __("Download")  + " " + item.format);
296
                svc_ajax('get', {action: "download-url", id: id}, function(data) {
297
                    svc_ajax('get', {action: "download-url", id: id, format: item.format}, function(data) {
297
                    access.attr("href", data.action.redirect);
298
                        download.attr("href", data.action);
298
                });
299
                    });
299
                $(el).append(" ");
300
                    $(el).append(" ");
301
                }
302
303
                if (item.formats) {
304
                    var lockable_formats = [];
305
                    for (var f in item.formats) {
306
                        if (f == item.format) continue;
307
308
                        if (item.formats[f]) {
309
                            var access = $('<a target="_blank">').appendTo(el);
310
                            decorate_button(access, __("Access online") + " " + f);
311
                            svc_ajax('get', {action: "download-url", id: id, format: f}, function(data) {
312
                                access.attr("href", data.action);
313
                            });
314
                            $(el).append(" ");
315
                        }
316
                        else {
317
                            lockable_formats.push(f);
318
                        }
319
                    }
320
                    if (lockable_formats.length > 0 && checkout_popup) {
321
                        $(el).append( ajax_button( __("Download as:"), function() {
322
                            checkout_format(el, id, lockable_formats, copies_available);
323
                        }) ).append(" ");
324
                    }
325
                }
326
327
                if (item.format) return item;
328
300
329
                $(el).append( ajax_button( __("Check in"), function() {
301
                $(el).append( ajax_button( __("Check in"), function() {
330
                    if( confirm( __("Are you sure you want to return this item?") ) ) {
302
                    if( confirm( __("Are you sure you want to return this item?") ) ) {
(-)a/opac/svc/overdrive (-4 / +1 lines)
Lines 101-109 eval { Link Here
101
                $action eq 'download-url' && do {
101
                $action eq 'download-url' && do {
102
                    my $id = $cgi->param('id')
102
                    my $id = $cgi->param('id')
103
                      or response_bad_request("No 'id' specified");
103
                      or response_bad_request("No 'id' specified");
104
                    my $format = $cgi->param('format')
104
                    $data{action} = $od->checkout_download_url($id);
105
                      or response_bad_request("No 'format' specified");
106
                    $data{action} = $od->checkout_download_url($id, $format, $page_url, $page_url);
107
                    last;
105
                    last;
108
                };
106
                };
109
107
110
- 

Return to bug 29686