NAME
Hetula::Client - Perl client implementation to communicate with Hetula.
DESCRIPTION
Perl client implementation to communicate with Hetula, the Patron data store
SYNOPSIS
my $hc = Hetula::Client->new({baseURL => 'https://hetula.example.com'});
my $loginResponse = $hc->login({username => 'master', password => 'blaster', organization => 'Administratoria'});
die($loginResponse->{error}) if ($loginResponse->{error});
my $loginActiveResp = $hc->loginActive();
ok(! $loginActiveResp->{error}, "Login active");
my $ssnAddResp = $hc->ssnAdd({ssn => 'bad-ssn'});
ok($ssnAddResp->{error}, "SSN add failed - Bad SSN '$ssnAddResp->{error}'");
my $ssnGetResp = $hc->ssnGet({id => 1});
ok(! $ssnGetResp->{error}, "SSN got");
my $ssnsBatchAddResp = $hc->ssnsBatchAdd(['101010-101A', '101010-102B']);
is(@$ssnsBatchAddResp, 2, "SSNs batch add");
new
@param1 {HASHRef} baseURL => https://hetula.example.com
credentials => filepath, Where to load the credentials file.
see slurpCredentials() for more info.
API Access methods
login
See Hetula API doc for endpoint POST /api/v1/auth
@param1 {HASHRef} username => String || undef if given via credentials during construction,
password => String || undef if given via credentials during construction,
organization => String || undef if given via credentials during construction,
loginActive
ssnAdd
See Hetula API doc for endpoint POST /api/v1/ssns
ssnGet
See Hetula API doc for endpoint GET /api/v1/users/<id>
@param1 {HASHRef} id => ssn id to get
ssnsBatchAdd
See Hetula API doc for endpoint GET /api/v1/ssns/batch
@param1 {ARRAYRef} of ssns
ssnsBatchAddChunked
Invokes the ssnsBatchAdd()-method repeatedly in small chunks. Useful for importing an inconveniently large amount of ssns that would otherwise timeout the Hetula-server.
@param1 {sub} Receives a feeder callback, which sends ssn-lists to the
ssnsBatchAdd()-method.
for ex.
sub {
#Keep sending ssns while there are ssns to send
return ['ssn1','ssn2','ssn3'] if @ssns;
#When ssns run out, return false to signal the end of transmission
return undef || [];
}
@param2 {sub} Receives a digester callback, which receives the ssnsBatchAdd()-methods
response|return value.
for ex.
sub {
my ($ssnReportsFromHetula) = @_;
print $FH_OUT "$_->{ssn}->{id},$_->{ssn}->{ssn},$_->{error}\n" for @$ssnReportsFromHetula;
}
ssnsBatchAddFromFile
Wrapper for ssnsBatchAddChunked(), where this manages the file IO as well.
@param1 {filepath} Where to read ssns from.
This can be a simple .csv-file, in this case the last (or only)
column is expected to be one containing the ssn that is
intended to be migrated to Hetula.
If there are any extra columns, they are appended to the
ssn report/result .csv-file as ssn report context.
@param2 {filepath} Where to write the ssn migration results/reports
userAdd
See Hetula API doc for endpoint POST /api/v1/users
userBasicAdd
Adds a user with only the most minimum permisions needed to push records into Hetula. Organization the user belongs to is implied from the currently logged in organization.
@param {HASHRef} username => 'MattiM',
password => 'Secret',
realname => 'Matti Meikäläinen',
userReadAdd
Adds a user with read access to Hetula. Organization the user belongs to is implied from the currently logged in organization.
@param {HASHRef} username => 'MattiM',
password => 'Secret',
realname => 'Matti Meikäläinen',
userMod
See Hetula API doc for endpoint PUT /api/v1/users/<id>
@param {HASHRef} username or id => mandatory,
other patron attributes => and values,
...
userChangePassword
@param {HASHRef} username or id => mandatory,
password => mandatory - the new password,
userDisableAccount
To recover from a disabled account, change the password
@param {String} username or id
HELPERS
slurpCredentials @static
Reads the contents of a credentials file.
The credentials file must consist of up to 4 lines, with each line specifying the following commandline argument replacements: username password organization url
@param1 {String} Path to the credentials file
@param2 {HASHRef} Optional, HASHRef where to inject the found credentials