private function decodeResponse(ResponseInterface $response)
    {
        $responseBody = trim((string) $response->getBody());

        if ($response->getHeader('Content-Type')[0] === 'text/plain;charset=UTF-8') {
            $lines = explode("\n", $responseBody);
            $data = [];

            // parse endomondo text response
            foreach ($lines as $line) {
                $items = explode('=', $line);
                if (count($items) === 2) {
                    $data[$items[0]] = $items[1];
                }
            }

            return $data;
        }

        $data = json_decode($responseBody, true);

        if (isset($data['error'])) {
            throw new EndomondoApiOldException('Api error: ' . $data['error']['type']);
        }

        return $data;
    }