Improve make request in nano health controller
This commit is contained in:
parent
bf82aea154
commit
eca79fcabb
|
@ -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(){
|
||||
|
|
Loading…
Reference in New Issue