Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Api {
- private $authApi;
- private $logger;
- function __construct()
- {
- global $_AUTH_API;
- $this->authApi = $_AUTH_API;
- $this->logger = new CustomLogs();
- }
- public function getBrands()
- {
- $options = [
- 'request' => 'get_brands',
- ];
- $brands = $this->requestApi($options);
- return $brands->rows;
- }
- public function get****() {}
- /**
- * @param $data
- *
- * @return array|mixed|object
- * @throws Exception
- */
- private function requestApi($data)
- {
- $data = $this->authApi + $data;
- $data = [
- 'data' => json_encode($data)
- ];
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, "https://api.com/api/");
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,FALSE);
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,2);
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
- $answer = json_decode(curl_exec($ch));
- curl_close($ch);
- if (empty($answer)) {
- $this->logger->log->error('Empty answer from API');
- throw new Exception('Empty answer from API');
- } else {
- if ($answer->success != true) {
- $this->logger->log->error('API error: ', (array) $answer );
- throw new Exception('API error: ' . $answer->message );
- } else {
- return $answer;
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment