Exemplo n.º 1
0
    def __init__(self,
                 account=None,
                 token=None,
                 base="https://api.twilio.com",
                 version="2010-04-01",
                 client=None):
        """
        Create a Twilio REST API client.
        """

        # Get account credentials
        if not account or not token:
            account, token = find_credentials()
            if not account or not token:
                raise TwilioException("Could not find account credentials")

        auth = (account, token)
        version_uri = "%s/%s" % (base, version)
        account_uri = "%s/%s/Accounts/%s" % (base, version, account)

        self.accounts = Accounts(version_uri, auth)
        self.applications = Applications(account_uri, auth)
        self.calls = Calls(account_uri, auth)
        self.caller_ids = CallerIds(account_uri, auth)
        self.notifications = Notifications(account_uri, auth)
        self.recordings = Recordings(account_uri, auth)
        self.transcriptions = Transcriptions(account_uri, auth)
        self.sms = Sms(account_uri, auth)
        self.phone_numbers = PhoneNumbers(account_uri, auth)
        self.conferences = Conferences(account_uri, auth)
        self.sandboxes = Sandboxes(account_uri, auth)

        self.auth = auth
        self.account_uri = account_uri
Exemplo n.º 2
0
    def get_instances(self, params=None, page=None, page_size=None):
        """
        Query the list resource for a list of InstanceResources.

        Raises a TwilioRestException if requesting a page of results that does
        not exist.

        :param dict params: List of URL parameters to be included in request
        :param int page: The page of results to retrieve (most recent at 0)
        :param int page_size: The number of results to be returned.

        :returns: -- the list of resources
        """
        params = params or {}

        if page is not None:
            params["Page"] = page

        if page_size is not None:
            params["PageSize"] = page_size

        resp, page = self.request("GET", self.uri, params=params)

        if self.key not in page:
            raise TwilioException("Key %s not present in response" % self.key)

        return [self.load_instance(ir) for ir in page[self.key]]
Exemplo n.º 3
0
    def __init__(self,
                 account=None,
                 token=None,
                 base="https://api.twilio.com",
                 version="2010-04-01",
                 client=None,
                 timeout=UNSET_TIMEOUT):
        """
        Create a Twilio REST 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
        auth = (account, token)
        version_uri = "%s/%s" % (base, version)
        account_uri = "%s/%s/Accounts/%s" % (base, version, account)

        self.accounts = Accounts(version_uri, auth, timeout)
        self.applications = Applications(account_uri, auth, timeout)
        self.authorized_connect_apps = AuthorizedConnectApps(
            account_uri, auth, timeout)
        self.calls = Calls(account_uri, auth, timeout)
        self.caller_ids = CallerIds(account_uri, auth, timeout)
        self.connect_apps = ConnectApps(account_uri, auth, timeout)
        self.notifications = Notifications(account_uri, auth, timeout)
        self.recordings = Recordings(account_uri, auth, timeout)
        self.transcriptions = Transcriptions(account_uri, auth, timeout)
        self.sms = Sms(account_uri, auth, timeout)
        self.phone_numbers = PhoneNumbers(account_uri, auth, timeout)
        self.conferences = Conferences(account_uri, auth, timeout)
        self.queues = Queues(account_uri, auth, timeout)
        self.sandboxes = Sandboxes(account_uri, auth, timeout)
        self.usage = Usage(account_uri, auth, timeout)
        self.messages = Messages(account_uri, auth, timeout)
        self.media = MediaList(account_uri, auth, timeout)
        self.sip = Sip(account_uri, auth, timeout)

        self.auth = auth
        self.account_uri = account_uri
        self.timeout = timeout
Exemplo n.º 4
0
    def get_instances(self, params=None, page=None, page_size=None):
        """
        Query the list resource for a list of InstanceResources
        """
        params = params or {}

        if page is not None:
            params["Page"] = page

        if page_size is not None:
            params["PageSize"] = page_size

        resp, page = self.request("GET", self.uri, params=params)

        if self.key not in page:
            raise TwilioException("Key %s not present in response" % self.key)

        return [self.load_instance(ir) for ir in page[self.key]]
Exemplo n.º 5
0
 def get(self, sid):
     raise TwilioException("Individual AvailablePhoneNumbers have no sid")