Skip to content

Instantly share code, notes, and snippets.

@Dyrcona
Last active December 10, 2020 15:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Dyrcona/34f36ba7aacd7b94e31f35c8a54f7f7e to your computer and use it in GitHub Desktop.
Save Dyrcona/34f36ba7aacd7b94e31f35c8a54f7f7e to your computer and use it in GitHub Desktop.
Perl script to test NCIPServer with Evergreen. It sends a LookupUser message to see if the servier is running and configuration is OK.
#!/usr/bin/perl
# ---------------------------------------------------------------
# Copyright © 2019 Jason J.A. Stephenson <jason@sigio.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# ---------------------------------------------------------------
use strict;
use warnings;
use LWP::UserAgent;
use HTTP::Request;
use HTML::Entities;
use Getopt::Long;
my $url;
my $fromAgency;
my $toAgency;
my $userBarcode;
GetOptions("url=s" => \$url,
"from-agency=s" => \$fromAgency,
"to-agency=s" => \$toAgency,
"user-barcode=s" => \$userBarcode)
or die("Error in command arguments");
die("Missing required argument(s)") unless($url && $fromAgency && $toAgency && $userBarcode);
$fromAgency = encode_entities($fromAgency);
$toAgency = encode_entities($toAgency);
$userBarcode = encode_entities($userBarcode);
my $data = <<EODATA;
<?xml version="1.0" encoding="utf-8"?>
<NCIPMessage version="http://www.niso.org/schemas/ncip/v2_02/ncip_v2_02.xsd" xmlns="http://www.niso.org/2008/ncip">
<LookupUser>
<InitiationHeader>
<FromAgencyId><AgencyId>$fromAgency</AgencyId></FromAgencyId>
<ToAgencyId><AgencyId>$toAgency</AgencyId></ToAgencyId>
</InitiationHeader>
<UserId>
<UserIdentifierValue>$userBarcode</UserIdentifierValue>
<UserIdentifierType>Barcode</UserIdentifierType>
</UserId>
<UserElementType>User Address Information</UserElementType>
<UserElementType>Block Or Trap</UserElementType>
<UserElementType>Name Information</UserElementType>
<UserElementType>User Privilege</UserElementType>
</LookupUser>
</NCIPMessage>
EODATA
my $ua = LWP::UserAgent->new;
my $req = HTTP::Request->new(POST => $url);
$req->content_type('application/xml');
$req->content($data);
my $res = $ua->request($req);
if ($res->is_success) {
print $res->content;
} else {
print $res->status_line . "\n";
print $res->content;
}
@Dyrcona
Copy link
Author

Dyrcona commented Dec 10, 2020

You can run it like this:

perl lookup_user.pl --from-agency <WHATEVER> --to-agency <OU_SHORTNAME> --user-barcode <BARCODE OF A PATRON> --url https://host.domain.tld/NCIP/

It should return a XML response with information about the patron. It could return a XML problem response if the patron doesn't exist or whatever. If it returns something other than a XML response, then something is wrong with the configuration on the server.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment