WebService::ILS(3pm)
π WebService::ILS π
okay bestie, sit DOWN, because we're talking about WebService::ILS β it's the standardised library discovery/circulation services situation, and it lives in the User Contributed Perl Documentation section of your manual. this page is the group chat for every service provider subclass, so let's get into it π¦
β¨ SYNOPSIS β¨
like, here's the vibe:
use WebService::ILS::<Provider Subclass>;
my $ils = WebService::ILS::<Provider Subclass>->new({
client_id => $client_id,
client_secret => $client_secret
});
my %search_params = (
query => "Some keyword",
sort => "rating",
);
my $result = $ils->search(\%search_params);
foreach (@{ $result->{items} }) {
...
}
foreach (2..$result->{pages}) {
$search_params{page} = $_;
my $next_results = $ils->search(\%search_params);
...
}
or, alternatively, the other route:
my $native_result = $ils->native_search(\%native_search_params);
πΈ DESCRIPTION πΈ
so WebService::ILS is literally an attempt to create a standardised interface for online library services providers. that's the whole mission statement, no cap.
plus, a native API interface is provided too. two for one, we love to see it π
and here's the tea: on this page we're describing constructor parameters and methods common to all service providers. the diversions and native interfaces? those get documented in their corresponding modules. iykyk.
π Supported service providers
WebService::ILS::OverDrive::Libraryβ OverDrive Library API <https://developer.overdrive.com/discovery-apis>WebService::ILS::OverDrive::Patronβ OverDrive Circulation API <https://developer.overdrive.com/circulation-apis>
π INTERFACE π
π Error handling
method calls will die on error, bestie. $@ will contain a multi-line string. see "error_message()" below for how to cope with that emotionally.
π Item record
the Item record gets returned by many methods, so we're specifying it right here, once, so nobody has to ask twice:
idisbntitlesubtitledescriptionauthorpublisherpublication_datelanguageratingβ user ratings metricspopularityβ checkout metricssubjectsβ subject categories (tags)facetsβ a hashref of facet => [values]mediaβ book, e-book, video, audio etcformatsβ an arrayref of available formatsimagesβ a hashref of size => urlencryption_keyβ for decryption purposesdrmβ subject to drm
heads up: not all fields are available for all service providers. and field values are not standardised. it's giving chaos but we move π
π CONSTRUCTOR π
new (%params_hash or $params_hashref)
client (vendor) related constructor params, given by service provider:
client_idβ client (vendor) identifierclient_secretβ secret key (password)library_idβ sometimes service providers provide access to different "libraries"
general constructor params:
user_agentβ LWP::UserAgent or a derivative; usually not needed, one is created for you πuser_agent_paramsβ LWP::UserAgent constructor params so you don't need to create user agent yourselfaccess_tokenβ as returned from the provider authentication systemaccess_token_typeβ as returned from the provider authentication system
these are also read-only attributes, jsyk β¨
and ngl: not all of client/library params are required for all service providers.
π¦ ATTRIBUTES π¦
user_agent
as provided to constructor, or auto created. super useful if one wants to change user agent attributes on the fly, eg:
$ils->user_agent->timeout(120);
π₯ DISCOVERY METHODS π₯
search ($params_hashref)
input params:
queryβ query (search) stringpage_sizeβ number of items per results pagepageβ wanted page numbersortβ resultset sort option (see below)
sort options are either an array or a comma separated string of options:
publication_dateβ date title was publishedavailable_dateβ date title became available for usersratingβ number of items per results page
sort order can be added after option with :, eg "publication_date:desc,rating:desc" β periodt.
returns search results record:
itemsβ an array of item recordspage_sizeβ number of items per results pagepageβ results page numberpagesβ total number of pagestotalβ total number of items found by the search
item_metadata ($item_id)
returns item record π
item_availability ($item_id)
returns item availability record:
idavailableβ booleancopies_availableβ number of copies availablecopies_ownedβ number of copies ownedtypeβ availability type, provider dependant
not all fields are available for all service providers. for example, some will providecopies_available, makingavailableredundant, whereas others will just provideavailable. π
is_item_available ($item_id)
returns boolean.
it's the simplified version of item_availability() β main character energy, less drama.
π§ INDIVIDUAL USER AUTHENTICATION AND METHODS π§
user_id / password
provider authentication API is used to get an authorized session.
auth_by_user_id($user_id, $password)
an example:
my $ils = WebService::ILS::Provider({
client_id => $client_id,
client_secret => $client_secret,
});
eval { $ils->auth_by_user_id( $user_id, $password ) };
if ($@) { some_error_handling(); return; }
$session{ils_access_token} = $ils->access_token;
$session{ils_access_token_type} = $ils->access_token_type;
...
Somewhere else in your app:
my $ils = WebService::ILS::Provider({
client_id => $client_id,
client_secret => $client_secret,
access_token => $session{ils_access_token},
access_token_type => $session{ils_access_token_type},
});
my $checkouts = $ils->checkouts;
π Authentication at the provider
user is redirected to the provider authentication url, and after authenticating at the provider, redirected back with some kind of auth token. this requires a url to handle the return redirect from the provider.
it can be used as an alternative to FB and Google auth. iconic.
this is just to give an idea β specifics heavily depend on the provider, so don't come for me πΈ
auth_url ($redirect_back_uri)
returns provider authentication url to redirect to.
auth_token_param_name ()
returns auth code url param name.
auth_by_token ($provider_token)
an example:
my $ils = WebService::ILS::Provider({
client_id => $client_id,
client_secret => $client_secret,
});
my $redirect_url = $ils->auth_url("http://myapp.com/ils-auth");
$response->redirect($redirect_url);
...
After successful authentication at the provider, provider redirects
back to specified app url (http://myapp.com/ils-auth)
/ils-auth handler:
my $auth_token = $req->param( $ils->auth_token_param_name )
or some_error_handling(), return;
local $@;
eval { $ils->auth_by_token( $auth_token ) };
if ($@) { some_error_handling(); return; }
$session{ils_access_token} = $ils->access_token;
$session{ils_access_token_type} = $ils->access_token_type;
...
Somewhere else in your app:
passing access token to the constructor as above
π CIRCULATION METHODS π
patron ()
returns patron record:
idactiveβ booleancopies_availableβ number of copies availablecheckout_limitβ number of checkouts allowedhold_limitβ number of holds allowed
holds ()
returns holds record:
totalβ number of items on holditemsβ list of individual items
in addition to the Item record fields described above, item records will have:
placed_datetimeβ hold timestamp, with or without timezonequeue_positionβ user's position in the waiting queue, if available
place_hold ($item_id)
returns holds item record (as described above).
in addition, "total" field will be incorported as well. π
remove_hold ($item_id)
returns true to indicate success.
returns true in case user does not have a hold on the item. throws exception in case of any other failure. dramatic but fair π€
checkouts ()
returns checkout record:
totalβ number of items on holditemsβ list of individual items
in addition to the Item record fields described above, item records will have:
checkout_datetimeβ checkout timestamp, with or without timezoneexpiresβ date (time) checkout expiresurlβ download/stream urlfilesβ an arrayref of downloadable file details title, url, size
checkout ($item_id)
returns checkout item record (as described above).
in addition, "total" field will be incorported as well.
return ($item_id)
returns true to indicate success.
returns true in case user does not have the item checked out. throws exception in case of any other failure.
π NATIVE METHODS π
all Discovery and Circulation methods (with exception of remove_hold() and return(), where it does not make sense) have native_*() counterparts, eg native_search(), native_item_availability(), native_checkout() etc. it's giving "i have a twin" π
in case of single item methods, native_item_availability(), native_checkout() etc, they take item_id as parameter. otherwise, it's a hashref of HTTP request params (GET or POST).
return value is a record as returned by API.
individual provider subclasses provide additional provider specific native methods. yes, the subclasses are the ones with extra lore β¨
β UTILITY METHODS β
Error constants
ERROR_ACCESS_TOKENERROR_NOT_AUTHENTICATED
error_message ($exception_string)
returns error message probably suitable for displaying to the user.
example:
my $res = eval { $ils->checkout($id) };
if ($@) {
my $msg = $ils->error_message($@);
display($msg);
log_error($@);
}
is_access_token_error ($exception_string)
returns true if the error is access token related.
is_not_authenticated_error ($exception_string)
returns true if the error is "Not authenticated".
π TODO π
- Federated search
(that's it. that's the whole list. we're manifesting it fr fr π«Ά)
π LICENSE π
Copyright (C) Catalyst IT NZ Ltd Copyright (C) Bywater Solutions
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
π AUTHOR π
Srdjan JankoviX <srdjan@catalyst.net.nz>
and that's the whole page bestie!! this was WebService::ILS(3pm) from perl v5.36.0, dated 2022-11-29 β go forth and search, hold, checkout and return, you absolute icon ππΈπ
π¦ where this page comes from
- debian bookworm: libwebservice-ils-perl 0.18-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libwebservice-ils-perl 0.18-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libwebservice-ils-perl 0.18-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libwebservice-ils-perl 0.18-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libwebservice-ils-perl 0.18-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms