Model/Api.php
private function _fetch(
        $uri,
        $method = \Zend_Http_Client::GET,
        $body = '',
        $test = false,
        $testApiKey = null,
        $logError = true
    ) {
        $apiKey = ($test == true) ? $testApiKey : $this->config->getApiKey();

        // Correctly format $body string
        if (is_array($body) == true) {
            $body = http_build_query($body);
        }

        // Client headers
        $headers = [
            self::FASTLY_HEADER_AUTH  . ': ' . $apiKey,
            'Accept: application/json'
        ];

        // Client options
        $options = [];

        // Request method specific header & option changes
        switch ($method) {
            case \Zend_Http_Client::DELETE:
                $options[CURLOPT_CUSTOMREQUEST] = \Zend_Http_Client::DELETE;
                break;
            case \Zend_Http_Client::PUT:
                $headers[] = 'Content-Type: application/x-www-form-urlencoded';
                $options[CURLOPT_CUSTOMREQUEST] = \Zend_Http_Client::PUT;

                if ($body != '') {
                    $options[CURLOPT_POSTFIELDS] = $body;
                }

                break;
            case \Zend_Http_Client::PATCH:
                $options[CURLOPT_CUSTOMREQUEST] = \Zend_Http_Client::PATCH;
                $headers[] = 'Content-Type: text/json';

                if ($body != '') {
                    $options[CURLOPT_POSTFIELDS] = $body;
                }

                break;
        }

        /** @var \Magento\Framework\HTTP\Adapter\Curl $client */
        $client = $this->curlFactory->create();

        // Execute request
        $client->setOptions($options);
        $client->write($method, $uri, '1.1', $headers, $body);
        $response = $client->read();
        $client->close();

        // Parse response
        $responseBody = \Zend_Http_Response::extractBody($response);
        $responseCode = \Zend_Http_Response::extractCode($response);
        $responseMessage = \Zend_Http_Response::extractMessage($response);

        // Return error based on response code
        if ($responseCode == '429') {
            throw new LocalizedException(__($responseMessage));
        } elseif ($responseCode != '200') {
            if ($logError == true) {
                $this->logger->critical('Return status ' . $responseCode, $uri);
            }

            return false;
        }

        return json_decode($responseBody);
    }
private function _fetch(
        $uri,
        $method = \Zend_Http_Client::GET,
        $body = '',
        $test = false,
        $testApiKey = null,
        $logError = true
    ) {
        $apiKey = ($test == true) ? $testApiKey : $this->config->getApiKey();

        // Correctly format $body string
        if (is_array($body) == true) {
            $body = http_build_query($body);
        }

        // Client headers
        $headers = [
            self::FASTLY_HEADER_AUTH  . ': ' . $apiKey,
            'Accept: application/json'
        ];

        // Client options
        $options = [];

        // Request method specific header & option changes
        switch ($method) {
            case \Zend_Http_Client::DELETE:
                $options[CURLOPT_CUSTOMREQUEST] = \Zend_Http_Client::DELETE;
                break;
            case \Zend_Http_Client::PUT:
                $headers[] = 'Content-Type: application/x-www-form-urlencoded';
                $options[CURLOPT_CUSTOMREQUEST] = \Zend_Http_Client::PUT;

                if ($body != '') {
                    $options[CURLOPT_POSTFIELDS] = $body;
                }

                break;
            case \Zend_Http_Client::PATCH:
                $options[CURLOPT_CUSTOMREQUEST] = \Zend_Http_Client::PATCH;
                $headers[] = 'Content-Type: text/json';

                if ($body != '') {
                    $options[CURLOPT_POSTFIELDS] = $body;
                }

                break;
        }

        /** @var \Magento\Framework\HTTP\Adapter\Curl $client */
        $client = $this->curlFactory->create();

        // Execute request
        $client->setOptions($options);
        $client->write($method, $uri, '1.1', $headers, $body);
        $response = $client->read();
        $client->close();

        // Parse response
        $responseBody = \Zend_Http_Response::extractBody($response);
        $responseCode = \Zend_Http_Response::extractCode($response);
        $responseMessage = \Zend_Http_Response::extractMessage($response);

        // Return error based on response code
        if ($responseCode == '429') {
            throw new LocalizedException(__($responseMessage));
        } elseif ($responseCode != '200') {
            if ($logError == true) {
                $this->logger->critical('Return status ' . $responseCode, $uri);
            }

            return false;
        }

        return json_decode($responseBody);
    }
Wrapper for API calls towards Fastly service

@param string    $uri    API Endpoint
@param string    $method HTTP Method for request
@param mixed[]|string    $body   Content
@param bool  $test   Use $testApiKey for request
@param string    $testApiKey API key to be tested
@param bool  $logError   When set to false, prevents writing failed requests to log

@return bool|mixed   Returns false on failiure
@throws LocalizedException