Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@ install:
- pip install requests
- pip install codecov
- pip install pytest pytest-cov
- pip install pycodestyle
- pip install .
script:
- coverage run --source=messagebird -m unittest discover -s tests/
- coverage report --fail-under=80
- pycodestyle --statistics --ignore=E121,E123,E126,E133,E226,E241,E242,E704,W503,W504,W505,E501 ./messagebird/
- pycodestyle --statistics --ignore=E121,E123,E126,E133,E226,E241,E242,E704,W503,W504,W505,E501 ./tests/
matrix:
allow_failures:
- python: 'nightly'
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ Your balance:

Please see the other examples for a complete overview of all the available API calls.

To run examples with arguments, try:
```shell script
$ python ./examples/voice_create_webhook.py --accessKey accessKeyWhichNotExist --url https://example.com --title HELLO_WEBHOOK --token HELLO_TOKEN
```

Conversations WhatsApp Sandbox
-------------
To use the whatsapp sandbox you need to add `messagebird.Feature.ENABLE_CONVERSATIONS_API_WHATSAPP_SANDBOX` to the list of features you want enabled. Don't forget to replace `YOUR_ACCESS_KEY` with your actual access key.
Expand Down
36 changes: 36 additions & 0 deletions examples/voice_create_webhook.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/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))
print(' parameter : {}\n'.format(error.parameter))



24 changes: 24 additions & 0 deletions examples/voice_delete_webhook.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/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))
37 changes: 37 additions & 0 deletions examples/voice_list_webhook.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/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)

args = vars(parser.parse_args())

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

webhooks_list = client.voice_list_webhooks(limit=5, offset=0)

if webhooks_list is None or webhooks_list.data is None:
print("\nNo webhooks\n")
exit(0)

# Print the object information.
print('\nThe following information was returned as a Voice Webhook objects:\n')
for webhook in webhooks_list.data:
print('{')
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))
print('}\n')

except messagebird.client.ErrorException as e:
print('An error occured while reading 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))
33 changes: 33 additions & 0 deletions examples/voice_read_webhook.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/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('--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_read_webhook(args['webhookId'])

# 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 reading 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))
37 changes: 37 additions & 0 deletions examples/voice_update_webhook.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env python
import argparse
import messagebird
from messagebird.voice_webhook import VoiceUpdateWebhookRequest

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)
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'])

update_webhook_request = VoiceUpdateWebhookRequest(title=args['title'], token=args['token'])
webhook = client.voice_update_webhook(args['webhookId'], update_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 updating 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))



9 changes: 5 additions & 4 deletions messagebird/balance.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from messagebird.base import Base


class Balance(Base):
def __init__(self):
self.amount = None
self.type = None
self.payment = None
def __init__(self):
self.amount = None
self.type = None
self.payment = None
19 changes: 10 additions & 9 deletions messagebird/base.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
from datetime import datetime

import dateutil.parser
import json


class Base(object):
def load(self, data):
for name, value in list(data.items()):
if hasattr(self, name) and not callable(getattr(self,name)):
setattr(self, name, value)
def load(self, data):
for name, value in list(data.items()):
if hasattr(self, name) and not callable(getattr(self, name)):
setattr(self, name, value)

return self
return self

@staticmethod
def value_to_time(value, format='%Y-%m-%dT%H:%M:%S+00:00'):
if value is not None:
return dateutil.parser.parse(value).replace(microsecond=0)
@staticmethod
def value_to_time(value, format='%Y-%m-%dT%H:%M:%S+00:00'):
if value is not None:
return dateutil.parser.parse(value).replace(microsecond=0)
6 changes: 3 additions & 3 deletions messagebird/call.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ def __init__(self):
@property
def data(self):
return self._data

@data.setter
def data(self, value):
self._data = CallData().load(value[0])

def __str__(self):
return "\n".join([
'id : %s' % self.id,
'data.'+'data.'.join(str(self._data).splitlines(True)),
])
'data.' + 'data.'.join(str(self._data).splitlines(True)),
])
12 changes: 6 additions & 6 deletions messagebird/call_data.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from messagebird.base import Base
from messagebird.webhook import Webhook


class CallData(Base):

def __init__(self):
self.id = None
self.status = None
Expand All @@ -13,27 +14,26 @@ def __init__(self):
self._endedAt = None
self._webhook = None


@property
def updatedAt(self):
return self._updatedAt

@updatedAt.setter
def updatedAt(self, value):
self._updatedAt = self.value_to_time(value, '%Y-%m-%dT%H:%M:%SZ')

@property
def createdAt(self):
return self._createdAt

@createdAt.setter
def createdAt(self, value):
self._createdAt = self.value_to_time(value, '%Y-%m-%dT%H:%M:%SZ')

@property
def endedAt(self):
return self._endedAt

@endedAt.setter
def endedAt(self, value):
self._endedAt = self.value_to_time(value, '%Y-%m-%dT%H:%M:%SZ')
Expand All @@ -56,4 +56,4 @@ def __str__(self):
'updatedAt : %s' % self.updatedAt,
'createdAt : %s' % self.createdAt,
'endedAt : %s' % self.endedAt,
])
])
3 changes: 2 additions & 1 deletion messagebird/call_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ def data(self, value):

self._data = items


class CallFlow(Base):

def __init__(self):
Expand Down Expand Up @@ -134,4 +135,4 @@ def load(self, data):
if hasattr(self, name) and not callable(getattr(self, name)):
setattr(self, name, value)

return self
return self
1 change: 0 additions & 1 deletion messagebird/call_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,3 @@ def data(self, value):
if isinstance(value, list):
self.count = len(value)
self.items = value

Loading