1 # Copyright 2016 Catalyst
3 # This file is part of Koha.
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
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.
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.
18 package Koha::ExternalContent::RecordedBooks;
23 use base qw(Koha::ExternalContent);
24 use WebService::ILS::RecordedBooks::PartnerPatron;
25 use WebService::ILS::RecordedBooks::Partner;
29 use constant logger => Koha::Logger->get();
31 __PACKAGE__->mk_accessors(qw(domain is_identified));
35 Koha::ExternalContent::RecordedBooks
39 use Koha::ExternalContent::RecordedBooks;
40 my $od_client = Koha::ExternalContent::RecordedBooks->new();
41 my $od_auth_url = $od_client->auth_url();
45 A (very) thin wrapper around C<WebService::ILS::RecordedBooks::Patron>
47 Takes "RecordedBooks*" Koha preferences
53 my $params = shift || {};
55 my $self = $class->SUPER::new($params);
56 unless ($params->{client}) {
57 my $client_secret = C4::Context->preference('RecordedBooksClientSecret')
58 or croak("RecordedBooksClientSecret pref not set");
59 my $library_id = C4::Context->preference('RecordedBooksLibraryID')
60 or croak("RecordedBooksLibraryID pref not set");
61 my $domain = C4::Context->preference('RecordedBooksDomain');
62 my $patron = $params->{koha_session_id} ? $self->koha_patron : undef;
65 $email = $patron->email
66 or $self->logger->warn("User with no email, cannot identify with RecordedBooks");
71 $client = eval { WebService::ILS::RecordedBooks::PartnerPatron->new(
72 client_secret => $client_secret,
73 library_id => $library_id,
77 $self->logger->warn("Invalid RecordedBooks user $email ($@)") if $@;
78 $self->is_identified($client);
80 $client ||= WebService::ILS::RecordedBooks::Partner->new(
81 client_secret => $client_secret,
82 library_id => $library_id,
85 $self->client( $client );
92 L<WebService::ILS::RecordedBooks::PartnerPatron> methods used without mods:
96 =item C<error_message()>
102 use vars qw{$AUTOLOAD};
105 (my $method = $AUTOLOAD) =~ s/.*:://;
106 return $self->client->$method(@_);