WebSmsComToolkit (version 1.0.2)
index
d:\eclipse_workspace\bpsdk-python\websmscomtoolkit.py

# WebSmsComToolkit.py
# A python module to send sms messages (text and binary) over api.websms.com Gateway
 
 
# Quick Example how to send a text message:
import sys
import traceback
import WebSmsComToolkit
 
username                = 'your_username'
password                = 'your_password'
gateway_url             = 'https://api.websms.com/'
recipient_address_list  = [4367612345678L]
message_text_unicode    = u'Willkommen zur BusinessPlatform SDK von websms.com! Diese Nachricht enth\u00E4lt 160 Zeichen. Sonderzeichen: \u00E4\u00F6\u00FC\u00DF. Eurozeichen: \u20ac. Das Ende wird nun ausgez\u00E4hlt43210'
max_sms_per_message     = 1
# true: do not send sms for real, just test interface
is_test                 = False
 
try:
  client  = WebSmsComToolkit.Client(gateway_url, username, password)
  message = WebSmsComToolkit.TextMessage(recipient_address_list, message_text_unicode)
  response = client.send(message, max_sms_per_message, is_test)
  
  print "Transferred/Sent"  
  print "transferId      : " + str(response.transferId)
  print "clientMessageId : " + str(response.clientMessageId)
  
except WebSmsComToolkit.ParameterValidationException, e:
  print "ParameterValidationException caught: " + str(e.message)
    
except WebSmsComToolkit.AuthorizationFailedException, e:
  print "AuthorizationFailedException caught: " + str(e.message)
  
except WebSmsComToolkit.ApiException, e:
  print "ApiException caught. statusMessage: " + str(e.message) + ", statusCode: " + str(e.code)
  
except WebSmsComToolkit.HttpConnectionException, e:
  print "HttpConnectionException caught: " + str(e.message) + " HTTP Status: " + str(e.code)
  
except WebSmsComToolkit.UnknownResponseException, e:
  print "UnknownResponseException caught: " + str(e.message)
    
except Exception, e:
  print "Exception caught: " , e
  traceback.print_exc(file=sys.stdout)

 
Modules
       
base64
platform
re
ssl
urllib2

 
Classes
       
__builtin__.object
Client
JsonWrapper
Message
BinaryMessage
TextMessage
Response
exceptions.Exception(exceptions.BaseException)
ApiException
AuthorizationFailedException
HttpConnectionException
ParameterValidationException
UnknownResponseException

 
class ApiException(exceptions.Exception)
    Exception for API Responses that did not return OK.(2000 or 2001)
contains the API status code
 
 
Method resolution order:
ApiException
exceptions.Exception
exceptions.BaseException
__builtin__.object

Methods defined here:
__init__(self, message, code)

Data descriptors defined here:
__weakref__
list of weak references to the object (if defined)

Data and other attributes inherited from exceptions.Exception:
__new__ = <built-in method __new__ of type object>
T.__new__(S, ...) -> a new object with type S, a subtype of T

Methods inherited from exceptions.BaseException:
__delattr__(...)
x.__delattr__('name') <==> del x.name
__getattribute__(...)
x.__getattribute__('name') <==> x.name
__getitem__(...)
x.__getitem__(y) <==> x[y]
__getslice__(...)
x.__getslice__(i, j) <==> x[i:j]
 
Use of negative indices is not supported.
__reduce__(...)
__repr__(...)
x.__repr__() <==> repr(x)
__setattr__(...)
x.__setattr__('name', value) <==> x.name = value
__setstate__(...)
__str__(...)
x.__str__() <==> str(x)
__unicode__(...)

Data descriptors inherited from exceptions.BaseException:
__dict__
args
message

 
class AuthorizationFailedException(exceptions.Exception)
    Authorization failed. Invalid or inactive Username/Password 
in e.G.: Basic Authentication
 
 
Method resolution order:
AuthorizationFailedException
exceptions.Exception
exceptions.BaseException
__builtin__.object

Methods defined here:
__init__(self, message, code=401)

Data descriptors defined here:
__weakref__
list of weak references to the object (if defined)

Data and other attributes inherited from exceptions.Exception:
__new__ = <built-in method __new__ of type object>
T.__new__(S, ...) -> a new object with type S, a subtype of T

Methods inherited from exceptions.BaseException:
__delattr__(...)
x.__delattr__('name') <==> del x.name
__getattribute__(...)
x.__getattribute__('name') <==> x.name
__getitem__(...)
x.__getitem__(y) <==> x[y]
__getslice__(...)
x.__getslice__(i, j) <==> x[i:j]
 
Use of negative indices is not supported.
__reduce__(...)
__repr__(...)
x.__repr__() <==> repr(x)
__setattr__(...)
x.__setattr__('name', value) <==> x.name = value
__setstate__(...)
__str__(...)
x.__str__() <==> str(x)
__unicode__(...)

Data descriptors inherited from exceptions.BaseException:
__dict__
args
message

 
class BinaryMessage(Message)
    Binary Message object for sending binary segments over Client.
Compared to the TextMessage class, a BinaryMessage contains its message content as a list of message segments.
Therefore when sending a BinaryMessage 'maxSmsPerMessage' parameter is not supported
 
Example for creating binary message object:
 
  message = WebSmsComToolkit.BinaryMessage([4367612345678L, 43676123456789L], ["BQAD/AIBWnVzYW1tZW4=","BQAD/AICZ2Vmw7xndC4="], True)
 
 
Method resolution order:
BinaryMessage
Message
__builtin__.object

Methods defined here:
__init__(self, recipients, message_content, user_data_header_present=False)
Constructor
 
Params: - recipients              : list of long
        - message_content         : list of string/unicode (containing binary encoded with base64) 
        - user_data_header_present: bool
 
Throws: ParameterValidationException
get_message_content(self)
Get message_content
 
Returns: messageContent (list of string/unicode) set for this message obejct
get_user_data_header_present(self)
Get user_data_header_present
 
Returns: userDataHeaderPresent set for this Message object (bool)
set_message_content(self, message_content)
Set message_content
 
Params: - message_content (list of string/unicode containing base64 encoded binary)
          e.G.: message.message_content(['BQAD/AIBWnVzYW1tZW4=','BQAD/AICZ2Vmw7xndC4=']);
 
Returns: messageContent set for this Message object
 
Throws: ParameterValidationException
set_user_data_header_present(self, userDataHeaderPresent)
Set user_data_header_present(userDataHeaderPresent)
 
Params: - userDataHeaderPresent: (bool)
          Set it to True when the binary that was base64 encoded contained user a data header
 
Returns: userDataHeaderPresent set for this Message object
 
Throws: ParameterValidationException

Data descriptors defined here:
message_content
Get message_content
 
Returns: messageContent (list of string/unicode) set for this message obejct
user_data_header_present
Get user_data_header_present
 
Returns: userDataHeaderPresent set for this Message object (bool)

Methods inherited from Message:
check_recipient_address_list(self, recipientAddressList)
Used internally to check validity of recipient_address_list (list of long)
data(self)
Read message data()
 
Returns: dict representation of Message object (only set values)
get_client_message_id(self)
Get client_message_id
Returns: clientMessaegId set for this Message object
get_notification_callback_url(self)
Get notification_callback_url
Returns: set notificationCallbackUrl of Message object
get_priority(self)
Get priority
Returns: priority set for this Message object
get_recipient_address_list(self)
Get recipient_address_list (list of long) from message
Returns: list
get_send_as_flash_sms(self)
Get send_as_flash_sms
returns: set sendAsFlashSms of Message object
get_sender_address(self)
Get sender_address from message
 
Returns: senderAddress of Message object
get_sender_address_type(self)
Get sender_address_type
 
Returns: a string of ['national', 'international', 'alphanumeric' or 'shortcode']
set_client_message_id(self, clientMessageId)
Set client_message_id(string)
 
Params: - clientMessageId: string with message id for this message. 
          This message id is returned with the response to the send request
          and used for notifications
 
Returns: clientMessaegId set for this Message object
 
Throws: ParameterValidationException
set_notification_callback_url(self, notificationCallbackUrl)
Set notification_callback_url
 
Params: - notificationCallbackUrl: string of notification callback URI
  customers URI that listens for delivery report notifications
  or replies for this message
  
Returns: set notificationCallbackUrl of Message object
 
Throws: ParameterValidationException
set_priority(self, priority)
Set priority(priority)
 
Params: - priority: message priority as integer (1 to 9)
  (level height must be supported by account settings)
 
Returns: priority set for this Message object
 
Throws: ParameterValidationException
set_recipient_address_list(self, recipients)
Set recipient_address_list(recipients)
Params: - recipients:  (list of long containing full international MSISDNs) e.G.: [4367612345678L, long("4912345678")]
Throws: - ParameterValidationException
set_send_as_flash_sms(self, sendAsFlashSms)
Set send_as_flash_sms(bool)
 
Params:  boolean: True, False or None
 
Returns: set sendAsFlashSms of Message object
set_sender_address(self, senderAddress)
Set sender_address
available sender address is dependend on user account
 
Params: - senderAddress: string of sender address (msisdn or alphanumeric)
 
Returns: senderAddress of Message object
 
Throws: ParameterValidationException
set_sender_address_type(self, senderAddressType)
Set sender_address_type
  available one of: ('national', 'international', 'alphanumeric' or 'shortcode')
 
Returns: sender_adress_type  set
 
Throws: ParameterValidationException

Data descriptors inherited from Message:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)
client_message_id
Get client_message_id
Returns: clientMessaegId set for this Message object
notification_callback_url
Get notification_callback_url
Returns: set notificationCallbackUrl of Message object
priority
Get priority
Returns: priority set for this Message object
recipient_address_list
Get recipient_address_list (list of long) from message
Returns: list
send_as_flash_sms
Get send_as_flash_sms
returns: set sendAsFlashSms of Message object
sender_address
Get sender_address from message
 
Returns: senderAddress of Message object
sender_address_type
Get sender_address_type
 
Returns: a string of ['national', 'international', 'alphanumeric' or 'shortcode']

Data and other attributes inherited from Message:
availableSenderAddressType = ['national', 'international', 'alphanumeric', 'shortcode']

 
class Client(__builtin__.object)
    Client used to send sms messages (TextMessage or BinaryMessage objects)
Create once and send messages with its send() method
 
Example:
  client = WebSmsComToolkit.Client('http://api.websms.com/', username, password)
 
  Methods defined here:
__init__(self, url_base, username, password)
Constructor requiring base url, username and password
You only need to create the client once.
get_timeout(self)
Get timeout of urllib2 client
 
Returns: seconds (int)
get_verbose(self)
Get verbose mode of Client
 
Returns: verbose mode (bool)
send(self, message_object=None, max_sms_per_message=None, is_test=None)
Send message to websms.com API
 
Params: - message_object      : Must be instanceof TextMessage or BinaryMessage
        - max_sms_per_message : int (1-255) )limiting the maximum set sms per message (For TextMessage. Set it to None for BinaryMessage)
        - is_test             : bool indicating if message is a test message (False is default). 
                                Test Messages will not be sent, but generate a successful response.
Returns: - response of type Response
 
Throws: - ParameterValidationException
        - AuthorizationFailedException
        - ApiException
        - HttpConnectionException
        - Exception
set_timeout(self, seconds)
Set timeout of urllib2  (default is 10)
 
!ATTENTION! 
Will only work for python 2.6+, The optional timeout parameter specifies a timeout in 
seconds for blocking operations like the connection attempt.
 
For python <2.6, the global default timeout setting can be used, 
but are not affected by this timeout
 
Params: - seconds (int)
 
Returns: seconds set
set_verbose(self, bool_verbose)
Set verbose mode of Client
 
Params: - bool_verbose (boolean)
 
Returns: verbose mode set

Data descriptors defined here:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)
timeout
Get timeout of urllib2 client
 
Returns: seconds (int)
verbose
verbose mode

Data and other attributes defined here:
VERSION = '1.0.0'

 
class HttpConnectionException(exceptions.Exception)
    HTTP Connection failed.
 
 
Method resolution order:
HttpConnectionException
exceptions.Exception
exceptions.BaseException
__builtin__.object

