]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/perlmods/OpenILS/Application/Search/AddedContent.pm
d5a361edfa3b086a3ae0455a9e0bdd478d0ec990
[Evergreen.git] / Open-ILS / src / perlmods / OpenILS / Application / Search / AddedContent.pm
1 package OpenILS::Application::Search::AddedContent;
2 use base qw/OpenSRF::Application/;
3 use strict; use warnings;
4 use OpenILS::Application::AppUtils;
5 use OpenSRF::Utils::SettingsClient;
6 my $apputils = "OpenILS::Application::AppUtils";
7 use XML::LibXML;
8 use LWP::UserAgent;
9 use OpenSRF::EX qw(:try);
10
11
12 my $host;
13 my $username;
14 my $password;
15 my $urlbase = "ContentCafe";
16 my $types = {
17         toc                     => "TOC.asmx",
18         review          => "Review.asmx",
19         annotation      => "Annotation.asmx",
20         };
21
22 sub initialize {
23         my $conf = OpenSRF::Utils::SettingsClient->new;
24         $host = $conf->config_value(                                    
25                 "apps", "open-ils.search","app_settings", "added_content", "host");
26         $username = $conf->config_value(                                        
27                 "apps", "open-ils.search","app_settings", "added_content", "username");
28         $password = $conf->config_value(                                        
29                 "apps", "open-ils.search","app_settings", "added_content", "password");
30 }
31
32
33
34 __PACKAGE__->register_method(
35         method  => "added_content",
36         api_name        => "open-ils.search.added_content.retrieve",
37         notes           => <<"  NOTE");
38                 Returns a list values based on the added content type. 
39                 types include: toc, review, annotation
40                 PARAMS( ISBN ),
41         NOTE
42
43 sub added_content {
44         my( $self, $client, $isbn, $type ) = @_;
45
46         my $url = "$host/$urlbase/" . $types->{$type} . 
47                 "/fnDetailByItemKey?UserId=$username&Password=$password&ItemKey=$isbn";
48
49         warn "Added Content URL: $url\n";
50
51         my $data;
52         try {
53                 alarm(15);
54                 $data = LWP::UserAgent->new->get($url)->content;
55                 alarm(0);
56         } catch Error with {
57                 alarm(0);
58                 $data = [];
59         };
60         alarm(0);
61
62         warn "received content data:\n$data\n";
63
64         return $data if(ref($data));
65
66         return _parse_content($type, $data);
67 }
68
69 sub _parse_content {
70         my( $type, $data ) = @_;
71
72         my $doc = XML::LibXML->new->parse_string($data);
73         my $ret = [];
74         return $ret unless $doc;
75
76         if( $type eq "review" ) {
77
78                 warn '-'x50 . "\n";
79                 warn $doc->toString(1) . "\n";
80                 warn '-'x50 . "\n";
81
82                 my $nodelist = $doc->findnodes("//*[local-name()='ReviewText']");
83                 for my $rev ( $nodelist->get_nodelist() ) {
84                         push( @$ret, $rev->textContent );
85                 }
86         }
87
88         return $ret;
89 }
90
91
92 1;