[open-ils-commits] r13435 - trunk/Open-ILS/src/perlmods/OpenILS/WWW/AddedContent (erickson)
svn at svn.open-ils.org
svn at svn.open-ils.org
Mon Jun 22 16:45:24 EDT 2009
Author: erickson
Date: 2009-06-22 16:45:20 -0400 (Mon, 22 Jun 2009)
New Revision: 13435
Added:
trunk/Open-ILS/src/perlmods/OpenILS/WWW/AddedContent/OpenLibrary.pm
Log:
Patch from David Christensen to add support for fetching jacket images from Open Library:
Hi folks,
At a suggestion from the #OpenILS-Evergreen IRC channel, I'm putting this out there :-)
This is a patch to /openils/lib/perl5/OpenILS/WWW/AddedContent/Amazon.pm (it probably makes sense if it were to end up as OpenLibrary.pm, or some such) that enables getting book cover images from OpenLibrary (see http://openlibrary.org/dev/docs/api/covers for details on the OpenLibrary API).
A little comment section at the top shows the two changes that need to be made to opensrf.xml as well.
-David
Developer's Certificate of Origin 1.1
By making a contribution to this project, I certify that:
(a) The contribution was created in whole or in part by me and I
have the right to submit it under the open source license
indicated in the file; or
(b) The contribution is based upon previous work that, to the best
of my knowledge, is covered under an appropriate open source
license and I have the right under that license to submit that
work with modifications, whether created in whole or in part
by me, under the same open source license (unless I am
permitted to submit under a different license), as indicated
in the file; or
(c) The contribution was provided directly to me by some other
person who certified (a), (b) or (c) and I have not modified
it.
(d) I understand and agree that this project and the contribution
are public and that a record of the contribution (including all
personal information I submit with it, including my sign-off) is
maintained indefinitely and may be redistributed consistent with
this project or the open source license(s) involved.
Signed-off-by: David.A.Christensen at gmail.com
Added: trunk/Open-ILS/src/perlmods/OpenILS/WWW/AddedContent/OpenLibrary.pm
===================================================================
--- trunk/Open-ILS/src/perlmods/OpenILS/WWW/AddedContent/OpenLibrary.pm (rev 0)
+++ trunk/Open-ILS/src/perlmods/OpenILS/WWW/AddedContent/OpenLibrary.pm 2009-06-22 20:45:20 UTC (rev 13435)
@@ -0,0 +1,82 @@
+package OpenILS::WWW::AddedContent::OpenLibrary;
+use strict; use warnings;
+use OpenSRF::Utils::Logger qw/$logger/;
+use OpenSRF::Utils::SettingsParser;
+use OpenILS::WWW::AddedContent;
+use OpenSRF::Utils::JSON;
+use OpenSRF::EX qw/:try/;
+use XML::LibXML;
+
+# Edit the <added_content> section of /openils/conf/opensrf.xml
+# Change <module> to:
+# <module>OpenILS::WWW::AddedContent::OpenLibrary</module>
+# Change <base_url> to:
+# <base_url>http://covers.openlibrary.org/b/isbn/</base_url>
+
+
+my $AC = 'OpenILS::WWW::AddedContent';
+
+sub new {
+ my( $class, $args ) = @_;
+ $class = ref $class || $class;
+ return bless($args, $class);
+}
+
+sub base_url {
+ my $self = shift;
+ return $self->{base_url};
+}
+
+sub userid {
+ my $self = shift;
+ return $self->{userid};
+}
+
+
+# --------------------------------------------------------------------------
+sub jacket_small {
+ my( $self, $key ) = @_;
+ return $self->send_img(
+ $self->fetch_response('-S.jpg', $key));
+}
+
+sub jacket_medium {
+ my( $self, $key ) = @_;
+ return $self->send_img(
+ $self->fetch_response('-M.jpg', $key));
+
+}
+sub jacket_large {
+ my( $self, $key ) = @_;
+ return $self->send_img(
+ $self->fetch_response('-L.jpg', $key));
+}
+
+# --------------------------------------------------------------------------
+
+sub send_img {
+ my($self, $response) = @_;
+ return {
+ content_type => $response->header('Content-type'),
+ content => $response->content,
+ binary => 1
+ };
+}
+
+# returns the raw content returned from the URL fetch
+sub fetch_content {
+ my( $self, $page, $key ) = @_;
+ return $self->fetch_response($page, $key)->content;
+}
+
+# returns the HTTP response object from the URL fetch
+sub fetch_response {
+ my( $self, $page, $key ) = @_;
+ my $uname = $self->userid;
+ my $url = $self->base_url . "$key$page";
+ return $AC->get_url($url);
+}
+
+
+
+1;
More information about the open-ils-commits
mailing list