From d2214f5a6aa835bac6cc52b241cd6dc740e999fa Mon Sep 17 00:00:00 2001 From: Chris Cormack Date: Wed, 20 Nov 2013 11:14:00 +1300 Subject: [PATCH] Beginning work on LookupUser --- lib/NCIP/Handler/LookupItem.pm | 29 ++++++++++------------- lib/NCIP/Handler/LookupUser.pm | 43 ++++++++++++++++++++++++++++++++++ t/NCIP.t | 6 +++++ t/NCIP_Handler.t | 13 ++++++++-- 4 files changed, 73 insertions(+), 18 deletions(-) create mode 100644 lib/NCIP/Handler/LookupUser.pm diff --git a/lib/NCIP/Handler/LookupItem.pm b/lib/NCIP/Handler/LookupItem.pm index e5cd8da..db2dbb8 100644 --- a/lib/NCIP/Handler/LookupItem.pm +++ b/lib/NCIP/Handler/LookupItem.pm @@ -1,21 +1,18 @@ package NCIP::Handler::LookupItem; -# -#=============================================================================== -# -# FILE: LookupItem.pm -# -# DESCRIPTION: -# -# FILES: --- -# BUGS: --- -# NOTES: --- -# AUTHOR: Chris Cormack (rangi), chrisc@catalyst.net.nz -# ORGANIZATION: Koha Development Team -# VERSION: 1.0 -# CREATED: 19/09/13 10:52:44 -# REVISION: --- -#=============================================================================== +=head1 + + NCIP::Handler::LookupItem + +=head1 SYNOPSIS + + Not to be called directly, NCIP::Handler will pick the appropriate Handler + object, given a message type + +=head1 FUNCTIONS + +=cut + use Modern::Perl; diff --git a/lib/NCIP/Handler/LookupUser.pm b/lib/NCIP/Handler/LookupUser.pm new file mode 100644 index 0000000..9eb7e05 --- /dev/null +++ b/lib/NCIP/Handler/LookupUser.pm @@ -0,0 +1,43 @@ +package NCIP::Handler::LookupUser; + +=head1 + + NCIP::Handler::LookupUser + +=head1 SYNOPSIS + + Not to be called directly, NCIP::Handler will pick the appropriate Handler + object, given a message type + +=head1 FUNCTIONS + +=cut + + +use Modern::Perl; + +use NCIP::Handler; +use NCIP::Item; + +our @ISA = qw(NCIP::Handler); + +sub handle { + my $self = shift; + my $xmldoc = shift; + if ($xmldoc) { + # Given our xml document, lets find the itemid + my ($user_id) = + $xmldoc->getElementsByTagNameNS( $self->namespace(), + 'UserIdentifierValue' ); + warn $user_id->textContent(); +# my $item = NCIP::User->new( { itemid => $user_id->textContent(), ils => $self->ils} ); +# my ($itemdata,$error) = $item->itemdata(); +# if ($error){ +# handle error here +# } +# warn $user->itemid(); + } + return $self->type; +} + +1; diff --git a/t/NCIP.t b/t/NCIP.t index 660302e..8a6519f 100644 --- a/t/NCIP.t +++ b/t/NCIP.t @@ -50,3 +50,9 @@ ok( 'Try looking up an item, with agency' ); is( $response, 'LookupItem', 'We got lookupitem with agency' ); + +my $lookupuser = read_file('t/sample_data/LookupUser.xml'); + +ok( $response = $ncip->process_request($lookupuser), 'Try looking up a user' ); +is( $response, 'LookupUser', 'We got lookupuser' ); + diff --git a/t/NCIP_Handler.t b/t/NCIP_Handler.t index 4e8b90d..8c9e44d 100644 --- a/t/NCIP_Handler.t +++ b/t/NCIP_Handler.t @@ -18,7 +18,7 @@ use strict; use warnings; -use Test::More tests => 3; # last test to print +use Test::More tests => 4; # last test to print use lib 'lib'; use_ok('NCIP::Handler'); @@ -29,6 +29,15 @@ my $type = 'LookupItem'; ok( my $handler = NCIP::Handler->new( { namespace => $namespace, type => $type } ), - 'Create new handler' + 'Create new LookupItem handler' ); ok( my $response = $handler->handle() ); + +$type = 'LookupUser'; +ok( + $handler = + NCIP::Handler->new( { namespace => $namespace, type => $type } ), + 'Create new LookupItem handler' + ); +ok( $response = $handler->handle() ); + -- 2.43.2