From ca3ac134daa61818372d1fabe50fa70c68858136 Mon Sep 17 00:00:00 2001 From: Fawwaz Anugrah Wiradhika Dharmasatya <13520086.std.stei.itb.ac.id> Date: Mon, 28 Nov 2022 10:23:14 +0700 Subject: [PATCH] refactor: change fetching to using libry --- Controller/SubsciberController.php | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/Controller/SubsciberController.php b/Controller/SubsciberController.php index 682dcda..2b408d8 100644 --- a/Controller/SubsciberController.php +++ b/Controller/SubsciberController.php @@ -7,6 +7,7 @@ use Lib\Enums\Request\HttpStatus; use Lib\Interfaces\Routing\IRequest; use Lib\Interfaces\Routing\IResponse; use Model\Relations\Subscription; +use Lib\Service\Api\FetchAPI; class SubsciberController { static function setStatus(IRequest $req, IResponse $res) { @@ -140,20 +141,17 @@ class SubsciberController { } static function fetchSubscriptions(int $user_id,$db){ - $host = getenv("REST_HOST"); + $fetcher = new FetchAPI(getenv("REST_HOST")); + $param = [ + "page"=>1, + "limit"=>10 + ]; $rest_key = getenv("REST_KEY"); - $ch = curl_init("$host/singers?page=1&limit=10"); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); - curl_setopt( $ch , CURLOPT_RETURNTRANSFER, true); - curl_setopt( $ch , CURLOPT_SSL_VERIFYPEER, false); - curl_setopt( $ch , CURLOPT_SSL_VERIFYHOST, false); - curl_setopt( $ch , CURLOPT_TIMEOUT, 10000); - curl_setopt($ch, CURLOPT_HTTPHEADER, array( - "X-API-KEY: $rest_key" - )); - - $output = curl_exec($ch); - curl_close($ch); + $headers = [ + "X-API-KEY"=> $rest_key + ]; + $output = $fetcher->get("/singers",$param,$headers); + if(!$output){ return false; } -- GitLab