Skip to content
Snippets Groups Projects
Commit 4979e474 authored by Kenneth Ezekiel's avatar Kenneth Ezekiel
Browse files

add: try to call REST

parent 61228cfe
No related merge requests found
......@@ -43,6 +43,40 @@ class UserRepository extends BaseRepository
$user = $this->getById($user_id);
$userModel = new UserModel();
$userModel->constructFromArray($user);
$this->CallAPI("deleteURL", getenv('rest_url') . "/user/{$user_id}", ["user_id" => $user_id]);
return $this->delete($userModel);
}
// Method: POST, PUT, GET etc
// Data: array("param" => "value") ==> index.php?param=value
function CallAPI($method, $url, $data = [])
{
$curl = curl_init();
switch ($method) {
case "POST":
curl_setopt($curl, CURLOPT_POST, 1);
if ($data)
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
break;
case "PUT":
curl_setopt($curl, CURLOPT_PUT, 1);
break;
default:
if ($data)
$url = sprintf("%s?%s", $url, http_build_query($data));
}
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($curl);
curl_close($curl);
return $result;
}
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment