<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Api extends CI_Model
{


    private static $db;

    function __construct(){
        parent::__construct();

self::$db = &get_instance()->db;



    }

    static function curlGet($Apikey,$requestUrl, $method = "GET")
    {
        try {
            $curl = curl_init();

            curl_setopt_array($curl, array(
                CURLOPT_URL => config_item('apiAddress').$requestUrl,
                CURLOPT_RETURNTRANSFER => true,
                CURLOPT_ENCODING => "",
                CURLOPT_MAXREDIRS => 10,
                //CURLOPT_TIMEOUT => 0,
                CURLOPT_FOLLOWLOCATION => true,
                CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
                CURLOPT_CUSTOMREQUEST => $method,
                CURLOPT_HTTPHEADER => array(
                    "Apikey: " . $Apikey,
                    "Content-Type: application/json"
                ),
            ));
            $response = curl_exec($curl);
            curl_close($curl);
            return $response;


        } catch (\Exception  $e) {
            return (object)['status' => false, 'errorCode' => $e->getCode(), 'errorDescription' => $e->getMessage()];
        }
    }

    static function curlPost($Apikey,$requestUrl, $method = "POST", $data)
    {
//echo config_item('apiAddress').$requestUrl;
        try {
            $curl = curl_init();

            curl_setopt_array($curl, array(
                CURLOPT_URL => config_item('apiAddress').$requestUrl,
                CURLOPT_RETURNTRANSFER => true,
                CURLOPT_ENCODING => "",
                CURLOPT_MAXREDIRS => 10,
                CURLOPT_TIMEOUT => 0,
                CURLOPT_FOLLOWLOCATION => true,
                CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
                CURLOPT_CUSTOMREQUEST => $method,
                CURLOPT_POSTFIELDS => json_encode($data),
                CURLOPT_HTTPHEADER => array(
                    "Apikey: " . $Apikey,
                    "Accept: application/json",
                    "Accept-Encoding: gzip",
                    "Content-Type: application/json"
                ),
            ));

            $response = curl_exec($curl);

            curl_close($curl);
            return $response;


        } catch (\Exception  $e) {
            return (object)['status' => false, 'errorCode' => $e->getCode(), 'errorDescription' => $e->getMessage()];
        }
    }

}

/* End of file Genel.php */

