Esempio n. 1
0
    def request(self, path, method=None, vars=None):
        """sends a request and gets a response from the Telapi REST API

        .. deprecated:: 3.0

        :param path: the URL (relative to the endpoint URL, after the /v1
        :param url: the HTTP method to use, defaults to POST
        :param vars: for POST or PUT, a dict of data to send

        :returns: Telapi response in XML or raises an exception on error

        This method is only included for backwards compatability reasons.
        It will be removed in a future version
        """
        logging.warning(":meth:`TelapiRestClient.request` is deprecated and "
                        "will be removed in a future version")

        vars = vars or {}
        params = None
        data = None

        if not path or len(path) < 1:
            raise ValueError('Invalid path parameter')
        if method and method not in ['GET', 'POST', 'DELETE', 'PUT']:
            raise NotImplementedError(
                'HTTP %s method not implemented' % method)

        if path[0] == '/':
            uri = _TWILIO_API_URL + path
        else:
            uri = _TWILIO_API_URL + '/' + path

        if method == "GET":
            params = vars
        elif method == "POST" or method == "PUT":
            data = vars

        headers = {
            "User-Agent": "telapi-python",
            }

        resp = make_request(method, uri, auth=self.auth, data=data,
                            params=params, headers=headers)

        return resp.content
def test_resp_uri():
    resp = make_request("GET", "http://httpbin.org/get")
    assert_equals(resp.url, "http://httpbin.org/get")
def check_get_params(url, params):
    resp = make_request("GET", url, params=params)
    body = json.loads(resp.content)

    assert_equals(body["args"]["hey"], "you")
    assert_equals(body["args"]["foo"], "bar")