From d8b45d0459a5fa96e451781dc7c95039f11d8232 Mon Sep 17 00:00:00 2001 From: Chris Cormack Date: Tue, 17 Dec 2013 10:01:40 +1300 Subject: [PATCH] Looking up and finding user data, now just to send the response --- lib/NCIP/Handler/LookupUser.pm | 19 +++++++++---------- lib/NCIP/ILS/Koha.pm | 11 ++++++++++- lib/NCIP/User.pm | 15 ++++++++++++--- t/NCIP.t | 2 +- 4 files changed, 32 insertions(+), 15 deletions(-) diff --git a/lib/NCIP/Handler/LookupUser.pm b/lib/NCIP/Handler/LookupUser.pm index 9eb7e05..dc78795 100644 --- a/lib/NCIP/Handler/LookupUser.pm +++ b/lib/NCIP/Handler/LookupUser.pm @@ -13,11 +13,10 @@ package NCIP::Handler::LookupUser; =cut - use Modern::Perl; use NCIP::Handler; -use NCIP::Item; +use NCIP::User; our @ISA = qw(NCIP::Handler); @@ -25,19 +24,19 @@ 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(); + + my $user = NCIP::User->new( + { userid => $user_id->textContent(), ils => $self->ils } ); + $user->initialise(); + use Data::Dumper; + warn Dumper $user->userdata(); + return $user->userid(); } - return $self->type; } 1; diff --git a/lib/NCIP/ILS/Koha.pm b/lib/NCIP/ILS/Koha.pm index d14256c..968a98d 100644 --- a/lib/NCIP/ILS/Koha.pm +++ b/lib/NCIP/ILS/Koha.pm @@ -19,9 +19,18 @@ package NCIP::ILS::Koha; use Modern::Perl; use Object::Tiny qw{ name }; +use C4::Members qw{ GetMemberDetails }; sub itemdata { my $self = shift; - return ( {barcode=>'123',title=>'fish'}, undef); + return ( { barcode => '123', title => 'fish' }, undef ); } + +sub userdata { + my $self = shift; + my $userid = shift; + my $userdata = GetMemberDetails( undef, $userid ); + return $userdata; +} + 1; diff --git a/lib/NCIP/User.pm b/lib/NCIP/User.pm index 46e2d96..6cd2899 100644 --- a/lib/NCIP/User.pm +++ b/lib/NCIP/User.pm @@ -14,7 +14,15 @@ use base qw(Class::Accessor); # User Id # Make accessors for the ones that makes sense -NCIP::User->mk_accessors(qw(firstname surname address language privilege userid dateofbirth)); +NCIP::User->mk_accessors(qw(userid ils userdata)); + +sub initialise { + my $self = shift; + my $ils = $self->ils; + my ( $userdata, $error ) = $ils->userdata( $self->userid ); + $self->{'userdata'} = $userdata; + +} sub authentication { } @@ -23,8 +31,9 @@ sub previous_userids { } sub status { - # Is the user blocked - # if so, why + + # Is the user blocked + # if so, why } 1; diff --git a/t/NCIP.t b/t/NCIP.t index c5720a5..4c18ec3 100644 --- a/t/NCIP.t +++ b/t/NCIP.t @@ -53,5 +53,5 @@ is( $response, 'LookupItem', 'We got lookupitem with agency' ); my $lookupuser = read_file('t/sample_data/LookupUser.xml') || die "Cant open file"; ok( $response = $ncip->process_request($lookupuser), 'Try looking up a user' ); -is( $response, 'LookupUser', 'We got lookupuser' ); +is( $response, 'FLO-WHEELOCK', 'Got the user we expected' ); -- 2.43.2