def request(cls, method, url, **kwargs):
        """Make a http call to a remote API and return a json response."""
        user_agent = 'gandi.cli/%s' % __version__

        headers = {'User-Agent': user_agent,
                   'Content-Type': 'application/json; charset=utf-8'}
        if kwargs.get('headers'):
            headers.update(kwargs.pop('headers'))
        try:
            response = requests.request(method, url, headers=headers,
                                        **kwargs)
            response.raise_for_status()
            try:
                return response.json(), response.headers
            except ValueError as err:
                return response.text, response.headers
        except (socket.error, requests.exceptions.ConnectionError):
            msg = 'Remote API service is unreachable'
            raise APICallFailed(msg)
        except Exception as err:
            if isinstance(err, requests.HTTPError):
                try:
                    resp = response.json()
                except Exception:
                    msg = 'An unknown error has occurred: %s' % err
                    raise APICallFailed(msg)

                if resp.get('message'):
                    error = resp.get('message')
                if resp.get('errors'):
                    error = cls.format_errors(resp.get('errors'))
                msg = '%s: %s' % (err, error)
            else:
                msg = 'An unknown error has occurred: %s' % err
            raise APICallFailed(msg)
Make a http call to a remote API and return a json response.