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

Evergreen Git git at git.evergreen-ils.org
Thu Nov 17 19:10:31 EST 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  7adc27d5e8db4c3c16c0da5a553dd409cf196620 (commit)
      from  1934d49521b7e10daa8094757d8fe33e28dc15d4 (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 7adc27d5e8db4c3c16c0da5a553dd409cf196620
Author: Dan Wells <dbw2 at calvin.edu>
Date:   Thu Nov 17 16:13:02 2011 -0500

    Switch to new Google Books API; make SSL friendly
    
    As implied in the title, this commit does two things.  First, it
    switches to the new Google Books API (which is both imminent and
    also necessary to make SSL calls work).  Though the information is
    scant, from what I have read and experienced, we do not need an
    API key to do searches and previews.  I have also not hit any kind
    of unauthenticated limit in several days of heavy testing, so I
    would figure we are safe (at this point) for normal end-user OPAC
    browsing.
    
    Second, all Google Book requests are now done over https.  This
    eliminates the majority of mixed content warnings when browsing
    securely, though you still get a warning when you actually do
    preview a book.
    
    In addition to possibly implementing protocol detection (rather
    than doing https all the time as a "lowest" common denominator),
    there are a few minor points where we might consider future changes.
    Those points are commented within the code.
    
    Signed-off-by: Dan Wells <dbw2 at calvin.edu>
    Signed-off-by: Dan Scott <dscott at laurentian.ca>

diff --git a/Open-ILS/web/opac/skin/default/js/rdetail.js b/Open-ILS/web/opac/skin/default/js/rdetail.js
index 2d08344..13c5eab 100644
--- a/Open-ILS/web/opac/skin/default/js/rdetail.js
+++ b/Open-ILS/web/opac/skin/default/js/rdetail.js
@@ -1254,7 +1254,7 @@ function rdetailCheckForGBPreview() {
 function searchForGBPreview( isbn ) {
 	dojo.require("dojo.io.script");
 	dojo.io.script.get({"url": "https://www.google.com/jsapi"});
-	dojo.io.script.get({"url": "http://books.google.com/books", "content": { "bibkeys": isbn, "jscmd": "viewapi", "callback": "GBPreviewCallback"}});
+	dojo.io.script.get({"url": "https://www.googleapis.com/books/v1/volumes", "content": { "q": "isbn:" + isbn, "callback": "GBPreviewCallback"}});
 }
 
 /**
@@ -1266,21 +1266,17 @@ function searchForGBPreview( isbn ) {
  * @param {JSON} GBPBookInfo is the JSON object pulled from the Google books service.
  */
 function GBPreviewCallback(GBPBookInfo) {
-	var GBPreviewDiv = document.getElementById("rdetail_preview_div");
-	var GBPBook;
+	if (GBPBookInfo.totalItems < 1) return;
 
-	for ( i in GBPBookInfo ) {
-		GBPBook = GBPBookInfo[i];
-	}
-
-	if ( !GBPBook ) {
+	var accessInfo = GBPBookInfo.items[0].accessInfo;
+	if ( !accessInfo ) {
 		return;
 	}
 
-	if ( GBPBook.preview != "noview" ) {
+	if ( accessInfo.embeddable ) {
 		// Add a button below the book cover image to load the preview.
 		GBPBadge = document.createElement( 'img' );
-		GBPBadge.src = 'http://books.google.com/intl/en/googlebooks/images/gbs_preview_button1.gif';
+		GBPBadge.src = 'https://www.google.com/intl/en/googlebooks/images/gbs_preview_button1.gif';
 		GBPBadge.title = $('rdetail_preview_badge').innerHTML;
 		GBPBadge.style.border = 0;
 		GBPBadgelink = document.createElement( 'a' );
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 c8d510d..d5052d3 100644
--- a/Open-ILS/web/opac/skin/default/js/result_common.js
+++ b/Open-ILS/web/opac/skin/default/js/result_common.js
@@ -428,15 +428,37 @@ function buildunAPISpan (span, type, id) {
 }
 
 function unhideGoogleBooksLink (data) {
-    for ( var i in data ) {
-        //if (data[i].preview == 'noview') continue;
+    for (var i = 0; i < data.items.length; i++) {
+        var item = data.items[i];
+
+        var gbspan;
+        for (var j = 0; j < item.volumeInfo.industryIdentifiers.length; j++) {
+            // XXX: As of 11-17-2011, some items do not return their own ISBN
+            // as an identifier, so this code fails.  For example:
+            // https://www.googleapis.com/books/v1/volumes?q=isbn:0743243560&callback=unhideGoogleBooksLink
+            // It seems the only way around this would be doing a separate
+            // search for each result rather than one search for the whole
+            // page.  Informal testing seems to indicate that these books
+            // are generally Google-unfriendly (no previews, not embeddable),
+            // so we will live without them for now.
+            var ident = item.volumeInfo.industryIdentifiers[j].identifier;
+            gbspan = $n(document.documentElement, 'googleBooksLink-' + ident);
+            if (gbspan) break;
+        }
+        if (!gbspan) continue;
 
-        var gbspan = $n(document.documentElement, 'googleBooksLink-' + i);
         var gba = $n(gbspan, "googleBooks-link");
 
         gba.setAttribute(
             'href',
-            data[i].info_url
+            item.volumeInfo.infoLink
+            // XXX: we might consider constructing the above link ourselves,
+            // as the link provided populates the search box with our original
+            // multi-item search.  Something like:
+            // 'http://books.google.com/books?id=' + item.id
+            // Postive: cleaner display
+            // Negative: more fragile (link format subject to change; likely
+            // enough to matter?)
         );
         removeCSSClass( gbspan, 'hide_me' );
     }
@@ -465,9 +487,13 @@ function resultDisplayRecord(rec, pos, is_mr) {
 
         if (googleBooksLink) {
             var gbspan = $n(r, "googleBooksLink");
+            // Google never has dashes in the ISBN, records sometimes do;
+            // remove them to match results list
+            // XXX: consider making part of cleanISBN(), or we can work around
+            // this if we move to one request per record
             gbspan.setAttribute(
                 'name',
-                gbspan.getAttribute('name') + '-' + currentISBN
+                gbspan.getAttribute('name') + '-' + currentISBN.toString().replace(/-/g,"")
             );
 
         }
@@ -798,8 +824,8 @@ function fetchGoogleBooksLink () {
         var scriptElement = document.createElement("script");
         scriptElement.setAttribute("id", "jsonScript");
         scriptElement.setAttribute("src",
-            "http://books.google.com/books?bibkeys=" + 
-            escape(isbnList.join(', ')) + "&jscmd=viewapi&callback=unhideGoogleBooksLink");
+            "https://www.googleapis.com/books/v1/volumes?q=" +
+            escape('isbn:' + isbnList.join(' | isbn:')) + "&callback=unhideGoogleBooksLink");
         scriptElement.setAttribute("type", "text/javascript");
         // make the request to Google Book Search
         document.documentElement.firstChild.appendChild(scriptElement);

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

Summary of changes:
 Open-ILS/web/opac/skin/default/js/rdetail.js       |   16 +++-----
 Open-ILS/web/opac/skin/default/js/result_common.js |   40 ++++++++++++++++---
 2 files changed, 39 insertions(+), 17 deletions(-)


hooks/post-receive
-- 
Evergreen ILS


More information about the open-ils-commits mailing list