src/xAC.php
public function call($endpoint, $method = 'GET', array $data = [])
    {
        if (substr($endpoint, -1) == '/') {
            $endpoint = substr($endpoint, 0, strlen($endpoint)-1);
        }
        
        self::log("Calling $method /api/$endpoint");
            
        $params = [
            'headers'=> [
                'Accept'     => sprintf('application/vnd.xac.v%d+json', self::$apiVersion),
                'AC-API-KEY' => self::$apiKey,
            ],
        ];
        
        if (count($data) > 0) {
            $params['json'] = $data;
        }
        
        try {
            $this->initTransport();
            
            $res = $this->transport->request($method, $endpoint, $params);
        } catch (ConnectException $e) {
            self::log($e->getMessage(), Logger::ERROR);
            throw new \Exception($e->getMessage());
        
        } catch (ServerException $e) {
            $response = json_decode((string) $e->getResponse()->getBody(), true);
            self::$lastResponse = $response['ACResponse'];
            self::$lastResponse['httpCode'] = $e->getResponse()->getStatusCode();
            self::log($e->getMessage(), Logger::ERROR);
            throw new \Exception(self::$lastResponse['message']);
        
        } catch (ClientException $e) {
            $response = json_decode((string) $e->getResponse()->getBody(), true);
            self::$lastResponse = $response['ACResponse'];
            self::$lastResponse['httpCode'] = $e->getResponse()->getStatusCode();
            self::log($e->getMessage(), Logger::ERROR);
            throw new \Exception(self::$lastResponse['message']);
             
        } finally {
            if (isset($res)) {
                $response = json_decode((string) $res->getBody(), !self::$returnObject);
                $response = $response['ACResponse'];
            }
        }
        
        self::$lastResponse = $response;
        
        return $response['body']['data'];
    }
public function call($endpoint, $method = 'GET', array $data = [])
    {
        if (substr($endpoint, -1) == '/') {
            $endpoint = substr($endpoint, 0, strlen($endpoint)-1);
        }
        
        self::log("Calling $method /api/$endpoint");
            
        $params = [
            'headers'=> [
                'Accept'     => sprintf('application/vnd.xac.v%d+json', self::$apiVersion),
                'AC-API-KEY' => self::$apiKey,
            ],
        ];
        
        if (count($data) > 0) {
            $params['json'] = $data;
        }
        
        try {
            $this->initTransport();
            
            $res = $this->transport->request($method, $endpoint, $params);
        } catch (ConnectException $e) {
            self::log($e->getMessage(), Logger::ERROR);
            throw new \Exception($e->getMessage());
        
        } catch (ServerException $e) {
            $response = json_decode((string) $e->getResponse()->getBody(), true);
            self::$lastResponse = $response['ACResponse'];
            self::$lastResponse['httpCode'] = $e->getResponse()->getStatusCode();
            self::log($e->getMessage(), Logger::ERROR);
            throw new \Exception(self::$lastResponse['message']);
        
        } catch (ClientException $e) {
            $response = json_decode((string) $e->getResponse()->getBody(), true);
            self::$lastResponse = $response['ACResponse'];
            self::$lastResponse['httpCode'] = $e->getResponse()->getStatusCode();
            self::log($e->getMessage(), Logger::ERROR);
            throw new \Exception(self::$lastResponse['message']);
             
        } finally {
            if (isset($res)) {
                $response = json_decode((string) $res->getBody(), !self::$returnObject);
                $response = $response['ACResponse'];
            }
        }
        
        self::$lastResponse = $response;
        
        return $response['body']['data'];
    }
public function call ( $ endpoint , $ method = 'GET' , array $ data = [ ] ) { if ( substr ( $ endpoint , - 1 ) == '/' ) { $ endpoint = substr ( $ endpoint , 0 , strlen ( $ endpoint ) - 1 ) ; } self :: log ( "Calling $method /api/$endpoint" ) ; $ params = [ 'headers' => [ 'Accept' => sprintf ( 'application/vnd.xac.v%d+json' , self :: $ apiVersion ) , 'AC-API-KEY' => self :: $ apiKey , ] , ] ; if ( count ( $ data ) > 0 ) { $ params [ 'json' ] = $ data ; } try { $ this -> initTransport ( ) ; $ res = $ this -> transport -> request ( $ method , $ endpoint , $ params ) ; } catch ( ConnectException $ e ) { self :: log ( $ e -> getMessage ( ) , Logger :: ERROR ) ; throw new \ Exception ( $ e -> getMessage ( ) ) ; } catch ( ServerException $ e ) { $ response = json_decode ( ( string ) $ e -> getResponse ( ) -> getBody ( ) , true ) ; self :: $ lastResponse = $ response [ 'ACResponse' ] ; self :: $ lastResponse [ 'httpCode' ] = $ e -> getResponse ( ) -> getStatusCode ( ) ; self :: log ( $ e -> getMessage ( ) , Logger :: ERROR ) ; throw new \ Exception ( self :: $ lastResponse [ 'message' ] ) ; } catch ( ClientException $ e ) { $ response = json_decode ( ( string ) $ e -> getResponse ( ) -> getBody ( ) , true ) ; self :: $ lastResponse = $ response [ 'ACResponse' ] ; self :: $ lastResponse [ 'httpCode' ] = $ e -> getResponse ( ) -> getStatusCode ( ) ; self :: log ( $ e -> getMessage ( ) , Logger :: ERROR ) ; throw new \ Exception ( self :: $ lastResponse [ 'message' ] ) ; } finally { if ( isset ( $ res ) ) { $ response = json_decode ( ( string ) $ res -> getBody ( ) , ! self :: $ returnObject ) ; $ response = $ response [ 'ACResponse' ] ; } } self :: $ lastResponse = $ response ; return $ response [ 'body' ] [ 'data' ] ; }
Make a HTTP Request and return response
@param string $endpoint
@param string $method
@param array  $data
@throws \Exception
@return array
Make a HTTP Request and return response