當前位置: 首頁>>代碼示例>>Python>>正文


Python TwilioRestClient.request方法代碼示例

本文整理匯總了Python中twilio.rest.TwilioRestClient.request方法的典型用法代碼示例。如果您正苦於以下問題:Python TwilioRestClient.request方法的具體用法?Python TwilioRestClient.request怎麽用?Python TwilioRestClient.request使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在twilio.rest.TwilioRestClient的用法示例。


在下文中一共展示了TwilioRestClient.request方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: RestClientTest

# 需要導入模塊: from twilio.rest import TwilioRestClient [as 別名]
# 或者: from twilio.rest.TwilioRestClient import request [as 別名]
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,代碼行數:36,代碼來源:test_client.py

示例2: RestClientTest

# 需要導入模塊: from twilio.rest import TwilioRestClient [as 別名]
# 或者: from twilio.rest.TwilioRestClient import request [as 別名]
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,代碼行數:29,代碼來源:test_client.py

示例3: RestClientTest

# 需要導入模塊: from twilio.rest import TwilioRestClient [as 別名]
# 或者: from twilio.rest.TwilioRestClient import request [as 別名]
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,代碼行數:59,代碼來源:test_client.py

示例4: exit

# 需要導入模塊: from twilio.rest import TwilioRestClient [as 別名]
# 或者: from twilio.rest.TwilioRestClient import request [as 別名]
  for number in dial:
    if number in phonebook:
      number = phonebook[number]
    elif not number_re.match(number):
      print "bad number to dial: ", number
      exit(1)
    call(number)
elif command == "CARPETBOMB":
  conferences = client.conferences.list()
  for conference in conferences:
    if conference.status != "completed":
      ps = conference.participants.list()
      for p in ps:
        print "kicking %s..." % p.name
        client.request(
          "/2010-04-01/Accounts/%s/Conferences/%s/Participants/%s" % (
            account, conference.sid, p.call_sid),
          "DELETE")
elif command == "preside":
  targetPopulation = int(args[0])

  # preside:
  print "building a kingdom of %s happy(ish) subjects..." % targetPopulation
  mains = client.conferences.list(status='in-progress', friendly_name='main')
  if len(mains) == 0:
    print "kingdom is down."
  elif len(mains) == 1:
    print "kingdom is up."
  else:
    print "i didn't expect this... len(mains):", len(mains)
    exit(1)
開發者ID:bdon,項目名稱:partyline,代碼行數:33,代碼來源:puppetmaster.py


注:本文中的twilio.rest.TwilioRestClient.request方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。