File: Library.pm

package info (click to toggle)
libwebservice-ils-perl 0.18-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 348 kB
  • sloc: perl: 2,645; makefile: 2; sh: 2
file content (93 lines) | stat: -rw-r--r-- 1,811 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package WebService::ILS::OverDrive::Library;

use Modern::Perl;

=encoding utf-8

=head1 NAME

WebService::ILS::OverDrive::Library - WebService::ILS module for OverDrive
discovery only services

=head1 SYNOPSIS

    use WebService::ILS::OverDrive::Library;

=head1 DESCRIPTION

See L<WebService::ILS::OverDrive>

=cut

use Carp;
use HTTP::Request::Common;

use parent qw(WebService::ILS::OverDrive);

__PACKAGE__->_set_param_spec({
    library_id        => { required => 1, defined => 1 },
});

sub make_access_token_request {
    my $self = shift;

    return HTTP::Request::Common::POST( 'https://oauth.overdrive.com/token', {
        grant_type => 'client_credentials'
    } );
}

sub collection_token {
    my $self = shift;

    if (my $collection_token = $self->SUPER::collection_token) {
        return $collection_token;
    }
    
    $self->native_library_account;
    my $collection_token = $self->SUPER::collection_token
      or die "Library has no collections\n";
    return $collection_token;
}

=head1 NATIVE METHODS

=head2 native_library_account ()

See L<https://developer.overdrive.com/apis/library-account>

=cut

sub native_library_account {
    my $self = shift;

    my $library = $self->get_response($self->library_url);
    if (my $collection_token = $library->{collectionToken}) {
        $self->SUPER::collection_token( $collection_token);
    }
    return $library;
}

# Discovery helpers

sub library_url {
    my $self = shift;
    return $self->discovery_action_url("/libraries/".$self->library_id);
}

1;

__END__

=head1 LICENSE

Copyright (C) Catalyst IT NZ Ltd
Copyright (C) Bywater Solutions

This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.

=head1 AUTHOR

Srdjan Janković E<lt>srdjan@catalyst.net.nzE<gt>

=cut