def validate(self, phone_number, **kwargs): """ Begin the validation process for the given number. Returns a dictionary with the following keys **account_sid**: The unique id of the Account to which the Validation Request belongs. **phone_number**: The incoming phone number being validated, formatted with a '+' and country code e.g., +16175551212 **friendly_name**: The friendly name you provided, if any. **validation_code**: The 6 digit validation code that must be entered via the phone to validate this phone number for Caller ID. :param phone_number: The phone number to call and validate :param friendly_name: A description for the new caller ID :param call_delay: Number of seconds to delay the validation call. :param extension: Digits to dial after connecting the validation call. :returns: A response dictionary """ kwargs["phone_number"] = phone_number params = transform_params(kwargs) resp, validation = self.request("POST", self.uri, data=params) return validation
def get(self, number, include_carrier_info=False, country_code=None): """Look up a phone number. :param str number: The phone number to query. :param bool include_carrier_info: Whether to do a carrier lookup on the phone number. See twilio.com for the latest pricing. :param str country_code: If the number is provided in a local format rather than E.164, specify the two-letter code of the country to parse the number for. """ params = {} if country_code is not None: params['country_code'] = country_code if include_carrier_info: params['type'] = 'carrier' params = transform_params(params) try: number = urllib.quote_plus(number) except: number = urllib.parse.quote_plus(number) uri = "%s/%s" % (self.uri, number) _, item = self.request("GET", uri, params=params) return self.load_instance(item)
def get(self, number, include_caller_name=False, include_carrier_info=False, country_code=None): """Look up a phone number. :param str number: The phone number to query. :param bool include_carrier_info: Whether to do a carrier lookup on the phone number. See twilio.com for the latest pricing. :param str country_code: If the number is provided in a local format rather than E.164, specify the two-letter code of the country to parse the number for. """ params = {} if country_code is not None: params['country_code'] = country_code if include_caller_name: params['type'] = list() params['type'].append('caller-name') if include_carrier_info: params['type'] = params.get('type') or list() params['type'].append('carrier') params = transform_params(params) uri = "%s/%s" % (self.uri, number) _, item = self.request("GET", uri, params=params) return self.load_instance(item)
def test_fparam_booleans(self): d = {"HEY": None, "YOU": 3, "Activated": False} ed = {"YOU":3, "Activated": "false"} self.assertEquals(transform_params(d), ed)
def test_fparam(self): d = {"HEY": None, "YOU": 3} ed = {"YOU":3} self.assertEquals(transform_params(d), ed)
def test_multi_param(self): d = {"Normal": 3, "Multiple": ["One", "Two"]} ed = {"Normal": 3, "Multiple": ["One", "Two"]} self.assertEquals(transform_params(d), ed)
def test_fparam_booleans(): d = {"HEY": None, "YOU": 3, "Activated": False} ed = {"YOU": 3, "Activated": "false"} assert_equal(transform_params(d), ed)
def test_multi_param(): d = {"Normal": 3, "Multiple": ["One", "Two"]} ed = {"Normal": 3, "Multiple": ["One", "Two"]} assert_equal(transform_params(d), ed)
def test_fparam(): d = {"HEY": None, "YOU": 3} ed = {"YOU": 3} assert_equal(transform_params(d), ed)