How to use the messagebird.voice_webhook.VoiceCreateWebhookRequest function in messagebird

To help you get started, we’ve selected a few messagebird examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github messagebird / python-rest-api / tests / test_voice_webhook.py View on Github external
def test_voice_create_webhook_request_validation(self):
        url = "https://example.com/"
        title = "FooBar"
        token = "FooBarToken"
        blank_string = '    '

        with self.assertRaises(ValidationError):
            VoiceCreateWebhookRequest(title=title)

        request = VoiceCreateWebhookRequest(url=url, title=title)

        self.assertEqual(url, request.url)
        self.assertEqual(title, request.title)
        self.assertEqual(None, request.token)

        request.url = url + url
        with self.assertRaises(ValidationError):
            request.url = blank_string
github messagebird / python-rest-api / tests / test_voice_webhook.py View on Github external
http_client.request.return_value = '''{
          "data": [
            {
              "id": "534e1848-235f-482d-983d-e3e11a04f58a",
              "url": "https://example.com/",
              "token": "foobar",
              "createdAt": "2017-03-15T14:10:07Z",
              "updatedAt": "2017-03-15T14:10:07Z"
            }
          ],
          "_links": {
            "self": "/webhooks/534e1848-235f-482d-983d-e3e11a04f58a"
          }
        }'''

        create_webhook_request = VoiceCreateWebhookRequest(url="https://example.com/", title="FooBar", token="foobar")
        created_webhook = Client('', http_client).voice_create_webhook(create_webhook_request)

        http_client.request.assert_called_once_with(VOICE_API_ROOT + '/' + VOICE_WEB_HOOKS_PATH, 'POST',
                                                    create_webhook_request.__dict__())
        self.assertEqual(create_webhook_request.url, created_webhook.url)
        self.assertEqual(create_webhook_request.token, created_webhook.token)
github messagebird / python-rest-api / tests / test_voice_webhook.py View on Github external
def test_voice_create_webhook_request_validation(self):
        url = "https://example.com/"
        title = "FooBar"
        token = "FooBarToken"
        blank_string = '    '

        with self.assertRaises(ValidationError):
            VoiceCreateWebhookRequest(title=title)

        request = VoiceCreateWebhookRequest(url=url, title=title)

        self.assertEqual(url, request.url)
        self.assertEqual(title, request.title)
        self.assertEqual(None, request.token)

        request.url = url + url
        with self.assertRaises(ValidationError):
            request.url = blank_string
github messagebird / python-rest-api / tests / test_voice_webhook.py View on Github external
def test_check_serialization(self):
        json_serialize(VoiceCreateWebhookRequest(url="https://someurl.com", title="foobar"))
        json_serialize(VoiceUpdateWebhookRequest(title="foobar"))
github messagebird / python-rest-api / examples / voice_create_webhook.py View on Github external
#!/usr/bin/env python
import argparse
import messagebird
from messagebird.voice_webhook import VoiceCreateWebhookRequest

parser = argparse.ArgumentParser()
parser.add_argument('--accessKey', help='access key for MessageBird API', type=str, required=True)
parser.add_argument('--url', help='url for the webhook', type=str, required=True)
parser.add_argument('--title', help='title for the webhook', type=str)
parser.add_argument('--token', help='token for the webhook', type=str)
args = vars(parser.parse_args())

try:
    client = messagebird.Client(args['accessKey'])

    create_webhook_request = VoiceCreateWebhookRequest(url=args['url'], title=args['title'], token=args['token'])
    webhook = client.voice_create_webhook(create_webhook_request)

    # Print the object information.
    print('\nThe following information was returned as a Voice Webhook object:\n')
    print('  id                 : {}'.format(webhook.id))
    print('  token              : {}'.format(webhook.token))
    print('  url                : {}'.format(webhook.url))
    print('  createdAt          : {}'.format(webhook.createdAt))
    print('  updatedAt          : {}'.format(webhook.updatedAt))

except messagebird.client.ErrorException as e:
    print('An error occured while creating a Voice Webhook object:')

    for error in e.errors:
        print('  code        : {}'.format(error.code))
        print('  description : {}'.format(error.description))