How to use the messagebird.Client 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_conversation_webhook.py View on Github external
def test_conversation_webhook_read(self):
        http_client = Mock()
        http_client.request.return_value = '{"id":"5031e2da142d401c93fbc38518ebb604","url":"https://example.com","channelId":"c0dae31e440145e094c4708b7d908842","events":["conversation.created","conversation.updated"],"status":"enabled","createdDatetime":"2019-04-03T08:41:37Z","updatedDatetime":null}'

        web_hook = Client('', http_client).conversation_read_webhook('webhook-id')

        http_client.request.assert_called_once_with('webhooks/webhook-id', 'GET', None)
        self.assertEqual(datetime(2019, 4, 3, 8, 41, 37, tzinfo=tzutc()), web_hook.createdDatetime)
        self.assertEqual(None, web_hook.updatedDatetime)
        self.assertEqual(['conversation.created', 'conversation.updated'], web_hook.events)
github messagebird / python-rest-api / tests / test_verify.py View on Github external
def test_verify_delete_invalid(self):
        http_client = Mock()
        http_client.request.return_value = '{"errors": [{"code": 20,"description": "verification id not found","parameter": null}]}'

        with self.assertRaises(ErrorException):
            Client('', http_client).verify_delete('non-existent-verify-id')

        http_client.request.assert_called_once_with('verify/non-existent-verify-id', 'DELETE', None)
github messagebird / python-rest-api / tests / test_number.py View on Github external
def test_purchased_numbers_list(self):
        http_client = Mock()
        http_client.request.return_value = '{"items":[{"number":"3197010260188","country":"NL","region":"","locality":"","features":["sms","voice"],"type":"mobile"}],"limit":20,"count":1}'

        numbers = Client('', http_client).purchased_numbers_list({'number': 319}, 40, 2)

        http_client.request.assert_called_once_with('phone-numbers', 'GET', {'number': 319, 'limit': 40, 'offset': 2})

        self.assertEqual(1, numbers.count)
        self.assertEqual(1, len(numbers.items))
        self.assertEqual('3197010260188', numbers.items[0].number)
github messagebird / python-rest-api / tests / test_verify.py View on Github external
def test_verify_create(self):
        http_client = Mock()
        http_client.request.return_value = '{}'

        Client('', http_client).verify_create('31612345678', {})

        http_client.request.assert_called_once_with('verify', 'POST', {'recipient': '31612345678'})
github messagebird / python-rest-api / examples / lookup_hlr.py View on Github external
try:
  ACCESS_KEY
except NameError:
  print('You need to set an ACCESS_KEY constant in this file')
  sys.exit(1)

try:
  PHONE_NUMBER
except NameError:
  print('You need to set a PHONE_NUMBER constant in this file')
  sys.exit(1)

try:
  # Create a MessageBird client with the specified ACCESS_KEY.
  client = messagebird.Client(ACCESS_KEY)

  # Create a new Lookup HLR object.
  lookup_hlr = client.lookup_hlr(PHONE_NUMBER)

  # Print the object information.
  print('\nThe following information was returned as a Lookup HLR object:\n')
  print('  id              : %s' % lookup_hlr.id)
  print('  href            : %s' % lookup_hlr.href)
  print('  msisdn          : %d' % lookup_hlr.msisdn)
  print('  network         : %d' % lookup_hlr.network)
  print('  reference       : %s' % lookup_hlr.reference)
  print('  status          : %s' % lookup_hlr.status)
  print('  details         : %s' % lookup_hlr.details)
  print('  createdDatetime : %s' % lookup_hlr.createdDatetime)
  print('  statusDatetime  : %s\n' % lookup_hlr.statusDatetime)
github messagebird / python-rest-api / examples / conversation_read.py View on Github external
#!/usr/bin/env python
import messagebird
import argparse

parser = argparse.ArgumentParser()
parser.add_argument('--accessKey', help='access key for MessageBird API', type=str, required=True)
parser.add_argument('--conversationId', help='conversation that you want the message list', type=str, required=True)
args = vars(parser.parse_args())

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

    conversation = client.conversation_read(args['conversationId'])

    # Print the object information.
    print('The following information was returned as a Conversation object:')
    print(conversation)

except messagebird.client.ErrorException as e:
    print('An error occured while requesting a Conversation object:')

    for error in e.errors:
        print('  code        : %d' % error.code)
        print('  description : %s' % error.description)
        print('  parameter   : %s\n' % error.parameter)
github messagebird / python-rest-api / examples / conversation_list.py View on Github external
#!/usr/bin/env python
import messagebird
import argparse

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

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

    conversationList = client.conversation_list()

    # Print the object information.
    print('The following information was returned as a Conversation List object:')
    print(conversationList)

except messagebird.client.ErrorException as e:
    print('An error occured while requesting a Message object:')

    for error in e.errors:
        print('  code        : %d' % error.code)
        print('  description : %s' % error.description)
        print('  parameter   : %s\n' % error.parameter)
github messagebird / python-rest-api / examples / voice_messages_list.py View on Github external
import argparse
import messagebird
import sys
import os
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))


parser = argparse.ArgumentParser()
parser.add_argument(
    '--accessKey', help='access key for MessageBird API', type=str, required=True)

args = vars(parser.parse_args())

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

    # Fetch Voice Messages List from a specific offset, and within a defined limit.
    voiceMessageList = client.voice_message_list(limit=10, offset=0)

    # Print the object information.
    print('The following information was returned as a Voice Messages List object:')
    print('  Containing the following items:')
    print(voiceMessageList)
    for item in voiceMessageList.items:
        print('  {')
        print('  id                : %s' % item.id)
        print('  href              : %s' % item.href)
        print('  originator        : %s' % item.originator)
        print('  body              : %s' % item.body)
        print('  reference         : %s' % item.reference)
        print('  language          : %s' % item.language)
github messagebird / python-rest-api / examples / voice_delete_webhook.py View on Github external
#!/usr/bin/env python
import argparse
import messagebird

parser = argparse.ArgumentParser()
parser.add_argument('--accessKey', help='access key for MessageBird API', type=str, required=True)
parser.add_argument('--webhookId', help='webhook that you want to update', type=str, required=True)

args = vars(parser.parse_args())

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

    # Print the object information.
    print('Webhook has been deleted')

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

    for error in e.errors:
        print('  code        : {}'.format(error.code))
        print('  description : {}'.format(error.description))
        print('  parameter   : {}\n'.format(error.parameter))
github messagebird / python-rest-api / examples / voice_message_create.py View on Github external
#!/usr/bin/env python

import sys, os
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))

import messagebird

ACCESS_KEY = 'test_gshuPaZoeEG6ovbc8M79w0QyM'

try:
  # Create a MessageBird client with the specified ACCESS_KEY.
  client = messagebird.Client(ACCESS_KEY)

  # Send a new voice message.
  vmsg = client.voice_message_create('31612345678', 'Hello World', { 'reference' : 'Foobar' })

  # Print the object information.
  print('\nThe following information was returned as a VoiceMessage object:\n')
  print('  id                : %s' % vmsg.id)
  print('  href              : %s' % vmsg.href)
  print('  originator        : %s' % vmsg.originator)
  print('  body              : %s' % vmsg.body)
  print('  reference         : %s' % vmsg.reference)
  print('  language          : %s' % vmsg.language)
  print('  voice             : %s' % vmsg.voice)
  print('  repeat            : %s' % vmsg.repeat)
  print('  ifMachine         : %s' % vmsg.ifMachine)
  print('  scheduledDatetime : %s' % vmsg.scheduledDatetime)