}
}
+sub get_details {
+ my ($self, $conn, $session_id, $title_id) = @_;
+ my $handler = new_handler($session_id);
+ return $handler->get_title_info($title_id);
+}
+__PACKAGE__->register_method(
+ method => 'get_details',
+ api_name => 'open-ils.ebook_api.title.details',
+ api_level => 1,
+ argc => 2,
+ signature => {
+ desc => "Get basic metadata for an ebook title",
+ params => [
+ {
+ name => 'session_id',
+ desc => 'The session ID (provided by open-ils.ebook_api.start_session)',
+ type => 'string'
+ },
+ {
+ name => 'title_id',
+ desc => 'The title ID (ISBN, unique identifier, etc.)',
+ type => 'string'
+ }
+ ],
+ return => {
+ desc => 'Success: { title => "Title", author => "Author Name" } / Failure: { error => "Title not found" }',
+ type => 'hashref'
+ }
+ }
+);
+
sub get_availability {
my ($self, $conn, $session_id, $title_id) = @_;
my $handler = new_handler($session_id);
return;
}
+# get basic metadata for an item (title, author, cover image if any)
+# GET http://api.oneclickdigital.us/v1/libraries/{libraryId}/titles/{isbn}
+sub get_title_info {
+ my ($self, $isbn) = @_;
+ my $base_uri = $self->{base_uri};
+ my $library_id = $self->{library_id};
+ my $session_id = $self->{session_id};
+ my $req = {
+ method => 'GET',
+ uri => "$base_uri/libraries/$library_id/titles/$isbn"
+ };
+ my $res = $self->request($req, $session_id);
+ if (defined ($res)) {
+ return {
+ title => $res->{content}->{title},
+ author => $res->{content}->{authors}[0]{text}
+ };
+ } else {
+ $logger->error("EbookAPI: could not retrieve OneClickdigital title details for ISBN $isbn");
+ return;
+ }
+}
+
# does this title have available "copies"? y/n
# GET http://api.oneclickdigital.us/v1/libraries/{libraryID}/media/{isbn}/availability
sub do_availability_lookup {
# - do_client_auth: authenticate client with external API (e.g. get client
# token if needed)
# - do_patron_auth: get a patron-specific bearer token, or just the patron ID
+# - get_title_info: get basic title details (title, author, optional cover image)
# - do_holdings_lookup: how many total/available "copies" are there for this
# title? (n/a for OneClickdigital)
# - do_availability_lookup: does this title have available "copies"? y/n
return undef;
}
+# get basic info (title, author, eventually a thumbnail URL) for a title
+sub get_title_info {
+ my $self = shift;
+
+ # External ID for title. Depending on the API, this could be an ISBN
+ # or an identifier unique to that vendor.
+ my $title_id = shift;
+
+ # Prepare data structure to be used as return value.
+ my $title_info = {
+ title => '',
+ author => ''
+ };
+
+ # If title lookup fails or title is not found, our return value
+ # is somewhat different.
+ my $title_not_found = {
+ error => 'Title not found.'
+ };
+
+ # For testing purposes, we have only three valid titles (001, 002, 003).
+ # All other title IDs return an error message.
+ if ($title_id eq '001') {
+ $title_info->{title} = 'The Fellowship of the Ring';
+ $title_info->{author} = 'J.R.R. Tolkien';
+ } elsif ($title_id eq '002') {
+ $title_info->{title} = 'The Two Towers';
+ $title_info->{author} = 'J.R.R. Tolkien';
+ } elsif ($title_id eq '003') {
+ $title_info->{title} = 'The Return of the King';
+ $title_info->{author} = 'J.R.R. Tolkien';
+ } else {
+ return $title_not_found;
+ }
+ return $title_info;
+}
+
# get detailed holdings information (copy counts and formats), OR basic
# availability if detailed info is not provided by the API
sub do_holdings_lookup {
#!perl
use strict; use warnings;
-use Test::More tests => 21; # XXX
+use Test::More tests => 23; # XXX
use OpenILS::Utils::TestUtils;
diag("Tests Ebook API");
# 3. Title availability and holdings.
# ------------------------------------------------------------
+# Title details for valid title ID.
+my $title_001_details_req = $ebook_api->request(
+ 'open-ils.ebook_api.title.details', $session_id, '001');
+my $title_001_details = $title_001_details_req->recv->content;
+ok(ref($title_001_details) && $title_001_details->{title}, 'Title details check 1/2 (valid title)');
+
+# Title details for invalid title ID.
+my $title_004_details_req = $ebook_api->request(
+ 'open-ils.ebook_api.title.details', $session_id, '004');
+my $title_004_details = $title_004_details_req->recv->content;
+ok(ref($title_004_details) && $title_004_details->{error}, 'Title details check 1/2 (invalid title returns error message)');
+
# Title is not available.
my $title_001_avail_req = $ebook_api->request(
'open-ils.ebook_api.title.availability', $session_id, '001');