def api_request(self, url, data=None, method='GET', raw=False, file=None):
        """ Perform an API request to the given URL, optionally
        including the specified data

        :type url: String
        :param url: the URL to which to make the request
        :type data: String
        :param data: the data to send with the request, if any
        :type method: String
        :param method: the HTTP request method
        :type raw: Boolean
        :para raw: if True, return the raw response, otherwise treat as JSON and return the parsed response
        :type file: String
        :param file: (Optional) full path to file to be uploaded in a POST request


        :returns: the response from the server either as a raw response or a Python dictionary
            generated by parsing the JSON response

        :raises: APIError if the API request is not successful


        """

        if method is 'GET':
            response = self.oauth.get(url)
        elif method is 'POST':
            if file is not None:
                response = self.oauth.post(url, data=data, file=file)
            else:
                response = self.oauth.post(url, data=data)
        elif method is 'PUT':
            response = self.oauth.put(url, data=data)
        elif method is 'DELETE':
            response = self.oauth.delete(url)
        else:
            raise APIError("Unknown request method: %s" % (method,))

        # check for error responses
        if response.status_code >= 400:
            raise APIError(response.status_code,
                           '',
                           "Error accessing API (url: %s, method: %s)\nData: %s\nMessage: %s" % (url, method, data, response.text))

        if raw:
            return response.content
        else:
            return response.json()
Perform an API request to the given URL, optionally
        including the specified data

        :type url: String
        :param url: the URL to which to make the request
        :type data: String
        :param data: the data to send with the request, if any
        :type method: String
        :param method: the HTTP request method
        :type raw: Boolean
        :para raw: if True, return the raw response, otherwise treat as JSON and return the parsed response
        :type file: String
        :param file: (Optional) full path to file to be uploaded in a POST request


        :returns: the response from the server either as a raw response or a Python dictionary
            generated by parsing the JSON response

        :raises: APIError if the API request is not successful