Methods defined here:
__init__(self, message, code=0)

Data descriptors defined here:
__weakref__
list of weak references to the object (if defined)

Data and other attributes inherited from exceptions.Exception:
__new__ = <built-in method __new__ of type object>
T.__new__(S, ...) -> a new object with type S, a subtype of T

Methods inherited from exceptions.BaseException:
__delattr__(...)
x.__delattr__('name') <==> del x.name
__getattribute__(...)
x.__getattribute__('name') <==> x.name
__getitem__(...)
x.__getitem__(y) <==> x[y]
__getslice__(...)
x.__getslice__(i, j) <==> x[i:j]
 
Use of negative indices is not supported.
__reduce__(...)
__repr__(...)
x.__repr__() <==> repr(x)
__setattr__(...)
x.__setattr__('name', value) <==> x.name = value
__setstate__(...)
__str__(...)
x.__str__() <==> str(x)
__unicode__(...)

Data descriptors inherited from exceptions.BaseException:
__dict__
args
message

 
class JsonWrapper(__builtin__.object)
    This class can be used to offer a custom 'loads' and 'dumps' function for JSON by overwriting it
 
  Methods defined here:
__init__(self)
dumps(self, param)
loads(self, param)

Data descriptors defined here:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

 
class Message(__builtin__.object)
    Abstract Base Message object
inherited by TextMessage and BinaryMessage
 
  Methods defined here:
__init__(self, recipients)
check_recipient_address_list(self, recipientAddressList)
Used internally to check validity of recipient_address_list (list of long)
data(self)
Read message data()
 
Returns: dict representation of Message object (only set values)
get_client_message_id(self)
Get client_message_id
Returns: clientMessaegId set for this Message object
get_notification_callback_url(self)
Get notification_callback_url
Returns: set notificationCallbackUrl of Message object
get_priority(self)
Get priority
Returns: priority set for this Message object
get_recipient_address_list(self)
Get recipient_address_list (list of long) from message
Returns: list
get_send_as_flash_sms(self)
Get send_as_flash_sms
returns: set sendAsFlashSms of Message object
get_sender_address(self)
Get sender_address from message
 
Returns: senderAddress of Message object
get_sender_address_type(self)
Get sender_address_type
 
Returns: a string of ['national', 'international', 'alphanumeric' or 'shortcode']
set_client_message_id(self, clientMessageId)
Set client_message_id(string)
 
Params: - clientMessageId: string with message id for this message. 
          This message id is returned with the response to the send request
          and used for notifications
 
Returns: clientMessaegId set for this Message object
 
Throws: ParameterValidationException
set_notification_callback_url(self, notificationCallbackUrl)
Set notification_callback_url
 
Params: - notificationCallbackUrl: string of notification callback URI
  customers URI that listens for delivery report notifications
  or replies for this message
  
Returns: set notificationCallbackUrl of Message object
 
Throws: ParameterValidationException
set_priority(self, priority)
Set priority(priority)
 
Params: - priority: message priority as integer (1 to 9)
  (level height must be supported by account settings)
 
Returns: priority set for this Message object
 
Throws: ParameterValidationException
set_recipient_address_list(self, recipients)
Set recipient_address_list(recipients)
Params: - recipients:  (list of long containing full international MSISDNs) e.G.: [4367612345678L, long("4912345678")]
Throws: - ParameterValidationException
set_send_as_flash_sms(self, sendAsFlashSms)
Set send_as_flash_sms(bool)
 
Params:  boolean: True, False or None
 
Returns: set sendAsFlashSms of Message object
set_sender_address(self, senderAddress)
Set sender_address
available sender address is dependend on user account
 
Params: - senderAddress: string of sender address (msisdn or alphanumeric)
 
Returns: senderAddress of Message object
 
Throws: ParameterValidationException
set_sender_address_type(self, senderAddressType)
Set sender_address_type
  available one of: ('national', 'international', 'alphanumeric' or 'shortcode')
 
Returns: sender_adress_type  set
 
Throws: ParameterValidationException

