本文整理汇总了Python中twilio.rest.TwilioRestClient类的典型用法代码示例。如果您正苦于以下问题:Python TwilioRestClient类的具体用法?Python TwilioRestClient怎么用?Python TwilioRestClient使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TwilioRestClient类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: _make_client
def _make_client(configuration):
account_sid = configuration['twilio']['account_sid']
auth_token = configuration['twilio']['auth_token']
number = configuration['twilio']['number']
client = TwilioRestClient(account_sid, auth_token)
client.from_ = number
return client
开发者ID:walkr,项目名称:nanosphere,代码行数:7,代码来源:sms.py
示例2: RestClientTest
class RestClientTest(unittest.TestCase):
def setUp(self):
self.client = TwilioRestClient("ACCOUNT_SID", "AUTH_TOKEN")
@patch("twilio.rest.make_request")
def test_request(self, mock):
self.client.request("2010-04-01", method="GET")
mock.assert_called_with("GET", "https://api.twilio.com/2010-04-01",
headers={"User-Agent": 'twilio-python'}, params={},
auth=("ACCOUNT_SID", "AUTH_TOKEN"), data=None)
def test_connect_apps(self):
self.assertIsInstance(self.client.connect_apps,
resources.ConnectApps)
def test_authorized_apps(self):
self.assertIsInstance(self.client.authorized_connect_apps,
resources.AuthorizedConnectApps)
@patch("twilio.rest.resources.make_request")
def test_conferences(self, mock):
mock.return_value = Mock()
mock.return_value.ok = True
mock.return_value.content = '{"conferences": []}'
self.client.conferences.list()
开发者ID:Qwikon,项目名称:twilio-python,代码行数:27,代码来源:test_client.py
示例3: RestClientTest
class RestClientTest(unittest.TestCase):
def setUp(self):
self.client = TwilioRestClient("ACCOUNT_SID", "AUTH_TOKEN")
@patch("twilio.rest.make_request")
def test_request(self, mock):
self.client.request("2010-04-01", method="GET")
mock.assert_called_with("GET", "https://api.twilio.com/2010-04-01",
headers={"User-Agent": 'twilio-python'}, params={},
auth=AUTH, data=None)
def test_connect_apps(self):
self.assertIsInstance(self.client.connect_apps,
resources.ConnectApps)
def test_authorized_apps(self):
self.assertIsInstance(self.client.authorized_connect_apps,
resources.AuthorizedConnectApps)
@patch("twilio.rest.resources.base.make_request")
def test_conferences(self, mock):
mock.return_value = Mock()
mock.return_value.ok = True
mock.return_value.content = '{"conferences": []}'
self.client.conferences.list()
@patch("twilio.rest.resources.base.make_twilio_request")
def test_members(self, mock):
resp = create_mock_json("tests/resources/members_list.json")
mock.return_value = resp
self.client.members("QU123").list()
uri = "https://api.twilio.com/2010-04-01/Accounts/ACCOUNT_SID/Queues/QU123/Members"
mock.assert_called_with("GET", uri, params={}, auth=AUTH)
开发者ID:Shakahs,项目名称:twilio-python,代码行数:34,代码来源:test_client.py
示例4: beacon
def beacon(config):
'''
Emit a dict name "texts" whose value is a list
of texts.
.. code-block:: yaml
beacons:
twilio_txt_msg:
account_sid: "<account sid>"
auth_token: "<auth token>"
twilio_number: "+15555555555"
poll_interval: 10
poll_interval defaults to 10 seconds
'''
log.trace('twilio_txt_msg beacon starting')
ret = []
if not all([config['account_sid'], config['auth_token'], config['twilio_number']]):
return ret
output = {}
poll_interval = config.get('poll_interval')
if not poll_interval:
# Let's default to polling every 10 secons
poll_interval = 10
now = datetime.now()
if 'twilio_txt_msg' in __context__:
timedelta = now - __context__['twilio_txt_msg']
if timedelta.seconds < poll_interval:
log.trace('Twilio beacon poll interval not met.')
log.trace('Twilio polling in {0}'.format(poll_interval - timedelta.seconds))
return ret
output['texts'] = []
client = TwilioRestClient(config['account_sid'], config['auth_token'])
messages = client.messages.list(to=config['twilio_number'])
log.trace('Num messages: {0}'.format(len(messages)))
if len(messages) < 1:
log.trace('Twilio beacon has no texts')
__context__['twilio_txt_msg'] = now
return ret
for message in messages:
item = {}
item['id'] = str(message.sid)
item['body'] = str(message.body)
item['from'] = str(message.from_)
item['sent'] = str(message.date_sent)
item['images'] = []
if int(message.num_media):
media = client.media(message.sid).list()
if len(media):
for pic in media:
item['images'].append(str(pic.uri))
output['texts'].append(item)
message.delete()
__context__['twilio_txt_msg'] = now
ret.append(output)
return ret
开发者ID:digideskio,项目名称:headless,代码行数:60,代码来源:twilio_txt_msg.py
示例5: RestClientTest
class RestClientTest(unittest.TestCase):
def setUp(self):
self.client = TwilioRestClient("ACCOUNT_SID", "AUTH_TOKEN")
self.task_router_client = TwilioTaskRouterClient("ACCOUNT_SID",
"AUTH_TOKEN")
@patch("twilio.rest.base.make_request")
def test_request(self, mock):
self.client.request("2010-04-01", method="GET")
mock.assert_called_with("GET", "https://api.twilio.com/2010-04-01",
headers={"User-Agent": ANY,
'Accept-Charset': 'utf-8',
'Authorization':
'Basic QUNDT1VOVF9TSUQ6QVVUSF9UT0tFTg=='},
params={}, auth=AUTH, data=None)
called_kwargs = mock.mock_calls[0][2]
self.assertTrue(
'twilio-python' in called_kwargs['headers']['User-Agent']
)
def test_connect_apps(self):
assert_true(isinstance(self.client.connect_apps,
resources.ConnectApps))
def test_authorized_apps(self):
assert_true(isinstance(self.client.authorized_connect_apps,
resources.AuthorizedConnectApps))
@patch("twilio.rest.resources.base.make_request")
def test_conferences(self, mock):
mock.return_value = Mock()
mock.return_value.ok = True
mock.return_value.content = '{"conferences": []}'
self.client.conferences.list()
@patch("twilio.rest.resources.base.make_twilio_request")
def test_members(self, mock):
resp = create_mock_json("tests/resources/members_list.json")
mock.return_value = resp
self.client.members("QU123").list()
uri = "https://api.twilio.com/2010-04-01/Accounts/ACCOUNT_SID" \
"/Queues/QU123/Members"
mock.assert_called_with("GET", uri, params={}, auth=AUTH,
use_json_extension=True)
@patch("twilio.rest.resources.base.make_request")
def test_workflows(self, request):
resp = create_mock_json(
"tests/resources/task_router/workflows_list.json"
)
request.return_value = resp
workflows = self.task_router_client.workflows("WS123")
workflows = workflows.list()
assert_true(workflows[0].sid is not None)
uri = "https://taskrouter.twilio.com/v1/Workspaces/WS123/Workflows"
request.assert_called_with("GET", uri, headers=ANY, params={},
auth=AUTH)
开发者ID:lyft,项目名称:twilio-python,代码行数:57,代码来源:test_client.py
示例6: beacon
def beacon(config):
'''
Emit a dict name "texts" whose value is a list
of texts.
.. code-block:: yaml
beacons:
twilio_txt_msg:
account_sid: "<account sid>"
auth_token: "<auth token>"
twilio_number: "+15555555555"
interval: 10
'''
log.trace('twilio_txt_msg beacon starting')
ret = []
if not all([config['account_sid'], config['auth_token'], config['twilio_number']]):
return ret
output = {}
output['texts'] = []
client = TwilioRestClient(config['account_sid'], config['auth_token'])
messages = client.messages.list(to=config['twilio_number'])
log.trace('Num messages: {0}'.format(len(messages)))
if len(messages) < 1:
log.trace('Twilio beacon has no texts')
return ret
for message in messages:
item = {}
item['id'] = str(message.sid)
item['body'] = str(message.body)
item['from'] = str(message.from_)
item['sent'] = str(message.date_sent)
item['images'] = []
if int(message.num_media):
media = client.media(message.sid).list()
if len(media):
for pic in media:
item['images'].append(str(pic.uri))
output['texts'].append(item)
message.delete()
ret.append(output)
return ret
开发者ID:DaveQB,项目名称:salt,代码行数:45,代码来源:twilio_txt_msg.py
示例7: RestClientTimeoutTest
class RestClientTimeoutTest(unittest.TestCase):
def setUp(self):
self.client = TwilioRestClient("ACCOUNT_SID", "AUTH_TOKEN", timeout=sentinel.timeout)
@patch("twilio.rest.resources.base.make_twilio_request")
def test_members(self, mock_request):
resp = create_mock_json("tests/resources/members_list.json")
mock_request.return_value = resp
self.client.members("QU123").list()
mock_request.assert_called_with("GET", ANY, params=ANY, auth=AUTH, timeout=sentinel.timeout)
@patch("twilio.rest.resources.base.make_twilio_request")
def test_arbitrary_member(self, mock_request):
mock_response = Mock()
mock_response.ok = True
mock_response.content = json.dumps({"short_codes": []})
mock_request.return_value = mock_response
self.assertEqual([], self.client.sms.short_codes.list())
mock_request.assert_called_once_with("GET", ANY, params=ANY, auth=AUTH, timeout=sentinel.timeout)
开发者ID:Stackdriver,项目名称:twilio-python,代码行数:19,代码来源:test_client.py
示例8: TwilioRestClient
# Download the Python helper library from twilio.com/docs/python/install
from twilio.rest import TwilioRestClient
# Your Account Sid and Auth Token from twilio.com/user/account
account_sid = "{{ account_sid }}"
auth_token = "{{ auth_token }}"
client = TwilioRestClient(account_sid, auth_token)
# A list of media objects with the properties described above
medias = client.media('MM800f449d0399ed014aae2bcc0cc2f2ec').list()
开发者ID:looselycoupledlabs,项目名称:api-snippets,代码行数:10,代码来源:list-get-example-4.py
示例9: TwilioClient
class TwilioClient(object):
CORP_FMT = '''Company: {}
Last price: {:.2f}
Ask: {:.2f}
Bid: {:.2f}'''
COUNTRY_FMT = '''Country: {}
Population: {:.0f} million
Unemployment rate: {:.3f}%'''
BASE_FMT = '''
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Message>{}.</Message>
</Response>
'''
MEDIA_FMT = '''
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Message>
<Media>{}</Media>
<Body>{}.</Body>
</Message>
</Response>
'''
REJ_FMT = "Nothing recognized."
PRIV_FMT = "This company is not privately traded."
OUR_NUM = "+16466473401"
def __init__(self,
tw_client_id=TW_CLIENT_ID,
tw_secret_key=TW_SECRET_KEY,
tw_app_id=TW_APP_ID):
self.acc_sid = tw_app_id
self.twilio = TwilioRestClient(tw_client_id, tw_secret_key)
@staticmethod
def _plusify(num):
return ("+{}" if not "+" in num else "{}").format(num)
def get_media(self, recvd):
return self.twilio.media(recvd.sid)
def _message(self, recvd, body, media=None):
message = self.twilio.messages.create(
body=body,
media_url=[media] if media else None,
to=self._plusify(recvd.sender),
from_=self.OUR_NUM)
print "sent message: ", message
def reject(self, recvd):
self._message(recvd, self.REJ_FMT)
def private(self, recvd):
self._message(recvd, self.PRIV_FMT)
def accept(self, recvd, best_match, info):
print "trying to accept ", info
self._message(recvd,
self.CORP_FMT.format(
best_match,
float(info['PX_LAST']),
float(info['PX_ASK']),
float(info['PX_BID'])))
def country(self, recvd, best_match, info):
self._message(recvd,
self.COUNTRY_FMT.format(
best_match.capitalize(),
float(info['WPOP']),
float(info['UNEMP'])))
开发者ID:spencermountain,项目名称:north_chicago,代码行数:76,代码来源:sms.py
示例10: setUp
def setUp(self):
self.client = TwilioRestClient("ACCOUNT_SID", "AUTH_TOKEN")
开发者ID:Shakahs,项目名称:twilio-python,代码行数:2,代码来源:test_client.py
示例11: TwilioRestClient
# Download the Python helper library from twilio.com/docs/python/install
from twilio.rest import TwilioRestClient
# Your Account Sid and Auth Token from twilio.com/user/account
account_sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
auth_token = "your_auth_token"
client = TwilioRestClient(account_sid, auth_token)
# A list of participant objects with the properties described above
participants = client.participants('CFbbe4632a3c49700934481addd5ce1659').list()
开发者ID:GilbertoBotaro,项目名称:api-snippets,代码行数:10,代码来源:list-get-example-1.5.x.py
示例12: TwilioRestClient
# Download the Python helper library from twilio.com/docs/python/install
from twilio.rest import TwilioRestClient
# Your Account Sid and Auth Token from twilio.com/user/account
account_sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
auth_token = "{{ auth_token }}"
client = TwilioRestClient(account_sid, auth_token)
member = client.members('QU5ef8732a3c49700934481addd5ce1659').dequeue("http://demo.twilio.com/docs/voice.xml", "CA5ef8732a3c49700934481addd5ce1659", method="POST")
print member.position
开发者ID:crtr0,项目名称:api-snippets,代码行数:10,代码来源:instance-post-example-2.py
示例13: TwilioRestClient
# Download the Python helper library from twilio.com/docs/python/install
from twilio.rest import TwilioRestClient
# Your Account Sid and Auth Token from twilio.com/user/account
account_sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
auth_token = "your_auth_token"
client = TwilioRestClient(account_sid, auth_token)
# A list of member objects with the properties described above
members = client.members('QU5ef8732a3c49700934481addd5ce1659').list()
开发者ID:GilbertoBotaro,项目名称:api-snippets,代码行数:10,代码来源:list-get-example-1.5.x.py
示例14: TwilioRestClient
url = active_xml)
print "ok"
except TwilioRestException as e:
if "21211" in e.msg or "13224" in e.msg:
print "bad number"
return False
elif "21215" in e.msg:
print "international number: %s" % number
return False
else:
raise e
return True
account = "TWILIO_ACCOUnt_ID_HERE"
token = "TWILIO_AUTH_TOKEN_HERE"
client = TwilioRestClient(account, token)
number_re = re.compile(r'^\d{10}$')
os.chdir(os.path.dirname(sys.argv[0]))
db_path = './numbers.sqlite'
db = sqlite3.connect(db_path)
c = db.cursor()
parser = optparse.OptionParser()
options, args = parser.parse_args()
if len(args) == 0:
print "usage: %s command..."
exit(1)
开发者ID:bdon,项目名称:partyline,代码行数:31,代码来源:puppetmaster.py
示例15: setUp
def setUp(self):
self.client = TwilioRestClient("ACCOUNT_SID", "AUTH_TOKEN")
self.task_router_client = TwilioTaskRouterClient("ACCOUNT_SID",
"AUTH_TOKEN")
开发者ID:lyft,项目名称:twilio-python,代码行数:4,代码来源:test_client.py
示例16: __init__
def __init__(self,
tw_client_id=TW_CLIENT_ID,
tw_secret_key=TW_SECRET_KEY,
tw_app_id=TW_APP_ID):
self.acc_sid = tw_app_id
self.twilio = TwilioRestClient(tw_client_id, tw_secret_key)
开发者ID:spencermountain,项目名称:north_chicago,代码行数:6,代码来源:sms.py
示例17: TwilioRestClient
# Download the Python helper library from twilio.com/docs/python/install
from twilio.rest import TwilioRestClient
# Your Account Sid and Auth Token from twilio.com/user/account
account_sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
auth_token = "your_auth_token"
client = TwilioRestClient(account_sid, auth_token)
participant = client.participants("CFbbe4632a3c49700934481addd5ce1659").update(
"CA386025c9bf5d6052a1d1ea42b4d16662", muted="True"
)
print(participant.muted)
开发者ID:TwilioDevEd,项目名称:api-snippets,代码行数:12,代码来源:instance-post-example-1.5.x.py
示例18: TwilioRestClient
# Download the Python helper library from twilio.com/docs/python/install
from twilio.rest import TwilioRestClient
# Your Account Sid and Auth Token from twilio.com/user/account
account_sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
auth_token = "your_auth_token"
client = TwilioRestClient(account_sid, auth_token)
client.participants('CFbbe4632a3c49700934481addd5ce1659'
).delete("CA386025c9bf5d6052a1d1ea42b4d16662")
开发者ID:GilbertoBotaro,项目名称:api-snippets,代码行数:10,代码来源:instance-delete-example-1.5.x.py
示例19: TwilioRestClient
# Download the Python helper library from twilio.com/docs/python/install
from twilio.rest import TwilioRestClient
# Your Account Sid and Auth Token from twilio.com/user/account
account_sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
auth_token = "your_auth_token"
client = TwilioRestClient(account_sid, auth_token)
# A list of dependent phone number objects
numbers = client.dependent_phone_numbers('AD2a0747eba6abf96b7e3c3ff0b4530f6e'
).list()
for number in numbers:
print(number.friendly_name)
开发者ID:GilbertoBotaro,项目名称:api-snippets,代码行数:14,代码来源:list-dependent-pns-example-1.5.x.py
示例20: TwilioRestClient
# Download the Python helper library from twilio.com/docs/python/install
from twilio.rest import TwilioRestClient
# Your Account Sid and Auth Token from twilio.com/user/account
account_sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
auth_token = "your_auth_token"
client = TwilioRestClient(account_sid, auth_token)
member = client.members('QU5ef8732a3c49700934481addd5ce1659'
).get("CA386025c9bf5d6052a1d1ea42b4d16662")
print(member.wait_time)
开发者ID:GilbertoBotaro,项目名称:api-snippets,代码行数:11,代码来源:instance-get-example-1.5.x.py
注:本文中的twilio.rest.TwilioRestClient类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论