diff --git a/library/Class/WebService/SIGB/AbstractRESTService.php b/library/Class/WebService/SIGB/AbstractRESTService.php index e4d062ab02309a92caa24fbd8324a66cc7d3de88..2d837c636b410baf3ab2681d15d409dc839681a6 100644 --- a/library/Class/WebService/SIGB/AbstractRESTService.php +++ b/library/Class/WebService/SIGB/AbstractRESTService.php @@ -107,21 +107,13 @@ abstract class Class_WebService_SIGB_AbstractRESTService extends Class_WebServic } - /** - * Retourne le nom du tag utilisé pour les messages d'erreurs dans les réponses XML / ILSDI - * @return string - */ - public function ilsdiGetErrorTag() { - return 'error'; - } - /** * @param array $params * @param Class_WebService_SIGB_AbstractILSDIPatronInfoReader $reader * @return Class_WebService_SIGB_Emprunteur */ - public function ilsdiGetPatronInfo($params, $reader) { + public function ilsdiGetPatronInfo($params, $reader, $error_tag='error') { $emprunteur = Class_WebService_SIGB_Emprunteur::newInstance()->setService($this); $params = array_merge(array('service' => 'GetPatronInfo'), $params); @@ -130,7 +122,7 @@ abstract class Class_WebService_SIGB_AbstractRESTService extends Class_WebServic if (0 === strpos($xml, '<html>')) return $emprunteur; - if ($this->_getTagData($xml, $this->ilsdiGetErrorTag())) + if ($this->_getTagData($xml, $error_tag)) return $emprunteur; return $reader @@ -145,54 +137,28 @@ abstract class Class_WebService_SIGB_AbstractRESTService extends Class_WebServic * @return array */ public function ilsdiHoldTitle($params, $error_tag = 'error') { - $params = array_merge(array('service' => 'HoldTitle'), $params); - - try { - $xml = $this->httpGet($params); - } catch (Exception $e) { - return $this->_getNetworkError(); - } - - if (0 === strpos($xml, '<html>')) - return $this->_getNetworkError(); - - if ('' != $this->_getTagData($xml, $this->ilsdiGetErrorTag())) - return $this->_error('Réservation impossible'); - - return $this->_success(); + return $this->ilsdiAction('HoldTitle', $params, $error_tag, 'Réservation impossible'); } - - - /** * @param array $params */ - public function ilsdiCancelHold($params) { - $params = array_merge(array('service' => 'CancelHold'), $params); - - try { - $xml = $this->httpGet($params); - } catch (Exception $e) { - return $this->_getNetworkError(); - } - - if (0 === strpos($xml, '<html>')) - return $this->_getNetworkError(); - - if ('' != $this->_getTagData($xml, 'error')) - return $this->_error('Annulation impossible'); - - return $this->_success(); + public function ilsdiCancelHold($params, $error_tag='error') { + return $this->ilsdiAction('CancelHold', $params, $error_tag, 'Annulation impossible'); } /** * @param array $params */ - public function ilsdiRenewLoan($params) { - $params = array_merge(array('service' => 'RenewLoan'), $params); + public function ilsdiRenewLoan($params, $error_tag='error') { + return $this->ilsdiAction('RenewLoan', $params, $error_tag, 'Prolongation impossible'); + } + + + public function ilsdiAction($name, $params, $error_tag, $error_message) { + $params = array_merge(array('service' => $name), $params); try { $xml = $this->httpGet($params); @@ -203,8 +169,8 @@ abstract class Class_WebService_SIGB_AbstractRESTService extends Class_WebServic if (0 === strpos($xml, '<html>')) return $this->_getNetworkError(); - if ('' != $this->_getTagData($xml, 'error')) - return $this->_error('Prolongation impossible'); + if ('' != $this->_getTagData($xml, $error_tag)) + return $this->_error($error_message); return $this->_success(); } diff --git a/library/Class/WebService/SIGB/Koha/Service.php b/library/Class/WebService/SIGB/Koha/Service.php index ab3974c8a4bc575b9ae799ef749d00ea6f4ba4f4..81cff0dbc7616b3094600c20b4ffdc7f29b35825 100644 --- a/library/Class/WebService/SIGB/Koha/Service.php +++ b/library/Class/WebService/SIGB/Koha/Service.php @@ -56,15 +56,6 @@ class Class_WebService_SIGB_Koha_Service extends Class_WebService_SIGB_AbstractR } - /** - * Retourne le nom du tag utilisé pour les messages d'erreurs dans les réponses XML / ILSDI - * @return string - */ - public function ilsdiGetErrorTag() { - return 'code'; - } - - /** * @param Class_Users $user * @param Class_Exemplaire $exemplaire @@ -108,16 +99,10 @@ class Class_WebService_SIGB_Koha_Service extends Class_WebService_SIGB_AbstractR * @return array */ public function prolongerPret($user, $pret_id) { - $emprunteur_id = $this->_authenticate($user); - - $xml_renew = $this->httpGet(array('service' => 'RenewLoan', - 'patron_id' => $emprunteur_id, - 'item_id' => $pret_id)); - - if (!$this->_getTagData($xml_renew, 'message')) - return $this->_success(); - - return $this->_error('Prolongation impossible'); + return $this->ilsdiRenewLoan(array( + 'patron_id' => $this->_authenticate($user), + 'item_id' => $pret_id), + 'message'); }