Data descriptors defined here:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)
client_message_id
Get client_message_id
Returns: clientMessaegId set for this Message object
notification_callback_url
Get notification_callback_url
Returns: set notificationCallbackUrl of Message object
priority
Get priority
Returns: priority set for this Message object
recipient_address_list
Get recipient_address_list (list of long) from message
Returns: list
send_as_flash_sms
Get send_as_flash_sms
returns: set sendAsFlashSms of Message object
sender_address
Get sender_address from message
 
Returns: senderAddress of Message object
sender_address_type
Get sender_address_type
 
Returns: a string of ['national', 'international', 'alphanumeric' or 'shortcode']

Data and other attributes defined here:
availableSenderAddressType = ['national', 'international', 'alphanumeric', 'shortcode']

 
class ParameterValidationException(exceptions.Exception)
    Some parameter given is invalid
 
 
Method resolution order:
ParameterValidationException
exceptions.Exception
exceptions.BaseException
__builtin__.object

Methods defined here:
__init__(self, message, code=0)

Data descriptors defined here:
__weakref__
list of weak references to the object (if defined)

Data and other attributes inherited from exceptions.Exception:
__new__ = <built-in method __new__ of type object>
T.__new__(S, ...) -> a new object with type S, a subtype of T

Methods inherited from exceptions.BaseException:
__delattr__(...)
x.__delattr__('name') <==> del x.name
__getattribute__(...)
x.__getattribute__('name') <==> x.name
__getitem__(...)
x.__getitem__(y) <==> x[y]
__getslice__(...)
x.__getslice__(i, j) <==> x[i:j]
 
Use of negative indices is not supported.
__reduce__(...)
__repr__(...)
x.__repr__() <==> repr(x)
__setattr__(...)
x.__setattr__('name', value) <==> x.name = value
__setstate__(...)
__str__(...)
x.__str__() <==> str(x)
__unicode__(...)

Data descriptors inherited from exceptions.BaseException:
__dict__
args
message

 
class Response(__builtin__.object)
    Response object returned by Client
Offers properties:
    - rawContent      : response content of send request (unicode)
    - statusCode      : status code returned from API (int)
    - statusMessage   : description of status code (string)
    - transferId      : the id of the message transfer to the API (unicode)
    - clientMessageId : the message id (unicode)
 
  Methods defined here:
__init__(self, raw_content, statusCode, statusMessage, transferId, clientMessageId=None)

Data descriptors defined here:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

 
class TextMessage(Message)
    Text Message Class for sending utf8 text message over Client.
Compared to the BinaryMessage class, a TextMessage has one messageContent that will be sent as one or multiple sms.
The 'maxSmsPerMessage' parameter when sending the message limits the generated sms amount
 
Example for creating message object
 
  message = WebSmsComToolkit.TextMessage([4367612345678L,43676123456789L], u'Hallo Welt')
 
 
Method resolution order:
TextMessage
Message
__builtin__.object

Methods defined here:
__init__(self, recipients, message_content)
Constructor
 
Params: - recipients      : list of long 
        - message_content : unicode
        
Throws ParameterValidationException
get_message_content(self)
Get message_content
 
Returns: messageContent set for this Message object
set_message_content(self, message_content)
Set message_content(unicode)
 
Params: - message_content: unicode string
 
Returns: set messageContent of this Message object
 
Throws: ParameterValidationException

Data descriptors defined here:
message_content
Get message_content
 
Returns: messageContent set for this Message object

Methods inherited from Message:
check_recipient_address_list(self, recipientAddressList)
Used internally to check validity of recipient_address_list (list of long)
data(self)
Read message data()
 
Returns: dict representation of Message object (only set values)
get_client_message_id(self)
Get client_message_id
Returns: clientMessaegId set for this Message object
get_notification_callback_url(self)
Get notification_callback_url
Returns: set notificationCallbackUrl of Message object
get_priority(self)
Get priority
Returns: priority set for this Message object
get_recipient_address_list(self)
Get recipient_address_list (list of long) from message
Returns: list
get_send_as_flash_sms(self)
Get send_as_flash_sms
returns: set sendAsFlashSms of Message object
get_sender_address(self)
Get sender_address from message
 
