1 package C4::External::Syndetics;
2 # Copyright (C) 2006 LibLime
3 # <jmf at liblime dot com>
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along with
17 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
18 # Suite 330, Boston, MA 02111-1307 USA
23 use HTTP::Request::Common;
28 use vars qw($VERSION @ISA @EXPORT);
35 &get_syndetics_summary
37 &get_syndetics_editions
38 &get_syndetics_excerpt
39 &get_syndetics_reviews
45 C4::External::Syndetics - Functions for retrieving Syndetics content in Koha
49 This module provides facilities for retrieving Syndetics.com content in Koha
51 =head2 get_syndetics_summary
55 my $syndetics_summary= &get_syndetics_summary( $xisbn );
59 Get Summary data from Syndetics
63 sub get_syndetics_summary {
67 $isbn = _normalize_match_point ($isbn);
69 # grab the AWSAccessKeyId: mine is '0V5RRRRJZ3HR2RQFNHR2'
70 my $syndetics_client_code = C4::Context->preference('SyndeticsClientCode');
72 my $url = "http://syndetics.com/index.aspx?isbn=$isbn/SUMMARY.XML&client=$syndetics_client_code&type=xw10";
73 my $ua = LWP::UserAgent->new;
76 my $response = $ua->get($url);
77 unless ($response->content_type =~ /xml/) {
81 my $content = $response->content;
83 warn "could not retrieve $url" unless $content;
84 my $xmlsimple = XML::Simple->new();
85 $response = $xmlsimple->XMLin(
87 forcearray => [ qw(Fld520) ],
89 # manipulate response USMARC VarFlds VarDFlds Notes Fld520 a
91 $summary = \@{$response->{VarFlds}->{VarDFlds}->{Notes}->{Fld520}} if $response;
92 return $summary if $summary;
95 sub get_syndetics_toc {
99 $isbn = _normalize_match_point ($isbn);
101 # grab the AWSAccessKeyId: mine is '0V5RRRRJZ3HR2RQFNHR2'
102 my $syndetics_client_code = C4::Context->preference('SyndeticsClientCode');
104 my $url = "http://syndetics.com/index.aspx?isbn=$isbn/TOC.XML&client=$syndetics_client_code&type=xw10";
105 my $ua = LWP::UserAgent->new;
109 my $response = $ua->get($url);
110 unless ($response->content_type =~ /xml/) {
114 my $content = $response->content;
115 warn "could not retrieve $url" unless $content;
116 my $xmlsimple = XML::Simple->new();
117 $response = $xmlsimple->XMLin(
119 forcearray => [ qw(Fld970) ],
121 # manipulate response USMARC VarFlds VarDFlds Notes Fld520 a
123 $toc = \@{$response->{VarFlds}->{VarDFlds}->{SSIFlds}->{Fld970}} if $response;
127 sub get_syndetics_excerpt {
131 $isbn = _normalize_match_point ($isbn);
133 # grab the AWSAccessKeyId: mine is '0V5RRRRJZ3HR2RQFNHR2'
134 my $syndetics_client_code = C4::Context->preference('SyndeticsClientCode');
136 my $url = "http://syndetics.com/index.aspx?isbn=$isbn/DBCHAPTER.XML&client=$syndetics_client_code&type=xw10";
137 my $ua = LWP::UserAgent->new;
140 my $response = $ua->get($url);
141 unless ($response->content_type =~ /xml/) {
145 my $content = $response->content;
146 warn "could not retrieve $url" unless $content;
147 my $xmlsimple = XML::Simple->new();
148 $response = $xmlsimple->XMLin(
150 forcearray => [ qw(Fld520) ],
152 # manipulate response USMARC VarFlds VarDFlds Notes Fld520 a
154 $excerpt = \@{$response->{VarFlds}->{VarDFlds}->{Notes}->{Fld520}} if $response;
155 return XMLout($excerpt) if $excerpt;
158 sub get_syndetics_reviews {
162 $isbn = _normalize_match_point ($isbn);
164 # grab the AWSAccessKeyId: mine is '0V5RRRRJZ3HR2RQFNHR2'
165 my $syndetics_client_code = C4::Context->preference('SyndeticsClientCode');
167 my $review_sources = [
168 {title => 'Library Journal Review', file => 'LJREVIEW.XML'},
169 {title => 'Publishers Weekly Review', file => 'PWREVIEW.XML'},
170 {title => 'School Library Journal Review', file => 'SLJREVIEW.XML'},
171 {title => 'CHOICE Review', file => 'CHREVIEW.XML'},
172 {title => 'Booklist Review', file => 'BLREVIEW.XML'},
173 {title => 'Horn Book Review', file => 'HBREVIEW.XML'},
174 {title => 'Kirkus Book Review', file => 'KIRKREVIEW.XML'},
175 {title => 'Criticas Review', file => 'CRITICASREVIEW.XML'}
178 for my $source (@$review_sources) {
179 my $url = "http://syndetics.com/index.aspx?isbn=$isbn/$source->{file}&client=$syndetics_client_code&type=xw10";
181 my $ua = LWP::UserAgent->new;
185 my $response = $ua->get($url);
186 unless ($response->content_type =~ /xml/) {
190 my $content = $response->content;
191 warn "could not retrieve $url" unless $content;
192 my $xmlsimple = XML::Simple->new();
194 $response = $xmlsimple->XMLin(
196 forcearray => [ qw(Fld520) ],
200 # This particular review deserializes differently
201 if ($source->{file} =~ /BLREVIEW.XML/) {
202 for my $subfield_a (@{$response->{VarFlds}->{VarDFlds}->{Notes}->{Fld520}}) {
204 for my $content (@{$subfield_a->{a}->{content}}) {
205 push @content, {content => $content};
207 push @reviews, {title => $source->{title}, reviews => \@content}; #[ {content => $content} ]};
211 push @reviews, {title => $source->{title}, reviews => \@{$response->{VarFlds}->{VarDFlds}->{Notes}->{Fld520}}} unless $@;
218 sub get_syndetics_editions {
222 $isbn = _normalize_match_point ($isbn);
224 # grab the AWSAccessKeyId: mine is '0V5RRRRJZ3HR2RQFNHR2'
225 my $syndetics_client_code = C4::Context->preference('SyndeticsClientCode');
227 my $url = "http://syndetics.com/index.aspx?isbn=$isbn/FICTION.XML&client=$syndetics_client_code&type=xw10";
228 my $ua = LWP::UserAgent->new;
232 my $response = $ua->get($url);
233 unless ($response->content_type =~ /xml/) {
237 my $content = $response->content;
239 warn "could not retrieve $url" unless $content;
240 my $xmlsimple = XML::Simple->new();
241 $response = $xmlsimple->XMLin(
243 forcearray => [ qw(Fld020) ],
245 # manipulate response USMARC VarFlds VarDFlds Notes Fld520 a
247 $similar_items = \@{$response->{VarFlds}->{VarDFlds}->{NumbCode}->{Fld020}} if $response;
248 return $similar_items if $similar_items;
251 sub _normalize_match_point {
252 my $match_point = shift;
253 (my $normalized_match_point) = $match_point =~ /([\d-]*[X]*)/;
254 $normalized_match_point =~ s/-//g;
256 return $normalized_match_point;
266 Joshua Ferraro <jmf@liblime.com>