public function get($url) {

        $curl = $this->_createCurlHandle();

        // Configure our cURL handle for our GET call
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($curl, CURLOPT_HEADER, true);
        curl_setopt($curl, CURLOPT_POST, 0);
        curl_setopt($curl, CURLOPT_URL, $url);

        // Perform our request and check the response
        $response = curl_exec($curl);
        $code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
        $this->logger->info("Request returned a $code response.");
        $header_size = curl_getinfo($curl, CURLINFO_HEADER_SIZE);
        curl_close($curl);

        // Extract header information from the response
        $headers = [];
        $raw_headers = explode("\n", substr($response, 0, $header_size));
        array_shift($raw_headers);
        foreach ($raw_headers as $header) {
            if (!trim($header)) {
                continue;
            }
            $field = explode(": ", $header);
            $headers[array_shift($field)] = trim(implode(': ', $field));
        }

        // Low level debug output
        foreach ($headers as $header => $value) {
            $this->logger->debug($header . ': ' . $value);
        }
        $body = substr($response, $header_size);
        $this->logger->debug($body);

        // Check our result for unexpected errors
        switch ($code) {
            case 401:
                throw new InvalidCredentialsException("Invalid API key specified.");
            case 400:
                throw new RuntimeException("Bad request. Check the URL you specified for errors.");
            case 404:
                throw new RuntimeException("Unknown endpoint specified. Check the URL you specified for errors.");
            case 429:
                throw new RateLimitExceededException("Ratelimit reached. Please try again in {$headers['Retry-After']} seconds.");
            case 503:
                throw new RuntimeException("Service unavailable. It is possible that your client has been throttled.");
        }

        // Check for unexpected errors
        if ($code != 200 && $code != 204) {
            throw new RuntimeException("Remote server returned an unexpected response: $code");
        }

        $this->logger->info("Response size: " . strlen($body));

        return $body;
    }
public function get($url) {

        $curl = $this->_createCurlHandle();

        // Configure our cURL handle for our GET call
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($curl, CURLOPT_HEADER, true);
        curl_setopt($curl, CURLOPT_POST, 0);
        curl_setopt($curl, CURLOPT_URL, $url);

        // Perform our request and check the response
        $response = curl_exec($curl);
        $code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
        $this->logger->info("Request returned a $code response.");
        $header_size = curl_getinfo($curl, CURLINFO_HEADER_SIZE);
        curl_close($curl);

        // Extract header information from the response
        $headers = [];
        $raw_headers = explode("\n", substr($response, 0, $header_size));
        array_shift($raw_headers);
        foreach ($raw_headers as $header) {
            if (!trim($header)) {
                continue;
            }
            $field = explode(": ", $header);
            $headers[array_shift($field)] = trim(implode(': ', $field));
        }

        // Low level debug output
        foreach ($headers as $header => $value) {
            $this->logger->debug($header . ': ' . $value);
        }
        $body = substr($response, $header_size);
        $this->logger->debug($body);

        // Check our result for unexpected errors
        switch ($code) {
            case 401:
                throw new InvalidCredentialsException("Invalid API key specified.");
            case 400:
                throw new RuntimeException("Bad request. Check the URL you specified for errors.");
            case 404:
                throw new RuntimeException("Unknown endpoint specified. Check the URL you specified for errors.");
            case 429:
                throw new RateLimitExceededException("Ratelimit reached. Please try again in {$headers['Retry-After']} seconds.");
            case 503:
                throw new RuntimeException("Service unavailable. It is possible that your client has been throttled.");
        }

        // Check for unexpected errors
        if ($code != 200 && $code != 204) {
            throw new RuntimeException("Remote server returned an unexpected response: $code");
        }

        $this->logger->info("Response size: " . strlen($body));

        return $body;
    }
public function get ( $ url ) { $ curl = $ this -> _createCurlHandle ( ) ; // Configure our cURL handle for our GET call curl_setopt ( $ curl , CURLOPT_RETURNTRANSFER , true ) ; curl_setopt ( $ curl , CURLOPT_HEADER , true ) ; curl_setopt ( $ curl , CURLOPT_POST , 0 ) ; curl_setopt ( $ curl , CURLOPT_URL , $ url ) ; // Perform our request and check the response $ response = curl_exec ( $ curl ) ; $ code = curl_getinfo ( $ curl , CURLINFO_HTTP_CODE ) ; $ this -> logger -> info ( "Request returned a $code response." ) ; $ header_size = curl_getinfo ( $ curl , CURLINFO_HEADER_SIZE ) ; curl_close ( $ curl ) ; // Extract header information from the response $ headers = [ ] ; $ raw_headers = explode ( "\n" , substr ( $ response , 0 , $ header_size ) ) ; array_shift ( $ raw_headers ) ; foreach ( $ raw_headers as $ header ) { if ( ! trim ( $ header ) ) { continue ; } $ field = explode ( ": " , $ header ) ; $ headers [ array_shift ( $ field ) ] = trim ( implode ( ': ' , $ field ) ) ; } // Low level debug output foreach ( $ headers as $ header => $ value ) { $ this -> logger -> debug ( $ header . ': ' . $ value ) ; } $ body = substr ( $ response , $ header_size ) ; $ this -> logger -> debug ( $ body ) ; // Check our result for unexpected errors switch ( $ code ) { case 401 : throw new InvalidCredentialsException ( "Invalid API key specified." ) ; case 400 : throw new RuntimeException ( "Bad request. Check the URL you specified for errors." ) ; case 404 : throw new RuntimeException ( "Unknown endpoint specified. Check the URL you specified for errors." ) ; case 429 : throw new RateLimitExceededException ( "Ratelimit reached. Please try again in {$headers['Retry-After']} seconds." ) ; case 503 : throw new RuntimeException ( "Service unavailable. It is possible that your client has been throttled." ) ; } // Check for unexpected errors if ( $ code != 200 && $ code != 204 ) { throw new RuntimeException ( "Remote server returned an unexpected response: $code" ) ; } $ this -> logger -> info ( "Response size: " . strlen ( $ body ) ) ; return $ body ; }
Perform a GET request using a cURL handle

@param  string $url What URL are we requesting from the API?
@return string      Returns the body of the response
Perform a GET request using a cURL handle