added a basic Amazon plugin so that new installs can use this module by default for...
authorerickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 30 Aug 2007 12:56:54 +0000 (12:56 +0000)
committererickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 30 Aug 2007 12:56:54 +0000 (12:56 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@7750 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/examples/opensrf.xml.example
Open-ILS/src/perlmods/OpenILS/WWW/AddedContent/Amazon.pm [new file with mode: 0644]

index 30ec0ed..cbfe6a2 100644 (file)
@@ -135,15 +135,38 @@ Example opensrf config file for OpenILS
 
 
         <added_content>
-            <!-- configure an added content plugin -->
-            <!--
-            <module>OpenILS::WWW::AddedContent::MY_MODULE</module>
-            <userid>MY_USER_ID</userid>
-            <base_url>MY_BASE_URL</base_url>
-            <timeout>2</timeout>
+
+            <!-- XXX If you use the Amazon plugin, you must link back to Amazon in the OPAC -->
+
+            <!-- load the Amazon added content module -->
+            <module>OpenILS::WWW::AddedContent::Amazon</module>
+            <!-- Base URL for Amazon added content fetching.  This URL may
+                need to be shortened when new (read: non-image) content 
+                fetching capabilities are added -->
+            <base_url>http://images.amazon.com/images/P/</base_url>
+
+            <!-- Max number of seconds to wait for an added content request to 
+                return data.  Data not returned within the timeout is considered
+                a failure -->
+            <timeout>4</timeout>
+
+            <!-- After added content lookups have been disabled due to too many
+                lookup failures, this is the amount of time to wait before
+                we try again -->
             <retry_timeout>600</retry_timeout>
-            <max_errors>5</max_errors>
+
+            <!-- maximum number of consecutive lookup errors a given process can 
+                have before added content lookups are disabled for everyone -->
+            <max_errors>4</max_errors>
+
+            <!-- If a userid is required to access the added content.. -->
+            <userid>MY_USER_ID</userid>
+
+            <!--
+                You can add free-form settings here and they will be accessible
+                within the added content module
             -->
+
         </added_content>
 
 
diff --git a/Open-ILS/src/perlmods/OpenILS/WWW/AddedContent/Amazon.pm b/Open-ILS/src/perlmods/OpenILS/WWW/AddedContent/Amazon.pm
new file mode 100644 (file)
index 0000000..86c19c6
--- /dev/null
@@ -0,0 +1,134 @@
+package OpenILS::WWW::AddedContent::Amazon;
+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;
+
+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('_SCMZZZZZZZ_.jpg', $key));
+}
+
+sub jacket_medium {
+    my( $self, $key ) = @_;
+    return $self->send_img(
+        $self->fetch_response('_SCMZZZZZZZ_.jpg', $key));
+
+}
+sub jacket_large {
+    my( $self, $key ) = @_;
+    return $self->send_img(
+        $self->fetch_response('_SCZZZZZZZ_.jpg', $key));
+}
+
+# --------------------------------------------------------------------------
+
+sub toc_html {
+    my( $self, $key ) = @_;
+}
+
+sub toc_xml {
+    my( $self, $key ) = @_;
+}
+
+sub toc_json {
+    my( $self, $key ) = @_;
+}
+
+# --------------------------------------------------------------------------
+
+sub anotes_html {
+    my( $self, $key ) = @_;
+}
+
+sub anotes_xml {
+    my( $self, $key ) = @_;
+}
+
+sub anotes_json {
+    my( $self, $key ) = @_;
+}
+
+
+# --------------------------------------------------------------------------
+
+sub excerpt_html {
+    my( $self, $key ) = @_;
+}
+
+sub excerpt_xml {
+    my( $self, $key ) = @_;
+}
+
+sub excerpt_json {
+    my( $self, $key ) = @_;
+}
+
+# --------------------------------------------------------------------------
+
+sub reviews_html {
+    my( $self, $key ) = @_;
+}
+
+# we have to aggregate the reviews
+sub reviews_xml {
+    my( $self, $key ) = @_;
+}
+
+
+sub reviews_json {
+    my( $self, $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.01.$page";
+    return $AC->get_url($url);
+}
+
+
+
+1;