Bug 24583: Rewrite mandatory/class_sources to YAML
[koha.git] / C4 / Search / PazPar2.pm
bloba1682930d0437f1b35c8853511ef4741645e88b2
1 package C4::Search::PazPar2;
3 # Copyright (C) 2007 LibLime
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
20 use Modern::Perl;
22 use LWP::UserAgent;
23 use URI;
24 use URI::QueryParam;
25 use XML::Simple;
27 =head1 NAME
29 C4::Search::PazPar2 - implement client for PazPar2
31 [Note: may rename to Net::PazPar2 or somesuch if decide to put on CPAN separate
32 from Koha]
34 =head1 SYNOPSIS
36 =cut
38 =head1 DESCRIPTION
40 =cut
42 sub new {
43 my $class = shift;
44 my $endpoint = shift;
46 my $self = {};
47 $self->{'endpoint'} = $endpoint;
48 $self->{'session'} = '';
49 $self->{'ua'} = LWP::UserAgent->new;
50 bless $self, $class;
52 return $self;
55 sub init {
56 my $self = shift;
58 my $uri = URI->new($self->{'endpoint'});
59 $uri->query_param(command => 'init');
60 my $response = $self->{'ua'}->get($uri);
61 if ($response->is_success) {
62 my $message = XMLin($response->content);
63 if ($message->{'status'} eq 'OK') {
64 $self->{'session'} = $message->{'session'};
66 } else {
67 warn $response->status_line;
71 sub search {
72 my $self = shift;
73 my $query = shift;
75 my $uri = URI->new($self->{'endpoint'});
76 $uri->query_param(command => 'search');
77 $uri->query_param(session => $self->{'session'});
78 $uri->query_param(query => $query);
79 my $response = $self->{'ua'}->get($uri);
80 if ($response->is_success) {
81 #print $response->content, "\n";
82 } else {
83 warn $response->status_line;
88 sub stat {
89 my $self = shift;
91 my $uri = URI->new($self->{'endpoint'});
92 $uri->query_param(command => 'stat');
93 $uri->query_param(session => $self->{'session'});
94 my $response = $self->{'ua'}->get($uri);
95 if ($response->is_success) {
96 return $response->content;
97 } else {
98 warn $response->status_line;
99 return;
103 sub show {
104 my $self = shift;
105 my $start = shift;
106 my $count = shift;
107 my $sort = shift;
109 my $uri = URI->new($self->{'endpoint'});
110 $uri->query_param(command => 'show');
111 $uri->query_param(start => $start);
112 $uri->query_param(num => $count);
113 $uri->query_param(block => 1);
114 $uri->query_param(session => $self->{'session'});
115 $uri->query_param(sort => $sort);
116 my $response = $self->{'ua'}->get($uri);
117 if ($response->is_success) {
118 return $response->content;
119 } else {
120 warn $response->status_line;
121 return;
126 sub record {
127 my $self = shift;
128 my $id = shift;
129 my $offset = shift;
131 my $uri = URI->new($self->{'endpoint'});
132 $uri->query_param(command => 'record');
133 $uri->query_param(id => $id);
134 $uri->query_param(offset => $offset);
135 $uri->query_param(binary => 1);
136 $uri->query_param(session => $self->{'session'});
137 my $response = $self->{'ua'}->get($uri);
138 if ($response->is_success) {
139 return $response->content;
140 } else {
141 warn $response->status_line;
142 return;
146 sub termlist {
147 my $self = shift;
148 my $name = shift;
150 my $uri = URI->new($self->{'endpoint'});
151 $uri->query_param(command => 'termlist');
152 $uri->query_param(name => $name);
153 $uri->query_param(session => $self->{'session'});
154 my $response = $self->{'ua'}->get($uri);
155 if ($response->is_success) {
156 return $response->content;
157 } else {
158 warn $response->status_line;
159 return;
166 =head1 AUTHOR
168 Koha Development Team <http://koha-community.org/>
170 Galen Charlton <galen.charlton@liblime.com>
172 =cut