1 package Koha
::Illrequest
::Availability
;
3 # Copyright 2019 PTFS Europe Ltd
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>.
23 use MIME
::Base64
qw( encode_base64 );
24 use URI
::Escape
qw( uri_escape );
25 use Encode
qw( encode );
31 Koha::Illrequest::Availability - Koha ILL Availability Searching
35 Object-oriented class that provides availability searching via
40 This class provides the ability to identify and fetch API services
41 that can be used to search for item availability
49 my $availability = Koha::Illrequest::Logger->new($metadata);
51 Create a new Koha::Illrequest::Availability object.
52 We also store the metadata to be used for searching
57 my ( $class, $metadata ) = @_;
60 $self->{metadata
} = $metadata;
69 my $services = Koha::Illrequest::Availability->get_services($params);
71 Given our metadata, iterate plugins with the right method and
72 check if they can service our request and, if so, return an arrayref
73 of services. Optionally accept a hashref specifying additional filter
79 my ( $self, $params ) = @_;
82 method
=> 'ill_availability_services'
85 if ($params->{metadata
}) {
86 $plugin_filter->{metadata
} = $params->{metadata
};
89 my @candidates = Koha
::Plugins
->new()->GetPlugins($plugin_filter);
91 foreach my $plugin(@candidates) {
92 my $valid_service = $plugin->ill_availability_services({
93 metadata
=> $self->{metadata
},
94 ui_context
=> $params->{ui_context
}
96 push @services, $valid_service if $valid_service;
104 my $prepared = Koha::Illrequest::Availability->prep_metadata($metadata);
106 Given our metadata, return a string representing that metadata that can be
107 passed in a URL (encoded in JSON then Base64 encoded)
112 my ( $self, $metadata ) = @_;
114 # We sort the metadata hashref by key before encoding it, primarily
115 # so this function returns something predictable that we can test!
116 my $json = JSON
->new;
117 $json->canonical([1]);
118 return uri_escape
(encode_base64
(encode
('utf-8',$json->encode($metadata))));
123 Andrew Isherwood <andrew.isherwood@ptfs-europe.com>