From 2355ee98b0e887009e0dbd79865c9d976df5e583 Mon Sep 17 00:00:00 2001 From: pbarroca <pbarroca@afi-sa.fr> Date: Fri, 10 Jul 2015 09:59:39 +0200 Subject: [PATCH] rel #27067 : refacto + version file --- VERSIONS_WIP/27067 | 1 + .../WebService/SIGB/AbstractRESTService.php | 30 ++++++++++++------- 2 files changed, 21 insertions(+), 10 deletions(-) create mode 100644 VERSIONS_WIP/27067 diff --git a/VERSIONS_WIP/27067 b/VERSIONS_WIP/27067 new file mode 100644 index 00000000000..4266f52e993 --- /dev/null +++ b/VERSIONS_WIP/27067 @@ -0,0 +1 @@ + - ticket #27067 : Koha : Webservice de création des suggestions \ No newline at end of file diff --git a/library/Class/WebService/SIGB/AbstractRESTService.php b/library/Class/WebService/SIGB/AbstractRESTService.php index 4ccaad37fc3..c315f04f551 100644 --- a/library/Class/WebService/SIGB/AbstractRESTService.php +++ b/library/Class/WebService/SIGB/AbstractRESTService.php @@ -80,15 +80,11 @@ abstract class Class_WebService_SIGB_AbstractRESTService extends Class_WebServic * @return string */ public function httpGet($options) { - $url = $this->buildQueryURL($options); - try { - $response = $this->getWebClient()->open_url($url); - $this->log(); - return $response; - } catch (Exception $e) { - $this->logError($url, $e->getMessage()); - return ''; - } + $closure = function($client, $url) { + return $client->open_url($url); + }; + + return $this->_withClientDo($options, $closure); } @@ -98,9 +94,23 @@ abstract class Class_WebService_SIGB_AbstractRESTService extends Class_WebServic * @return string response body */ public function httpPost($options, $datas) { + $closure = function($client, $url) use ($datas) { + return $client->postData($url, $datas); + }; + + return $this->_withClientDo($options, $closure); + } + + + /** + * @param $options array url query part + * @param $closure + * @return response body + */ + protected function _withClientDo($options, $closure) { $url = $this->buildQueryURL($options); try { - $response = $this->getWebClient()->postData($url, $datas); + $response = $closure($this->getWebClient(), $url); $this->log(); return $response; } catch (Exception $e) { -- GitLab