--- /dev/null
+#!/usr/bin/perl
+use strict; use warnings;
+
+use Digest::MD5 qw(md5_hex);
+use RPC::XML qw/smart_encode/;
+use RPC::XML::Client;
+use Data::Dumper; # for debugging
+$RPC::XML::ALLOW_NIL = 1;
+
+die "usage: $0 <host> <location> <username> <password> <patron_barcode>\n" unless $ARGV[4];
+
+
+# some example query params
+my $host = shift;
+my $location = shift;
+my $username = shift;
+my $password = shift;
+my $barcode = shift;
+
+
+$host = "http://$host/xml-rpc";
+
+# --------------------------------------------------------------------
+# Login to the system so we can get an authentication token
+# --------------------------------------------------------------------
+my $authkey = login( $username, $password );
+
+# --------------------------------------------------------------------
+# Grab a patron by barcode
+# --------------------------------------------------------------------
+my $resp = request(
+ 'open-ils.actor',
+ 'open__ils.actor.user.fleshed.retrieve_by_barcode',
+ $authkey, $barcode);
+
+
+
+# --------------------------------------------------------------------
+# Get the Perl-ized version of the data
+# --------------------------------------------------------------------
+my $user_data = $resp->value;
+
+# bump up the expiration date by a year
+my $expire_date = $user_data->{__data__}->{expire_date};
+print "Original expire date: $expire_date\n";
+
+my $expire_year = substr($expire_date, 0, 4);
+$expire_year = sprintf('%-04.4d', int($expire_year) + 1);
+substr($expire_date, 0, 4) = $expire_year;
+print "New expire date: $expire_date\n";
+
+$user_data->{__data__}->{expire_date} = $expire_date;
+$user_data->{__data__}->{ischanged} = 't';
+
+# and manipulate any addresses...
+foreach my $addr (@{ $user_data->{__data__}->{addresses} }) {
+ $addr->{__data__}->{street1} .= 'Z';
+ $addr->{__data__}->{ischanged} = 't';
+}
+
+my $update_resp = request(
+ 'open-ils.actor',
+ 'open__ils.actor.patron.update',
+ $authkey, $user_data);
+
+# --------------------------------------------------------------------
+# This sends an XML-RPC request and returns the RPC::XML::response
+# object.
+# $resp->value gives the Perl,
+# $resp->as_string gives the XML
+# --------------------------------------------------------------------
+sub request {
+ my( $service, $method, @args ) = @_;
+ my $connection = RPC::XML::Client->new("$host/$service", useragent => [ssl_opts => {verify_hostname => 0}]);
+ my $resp = $connection->send_request($method, smart_encode(@args));
+ return $resp;
+}
+
+
+
+
+
+# --------------------------------------------------------------------
+# Login
+# --------------------------------------------------------------------
+sub login {
+ my( $username, $password ) = @_;
+
+ my $seed = request(
+ 'open-ils.auth',
+ 'open__ils.auth.authenticate.init', $username )->value;
+
+ die "No auth seed returned\n" unless $seed;
+
+ my $response = request(
+ 'open-ils.auth',
+ 'open__ils.auth.authenticate.complete',
+ {
+ username => $username,
+ password => md5_hex($seed . md5_hex($password)),
+ type => 'opac',
+ }
+ )->value;
+
+ die "No login response returned\n" unless $response;
+
+ my $key = $response->{payload}->{authtoken};
+
+ die "Login failed\n" unless $key;
+
+ warn $key;
+
+ return $key;
+}
+
+