[open-ils-commits] [GIT] Evergreen ILS branch master updated. ee4a2cb8f73cc15311f9fc777e287dd98744b3e1

Evergreen Git git at git.evergreen-ils.org
Tue Jun 21 15:20:41 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, master has been updated
       via  ee4a2cb8f73cc15311f9fc777e287dd98744b3e1 (commit)
       via  976321b7af3b9967df38f8adef617fce9eca9ff2 (commit)
       via  25468fa7e64263758f6b3d5741802ac462e029f9 (commit)
       via  b50a81676f63c97cf555f68a1bb2c2abc880f559 (commit)
       via  681a3fc0588d9e46f2f01976a0592a09726ae30b (commit)
       via  a00f47c67a7606be5575e43997a848c6c97d1ac5 (commit)
       via  223d98f31da37887988c61cc89c68d8f539c8617 (commit)
       via  62ddc37d78e07d3aa55b1003b187179f8eedc22a (commit)
       via  782410700751b4104d81413bce6dd693a067e286 (commit)
       via  00173c0974c5a605c5ca92f27d4598bb611324a6 (commit)
      from  aa155d652e018084f5bc5369df86e46c3ea822a7 (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 ee4a2cb8f73cc15311f9fc777e287dd98744b3e1
Author: Dan Scott <dan at coffeecode.net>
Date:   Sun Jun 12 21:24:01 2011 -0400

    Refactor cover image fetching in OpenLibrary added content
    
    We were only trying to retrieve images from the items array in the
    OpenLibrary response, but there are only items if the OpenLibrary has
    online editions available - whereas there may be covers attached to the
    metadata for the work. So now we make the metadata work harder.
    
    Also, cut down on broken images in search results by short-circuiting if
    OpenLibrary doesn't have a matching record for a given ISBN.
    
    Thanks to Bill Erickson for pointing out that there were a lot of blank
    images getting returned due to the items reliance.
    
    Signed-off-by: Dan Scott <dan at coffeecode.net>
    Signed-off-by: Bill Erickson <berick 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 a157389..c2c2cc6 100644
--- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/AddedContent/OpenLibrary.pm
+++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/AddedContent/OpenLibrary.pm
@@ -331,22 +331,40 @@ sub fetch_items_response {
     return $book_results->{items};
 }
 
-
 # returns a cover image from the list of associated items
 # TODO: Look for the best match in the array of items
 sub fetch_cover_response {
     my( $self, $size, $key ) = @_;
 
-    my $items = $self->fetch_items_response($key);
+    my $cover;
+
+    my $response = $self->fetch_response($key);
 
-    if (!$items) {
+    # Short-circuit if we get an empty response, or a response
+    #with no matching records
+    if (!$response or scalar(keys %$response) == 0) {
         return $AC->get_url($blank_img);
     }
 
+    # Try to return a cover image from the record->data metadata
+    foreach my $rec_key (keys %{$response->{records}}) {
+        my $record = $response->{records}->{$rec_key};
+        if (exists $record->{data}->{cover}->{$size}) {
+            $cover = $record->{data}->{cover}->{$size};
+        }
+        if ($cover) {
+            return $AC->get_url($cover);
+        }
+    }
+
+    # If we didn't find a cover in the record metadata, look in the items
+    # Seems unlikely, but might as well try.
+    my $items = $response->{items};
+
     $logger->debug("$key: items request got " . scalar(@$items) . " items back");
 
     foreach my $item (@$items) {
-        if ($item->{cover}) {
+        if (exists $item->{cover}->{$size}) {
             return $AC->get_url($item->{cover}->{$size}) || 0;
         }
     }
diff --git a/Open-ILS/web/opac/skin/default/js/result_common.js b/Open-ILS/web/opac/skin/default/js/result_common.js
index 3988e1e..6a5d8c3 100644
--- a/Open-ILS/web/opac/skin/default/js/result_common.js
+++ b/Open-ILS/web/opac/skin/default/js/result_common.js
@@ -763,7 +763,7 @@ function renderOpenLibraryLinks(response) {
             );
         } else if (ol_ebooks[isbn]['similar_lendable']) {
             createOpenLibraryLink(
-                isbn, ol_ebooks[isbn]['similar_full'], 'Borrow similar online'
+                isbn, ol_ebooks[isbn]['similar_lendable'], 'Borrow similar online'
             );
         }
     }

commit 976321b7af3b9967df38f8adef617fce9eca9ff2
Author: Dan Scott <dan at coffeecode.net>
Date:   Thu Jun 2 14:40:57 2011 -0400

    Teach result_common.js to OpenLibrary requests
    
    Now that the proxied OpenLibrary requests are working, teach
    result_common.js to use them and get an advantage from being an
    access-rights-authenticated IP address (if applicable).
    
    Signed-off-by: Dan Scott <dscott at laurentian.ca>
    Signed-off-by: Bill Erickson <berick 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 32a0350..a157389 100644
--- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/AddedContent/OpenLibrary.pm
+++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/AddedContent/OpenLibrary.pm
@@ -247,6 +247,8 @@ sub proxy_json {
     my( $self, $key ) = @_;
 
     my $url = $read_api . $key;
+    $logger->debug("proxy_json with key '$key', url $url");
+
     $self->send_json($AC->get_url($url)->content());
 }
 
diff --git a/Open-ILS/web/opac/skin/default/js/result_common.js b/Open-ILS/web/opac/skin/default/js/result_common.js
index 00194f1..3988e1e 100644
--- a/Open-ILS/web/opac/skin/default/js/result_common.js
+++ b/Open-ILS/web/opac/skin/default/js/result_common.js
@@ -698,12 +698,14 @@ function fetchOpenLibraryLinks() {
             isbns += 'isbn:' + isbn + '|';
         });
         isbns = isbns.replace(/.$/, '');
-        dojo.require('dojo.io.script');
-        dojo.io.script.get({
-            "url":"http://openlibrary.org/api/volumes/brief/json/" + isbns + '?callback=renderOpenLibraryLinks',
-            "callback": "renderOpenLibraryLinks"
-        });
     }
