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 = []){
|
private function makeRequest($method , $path , $request_body = []){
|
||||||
if($this->isLogged()) {
|
if(!$this->isLogged()) {
|
||||||
$url = NANO_SANTE_SERVICE_URL.$path;
|
return json_encode(['status' => 500]);
|
||||||
$ch = curl_init($url);
|
}
|
||||||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
|
|
||||||
/* set the content type json */
|
$url = NANO_SANTE_SERVICE_URL.$path;
|
||||||
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
|
$ch = curl_init($url);
|
||||||
'Content-Type:application/json',
|
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
|
||||||
'Authorization:'.NANO_SANTE_SERVICE_TOKEN,
|
/* set the content type json */
|
||||||
'X-localization:'. $this->session->userdata('site_lang') == 'french' ? 'fr' : 'en'
|
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
|
||||||
));
|
'Content-Type:application/json',
|
||||||
/* set return type json */
|
'Authorization:'.NANO_SANTE_SERVICE_TOKEN,
|
||||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
'X-localization:'. $this->session->userdata('site_lang') == 'french' ? 'fr' : 'en'
|
||||||
$body = new \stdClass();
|
));
|
||||||
foreach ($request_body as $key => $value){
|
/* set return type json */
|
||||||
$body->{$key} = $value;
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||||
}
|
$body = new \stdClass();
|
||||||
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($body));
|
foreach ($request_body as $key => $value){
|
||||||
|
$body->{$key} = $value;
|
||||||
/* execute request */
|
}
|
||||||
$result = curl_exec($ch);
|
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($body));
|
||||||
/* close cURL resource */
|
|
||||||
curl_close($ch);
|
/* execute request */
|
||||||
|
$result = curl_exec($ch);
|
||||||
if ($result) {
|
/* close cURL resource */
|
||||||
return $result;
|
curl_close($ch);
|
||||||
}
|
|
||||||
|
if ($result) {
|
||||||
|
return $result;
|
||||||
|
}else{
|
||||||
|
return json_encode(['status' => 500]);
|
||||||
}
|
}
|
||||||
return json_encode(['status' => 500]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function storeExclusions(){
|
public function storeExclusions(){
|
||||||
|
|
Loading…
Reference in New Issue