[open-ils-commits] [GIT] Evergreen ILS branch rel_2_1 updated. b1d7ea123ca35c6df8c049c732756eb2273cffcf
Evergreen Git
git at git.evergreen-ils.org
Fri Nov 4 12:52:52 EDT 2011
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Evergreen ILS".
The branch, rel_2_1 has been updated
via b1d7ea123ca35c6df8c049c732756eb2273cffcf (commit)
via 0411654f158db8ec08cfb36dbb774b6357727896 (commit)
from 055618de599c620d13b0f76b9463fb5e6bbd7173 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit b1d7ea123ca35c6df8c049c732756eb2273cffcf
Author: dbs <dbs at dcc99617-32d9-48b4-a31d-7c20da2025e4>
Date: Wed Apr 27 16:18:54 2011 +0000
Turn ebooks AC from OpenLibrary into usable HTML
Add <a> elements to turn URLs into links, and use the upper case
ebook format as the content of the link. "Read online" is the one
i18n-unfriendly exception, but this is a good start.
Signed-off-by: Dan Scott <dscott at laurentian.ca>
git-svn-id: svn://svn.open-ils.org/ILS/trunk@20346 dcc99617-32d9-48b4-a31d-7c20da2025e4
Signed-off-by: Lebbeous Fogle-Weekley <lebbeous at esilibrary.com>
diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/AddedContent/OpenLibrary.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/AddedContent/OpenLibrary.pm
index 0d29acf..b3534dd 100644
--- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/AddedContent/OpenLibrary.pm
+++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/AddedContent/OpenLibrary.pm
@@ -145,7 +145,7 @@ sub ebooks_html {
# Internet Archive online reader
my $stream_url = $ebooks_json->[0]->{'read_url'} || '';
if ($stream_url) {
- $ebook_html .= "<div class='ebook_stream'>$stream_url</div>\n";
+ $ebook_html .= "<li class='ebook_stream'><a href='$stream_url'>Read online</a></li>\n";
$logger->debug("$key: stream URL = $stream_url");
}
@@ -155,12 +155,12 @@ sub ebooks_html {
if ($ebook_formats->{$ebook} eq 'read_url') {
next;
}
- $ebook_html .= "<div class='$ebook'>" .
- $ebook_formats->{$ebook}->{'url'} . "</div>\n";
+ $ebook_html .= "<li class='ebook_$ebook'><a href='" .
+ $ebook_formats->{$ebook}->{'url'} . "'>" . uc($ebook) . "</a></li>\n";
}
$logger->debug("$key: $ebook_html");
- $self->send_html("<div class='ebooks'>$ebook_html</div>");
+ $self->send_html("<ul class='ebooks'>$ebook_html</ul>");
}
=head1
commit 0411654f158db8ec08cfb36dbb774b6357727896
Author: dbs <dbs at dcc99617-32d9-48b4-a31d-7c20da2025e4>
Date: Wed Apr 27 15:54:48 2011 +0000
Teach OpenLibrary.pm how to extract ebook links from OpenLibrary results
If the Internet Archive has an available ebook, then OpenLibrary will
provide links to it in various formats. For now, we return the results
as a plain set of <div> elements with class attributes denoting what
kind of ebook was returned; i18n will have to take care of providing
an actual label. Oh, and I guess we want to turn these into actual
<a> links...
Signed-off-by: Dan Scott <dscott at laurentian.ca>
Signed-off-by: Lebbeous Fogle-Weekley <lebbeous at esilibrary.com>
diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/AddedContent/OpenLibrary.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/AddedContent/OpenLibrary.pm
index 41f8ee8..0d29acf 100644
--- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/AddedContent/OpenLibrary.pm
+++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/AddedContent/OpenLibrary.pm
@@ -1,6 +1,6 @@
# ---------------------------------------------------------------
# Copyright (C) 2009 David Christensen <david.a.christensen at gmail.com>
-# Copyright (C) 2009 Dan Scott <dscott at laurentian.ca>
+# Copyright (C) 2009-2011 Dan Scott <dscott at laurentian.ca>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@@ -30,7 +30,13 @@ my $AC = 'OpenILS::WWW::AddedContent';
# These URLs are always the same for OpenLibrary, so there's no advantage to
# pulling from opensrf.xml; we hardcode them here
-my $base_url = 'http://openlibrary.org/api/books?details=true&bibkeys=ISBN:';
+
+# jscmd=details is unstable but includes goodies such as Table of Contents
+my $base_url_details = 'http://openlibrary.org/api/books?format=json&jscmd=details&bibkeys=ISBN:';
+
+# jscmd=data is stable and contains links to ebooks, excerpts, etc
+my $base_url_data = 'http://openlibrary.org/api/books?format=json&jscmd=data&bibkeys=ISBN:';
+
my $cover_base_url = 'http://covers.openlibrary.org/b/isbn/';
sub new {
@@ -60,7 +66,6 @@ sub jacket_large {
# --------------------------------------------------------------------------
-
sub excerpt_html {
my( $self, $key ) = @_;
my $book_details_json = $self->fetch_details_response($key)->content();
@@ -101,6 +106,63 @@ sub excerpt_html {
$self->send_html("<div class='ac_excerpts'>$excerpt_html</div>");
}
+sub ebooks_html {
+ my( $self, $key ) = @_;
+ my $book_data_json = $self->fetch_data_response($key)->content();
+
+ $logger->debug("$key: " . $book_data_json);
+
+ my $ebook_html;
+
+ my $book_data = OpenSRF::Utils::JSON->JSON2perl($book_data_json);
+ my $book_key = (keys %$book_data)[0];
+
+ # We didn't find a matching book; short-circuit our response
+ if (!$book_key) {
+ $logger->debug("$key: no found book");
+ return 0;
+ }
+
+ my $ebooks_json = $book_data->{$book_key}->{ebooks};
+
+ # No ebooks are available for this book; short-circuit
+ if (!$ebooks_json or !scalar(@$ebooks_json)) {
+ $logger->debug("$key: no ebooks");
+ return 0;
+ }
+
+ # Check the availability of the ebooks
+ my $available = $ebooks_json->[0]->{'availability'} || '';
+ if (!$available) {
+ $logger->debug("$key: no available ebooks");
+ return 0;
+ }
+
+ # Build a basic list of available ebook types and their URLs
+ # ebooks appears to be an array containing one element - a hash
+
+ # First element of the hash is 'read_url' which is a URL to
+ # Internet Archive online reader
+ my $stream_url = $ebooks_json->[0]->{'read_url'} || '';
+ if ($stream_url) {
+ $ebook_html .= "<div class='ebook_stream'>$stream_url</div>\n";
+ $logger->debug("$key: stream URL = $stream_url");
+ }
+
+ my $ebook_formats = $ebooks_json->[0]->{'formats'} || '';
+ # Next elements are various ebook formats that are available
+ foreach my $ebook (keys %{$ebook_formats}) {
+ if ($ebook_formats->{$ebook} eq 'read_url') {
+ next;
+ }
+ $ebook_html .= "<div class='$ebook'>" .
+ $ebook_formats->{$ebook}->{'url'} . "</div>\n";
+ }
+
+ $logger->debug("$key: $ebook_html");
+ $self->send_html("<div class='ebooks'>$ebook_html</div>");
+}
+
=head1
OpenLibrary returns a JSON hash of zero or more book responses matching our
@@ -115,12 +177,7 @@ HTML table.
sub toc_html {
my( $self, $key ) = @_;
- my $book_details_json = $self->fetch_response($key)->content();
-
-
- # Trim the "var _OlBookInfo = " declaration that makes this
- # invalid JSON
- $book_details_json =~ s/^.+?({.*?});$/$1/s;
+ my $book_details_json = $self->fetch_details_response($key)->content();
$logger->debug("$key: " . $book_details_json);
@@ -168,7 +225,7 @@ sub toc_html {
sub toc_json {
my( $self, $key ) = @_;
my $toc = $self->send_json(
- $self->fetch_response($key)
+ $self->fetch_details_response($key)
);
}
@@ -208,9 +265,16 @@ sub send_html {
}
# returns the HTTP response object from the URL fetch
-sub fetch_response {
+sub fetch_data_response {
+ my( $self, $key ) = @_;
+ my $url = $base_url_data . "$key";
+ my $response = $AC->get_url($url);
+ return $response;
+}
+# returns the HTTP response object from the URL fetch
+sub fetch_details_response {
my( $self, $key ) = @_;
- my $url = $base_url . "$key";
+ my $url = $base_url_details . "$key";
my $response = $AC->get_url($url);
return $response;
}
-----------------------------------------------------------------------
Summary of changes:
.../lib/OpenILS/WWW/AddedContent/OpenLibrary.pm | 88 +++++++++++++++++---
1 files changed, 76 insertions(+), 12 deletions(-)
hooks/post-receive
--
Evergreen ILS
More information about the open-ils-commits
mailing list