Returns: senderAddress of Message object
get_sender_address_type(self)
Get sender_address_type
 
Returns: a string of ['national', 'international', 'alphanumeric' or 'shortcode']
set_client_message_id(self, clientMessageId)
Set client_message_id(string)
 
Params: - clientMessageId: string with message id for this message. 
          This message id is returned with the response to the send request
          and used for notifications
 
Returns: clientMessaegId set for this Message object
 
Throws: ParameterValidationException
set_notification_callback_url(self, notificationCallbackUrl)
Set notification_callback_url
 
Params: - notificationCallbackUrl: string of notification callback URI
  customers URI that listens for delivery report notifications
  or replies for this message
  
Returns: set notificationCallbackUrl of Message object
 
Throws: ParameterValidationException
set_priority(self, priority)
Set priority(priority)
 
Params: - priority: message priority as integer (1 to 9)
  (level height must be supported by account settings)
 
Returns: priority set for this Message object
 
Throws: ParameterValidationException
set_recipient_address_list(self, recipients)
Set recipient_address_list(recipients)
Params: - recipients:  (list of long containing full international MSISDNs) e.G.: [4367612345678L, long("4912345678")]
Throws: - ParameterValidationException
set_send_as_flash_sms(self, sendAsFlashSms)
Set send_as_flash_sms(bool)
 
Params:  boolean: True, False or None
 
Returns: set sendAsFlashSms of Message object
set_sender_address(self, senderAddress)
Set sender_address
available sender address is dependend on user account
 
Params: - senderAddress: string of sender address (msisdn or alphanumeric)
 
Returns: senderAddress of Message object
 
Throws: ParameterValidationException
set_sender_address_type(self, senderAddressType)
Set sender_address_type
  available one of: ('national', 'international', 'alphanumeric' or 'shortcode')
 
Returns: sender_adress_type  set
 
Throws: ParameterValidationException

Data descriptors inherited from Message:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)
client_message_id
Get client_message_id
Returns: clientMessaegId set for this Message object
notification_callback_url
Get notification_callback_url
Returns: set notificationCallbackUrl of Message object
priority
Get priority
Returns: priority set for this Message object
recipient_address_list
Get recipient_address_list (list of long) from message
Returns: list
send_as_flash_sms
Get send_as_flash_sms
returns: set sendAsFlashSms of Message object
sender_address
Get sender_address from message
 
Returns: senderAddress of Message object
sender_address_type
Get sender_address_type
 
Returns: a string of ['national', 'international', 'alphanumeric' or 'shortcode']

Data and other attributes inherited from Message:
availableSenderAddressType = ['national', 'international', 'alphanumeric', 'shortcode']

 
class UnknownResponseException(exceptions.Exception)
    Response is unknown
 
 
Method resolution order:
UnknownResponseException
exceptions.Exception
exceptions.BaseException
__builtin__.object

Methods defined here:
__init__(self, message, code=0)

Data descriptors defined here:
__weakref__
list of weak references to the object (if defined)

Data and other attributes inherited from exceptions.Exception:
__new__ = <built-in method __new__ of type object>
T.__new__(S, ...) -> a new object with type S, a subtype of T

Methods inherited from exceptions.BaseException:
__delattr__(...)
x.__delattr__('name') <==> del x.name
__getattribute__(...)
x.__getattribute__('name') <==> x.name
__getitem__(...)
x.__getitem__(y) <==> x[y]
__getslice__(...)
x.__getslice__(i, j) <==> x[i:j]
 
Use of negative indices is not supported.
__reduce__(...)
__repr__(...)
x.__repr__() <==> repr(x)
__setattr__(...)
x.__setattr__('name', value) <==> x.name = value
__setstate__(...)
__str__(...)
x.__str__() <==> str(x)
__unicode__(...)

Data descriptors inherited from exceptions.BaseException:
__dict__
args
message

 
Functions
       
warn(...)
Issue a warning, or maybe ignore it or raise an exception.

 
Data
        __author__ = 'Gerd Reifenauer'
__version__ = '1.0.2'
hexversion = 34014960

 
Author
        Gerd Reifenauer