From: erickson Date: Mon, 22 Jun 2009 20:45:20 +0000 (+0000) Subject: Patch from David Christensen to add support for fetching jacket images from Open... X-Git-Tag: sprint4-merge-nov22~9783 X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=4eb6e78a4d9d383fff78fc8442c26e7e1631ff03;p=working%2FEvergreen.git 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@gmail.com git-svn-id: svn://svn.open-ils.org/ILS/trunk@13435 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- diff --git a/Open-ILS/src/perlmods/OpenILS/WWW/AddedContent/OpenLibrary.pm b/Open-ILS/src/perlmods/OpenILS/WWW/AddedContent/OpenLibrary.pm new file mode 100644 index 0000000000..e2f1b84407 --- /dev/null +++ b/Open-ILS/src/perlmods/OpenILS/WWW/AddedContent/OpenLibrary.pm @@ -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 section of /openils/conf/opensrf.xml +# Change to: +# OpenILS::WWW::AddedContent::OpenLibrary +# Change to: +# http://covers.openlibrary.org/b/isbn/ + + +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;