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

(-)a/C4/Installer/PerlDependencies.pm (-1 / +1 lines)
Lines 860-866 our $PERL_DEPS = { Link Here
860
    'WebService::ILS' => {
860
    'WebService::ILS' => {
861
        'usage'    => 'Interface third party systems',
861
        'usage'    => 'Interface third party systems',
862
        'required' => '0',
862
        'required' => '0',
863
        'min_ver'  => '0.07',
863
        'min_ver'  => '0.08',
864
    },
864
    },
865
};
865
};
866
866
(-)a/Koha/ExternalContent/OneClickDigital.pm (+90 lines)
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 C4::Context;
26
use Koha::Logger;
27
28
use constant logger => Koha::Logger->get();
29
30
=head1 NAME
31
32
Koha::ExternalContent::OneClickDigital
33
34
=head1 SYNOPSIS
35
36
    use Koha::ExternalContent::OneClickDigital;
37
    my $od_client = Koha::ExternalContent::OneClickDigital->new();
38
    my $od_auth_url = $od_client->auth_url();
39
40
=head1 DESCRIPTION
41
42
A (very) thin wrapper around C<WebService::ILS::OneClickDigital::Patron>
43
44
Takes "OneClickDigital*" Koha preferences
45
46
=cut
47
48
sub new {
49
    my $class  = shift;
50
    my $params = shift || {};
51
    $params->{koha_session_id} or croak "No koha_session_id";
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 $patron = $self->koha_patron;
60
        $self->client( WebService::ILS::OneClickDigital::PartnerPatron->new(
61
            client_secret     => $client_secret,
62
            library_id        => $library_id,
63
            user_id           => $patron->email,
64
            user_agent_params => { agent => $class->agent_string }
65
        ) );
66
    }
67
    return $self;
68
}
69
70
=head1 METHODS
71
72
L<WebService::ILS::OneClickDigital::PartnerPatron> methods used without mods:
73
74
=over 4
75
76
=item C<error_message()>
77
78
=back
79
80
=cut
81
82
use vars qw{$AUTOLOAD};
83
sub AUTOLOAD {
84
    my $self = shift;
85
    (my $method = $AUTOLOAD) =~ s/.*:://;
86
    return $self->client->$method(@_);
87
}
88
sub DESTROY { }
89
90
1;
(-)a/t/db_dependent/Koha_ExternalContent_OneClickDigital.t (-1 / +57 lines)
Line 0 Link Here
0
- 
1
use Modern::Perl;
2
3
use t::lib::Mocks;
4
use t::lib::TestBuilder;
5
use Test::More tests => 3;                      # last test to print
6
use C4::Context;
7
use C4::Auth;
8
use Koha::Patron::Categories;
9
10
my $dbh = C4::Context->dbh;
11
# Start transaction
12
$dbh->{AutoCommit} = 0;
13
$dbh->begin_work;
14
die;
15
16
local $@;
17
eval { require WebService::ILS::OneClickDigital::PartnerPatron; }
18
  or diag($@);
19
SKIP: {
20
    skip "cannot filnd WebService::ILS::OneClickDigital::PartnerPatron", 3 if $@;
21
22
    use_ok('Koha::ExternalContent::OneClickDigital');
23
24
    my $ocd_user_email = $ENV{ONECLICKDIGITAL_TEST_USER_EMAIL};
25
    SKIP: {
26
        skip "Env ONECLICKDIGITAL_TEST_USER_EMAIL not set", 2 unless $ocd_user_email;
27
28
        my $ocd_secret = $ENV{ONECLICKDIGITAL_TEST_CLIENT_SECRET}
29
          || C4::Context->preference('OneClickDigitalClientSecret');
30
        my $ocd_library_id = $ENV{ONECLICKDIGITAL_TEST_LIBRARY_ID}
31
          || C4::Context->preference('OneClickDigitalLibraryID');
32
        skip "Env ONECLICKDIGITAL_TEST_CLIENT_SECRET ONECLICKDIGITAL_TEST_LIBRARY_ID not set", 2 unless $ocd_secret && $ocd_library_id;
33
34
        my $builder = t::lib::TestBuilder->new();
35
36
        t::lib::Mocks::mock_preference('OneClickDigitalClientSecret', $ocd_secret);
37
        t::lib::Mocks::mock_preference('OneClickDigitalLibraryID', $ocd_library_id);
38
39
        my $patron = $builder->build({
40
            source => 'Borrower',
41
            value => {
42
                email => $ocd_user_email,
43
            }
44
        });
45
46
        my $session = C4::Auth::get_session("");
47
        $session->param('number', $patron->{borrowernumber});
48
        $session->flush;
49
        my $client = Koha::ExternalContent::OneClickDigital->new({koha_session_id => $session->id});
50
51
        my $user_agent_string = $client->user_agent->agent();
52
        ok ($user_agent_string =~ m/^Koha/, 'User Agent string is set')
53
          or diag("User Agent string: $user_agent_string");
54
55
        ok ($client->search({query => "school"}), 'search()');
56
    }
57
}

Return to bug 17602