]> git.evergreen-ils.org Git - working/NCIPServer.git/blob - lib/NCIP/ILS.pm
Add lookupversion implemenation to NCIP::ILS.
[working/NCIPServer.git] / lib / NCIP / ILS.pm
1 # ---------------------------------------------------------------
2 # Copyright © 2014 Jason J.A. Stephenson <jason@sigio.com>
3 #
4 # This file is part of NCIPServer.
5 #
6 # NCIPServer is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
10 #
11 # NCIPServer is distributed in the hope that it will be useful, but
12 # WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 # General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with NCIPServer.  If not, see <http://www.gnu.org/licenses/>.
18 # ---------------------------------------------------------------
19 package NCIP::ILS;
20
21 use Modern::Perl;
22 use NCIP::Const;
23 use NCIP::Header;
24 use NCIP::Response;
25
26 sub new {
27     my $invocant = shift;
28     my $class = ref $invocant || $invocant;
29     my $self = bless {@_}, $class;
30     return $self;
31 }
32
33 # Methods required for SHAREit:
34
35 sub acceptitem {
36 }
37
38 sub cancelrequestitem {
39 }
40
41 sub checkinitem {
42 }
43
44 sub checkoutitem {
45 }
46
47 sub lookupuser {
48 }
49
50 sub renewitem {
51 }
52
53 sub requestitem {
54 }
55
56 # Other methods, just because.
57
58 # Handle a LookupVersion Request.  You probably want to just call this
59 # one from your subclasses rather than reimplement it.
60 sub lookupversion {
61     my $self = shift;
62     my $request = shift;
63
64     my $response = NCIP::Response->new({type => "LookupVersionResponse"});
65     $response->header($self->make_header($request));
66     my $payload = {
67         versions => [ NCIP::Const::SUPPORTED_VERSIONS ]
68     };
69     $response->data($payload);
70
71     return $response;
72 }
73
74 # A few helper methods:
75
76 # All subclasses will possibly want to create a ResponseHeader and the
77 # code for that would be highly redundant.  We supply a default
78 # implementation here that can retrieve the agency information from
79 # the InitiationHeader of the message, swap their values, and return a
80 # NCIP::Header.
81 sub make_header {
82     my $self = shift;
83     my $request = shift;
84
85     my $initheader;
86     my $header;
87
88     for my $key (keys %$request) {
89         if ($request->{$key}->{InitiationHeader}) {
90             $initheader = $request->{$key}->{InitiationHeader};
91             last;
92         }
93     }
94
95     if ($initheader && $initheader->{FromAgencyId}
96             && $initheader->{ToAgencyId}) {
97         $header = NCIP::Header->new(
98             FromAgencyId => $initheader->{ToAgencyId},
99             ToAgencyId => $initheader->{FromAgencyId}
100         );
101     }
102
103     return $header;
104 }
105
106 1;