Skip to content

Instantly share code, notes, and snippets.

@jvanlier
Created June 8, 2015 15:55
Show Gist options
  • Save jvanlier/3685f9c748c0af6169d9 to your computer and use it in GitHub Desktop.
Save jvanlier/3685f9c748c0af6169d9 to your computer and use it in GitHub Desktop.
Messagebird implementatie hack & fly
#!/usr/bin/env python
import messagebird
class SmsException(Exception): pass
class SmsConnector:
api_key = 'xxx'
def __init__(self):
self.client = messagebird.Client(self.api_key)
def _handle_exception(self, e):
errstr = ""
for error in e.errors:
errstr += "Errorcode: {0}. Error desc: {1}. Param: {2}\n". \
format(error.code, error.description, error.parameter)
raise SmsException(errstr)
def get_balance(self):
"""Check balance at MessageBird. Returns a string"""
try:
# Fetch the Balance object.
balance = self.client.balance()
balance_str = "Amount: {0}. Type: {1}. Payment: {2}". \
format(balance.amount, balance.type, balance.payment)
return balance_str
except messagebird.client.ErrorException as e:
self._handle_exception(e)
def send_message(self, number_list, message,name):
try:
message = self.client.message_create(
name,
number_list,
message,
{ 'reference' : 'Foobar' }
)
except messagebird.client.ErrorException as e:
self._handle_exception(e)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment