Line 0
Link Here
|
|
|
1 |
# Copyright 2016 Catalyst |
2 |
# |
3 |
# This file is part of Koha. |
4 |
# |
5 |
# Koha is free software; you can redistribute it and/or modify it under the |
6 |
# terms of the GNU General Public License as published by the Free Software |
7 |
# Foundation; either version 3 of the License, or (at your option) any later |
8 |
# version. |
9 |
# |
10 |
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY |
11 |
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR |
12 |
# A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
13 |
# |
14 |
# You should have received a copy of the GNU General Public License along |
15 |
# with Koha; if not, write to the Free Software Foundation, Inc., |
16 |
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
17 |
|
18 |
package Koha::ExternalContent::OneClickDigital; |
19 |
|
20 |
use Modern::Perl; |
21 |
use Carp; |
22 |
|
23 |
use base qw(Koha::ExternalContent); |
24 |
use WebService::ILS::OneClickDigital::PartnerPatron; |
25 |
use WebService::ILS::OneClickDigital::Partner; |
26 |
use C4::Context; |
27 |
use Koha::Logger; |
28 |
|
29 |
use constant logger => Koha::Logger->get(); |
30 |
|
31 |
=head1 NAME |
32 |
|
33 |
Koha::ExternalContent::OneClickDigital |
34 |
|
35 |
=head1 SYNOPSIS |
36 |
|
37 |
use Koha::ExternalContent::OneClickDigital; |
38 |
my $od_client = Koha::ExternalContent::OneClickDigital->new(); |
39 |
my $od_auth_url = $od_client->auth_url(); |
40 |
|
41 |
=head1 DESCRIPTION |
42 |
|
43 |
A (very) thin wrapper around C<WebService::ILS::OneClickDigital::Patron> |
44 |
|
45 |
Takes "OneClickDigital*" Koha preferences |
46 |
|
47 |
=cut |
48 |
|
49 |
sub new { |
50 |
my $class = shift; |
51 |
my $params = shift || {}; |
52 |
|
53 |
my $self = $class->SUPER::new($params); |
54 |
unless ($params->{client}) { |
55 |
my $client_secret = C4::Context->preference('OneClickDigitalClientSecret') |
56 |
or croak("OneClickDigitalClientSecret pref not set"); |
57 |
my $library_id = C4::Context->preference('OneClickDigitalLibraryID') |
58 |
or croak("OneClickDigitalLibraryID pref not set"); |
59 |
my $domain = C4::Context->preference('OneClickDigitalDomain'); |
60 |
my $patron = $params->{koha_session_id} ? $self->koha_patron : undef; |
61 |
my $client = $patron |
62 |
? WebService::ILS::OneClickDigital::PartnerPatron->new( |
63 |
client_secret => $client_secret, |
64 |
library_id => $library_id, |
65 |
$domain && $domain gt '' ? (domain => $domain) : (), |
66 |
user_id => $patron->email, |
67 |
user_agent_params => { agent => $class->agent_string } |
68 |
) |
69 |
: WebService::ILS::OneClickDigital::Partner->new( |
70 |
client_secret => $client_secret, |
71 |
library_id => $library_id, |
72 |
$domain && $domain gt '' ? (domain => $domain) : (), |
73 |
); |
74 |
$self->client( $client ); |
75 |
} |
76 |
return $self; |
77 |
} |
78 |
|
79 |
=head1 METHODS |
80 |
|
81 |
L<WebService::ILS::OneClickDigital::PartnerPatron> methods used without mods: |
82 |
|
83 |
=over 4 |
84 |
|
85 |
=item C<error_message()> |
86 |
|
87 |
=back |
88 |
|
89 |
=cut |
90 |
|
91 |
use vars qw{$AUTOLOAD}; |
92 |
sub AUTOLOAD { |
93 |
my $self = shift; |
94 |
(my $method = $AUTOLOAD) =~ s/.*:://; |
95 |
return $self->client->$method(@_); |
96 |
} |
97 |
sub DESTROY { } |
98 |
|
99 |
1; |