1 package Koha::SharedContent;
3 # Copyright 2016 BibLibre Morgane Alonso
5 # This file is part of Koha.
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 3 of the License, or (at your option) any later
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.
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.
25 our $MANA_IP = "http://10.25.159.107:5000";
28 my $mana_request = shift;
31 $mana_request->content_type('application/json');
32 my $userAgent = LWP::UserAgent->new;
33 my $response = $userAgent->request($mana_request);
35 if ( $response->code ne "204" ) {
36 $result = from_json( $response->decoded_content );
38 $result->{code} = $response->code;
40 return $result if ( $response->code =~ /^2..$/ );
43 sub manaNewUserPatchRequest {
47 my $url = "$MANA_IP/$resource/$id.json/newUser";
48 my $request = HTTP::Request->new( PATCH => $url );
50 return manaRequest($request);
57 my $url = "$MANA_IP/$resource.json";
58 my $request = HTTP::Request->new( POST => $url );
60 $content->{bulk_import} = 0;
61 my $json = to_json( $content, { utf8 => 1 } );
62 $request->content($json);
64 return manaRequest($request);
67 sub manaGetRequestWithId {
71 my $url = "$MANA_IP/$resource/$id.json";
72 my $request = HTTP::Request->new( GET => $url );
74 return manaRequest($request);
79 my $parameters = shift;
81 $parameters = join '&',
82 map { defined $parameters->{$_} ? $_ . "=" . $parameters->{$_} : () }
84 my $url = "$MANA_IP/$resource.json?$parameters";
85 my $request = HTTP::Request->new( GET => $url );
87 return manaRequest($request);