Bug 26673: Fix perlcritic complains
[koha-ffzg.git] / Koha / SharedContent.pm
index d2129d9..7082fe0 100644 (file)
@@ -4,18 +4,18 @@ package Koha::SharedContent;
 #
 # This file is part of Koha.
 #
-# Koha is free software; you can redistribute it and/or modify it under the
-# terms of the GNU General Public License as published by the Free Software
-# Foundation; either version 3 of the License, or (at your option) any later
-# version.
+# Koha is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
 #
-# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
-# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
-# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+# Koha is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
 #
-# You should have received a copy of the GNU General Public License along
-# with Koha; if not, write to the Free Software Foundation, Inc.,
-# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+# You should have received a copy of the GNU General Public License
+# along with Koha; if not, see <http://www.gnu.org/licenses>.
 
 use Modern::Perl;
 use JSON;
@@ -26,15 +26,23 @@ use Koha::Serials;
 use Koha::Reports;
 use C4::Context;
 
-=head1 DESCRIPTION
+=head1 NAME
+
+Koha::SharedContent - Set of methods for querying Mana KB server
 
-Package for accessing shared content via Mana
+=head1 DESCRIPTION
 
-=head2 Package Functions
+Package for accessing shared content via Mana KB. Methods here are intended
+to build and process queries for requesting from Mana KB server.
 
 =cut
 
-=head3 process_request
+=head2 process_request
+
+Koha::SharedContent::process_request($request);
+
+Send a request to Mana KB server. URL is defined in koha-conf.xml in mana_config
+tag. $request parameter must be a HTTP::Request object. See build_request method.
 
 =cut
 
@@ -50,15 +58,7 @@ sub process_request {
         $mana_request->content( to_json($content) );
     }
 
-    my $response = $userAgent->request($mana_request);
-
-    if ( $response->code != 200 ) {
-        return {
-            code => $response->code,
-            msg  => $response->message,
-        };
-    }
-
+    my $response = $userAgent->simple_request($mana_request);
     eval { $result = from_json( $response->decoded_content, { utf8 => 1} ); };
     $result->{code} = $response->code;
     if ( $@ ){
@@ -70,7 +70,12 @@ sub process_request {
     return $result ;
 }
 
-=head3 increment_entity_value
+=head2 increment_entity_value
+
+Koha::SharedContent::increment_entity_value($entity_type, $mana_entity_id, $field);
+
+Increment by 1 the field $field of a Mana entity. I.e, this is used to count the number
+of Koha instances using a specific entity.
 
 =cut
 
@@ -78,16 +83,18 @@ sub increment_entity_value {
     return process_request(build_request('increment', @_));
 }
 
-=head3 send_entity
+=head2 send_entity
+
+my $result = Koha::SharedContent::send_entity($language, $borrowernumber, $mana_entity_id, $entity_type);
+
+Share a Koha entity (i.e subscription or report) to Mana KB.
 
 =cut
 
 sub send_entity {
-    my ($lang, $loggedinuser, $resourceid, $resourcetype, $content) = @_;
+    my ($lang, $loggedinuser, $resourceid, $resourcetype) = @_;
 
-    unless ( $content ) {
-        $content = prepare_entity_data($lang, $loggedinuser, $resourceid, $resourcetype);
-    }
+    my $content = prepare_entity_data($lang, $loggedinuser, $resourceid, $resourcetype);
 
     my $result = process_request(build_request('post', $resourcetype, $content));
 
@@ -99,7 +106,28 @@ sub send_entity {
     return $result;
 }
 
-=head3 prepare_entity_data
+=head3 comment_entity
+
+my $result = Koha::SharedContent::comment_entity($resource_id, $resource_type, $comment);
+
+Send a comment about a Mana entity.
+
+=cut
+
+sub comment_entity {
+    my ($resourceid, $resourcetype, $comment) = @_;
+
+    my $result = process_request(build_request('post', 'resource_comment',
+            { resource_id => $resourceid, resource_type => $resourcetype, message => $comment }));
+
+    return $result;
+}
+
+=head2 prepare_entity_data
+
+$data = prepare_entity_data($language, $borrowernumber, $mana_entity_id, $entity_type);
+
+Prepare Koha entity data to be sent to Mana KB.
 
 =cut
 
@@ -133,7 +161,12 @@ sub prepare_entity_data {
     return $ressource_mana_info;
 }
 
-=head3 get_entity_by_id
+=head2 get_entity_by_id
+
+my $entity = Koha::SharedContent::get_entity_by_id($entity_type, $mana_entity_id, [{usecomments => 1}]);
+
+Retrieve a Mana entity to be imported into Koha. Add {usecomments => 1} to tell Mana to
+embed all user reviews.
 
 =cut
 
@@ -141,7 +174,12 @@ sub get_entity_by_id {
     return process_request(build_request('getwithid', @_));
 }
 
-=head3 search_entities
+=head2 search_entities
+
+my $result = Koha::SharedContent::search_entities( $entity_type, $search_params );
+my $entities = $result->{data};
+
+Search entities on ManaKB.
 
 =cut
 
@@ -149,7 +187,11 @@ sub search_entities {
     return process_request(build_request('get', @_));
 }
 
-=head3 build_request
+=head2 build_request
+
+$request = build_request($mana_method, [$param1, $param2, ...]);
+
+Create a HTTP::Request object to be passed to process_request.
 
 =cut
 
@@ -208,7 +250,11 @@ sub build_request {
     }
 }
 
-=head3 get_sharing_url
+=head2 get_sharing_url
+
+my $mana_url = get_sharing_url();
+
+Get the Mana KB server URL set in koha config file.
 
 =cut