+
+    dojo.xhrGet({
+        "url": "/opac/extras/ac/proxy/json/" + isbns,
+        "handleAs": "json",
+        "load": function (data) { renderOpenLibraryLinks(data); }
+    });
+
 }
 
 function renderOpenLibraryLinks(response) {

commit 25468fa7e64263758f6b3d5741802ac462e029f9
Author: Dan Scott <dan at coffeecode.net>
Date:   Thu Jun 2 13:03:22 2011 -0400

    Support proxying bulk Read API requests for access rights
    
    Using IP-based access right determination runs into problems with a pure
    JavaScript API, as users may be accessing the API from any location in
    the world. Proxying the requests via the library system server ensures
    that the access rights for users of those libraries are properly
    displayed.
    
    Signed-off-by: Dan Scott <dscott at laurentian.ca>
    Signed-off-by: Bill Erickson <berick 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 3bdaf6a..32a0350 100644
--- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/AddedContent/OpenLibrary.pm
+++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/AddedContent/OpenLibrary.pm
@@ -28,7 +28,8 @@ use Data::Dumper;
 
 my $AC = 'OpenILS::WWW::AddedContent';
 
-my $blank_img = 'http://images.concat.ca/opac/images/blank.png';
+# This should work for most setups
+my $blank_img = 'http://localhost/opac/images/blank.png';
 
 # This URL is always the same for OpenLibrary, so there's no advantage to
 # pulling from opensrf.xml
@@ -240,6 +241,16 @@ sub send_html {
     return { content_type => 'text/html', content => $HTML };
 }
 
+# proxy OpenLibrary requests so that the IP address of the library
+# can be used to determine access rights to materials
+sub proxy_json {
+    my( $self, $key ) = @_;
+
+    my $url = $read_api . $key;
+    $self->send_json($AC->get_url($url)->content());
+}
+
+
 # returns the HTTP response object from the URL fetch
 sub fetch_response {
     my( $self, $key ) = @_;

commit b50a81676f63c97cf555f68a1bb2c2abc880f559
Author: Dan Scott <dan at coffeecode.net>
Date:   Thu Jun 2 12:25:33 2011 -0400

    Return transparent images if no cover art is found
    
    For now the URL is hardcoded; later on we'll refactor AddedContent.pm to
    give us access to more information about our Apache environment to
    default to something much, much smarter.
    
    Signed-off-by: Dan Scott <dscott at laurentian.ca>
    Signed-off-by: Bill Erickson <berick 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 b140282..3bdaf6a 100644
--- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/AddedContent/OpenLibrary.pm
+++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/AddedContent/OpenLibrary.pm
@@ -28,6 +28,8 @@ use Data::Dumper;
 
 my $AC = 'OpenILS::WWW::AddedContent';
 
+my $blank_img = 'http://images.concat.ca/opac/images/blank.png';
+
 # This URL is always the same for OpenLibrary, so there's no advantage to
 # pulling from opensrf.xml
 
@@ -303,7 +305,7 @@ sub fetch_details_response {
 sub fetch_items_response {
     my ($self, $key) = @_;
 
-    my $book_results = $self->fetch_response($key);
+    my $book_results = $self->fetch_response($key) || return 0;
 
     my $items = $book_results->{items};
 
@@ -324,6 +326,10 @@ sub fetch_cover_response {
 
     my $items = $self->fetch_items_response($key);
 
+    if (!$items) {
+        return $AC->get_url($blank_img);
+    }
+
     $logger->debug("$key: items request got " . scalar(@$items) . " items back");
 
     foreach my $item (@$items) {
@@ -333,7 +339,9 @@ sub fetch_cover_response {
     }
 
     $logger->debug("$key: no covers for this book");
-    return 0;
+
+    # Return a blank image
+    return $AC->get_url($blank_img);
 }
 
 1;

commit 681a3fc0588d9e46f2f01976a0592a09726ae30b
Author: Dan Scott <dan at coffeecode.net>
Date:   Thu Jun 2 11:57:04 2011 -0400

    Working TOC HTML and cover images from OpenLibrary Read API
    
    TOCs are now part of the "data" response in the Read API.
    
    Covers are accessed with the "cover" key in the "items" objects.
    
    Signed-off-by: Dan Scott <dscott at laurentian.ca>
    Signed-off-by: Bill Erickson <berick 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 547d5b8..b140282 100644
--- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/AddedContent/OpenLibrary.pm
+++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/AddedContent/OpenLibrary.pm
@@ -62,7 +62,7 @@ sub jacket_large {
 
 sub ebooks_html {
     my( $self, $key ) = @_;
-    my $book_data_json = $self->fetch_response($key)->content();
+    my $book_data_json = $self->fetch_response($key);
 
     $logger->debug("$key: " . $book_data_json);
 
@@ -164,9 +164,9 @@ sub toc_html {
 
     my $toc_html;
     
-    my $details = $self->fetch_details_response($key) || return 0;
+    my $book_data = $self->fetch_data_response($key) || return 0;
 
-    my $toc_json = $details->{table_of_contents};
+    my $toc_json = $book_data->{table_of_contents};
 
     # No table of contents is available for this book; short-circuit
     if (!$toc_json or !scalar(@$toc_json)) {
@@ -178,7 +178,7 @@ sub toc_html {
     # and page number. Some rows may not contain section numbers, we should
     # protect against empty page numbers too.
     foreach my $chapter (@$toc_json) {
-	my $label = $chapter->{label};
+        my $label = $chapter->{label};
         if ($label) {
             $label .= '. ';
         }
@@ -247,7 +247,9 @@ sub fetch_response {
     $key = "isbn:$key";
 
     my $url = $read_api . $key;
-    my $response = $AC->get_url($url);
+    my $response = $AC->get_url($url)->content();
+
+    $logger->debug("$key: response was $response");
 
     my $book_results = OpenSRF::Utils::JSON->JSON2perl($response);
     my $record = $book_results->{$key};
@@ -261,14 +263,33 @@ sub fetch_response {
     return $record;
 }
 
+sub fetch_data_response {
+    my ($self, $key) = @_;
+
+    my $book_results = $self->fetch_response($key);
+
+    my $book_key = (keys %{$book_results->{records}})[0];
+
+    $logger->debug("$key: using record key $book_key");
+
+    # We didn't find a matching book; short-circuit our response
+    if (!$book_key || !$book_results->{records}->{$book_key}->{data}) {
+        $logger->debug("$key: no found book");
+        return 0;
+    }
+
+    return $book_results->{records}->{$book_key}->{data};
+}
+
+
 sub fetch_details_response {
     my ($self, $key) = @_;
 
-    my $book_results = $self->fetch_response($key)->content();
+    my $book_results = $self->fetch_response($key);
 
-    $logger->debug("$key: $book_results");
-    
-    my $book_key = (keys %$book_results)[0];
+    my $book_key = (keys %{$book_results->{records}})[0];
+
+    $logger->debug("$key: using record key $book_key");
 
     # We didn't find a matching book; short-circuit our response
     if (!$book_key) {
@@ -282,10 +303,8 @@ sub fetch_details_response {
 sub fetch_items_response {
     my ($self, $key) = @_;
 
-    my $book_results = $self->fetch_response($key)->content();
+    my $book_results = $self->fetch_response($key);
 
-    $logger->debug("$key: items $book_results");
-    
     my $items = $book_results->{items};
 
     # We didn't find a matching book; short-circuit our response
@@ -305,9 +324,11 @@ sub fetch_cover_response {
 
     my $items = $self->fetch_items_response($key);
 
+    $logger->debug("$key: items request got " . scalar(@$items) . " items back");
+
     foreach my $item (@$items) {
-        if ($item->{covers}) {
-            return $AC->get_url($item->{covers}->{$size}) || 0;
+        if ($item->{cover}) {
+            return $AC->get_url($item->{cover}->{$size}) || 0;
         }
     }
 

commit a00f47c67a7606be5575e43997a848c6c97d1ac5
Author: Dan Scott <dan at coffeecode.net>
Date:   Thu Jun 2 09:56:05 2011 -0400

    Get OpenLibrary covers from any related items
    
    Cover requests for exact matches sometimes fail to produce results, but
    covers from similar items (other editions of the same work) are often
    available. Take that!
    
    Signed-off-by: Dan Scott <dscott at laurentian.ca>
    Signed-off-by: Bill Erickson <berick 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 292cfd0..547d5b8 100644
--- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/AddedContent/OpenLibrary.pm
+++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/AddedContent/OpenLibrary.pm
@@ -124,12 +124,12 @@ sub excerpt_html {
 
     my $content = $self->fetch_details_response($key)->content();
 
-    my $first_sentence = $content->{details}->{first_sentence};
+    my $first_sentence = $content->{first_sentence};
     if ($first_sentence) {
         $excerpt_html .= "<div class='sentence1'>$first_sentence</div>\n";
     }
 
-    my $excerpts_json = $content->{details}->{$book_key}->{excerpts};
+    my $excerpts_json = $content->{excerpts};
     if ($excerpts_json && scalar(@$excerpts_json)) {
         # Load up excerpt text with comments in tooltip
         foreach my $excerpt (@$excerpts_json) {
@@ -279,29 +279,40 @@ sub fetch_details_response {
     return $book_results->{$book_key}->{details};
 }
 
-# returns the HTTP response object from the URL fetch
-sub fetch_cover_response {
-    my( $self, $size, $key ) = @_;
+sub fetch_items_response {
+    my ($self, $key) = @_;
 
-    my $response = $self->fetch_response($key)->content();
+    my $book_results = $self->fetch_response($key)->content();
 
-    my $book_data = OpenSRF::Utils::JSON->JSON2perl($response);
-    my $book_key = (keys %$book_data)[0];
+    $logger->debug("$key: items $book_results");
+    
+    my $items = $book_results->{items};
 
     # We didn't find a matching book; short-circuit our response
-    if (!$book_key) {
-        $logger->debug("$key: no found book");
+    if (!$items || scalar(@$items) == 0) {
+        $logger->debug("$key: no found items");
         return 0;
     }
 
-    my $covers_json = $book_data->{$book_key}->{cover};
-    if (!$covers_json) {
-        $logger->debug("$key: no covers for this book");
-        return 0;
+    return $book_results->{items};
+}
+
+
+# returns a cover image from the list of associated items
+# TODO: Look for the best match in the array of items
+sub fetch_cover_response {
+    my( $self, $size, $key ) = @_;
+
+    my $items = $self->fetch_items_response($key);
+
+    foreach my $item (@$items) {
+        if ($item->{covers}) {
+            return $AC->get_url($item->{covers}->{$size}) || 0;
+        }
     }
 
-    $logger->debug("$key: " . $covers_json->{$size});
-    return $AC->get_url($covers_json->{$size}) || 0;
+    $logger->debug("$key: no covers for this book");
+    return 0;
 }
 
 1;

commit 223d98f31da37887988c61cc89c68d8f539c8617
Author: Dan Scott <dan at coffeecode.net>
Date:   Thu Jun 2 09:46:24 2011 -0400

    Begin cutting AddedContent over to the OpenLibrary Read API
    
    Use the all-in-one Read API request to get results; this should
    cut our requests in half and improve our caching results.
    
    Signed-off-by: Dan Scott <dscott at laurentian.ca>
    Signed-off-by: Bill Erickson <berick 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 2be38a0..292cfd0 100644
--- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/AddedContent/OpenLibrary.pm
+++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/AddedContent/OpenLibrary.pm
@@ -28,16 +28,10 @@ use Data::Dumper;
 
 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
+# This URL is always the same for OpenLibrary, so there's no advantage to
+# pulling from opensrf.xml
 
-# 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/';
+my $read_api = 'http://openlibrary.org/api/volumes/brief/json/';
 
 sub new {
     my( $class, $args ) = @_;
@@ -68,7 +62,7 @@ sub jacket_large {
 
 sub ebooks_html {
     my( $self, $key ) = @_;
-    my $book_data_json = $self->fetch_data_response($key)->content();
+    my $book_data_json = $self->fetch_response($key)->content();
 
     $logger->debug("$key: " . $book_data_json);
 
@@ -125,27 +119,17 @@ sub ebooks_html {
 
 sub excerpt_html {
     my( $self, $key ) = @_;
-    my $book_details_json = $self->fetch_details_response($key)->content();
-
-    $logger->debug("$key: $book_details_json");
 
     my $excerpt_html;
-    
-    my $book_details = OpenSRF::Utils::JSON->JSON2perl($book_details_json);
-    my $book_key = (keys %$book_details)[0];
 
-    # We didn't find a matching book; short-circuit our response
-    if (!$book_key) {
-        $logger->debug("$key: no found book");
-        return 0;
-    }
+    my $content = $self->fetch_details_response($key)->content();
 
-    my $first_sentence = $book_details->{$book_key}->{first_sentence};
+    my $first_sentence = $content->{details}->{first_sentence};
     if ($first_sentence) {
         $excerpt_html .= "<div class='sentence1'>$first_sentence</div>\n";
     }
 
-    my $excerpts_json = $book_details->{$book_key}->{excerpts};
+    my $excerpts_json = $content->{details}->{$book_key}->{excerpts};
     if ($excerpts_json && scalar(@$excerpts_json)) {
         # Load up excerpt text with comments in tooltip
         foreach my $excerpt (@$excerpts_json) {
@@ -177,22 +161,12 @@ HTML table.
 
 sub toc_html {
     my( $self, $key ) = @_;
-    my $book_details_json = $self->fetch_details_response($key)->content();
-
-    $logger->debug("$key: " . $book_details_json);
 
     my $toc_html;
     
-    my $book_details = OpenSRF::Utils::JSON->JSON2perl($book_details_json);
-    my $book_key = (keys %$book_details)[0];
+    my $details = $self->fetch_details_response($key) || return 0;
 
-    # We didn't find a matching book; short-circuit our response
-    if (!$book_key) {
-        $logger->debug("$key: no found book");
-        return 0;
-    }
-
-    my $toc_json = $book_details->{$book_key}->{details}->{table_of_contents};
+    my $toc_json = $details->{table_of_contents};
 
     # No table of contents is available for this book; short-circuit
     if (!$toc_json or !scalar(@$toc_json)) {
@@ -225,7 +199,7 @@ sub toc_html {
 sub toc_json {
     my( $self, $key ) = @_;
     my $toc = $self->send_json(
-        $self->fetch_details_response($key)
+        $self->fetch_response($key)
     );
 }
 
@@ -265,25 +239,51 @@ sub send_html {
 }
 
 # returns the HTTP response object from the URL fetch
-sub fetch_data_response {
+sub fetch_response {
     my( $self, $key ) = @_;
-    my $url = $base_url_data . "$key";
+
+    # TODO: OpenLibrary can also accept lccn, oclc, olid...
+    # Hardcoded to only accept ISBNs for now.
+    $key = "isbn:$key";
+
+    my $url = $read_api . $key;
     my $response = $AC->get_url($url);
-    return $response;
+
+    my $book_results = OpenSRF::Utils::JSON->JSON2perl($response);
+    my $record = $book_results->{$key};
+
+    # We didn't find a matching book; short-circuit our response
+    if (!$record) {
+        $logger->debug("$key: no found record");
+        return 0;
+    }
+
+    return $record;
 }
-# returns the HTTP response object from the URL fetch
+
 sub fetch_details_response {
-    my( $self, $key ) = @_;
-    my $url = $base_url_details . "$key";
-    my $response = $AC->get_url($url);
-    return $response;
+    my ($self, $key) = @_;
+
+    my $book_results = $self->fetch_response($key)->content();
+
+    $logger->debug("$key: $book_results");
+    
+    my $book_key = (keys %$book_results)[0];
+
+    # We didn't find a matching book; short-circuit our response
+    if (!$book_key) {
+        $logger->debug("$key: no found book");
+        return 0;
+    }
+
+    return $book_results->{$book_key}->{details};
 }
 
 # returns the HTTP response object from the URL fetch
 sub fetch_cover_response {
     my( $self, $size, $key ) = @_;
 
-    my $response = $self->fetch_data_response($key)->content();
+    my $response = $self->fetch_response($key)->content();
 
     my $book_data = OpenSRF::Utils::JSON->JSON2perl($response);
     my $book_key = (keys %$book_data)[0];
@@ -304,5 +304,4 @@ sub fetch_cover_response {
     return $AC->get_url($covers_json->{$size}) || 0;
 }
 
-
 1;

commit 62ddc37d78e07d3aa55b1003b187179f8eedc22a
Author: Dan Scott <dan at coffeecode.net>
Date:   Thu Jun 2 01:42:49 2011 -0400

    Don't make OpenLibrary requests without an ID
    
    It is rather silly to make requests if you have not pulled any IDs out
    of the records to pass along to OpenLibrary, so do not do that. Also
    refactor and add a bit more defensiveness.
    
    Signed-off-by: Dan Scott <dan at coffeecode.net>
    Signed-off-by: Bill Erickson <berick at esilibrary.com>

diff --git a/Open-ILS/web/opac/skin/default/js/result_common.js b/Open-ILS/web/opac/skin/default/js/result_common.js
index a7e9fd7..00194f1 100644
--- a/Open-ILS/web/opac/skin/default/js/result_common.js
+++ b/Open-ILS/web/opac/skin/default/js/result_common.js
@@ -451,24 +451,22 @@ function resultDisplayRecord(rec, pos, is_mr) {
 	var r = table.rows[pos + 1];
     var currentISBN = cleanISBN(rec.isbn());
 
-    if (OpenLibraryLinks) {
-        var olspan = $n(r, 'openLibraryLink');
-        if (currentISBN) {
+    if (currentISBN) {
+        isbnList.push(currentISBN);
+        if (OpenLibraryLinks) {
+            var olspan = $n(r, 'openLibraryLink');
             olspan.setAttribute('name', olspan.getAttribute('name') + 
                 '-' + currentISBN
             );
         }
-    }
 
-    if (googleBooksLink) {
-	    var gbspan = $n(r, "googleBooksLink");
-        if (currentISBN) {
+        if (googleBooksLink) {
+            var gbspan = $n(r, "googleBooksLink");
             gbspan.setAttribute(
                 'name',
                 gbspan.getAttribute('name') + '-' + currentISBN
             );
 
-            isbnList.push(currentISBN);
         }
     }
 
@@ -686,7 +684,7 @@ function resultBuildFormatIcons( row, rec, is_mr ) {
 }
 
 function fetchOpenLibraryLinks() {
-    if (isbnList && OpenLibraryLinks) {
+    if (isbnList.length > 0 && OpenLibraryLinks) {
         /* OpenLibrary supports a number of different identifiers:
          * ISBN: isbn:<isbn>
          * LCCN: lccn:<lccn>
@@ -736,6 +734,11 @@ function renderOpenLibraryLinks(response) {
             }
         });
 
+        /* If there are no books to read or borrow, move on */
+        if (!ol_ebooks[isbn]) {
+            continue;
+        }
+
         /* Now populate the results page with our ebook goodness*/
         /* Go for the jugular - exact match with full access */
         if (ol_ebooks[isbn]['exact_full']) {

commit 782410700751b4104d81413bce6dd693a067e286
Author: Dan Scott <dan at coffeecode.net>
Date:   Wed Jun 1 01:58:27 2011 -0400

    Implement OpenLibrary ebook availability via Ajax
    
    George Oates provided an OpenLibrary GIF to use for the
    links, and we can drop the links right into the block of
    white space between copy counts and bibliographic info.
    
    Signed-off-by: Dan Scott <dan at coffeecode.net>
    Signed-off-by: Bill Erickson <berick at esilibrary.com>

diff --git a/Open-ILS/web/opac/images/openlibrary.gif b/Open-ILS/web/opac/images/openlibrary.gif
new file mode 100644
index 0000000..9ac053d
Binary files /dev/null and b/Open-ILS/web/opac/images/openlibrary.gif differ
diff --git a/Open-ILS/web/opac/skin/default/js/result_common.js b/Open-ILS/web/opac/skin/default/js/result_common.js
index 523ca7c..a7e9fd7 100644
--- a/Open-ILS/web/opac/skin/default/js/result_common.js
+++ b/Open-ILS/web/opac/skin/default/js/result_common.js
@@ -451,6 +451,15 @@ function resultDisplayRecord(rec, pos, is_mr) {
 	var r = table.rows[pos + 1];
     var currentISBN = cleanISBN(rec.isbn());
 
+    if (OpenLibraryLinks) {
+        var olspan = $n(r, 'openLibraryLink');
+        if (currentISBN) {
+            olspan.setAttribute('name', olspan.getAttribute('name') + 
+                '-' + currentISBN
+            );
+        }
+    }
+
     if (googleBooksLink) {
 	    var gbspan = $n(r, "googleBooksLink");
         if (currentISBN) {
@@ -677,55 +686,99 @@ function resultBuildFormatIcons( row, rec, is_mr ) {
 }
 
 function fetchOpenLibraryLinks() {
-    var data = '{ "records": { "/books/OL7577192M": { "recordURL": "http://openlibrary.org/books/OL7577192M", "oclcs": [], "publishDates": [ "August 1, 1959" ], "lccns": [], "isbns": [ "0451525221", "9780451525222" ], "issns": [], "data": { "publishers": [ { "name": "Signet Classics" } ], "identifiers": { "isbn_13": [ "9780451525222" ], "openlibrary": [ "OL7577192M" ], "isbn_10": [ "0451525221" ], "goodreads": [ "1138582" ], "librarything": [ "2264" ] }, "title": "The Scarlet Letter (Signet Classics)", "url": "http://mccabe-dev.us.archive.org:8080/books/OL7577192M/The_Scarlet_Letter_(Signet_Classics)", "number_of_pages": 10, "cover": { "small": "http://covers.openlibrary.org/b/id/295505-S.jpg", "large": "http://covers.openlibrary.org/b/id/295505-L.jpg", "medium": "http://covers.openlibrary.org/b/id/295505-M.jpg" }, "subject_places": [ { "url": "http://openlibrary.org/subjects/place:boston_(mass.)", "name": "Boston (Mass.)" }, { "url": "http://openlibrary.org/subjects/place:m
 assachusetts", "name": "Massachusetts" }, { "url": "http://openlibrary.org/subjects/place:boston", "name": "Boston" }, { "url": "http://openlibrary.org/subjects/place:new_england", "name": "New England" }, { "url": "http://openlibrary.org/subjects/place:england", "name": "England" }, { "url": "http://openlibrary.org/subjects/place:history", "name": "History" } ], "subjects": [ { "url": "http://openlibrary.org/subjects/fiction", "name": "Fiction" }, { "url": "http://openlibrary.org/subjects/puritans", "name": "Puritans" }, { "url": "http://openlibrary.org/subjects/puritans_in_fiction", "name": "Puritans in fiction" }, { "url": "http://openlibrary.org/subjects/history", "name": "History" }, { "url": "http://openlibrary.org/subjects/adultery_in_fiction", "name": "Adultery in fiction" }, { "url": "http://openlibrary.org/subjects/adultery", "name": "Adultery" }, { "url": "http://openlibrary.org/subjects/illegitimate_children", "name": "Illegitimate children" }, { "url": "http://o
 penlibrary.org/subjects/illegitimate_children_in_fiction", "name": "Illegitimate children in fiction" }, { "url": "http://openlibrary.org/subjects/triangles_(interpersonal_relations)", "name": "Triangles (Interpersonal relations)" }, { "url": "http://openlibrary.org/subjects/clergy", "name": "Clergy" }, { "url": "http://openlibrary.org/subjects/married_women_in_fiction", "name": "Married women in fiction" }, { "url": "http://openlibrary.org/subjects/married_women", "name": "Married women" }, { "url": "http://openlibrary.org/subjects/clergy_in_fiction", "name": "Clergy in fiction" }, { "url": "http://openlibrary.org/subjects/revenge", "name": "Revenge" }, { "url": "http://openlibrary.org/subjects/revenge_in_fiction", "name": "Revenge in fiction" }, { "url": "http://openlibrary.org/subjects/women_immigrants", "name": "Women immigrants" }, { "url": "http://openlibrary.org/subjects/women_immigrants_in_fiction", "name": "Women immigrants in fiction" }, { "url": "http://openlibrar
 y.org/subjects/massachusetts_in_fiction", "name": "Massachusetts in fiction" }, { "url": "http://openlibrary.org/subjects/american_fiction", "name": "American fiction" }, { "url": "http://openlibrary.org/subjects/women", "name": "Women" }, { "url": "http://openlibrary.org/subjects/women_in_fiction", "name": "Women in fiction" }, { "url": "http://openlibrary.org/subjects/study_guides", "name": "Study guides" }, { "url": "http://openlibrary.org/subjects/new_england_in_fiction", "name": "New England in fiction" }, { "url": "http://openlibrary.org/subjects/social_life_and_customs", "name": "Social life and customs" }, { "url": "http://openlibrary.org/subjects/examinations", "name": "Examinations" }, { "url": "http://openlibrary.org/subjects/juvenile_fiction", "name": "Juvenile fiction" }, { "url": "http://openlibrary.org/subjects/young_adult_fiction", "name": "Young adult fiction" }, { "url": "http://openlibrary.org/subjects/england_in_fiction", "name": "England in fiction" }, {
  "url": "http://openlibrary.org/subjects/vocabulary", "name": "Vocabulary" }, { "url": "http://openlibrary.org/subjects/historical_fiction", "name": "Historical fiction" }, { "url": "http://openlibrary.org/subjects/sat_(educational_test)", "name": "SAT (Educational test)" }, { "url": "http://openlibrary.org/subjects/english_language", "name": "English language" }, { "url": "http://openlibrary.org/subjects/nathaniel_hawthorne", "name": "Nathaniel Hawthorne" }, { "url": "http://openlibrary.org/subjects/lending_library", "name": "Lending library" }, { "url": "http://openlibrary.org/subjects/accessible_book", "name": "Accessible book" }, { "url": "http://openlibrary.org/subjects/protected_daisy", "name": "Protected DAISY" }, { "url": "http://openlibrary.org/subjects/litt\u00e9rature", "name": "Litt\u00e9rature" }, { "url": "http://openlibrary.org/subjects/adult\u00e8re", "name": "Adult\u00e8re" }, { "url": "http://openlibrary.org/subjects/femmes", "name": "Femmes" }, { "url": "h
 ttp://openlibrary.org/subjects/the_scarlet_letter_(hawthorne)", "name": "The scarlet letter (Hawthorne)" }, { "url": "http://openlibrary.org/subjects/puritains", "name": "Puritains" }, { "url": "http://openlibrary.org/subjects/romans,_nouvelles", "name": "Romans, nouvelles" }, { "url": "http://openlibrary.org/subjects/romance_norte_americano", "name": "Romance Norte Americano" }, { "url": "http://openlibrary.org/subjects/in_library", "name": "In library" } ], "publish_date": "August 1, 1959", "key": "/books/OL7577192M", "authors": [ { "url": "http://mccabe-dev.us.archive.org:8080/authors/OL26681A/Nathaniel_Hawthorne", "name": "Nathaniel Hawthorne" } ], "subject_people": [ { "url": "http://openlibrary.org/subjects/person:nathaniel_hawthorne_(1804-1864)", "name": "Nathaniel Hawthorne (1804-1864)" }, { "url": "http://openlibrary.org/subjects/person:nathaniel_hawthorne_(1804-1865)", "name": "Nathaniel Hawthorne (1804-1865)" } ], "subject_times": [ { "url": "http://openlibrary.or
 g/subjects/time:colonial_period,_ca._1600-1775", "name": "Colonial period, ca. 1600-1775" }, { "url": "http://openlibrary.org/subjects/time:colonial_period,_ca.1600-1775", "name": "Colonial period, ca.1600-1775" }, { "url": "http://openlibrary.org/subjects/time:19th_century", "name": "19th century" } ] } } }, "items": [ { "status": "lendable", "ol-work-id": "OL455305W", "ol-edition-id": "OL5849784M", "cover": { "small": "http://covers.openlibrary.org/b/id/6560185-S.jpg", "large": "http://covers.openlibrary.org/b/id/6560185-L.jpg", "medium": "http://covers.openlibrary.org/b/id/6560185-M.jpg" }, "itemURL": "http://openlibrary.org/books/OL5849784M/The_scarlet_letter/borrow", "enumcron": false, "contributor": "contributor", "fromRecord": "/books/OL7577192M", "match": "similar" }, { "status": "full access", "ol-work-id": "OL455305W", "ol-edition-id": "OL7106163M", "cover": { "small": "http://covers.openlibrary.org/b/id/5624131-S.jpg", "large": "http://covers.openlibrary.org/b/id/
 5624131-L.jpg", "medium": "http://covers.openlibrary.org/b/id/5624131-M.jpg" }, "itemURL": "http://www.archive.org/stream/scarletletterrom00hawtrich", "enumcron": false, "contributor": "contributor", "fromRecord": "/books/OL7577192M", "match": "similar" } ] }';
-renderOpenLibraryLinks(data);
-}
-
-function fetchOpenLibraryLinksReal() {
     if (isbnList && OpenLibraryLinks) {
-    alert('fetching');
+        /* OpenLibrary supports a number of different identifiers:
+         * ISBN: isbn:<isbn>
+         * LCCN: lccn:<lccn>
+         * OpenLibrary ID: olid:<openlibrary-ID>
+         *
+         * We'll just fire off ISBNs for now.
+         */
+
         var isbns = '';
         dojo.forEach(isbnList, function(isbn) {
-            isbns += 'isbn:' + isbn + ',';
+            isbns += 'isbn:' + isbn + '|';
         });
+        isbns = isbns.replace(/.$/, '');
         dojo.require('dojo.io.script');
         dojo.io.script.get({
-            "url":"http://mccabe-dev.us.archive.org:8080/api/shotgun",
-            "content": { "keys": isbns },
+            "url":"http://openlibrary.org/api/volumes/brief/json/" + isbns + '?callback=renderOpenLibraryLinks',
             "callback": "renderOpenLibraryLinks"
         });
     }
 }
 
 function renderOpenLibraryLinks(response) {
-    var results = dojo.fromJson(response);
     var ol_ebooks = {};
 
-    /* Iterate over each returned record */
-    for (var record in results.records) {
-        var edition = results.records[record];
-        /* Map ISBN that we care about to OL edition ID */
-        dojo.forEach(edition.isbns, function(isbn) {
-            ol_ebooks[isbn] = record;
-        });
-
-        /* Now iterate over the results to find matches for our original ISBNs;
-           if we find a match, take action */
-        dojo.forEach(isbnList, function (isbn) {
-            if (ol_ebooks[isbn]) {
-                var oled = ol_ebooks[isbn];
-                /* Find matching items by their fromEdition key */
-                dojo.forEach(results.items, function (item) {
-                    /* Populate the links if we have a match */
-                    if (item.fromRecord == oled) {
-                        /* alert for now */
-                        alert(item.status + ' ' + item.match + ' ' + item.url);
-                    }
-                });
+    /* Iterate over each identifier we requested */
+    for (var item_id in response) {
+
+        var isbn = item_id.replace(/^isbn:/, '');
+        /* Iterate over each matching item; OpenLibrary supplies access info:
+         *  * match: "exact" or "similar"
+         *  * status: "full access" or "lendable"
+         */
+        dojo.forEach(response[item_id].items, function(item) {
+            ol_ebooks[isbn] = {};
+            if (item.match == 'exact') {
+                if (item.status == 'full access') {
+                    ol_ebooks[isbn]['exact_full'] = item.itemURL;
+                } else {
+                    ol_ebooks[isbn]['exact_lendable'] = item.itemURL;
+                }
+            } else {
+                if (item.status == 'full access') {
+                    ol_ebooks[isbn]['similar_full'] = item.itemURL;
+                } else {
+                    ol_ebooks[isbn]['similar_lendable'] = item.itemURL;
+                }
             }
         });
-        
-    };
+
+        /* Now populate the results page with our ebook goodness*/
+        /* Go for the jugular - exact match with full access */
+        if (ol_ebooks[isbn]['exact_full']) {
+            createOpenLibraryLink(
+                isbn, ol_ebooks[isbn]['exact_full'], 'Read online'
+            );
+            continue;
+        }
+
+        /* Fall back to slightly less palatable options */
+        else if (ol_ebooks[isbn]['exact_lendable']) {
+            createOpenLibraryLink(
+                isbn, ol_ebooks[isbn]['exact_lendable'], 'Borrow online'
+            );
+        }
+
+        if (ol_ebooks[isbn]['similar_full']) {
+            createOpenLibraryLink(
+                isbn, ol_ebooks[isbn]['similar_full'], 'Read similar online'
+            );
+        } else if (ol_ebooks[isbn]['similar_lendable']) {
+            createOpenLibraryLink(
+                isbn, ol_ebooks[isbn]['similar_full'], 'Borrow similar online'
+            );
+        }
+    }
+}
+
+function createOpenLibraryLink(isbn, url, text) {
+    var ol_span = $n(document.documentElement, 'openLibraryLink-' + isbn);
+
+    var ol_a_span = dojo.create('a', {
+            "href": url,
+            "class": "classic_link"
+        }, ol_span
+    );
+    dojo.create('img', {
+            "src": "/opac/images/openlibrary.gif"
+        }, ol_a_span
+    );
+    dojo.create('br', null, ol_a_span);
+    ol_a_span.appendChild(dojo.doc.createTextNode(text));
+    dojo.removeClass(ol_span, 'hide_me');
 }
 
 function fetchGoogleBooksLink () {
diff --git a/Open-ILS/web/opac/skin/default/xml/result/result_table.xml b/Open-ILS/web/opac/skin/default/xml/result/result_table.xml
index 7ee942a..03345ef 100644
--- a/Open-ILS/web/opac/skin/default/xml/result/result_table.xml
+++ b/Open-ILS/web/opac/skin/default/xml/result/result_table.xml
@@ -44,6 +44,8 @@
                                     </a>
                                 </td>
 
+                                <!-- Empty span used for creating OpenLibrary links -->
+                                <td rowspan='4' name="openLibraryLink" style="text-align: center; vertical-align: middle; width: 15em;" class="hide_me"></td>
                                 <!-- Copy this td for each copy count appended -->
                                 <td  rowspan='4' nowrap='nowrap' name="copy_count_cell" class='copy_count_cell'> 
                                 </td>

commit 00173c0974c5a605c5ca92f27d4598bb611324a6
Author: Dan Scott <dan at coffeecode.net>
Date:   Fri May 27 23:55:38 2011 -0400

    integrate the OpenLibrary Read API into search results
    
    Still early days, but works based on the sample Read API
    output provided by Mike for a single ISBN search.
    
    Signed-off-by: Dan Scott <dan at coffeecode.net>
    Signed-off-by: Bill Erickson <berick at esilibrary.com>

diff --git a/Open-ILS/web/opac/skin/default/js/result_common.js b/Open-ILS/web/opac/skin/default/js/result_common.js
index dfd5455..523ca7c 100644
--- a/Open-ILS/web/opac/skin/default/js/result_common.js
+++ b/Open-ILS/web/opac/skin/default/js/result_common.js
@@ -5,8 +5,9 @@ var opac_strings = dojo.i18n.getLocalization("openils.opac", "opac");
 var recordsHandled = 0;
 var recordsCache = [];
 var lowHitCount = 4;
-var isbnList = '';
+var isbnList = new Array();
 var googleBooksLink = true;
+var OpenLibraryLinks = true;
 
 var resultFetchAllRecords = false;
 var resultCompiledSearch = null;
@@ -16,7 +17,7 @@ if( findCurrentPage() == MRESULT || findCurrentPage() == RRESULT ) {
 	G.evt.result.hitCountReceived.push(resultSetHitInfo);
 	G.evt.result.recordReceived.push(resultDisplayRecord, resultAddCopyCounts);
 	G.evt.result.copyCountsReceived.push(resultDisplayCopyCounts);
-	G.evt.result.allRecordsReceived.push( function(){unHideMe($('result_info_2'))}, fetchGoogleBooksLink, fetchChiliFreshReviews);
+	G.evt.result.allRecordsReceived.push( function(){unHideMe($('result_info_2'))}, fetchOpenLibraryLinks, fetchGoogleBooksLink, fetchChiliFreshReviews);
 
 	attachEvt('result','lowHits',resultLowHits);
 	attachEvt('result','zeroHits',resultZeroHits);
@@ -458,8 +459,7 @@ function resultDisplayRecord(rec, pos, is_mr) {
                 gbspan.getAttribute('name') + '-' + currentISBN
             );
 
-            if (isbnList) isbnList += ', ';
-            isbnList += currentISBN;
+            isbnList.push(currentISBN);
         }
     }
 
@@ -676,13 +676,65 @@ function resultBuildFormatIcons( row, rec, is_mr ) {
 	}
 }
 
+function fetchOpenLibraryLinks() {
+    var data = '{ "records": { "/books/OL7577192M": { "recordURL": "http://openlibrary.org/books/OL7577192M", "oclcs": [], "publishDates": [ "August 1, 1959" ], "lccns": [], "isbns": [ "0451525221", "9780451525222" ], "issns": [], "data": { "publishers": [ { "name": "Signet Classics" } ], "identifiers": { "isbn_13": [ "9780451525222" ], "openlibrary": [ "OL7577192M" ], "isbn_10": [ "0451525221" ], "goodreads": [ "1138582" ], "librarything": [ "2264" ] }, "title": "The Scarlet Letter (Signet Classics)", "url": "http://mccabe-dev.us.archive.org:8080/books/OL7577192M/The_Scarlet_Letter_(Signet_Classics)", "number_of_pages": 10, "cover": { "small": "http://covers.openlibrary.org/b/id/295505-S.jpg", "large": "http://covers.openlibrary.org/b/id/295505-L.jpg", "medium": "http://covers.openlibrary.org/b/id/295505-M.jpg" }, "subject_places": [ { "url": "http://openlibrary.org/subjects/place:boston_(mass.)", "name": "Boston (Mass.)" }, { "url": "http://openlibrary.org/subjects/place:m
 assachusetts", "name": "Massachusetts" }, { "url": "http://openlibrary.org/subjects/place:boston", "name": "Boston" }, { "url": "http://openlibrary.org/subjects/place:new_england", "name": "New England" }, { "url": "http://openlibrary.org/subjects/place:england", "name": "England" }, { "url": "http://openlibrary.org/subjects/place:history", "name": "History" } ], "subjects": [ { "url": "http://openlibrary.org/subjects/fiction", "name": "Fiction" }, { "url": "http://openlibrary.org/subjects/puritans", "name": "Puritans" }, { "url": "http://openlibrary.org/subjects/puritans_in_fiction", "name": "Puritans in fiction" }, { "url": "http://openlibrary.org/subjects/history", "name": "History" }, { "url": "http://openlibrary.org/subjects/adultery_in_fiction", "name": "Adultery in fiction" }, { "url": "http://openlibrary.org/subjects/adultery", "name": "Adultery" }, { "url": "http://openlibrary.org/subjects/illegitimate_children", "name": "Illegitimate children" }, { "url": "http://o
 penlibrary.org/subjects/illegitimate_children_in_fiction", "name": "Illegitimate children in fiction" }, { "url": "http://openlibrary.org/subjects/triangles_(interpersonal_relations)", "name": "Triangles (Interpersonal relations)" }, { "url": "http://openlibrary.org/subjects/clergy", "name": "Clergy" }, { "url": "http://openlibrary.org/subjects/married_women_in_fiction", "name": "Married women in fiction" }, { "url": "http://openlibrary.org/subjects/married_women", "name": "Married women" }, { "url": "http://openlibrary.org/subjects/clergy_in_fiction", "name": "Clergy in fiction" }, { "url": "http://openlibrary.org/subjects/revenge", "name": "Revenge" }, { "url": "http://openlibrary.org/subjects/revenge_in_fiction", "name": "Revenge in fiction" }, { "url": "http://openlibrary.org/subjects/women_immigrants", "name": "Women immigrants" }, { "url": "http://openlibrary.org/subjects/women_immigrants_in_fiction", "name": "Women immigrants in fiction" }, { "url": "http://openlibrar
 y.org/subjects/massachusetts_in_fiction", "name": "Massachusetts in fiction" }, { "url": "http://openlibrary.org/subjects/american_fiction", "name": "American fiction" }, { "url": "http://openlibrary.org/subjects/women", "name": "Women" }, { "url": "http://openlibrary.org/subjects/women_in_fiction", "name": "Women in fiction" }, { "url": "http://openlibrary.org/subjects/study_guides", "name": "Study guides" }, { "url": "http://openlibrary.org/subjects/new_england_in_fiction", "name": "New England in fiction" }, { "url": "http://openlibrary.org/subjects/social_life_and_customs", "name": "Social life and customs" }, { "url": "http://openlibrary.org/subjects/examinations", "name": "Examinations" }, { "url": "http://openlibrary.org/subjects/juvenile_fiction", "name": "Juvenile fiction" }, { "url": "http://openlibrary.org/subjects/young_adult_fiction", "name": "Young adult fiction" }, { "url": "http://openlibrary.org/subjects/england_in_fiction", "name": "England in fiction" }, {
  "url": "http://openlibrary.org/subjects/vocabulary", "name": "Vocabulary" }, { "url": "http://openlibrary.org/subjects/historical_fiction", "name": "Historical fiction" }, { "url": "http://openlibrary.org/subjects/sat_(educational_test)", "name": "SAT (Educational test)" }, { "url": "http://openlibrary.org/subjects/english_language", "name": "English language" }, { "url": "http://openlibrary.org/subjects/nathaniel_hawthorne", "name": "Nathaniel Hawthorne" }, { "url": "http://openlibrary.org/subjects/lending_library", "name": "Lending library" }, { "url": "http://openlibrary.org/subjects/accessible_book", "name": "Accessible book" }, { "url": "http://openlibrary.org/subjects/protected_daisy", "name": "Protected DAISY" }, { "url": "http://openlibrary.org/subjects/litt\u00e9rature", "name": "Litt\u00e9rature" }, { "url": "http://openlibrary.org/subjects/adult\u00e8re", "name": "Adult\u00e8re" }, { "url": "http://openlibrary.org/subjects/femmes", "name": "Femmes" }, { "url": "h
 ttp://openlibrary.org/subjects/the_scarlet_letter_(hawthorne)", "name": "The scarlet letter (Hawthorne)" }, { "url": "http://openlibrary.org/subjects/puritains", "name": "Puritains" }, { "url": "http://openlibrary.org/subjects/romans,_nouvelles", "name": "Romans, nouvelles" }, { "url": "http://openlibrary.org/subjects/romance_norte_americano", "name": "Romance Norte Americano" }, { "url": "http://openlibrary.org/subjects/in_library", "name": "In library" } ], "publish_date": "August 1, 1959", "key": "/books/OL7577192M", "authors": [ { "url": "http://mccabe-dev.us.archive.org:8080/authors/OL26681A/Nathaniel_Hawthorne", "name": "Nathaniel Hawthorne" } ], "subject_people": [ { "url": "http://openlibrary.org/subjects/person:nathaniel_hawthorne_(1804-1864)", "name": "Nathaniel Hawthorne (1804-1864)" }, { "url": "http://openlibrary.org/subjects/person:nathaniel_hawthorne_(1804-1865)", "name": "Nathaniel Hawthorne (1804-1865)" } ], "subject_times": [ { "url": "http://openlibrary.or
 g/subjects/time:colonial_period,_ca._1600-1775", "name": "Colonial period, ca. 1600-1775" }, { "url": "http://openlibrary.org/subjects/time:colonial_period,_ca.1600-1775", "name": "Colonial period, ca.1600-1775" }, { "url": "http://openlibrary.org/subjects/time:19th_century", "name": "19th century" } ] } } }, "items": [ { "status": "lendable", "ol-work-id": "OL455305W", "ol-edition-id": "OL5849784M", "cover": { "small": "http://covers.openlibrary.org/b/id/6560185-S.jpg", "large": "http://covers.openlibrary.org/b/id/6560185-L.jpg", "medium": "http://covers.openlibrary.org/b/id/6560185-M.jpg" }, "itemURL": "http://openlibrary.org/books/OL5849784M/The_scarlet_letter/borrow", "enumcron": false, "contributor": "contributor", "fromRecord": "/books/OL7577192M", "match": "similar" }, { "status": "full access", "ol-work-id": "OL455305W", "ol-edition-id": "OL7106163M", "cover": { "small": "http://covers.openlibrary.org/b/id/5624131-S.jpg", "large": "http://covers.openlibrary.org/b/id/
 5624131-L.jpg", "medium": "http://covers.openlibrary.org/b/id/5624131-M.jpg" }, "itemURL": "http://www.archive.org/stream/scarletletterrom00hawtrich", "enumcron": false, "contributor": "contributor", "fromRecord": "/books/OL7577192M", "match": "similar" } ] }';
+renderOpenLibraryLinks(data);
+}
+
+function fetchOpenLibraryLinksReal() {
+    if (isbnList && OpenLibraryLinks) {
+    alert('fetching');
+        var isbns = '';
+        dojo.forEach(isbnList, function(isbn) {
+            isbns += 'isbn:' + isbn + ',';
+        });
+        dojo.require('dojo.io.script');
+        dojo.io.script.get({
+            "url":"http://mccabe-dev.us.archive.org:8080/api/shotgun",
+            "content": { "keys": isbns },
+            "callback": "renderOpenLibraryLinks"
+        });
+    }
+}
+
+function renderOpenLibraryLinks(response) {
+    var results = dojo.fromJson(response);
+    var ol_ebooks = {};
+
+    /* Iterate over each returned record */
+    for (var record in results.records) {
+        var edition = results.records[record];
+        /* Map ISBN that we care about to OL edition ID */
+        dojo.forEach(edition.isbns, function(isbn) {
+            ol_ebooks[isbn] = record;
+        });
+
+        /* Now iterate over the results to find matches for our original ISBNs;
+           if we find a match, take action */
+        dojo.forEach(isbnList, function (isbn) {
+            if (ol_ebooks[isbn]) {
+                var oled = ol_ebooks[isbn];
+                /* Find matching items by their fromEdition key */
+                dojo.forEach(results.items, function (item) {
+                    /* Populate the links if we have a match */
+                    if (item.fromRecord == oled) {
+                        /* alert for now */
+                        alert(item.status + ' ' + item.match + ' ' + item.url);
+                    }
+                });
+            }
+        });
+        
+    };
+}
+
 function fetchGoogleBooksLink () {
-    if (isbnList && googleBooksLink) {
+    if (isbnList.length > 0 && googleBooksLink) {
         var scriptElement = document.createElement("script");
         scriptElement.setAttribute("id", "jsonScript");
         scriptElement.setAttribute("src",
             "http://books.google.com/books?bibkeys=" + 
-            escape(isbnList) + "&jscmd=viewapi&callback=unhideGoogleBooksLink");
+            escape(isbnList.join(', ')) + "&jscmd=viewapi&callback=unhideGoogleBooksLink");
         scriptElement.setAttribute("type", "text/javascript");
         // make the request to Google Book Search
         document.documentElement.firstChild.appendChild(scriptElement);

-----------------------------------------------------------------------

Summary of changes:
 .../lib/OpenILS/WWW/AddedContent/OpenLibrary.pm    |  182 ++++++++++++++------
 Open-ILS/web/opac/images/openlibrary.gif           |  Bin 0 -> 1406 bytes
 Open-ILS/web/opac/skin/default/js/result_common.js |  128 +++++++++++++-
 .../opac/skin/default/xml/result/result_table.xml  |    2 +
 4 files changed, 247 insertions(+), 65 deletions(-)
 create mode 100644 Open-ILS/web/opac/images/openlibrary.gif


hooks/post-receive
-- 
Evergreen ILS


More information about the open-ils-commits mailing list