From eca79fcabbfd3540b3d757e0469decd96f98e3d8 Mon Sep 17 00:00:00 2001 From: Djery-Tom Date: Wed, 6 Apr 2022 18:19:52 +0100 Subject: [PATCH] Improve make request in nano health controller --- .../controllers/NanoHealthController.php | 57 ++++++++++--------- 1 file changed, 30 insertions(+), 27 deletions(-) diff --git a/application/controllers/NanoHealthController.php b/application/controllers/NanoHealthController.php index 7975a7a7..29c1a7fc 100644 --- a/application/controllers/NanoHealthController.php +++ b/application/controllers/NanoHealthController.php @@ -409,34 +409,37 @@ class NanoHealthController extends CI_Controller } private function makeRequest($method , $path , $request_body = []){ - if($this->isLogged()) { - $url = NANO_SANTE_SERVICE_URL.$path; - $ch = curl_init($url); - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method); - /* set the content type json */ - curl_setopt($ch, CURLOPT_HTTPHEADER, array( - 'Content-Type:application/json', - 'Authorization:'.NANO_SANTE_SERVICE_TOKEN, - 'X-localization:'. $this->session->userdata('site_lang') == 'french' ? 'fr' : 'en' - )); - /* set return type json */ - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - $body = new \stdClass(); - foreach ($request_body as $key => $value){ - $body->{$key} = $value; - } - curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($body)); - - /* execute request */ - $result = curl_exec($ch); - /* close cURL resource */ - curl_close($ch); - - if ($result) { - return $result; - } + if(!$this->isLogged()) { + return json_encode(['status' => 500]); + } + + $url = NANO_SANTE_SERVICE_URL.$path; + $ch = curl_init($url); + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method); + /* set the content type json */ + curl_setopt($ch, CURLOPT_HTTPHEADER, array( + 'Content-Type:application/json', + 'Authorization:'.NANO_SANTE_SERVICE_TOKEN, + 'X-localization:'. $this->session->userdata('site_lang') == 'french' ? 'fr' : 'en' + )); + /* set return type json */ + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + $body = new \stdClass(); + foreach ($request_body as $key => $value){ + $body->{$key} = $value; + } + curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($body)); + + /* execute request */ + $result = curl_exec($ch); + /* close cURL resource */ + curl_close($ch); + + if ($result) { + return $result; + }else{ + return json_encode(['status' => 500]); } - return json_encode(['status' => 500]); } public function storeExclusions(){