File Coverage

File:C4/Search/PazPar2.pm
Coverage:87.2%

linestmtbrancondsubtimecode
1package C4::Search::PazPar2;
2
3# Copyright (C) 2007 LibLime
4#
5# This file is part of Koha.
6#
7# Koha is free software; you can redistribute it and/or modify it under the
8# terms of the GNU General Public License as published by the Free Software
9# Foundation; either version 2 of the License, or (at your option) any later
10# version.
11#
12# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License along
17# with Koha; if not, write to the Free Software Foundation, Inc.,
18# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
6
6
6
17672
107
256
use strict;
21#use warnings; FIXME - Bug 2505
22
23
6
6
6
59915
411982
345
use LWP::UserAgent;
24
6
6
6
137
95
256
use URI;
25
6
6
6
17806
5031
245
use URI::QueryParam;
26
6
6
6
235
10579
168
use XML::Simple;
27
28 - 37
=head1 NAME

C4::Search::PazPar2 - implement client for PazPar2

[Note: may rename to Net::PazPar2 or somesuch if decide to put on CPAN separate
 from Koha]

=head1 SYNOPSIS

=cut
38
39 - 41
=head1 DESCRIPTION

=cut
42
43sub new {
44
1
223516
    my $class = shift;
45
1
25
    my $endpoint = shift;
46
47
1
23
    my $self = {};
48
1
33
    $self->{'endpoint'} = $endpoint;
49
1
24
    $self->{'session'} = '';
50
1
31
    $self->{'ua'} = LWP::UserAgent->new;
51
1
2654
    bless $self, $class;
52
53
1
28
    return $self;
54}
55
56sub init {
57
1
741
    my $self = shift;
58
59
1
24
    my $uri = URI->new($self->{'endpoint'});
60
1
25811
    $uri->query_param(command => 'init');
61
1
162
    my $response = $self->{'ua'}->get($uri);
62
1
4639
    if ($response->is_success) {
63
0
0
        my $message = XMLin($response->content);
64
0
0
        if ($message->{'status'} eq 'OK') {
65
0
0
            $self->{'session'} = $message->{'session'};
66        }
67    } else {
68
1
23
        warn $response->status_line;
69    }
70}
71
72sub search {
73
1
1168
    my $self = shift;
74
1
15
    my $query = shift;
75
76
1
9
    my $uri = URI->new($self->{'endpoint'});
77
1
51
    $uri->query_param(command => 'search');
78
1
120
    $uri->query_param(session => $self->{'session'});
79
1
176
    $uri->query_param(query => $query);
80
1
175
    my $response = $self->{'ua'}->get($uri);
81
1
699
    if ($response->is_success) {
82        #print $response->content, "\n";
83    } else {
84
1
19
        warn $response->status_line;
85    }
86
87}
88
89sub stat {
90
1
788
    my $self = shift;
91
92
1
8
    my $uri = URI->new($self->{'endpoint'});
93
1
43
    $uri->query_param(command => 'stat');
94
1
108
    $uri->query_param(session => $self->{'session'});
95
1
143
    my $response = $self->{'ua'}->get($uri);
96
1
485
    if ($response->is_success) {
97
0
0
        return $response->content;
98    } else {
99
1
21
        warn $response->status_line;
100
1
110
        return;
101    }
102}
103
104sub show {
105
1
2
    my $self = shift;
106
1
1
    my $start = shift;
107
1
2
    my $count = shift;
108
1
1
    my $sort = shift;
109
110
1
7
    my $uri = URI->new($self->{'endpoint'});
111
1
45
    $uri->query_param(command => 'show');
112
1
126
    $uri->query_param(start => $start);
113
1
137
    $uri->query_param(num => $count);
114
1
169
    $uri->query_param(block => 1);
115
1
205
    $uri->query_param(session => $self->{'session'});
116
1
239
    $uri->query_param(sort => $sort);
117
1
564
    my $response = $self->{'ua'}->get($uri);
118
1
540
    if ($response->is_success) {
119
0
0
        return $response->content;
120    } else {
121
1
19
        warn $response->status_line;
122
1
96
        return;
123    }
124
125}
126
127sub record {
128
1
2
    my $self = shift;
129
1
2
    my $id = shift;
130
1
1
    my $offset = shift;
131
132
1
9
    my $uri = URI->new($self->{'endpoint'});
133
1
48
    $uri->query_param(command => 'record');
134
1
111
    $uri->query_param(id => $id);
135
1
598
    $uri->query_param(offset => $offset);
136
1
176
    $uri->query_param(binary => 1);
137
1
439
    $uri->query_param(session => $self->{'session'});
138
1
263
    my $response = $self->{'ua'}->get($uri);
139
1
577
    if ($response->is_success) {
140
0
0
        return $response->content;
141    } else {
142
1
20
        warn $response->status_line;
143
1
235
        return;
144    }
145}
146
147sub termlist {
148
1
2
    my $self = shift;
149
1
2
    my $name = shift;
150
151
1
8
    my $uri = URI->new($self->{'endpoint'});
152
1
51
    $uri->query_param(command => 'termlist');
153
1
115
    $uri->query_param(name => $name);
154
1
140
    $uri->query_param(session => $self->{'session'});
155
1
173
    my $response = $self->{'ua'}->get($uri);
156
1
498
    if ($response->is_success) {
157
0
0
        return $response->content;
158    } else {
159
1
538
        warn $response->status_line;
160
1
95
        return;
161    }
162
163}
164
1651;
166
167 - 173
=head1 AUTHOR

Koha Development Team <http://koha-community.org/>

Galen Charlton <galen.charlton@liblime.com>

=cut