Add support for get_user LibraryREST call
authorJeff Godin <jgodin@tadl.org>
Tue, 28 May 2013 21:09:38 +0000 (17:09 -0400)
committerJeff Godin <jgodin@tadl.org>
Tue, 28 May 2013 21:09:38 +0000 (17:09 -0400)
Add support for get_user LibraryREST call

Signed-off-by: Jeff Godin <jgodin@tadl.org>
Open-ILS/src/perlmods/lib/OpenILS/LibraryREST.pm

index acaba8a..94477a8 100644 (file)
@@ -70,4 +70,34 @@ sub get_auth {
     return 0;
 }
 
+sub get_user {
+    my $self = shift;
+    my $user = shift;
+    my $token = shift;
+    return unless ($user && $token);
+
+    my $target_user = shift | $user;
+
+    my $user_summary = $U->simplereq(
+        'open-ils.actor',
+        'open-ils.actor.user.opac.vital_stats',
+        $token
+    );
+
+    my $uobj = $user_summary->{user};
+
+    my $name_parts = [ $uobj->{first_given_name}, $uobj->{second_given_name}, $uobj->{family_name} ];
+    my $name = join(' ', @$name_parts);
+
+    return {
+        user => {
+                name => $name,
+                name_parts => $name_parts,
+            },
+        checkouts => $user_summary->{checkouts},
+        holds => $user_summary->{holds},
+        balance => $user_summary->{fines}->{balance_owed},
+    }
+}
+
 1;