def create(self, method, uri, params=None, data=None, headers=None, auth=None, timeout=None, allow_redirects=False): response = self.request( method, uri, params=params, data=data, headers=headers, auth=auth, timeout=timeout, allow_redirects=allow_redirects, ) if response.status_code < 200 or response.status_code >= 300: raise TwilioException('[{}] Unable to create record\n{}'.format( response.status_code, response.content)) return json.loads(response.content)
def __init__(self, account=None, token=None, base="https://api.twilio.com", version="2010-04-01", timeout=UNSET_TIMEOUT): """ Create a Twilio API client. """ # Get account credentials if not account or not token: account, token = find_credentials() if not account or not token: raise TwilioException(""" Twilio could not find your account credentials. Pass them into the TwilioRestClient constructor like this: client = TwilioRestClient(account='AC38135355602040856210245275870', token='2flnf5tdp7so0lmfdu3d') Or, add your credentials to your shell environment. From the terminal, run echo "export TWILIO_ACCOUNT_SID=AC3813535560204085626521" >> ~/.bashrc echo "export TWILIO_AUTH_TOKEN=2flnf5tdp7so0lmfdu3d7wod" >> ~/.bashrc and be sure to replace the values for the Account SID and auth token with the values from your Twilio Account at https://www.twilio.com/user/account. """) self.base = base self.auth = (account, token) self.timeout = timeout self.account_uri = "{0}/{1}/Accounts/{2}".format( base, version, account)
def load_page(self, payload): if 'meta' in payload and 'key' in payload['meta']: return payload[payload['meta']['key']] else: keys = set(payload.keys()) key = keys - self.META_KEYS if len(key) == 1: return payload[key.pop()] raise TwilioException('Page Records can not be deserialized')
def request(self, method, url, params=None, data=None, headers=None, auth=None, timeout=None, allow_redirects=False): raise TwilioException('HttpClient is an abstract class')
def update(self, sid, **kwargs): """Update an :class:`Address` with the given parameters. Parameters are described above in :meth:`create`, with the exception that `iso_country` cannot be updated on an existing Address (create a new one instead). """ if 'iso_country' in kwargs: raise TwilioException( "Cannot update iso_country on an existing Address", ) return self.update_instance(sid, kwargs)
def __init__(self, username=None, password=None, account_sid=None, http_client=None, environment=None): """ Initializes the Twilio Client :param str username: Username to authenticate with :param str password: Password to authenticate with :param str account_sid: Account Sid, defaults to Username :param HttpClient http_client: HttpClient, defaults to Httplib2Client :param dict environment: Environment to look for auth details, defaults to os.environ :returns: Twilio Client :rtype: twilio.rest.Client """ environment = environment or os.environ self.username = username or environment.get('TWILIO_ACCOUNT_SID') """ :type : str """ self.password = password or environment.get('TWILIO_AUTH_TOKEN') """ :type : str """ self.account_sid = account_sid or self.username """ :type : str """ if not self.username or not self.password: raise TwilioException("Credentials are required to create a TwilioClient") self.auth = (self.username, self.password) """ :type : tuple(str, str) """ self.http_client = http_client or Httplib2Client() """ :type : HttpClient """ # Domains self._api = None self._ip_messaging = None self._lookups = None self._monitor = None self._notifications = None self._preview = None self._pricing = None self._taskrouter = None self._trunking = None
def delete(self, method, uri, params=None, data=None, headers=None, auth=None, timeout=None, allow_redirects=False): response = self.request( method, uri, params=params, data=data, headers=headers, auth=auth, timeout=timeout, allow_redirects=allow_redirects, ) if response.status_code < 200 or response.status_code >= 300: raise TwilioException('Unable to delete record') return response.status_code == 204
def get(self, sid): raise TwilioException("Individual AvailablePhoneNumbers have no sid")
def get_instance(self, payload): raise TwilioException( 'Page.get_instance() must be implemented in the derived class')
def process_response(self, response): if response.status_code != 200: raise TwilioException('Unable to fetch page', response) return json.loads(response.content)
def raiseException(*args, **kwargs): raise TwilioException("Test error.")
def raiseException(*args, **kwargs): raise TwilioException("HTTP ERROR 500.")