src/ChrisKonnertz/DeepLy/HttpClient/GuzzleHttpClient.php
public function callApi($url, array $payload, $method)
    {
        if (! is_string($url)) {
            throw new \InvalidArgumentException('$url has to be a string');
        }
        if (! is_string($method)) {
            throw new \InvalidArgumentException('$method has to be a string');
        }

        $jsonData = $this->protocol->createRequestData($payload, $method);

        $options = ['body' => $jsonData];

        try {
            $guzzleResponse = $this->guzzle->post($url, $options);
        } catch (GuzzleException $exception) {
            $callException = new CallException('cURL error during DeepLy API call: '.$exception->getMessage());
            throw $callException;
        }

        $code = $guzzleResponse->getStatusCode();
        if ($code !== 200) {
            // Note that the response probably will contain an error description wrapped in a HTML page
            throw new CallException('Server side error during DeepLy API call: HTTP code '.$code);
        }

        if ($guzzleResponse->getBody() instanceof Stream) {
            $rawResponseData = $guzzleResponse->getBody()->getContents();
        } else {
            // This should never happen
            throw new CallException('$guzzleResponse->getBody() did not return a Stream object');
        }

        return $rawResponseData;
    }
public function callApi($url, array $payload, $method)
    {
        if (! is_string($url)) {
            throw new \InvalidArgumentException('$url has to be a string');
        }
        if (! is_string($method)) {
            throw new \InvalidArgumentException('$method has to be a string');
        }

        $jsonData = $this->protocol->createRequestData($payload, $method);

        $options = ['body' => $jsonData];

        try {
            $guzzleResponse = $this->guzzle->post($url, $options);
        } catch (GuzzleException $exception) {
            $callException = new CallException('cURL error during DeepLy API call: '.$exception->getMessage());
            throw $callException;
        }

        $code = $guzzleResponse->getStatusCode();
        if ($code !== 200) {
            // Note that the response probably will contain an error description wrapped in a HTML page
            throw new CallException('Server side error during DeepLy API call: HTTP code '.$code);
        }

        if ($guzzleResponse->getBody() instanceof Stream) {
            $rawResponseData = $guzzleResponse->getBody()->getContents();
        } else {
            // This should never happen
            throw new CallException('$guzzleResponse->getBody() did not return a Stream object');
        }

        return $rawResponseData;
    }
Executes an API call (a request) and returns the raw response data

@param  string $url     The URL of the API endpoint
@param  array  $payload The payload of the request. Will be encoded as JSON
@param  string $method  The name of the method of the API call
@return string          The raw response data as string (usually contains stringified JSON)
@throws CallException   Throws a call exception if the call could not be executed