Koha/Koha/ExternalContent/RecordedBooks.pm
Tomas Cohen Arazi 05705ab2ad
Bug 25527: Add logger to Koha::ExternalContent
This patch makes Koha::Logger initialization happen in the ->new method
for the Koha::ExternalContent-derived classes. In the case of RecordedBooks,
it doesn't look like it is used at all.

In the case of OverDrive, it will now use the Koha::ExternalContent
exported logger accessor.

I added tests for this addition to Koha::ExternalContent to the
OverDrive tests.

I also removed references to Test::DBIx::Class as it is not used at all.

To test:
1. Apply this patch
2. Run:
   $ kshell
  k$ prove t/db_dependent/Koha_ExternalContent_OverDrive.t
=> SUCCESS: Tests pass!

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Victor Grousset/tuxayo <victor@tuxayo.net>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
2020-05-18 15:25:03 +01:00

119 lines
3.2 KiB
Perl

# Copyright 2016 Catalyst
#
# This file is part of Koha.
#
# Koha is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# Koha is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Koha; if not, see <http://www.gnu.org/licenses>.
package Koha::ExternalContent::RecordedBooks;
use Modern::Perl;
use Carp;
use base qw(Koha::ExternalContent);
use WebService::ILS::RecordedBooks::PartnerPatron;
use WebService::ILS::RecordedBooks::Partner;
use C4::Context;
__PACKAGE__->mk_accessors(qw(domain is_identified));
=head1 NAME
Koha::ExternalContent::RecordedBooks
=head1 SYNOPSIS
use Koha::ExternalContent::RecordedBooks;
my $rb_client = Koha::ExternalContent::RecordedBooks->new();
my $rb_auth_url = $od_client->auth_url();
=head1 DESCRIPTION
A (very) thin wrapper around C<WebService::ILS::RecordedBooks::Patron>
Takes "RecordedBooks*" Koha preferences
=cut
=head2 Class Methods
=cut
=head3 new
my $rb_client = Koha::ExternalContent::RecordedBooks->new();
Create the object for interacting with RecordedBooks
=cut
sub new {
my $class = shift;
my $params = shift || {};
my $self = $class->SUPER::new($params);
unless ($params->{client}) {
my $client_secret = C4::Context->preference('RecordedBooksClientSecret')
or croak("RecordedBooksClientSecret pref not set");
my $library_id = C4::Context->preference('RecordedBooksLibraryID')
or croak("RecordedBooksLibraryID pref not set");
my $domain = C4::Context->preference('RecordedBooksDomain');
my $patron = $params->{koha_session_id} ? $self->koha_patron : undef;
my $email;
if ($patron) {
$email = $patron->email
or $self->logger->warn("User with no email, cannot identify with RecordedBooks");
}
my $client;
if ($email) {
local $@;
$client = eval { WebService::ILS::RecordedBooks::PartnerPatron->new(
client_secret => $client_secret,
library_id => $library_id,
domain => $domain,
user_id => $email,
) };
$self->logger->warn("Invalid RecordedBooks user $email ($@)") if $@;
$self->is_identified($client);
}
$client ||= WebService::ILS::RecordedBooks::Partner->new(
client_secret => $client_secret,
library_id => $library_id,
domain => $domain,
);
$self->client( $client );
}
return $self;
}
=head1 METHODS
L<WebService::ILS::RecordedBooks::PartnerPatron> methods used without mods:
=over 4
=item C<error_message()>
=back
=cut
use vars qw{$AUTOLOAD};
sub AUTOLOAD {
my $self = shift;
(my $method = $AUTOLOAD) =~ s/.*:://;
return $self->client->$method(@_);
}
sub DESTROY { }
1;