preliminary added content code
authorerickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 17 Nov 2005 23:18:33 +0000 (23:18 +0000)
committererickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 17 Nov 2005 23:18:33 +0000 (23:18 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@2063 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/perlmods/OpenILS/Application/Search/AddedContent.pm [new file with mode: 0644]

diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Search/AddedContent.pm b/Open-ILS/src/perlmods/OpenILS/Application/Search/AddedContent.pm
new file mode 100644 (file)
index 0000000..d5a361e
--- /dev/null
@@ -0,0 +1,92 @@
+package OpenILS::Application::Search::AddedContent;
+use base qw/OpenSRF::Application/;
+use strict; use warnings;
+use OpenILS::Application::AppUtils;
+use OpenSRF::Utils::SettingsClient;
+my $apputils = "OpenILS::Application::AppUtils";
+use XML::LibXML;
+use LWP::UserAgent;
+use OpenSRF::EX qw(:try);
+
+
+my $host;
+my $username;
+my $password;
+my $urlbase = "ContentCafe";
+my $types = {
+       toc                     => "TOC.asmx",
+       review          => "Review.asmx",
+       annotation      => "Annotation.asmx",
+       };
+
+sub initialize {
+       my $conf = OpenSRF::Utils::SettingsClient->new;
+       $host = $conf->config_value(                                    
+               "apps", "open-ils.search","app_settings", "added_content", "host");
+       $username = $conf->config_value(                                        
+               "apps", "open-ils.search","app_settings", "added_content", "username");
+       $password = $conf->config_value(                                        
+               "apps", "open-ils.search","app_settings", "added_content", "password");
+}
+
+
+
+__PACKAGE__->register_method(
+       method  => "added_content",
+       api_name        => "open-ils.search.added_content.retrieve",
+       notes           => <<"  NOTE");
+               Returns a list values based on the added content type. 
+               types include: toc, review, annotation
+               PARAMS( ISBN ),
+       NOTE
+
+sub added_content {
+       my( $self, $client, $isbn, $type ) = @_;
+
+       my $url = "$host/$urlbase/" . $types->{$type} . 
+               "/fnDetailByItemKey?UserId=$username&Password=$password&ItemKey=$isbn";
+
+       warn "Added Content URL: $url\n";
+
+       my $data;
+       try {
+               alarm(15);
+               $data = LWP::UserAgent->new->get($url)->content;
+               alarm(0);
+       } catch Error with {
+               alarm(0);
+               $data = [];
+       };
+       alarm(0);
+
+       warn "received content data:\n$data\n";
+
+       return $data if(ref($data));
+
+       return _parse_content($type, $data);
+}
+
+sub _parse_content {
+       my( $type, $data ) = @_;
+
+       my $doc = XML::LibXML->new->parse_string($data);
+       my $ret = [];
+       return $ret unless $doc;
+
+       if( $type eq "review" ) {
+
+               warn '-'x50 . "\n";
+               warn $doc->toString(1) . "\n";
+               warn '-'x50 . "\n";
+
+               my $nodelist = $doc->findnodes("//*[local-name()='ReviewText']");
+               for my $rev ( $nodelist->get_nodelist() ) {
+                       push( @$ret, $rev->textContent );
+               }
+       }
+
+       return $ret;
+}
+
+
+1;