|
UserManual
User Manual for the Python wrapper of the TextMagic HTTPS API
IntroductionThis module provides Python programmers an easy interface to the TextMagic HTTPS API. TextMagic HTTPS APIAs explained at http://api.textmagic.com/https-api/textmagic-api-commands, the TextMagic API has these commands:
It is also possible to set up a "Callback URL" to be notified of:
Python APITo use the API, you need to instantiate a "client" first: import textmagic.client
client = textmagic.client.TextMagicClient('your_username', 'your_api_password')All commands are implemented as methods on the TextMagicClient class. CommandssendThe send command allows sending of one or more messages. It takes these parameters:
The response contains:
For example: result = client.send("Hello, World!", "1234657890")
message_id = result['message_id'].keys()[0]or: result = client.send("Hello, Worlds!", ["1234657890", "2345678901"])
message_ids = result['message_id'].keys()also: result = client.send("Hello, Future!", "1234657890", send_time=time.strptime("2009-07-07 13:55:45", "%Y-%m-%d %H:%M:%S"))or: result = client.send("Hello, Future!", "1234657890", send_time=time.time()+300)accountThe account command retrieves your account balance. It takes no parameters. The response contains:
For example: balance = client.account()['balance'] message_statusThe message_status command reports on the delivery status of sent messages. It takes one parameter:
The response is a dictionary keyed on the message ids, with each value containing:
For example: response = client.message_status(message_id)
message_info = response[message_id]
delivery_status = message_info['status']
time_string = time.strftime("%a, %d %b %Y %H:%M:%S", message_info['created_time'])receiveThe receive command receives messages from your Inbox. It takes one parameter:
The response is a dictionary with items:
For example: received_messages = client.receive(0) messages_info = received_messages['messages'] num_messages = len(messages_info) for message_info in messages_info: print "%(text)s received from %(from)s" % message_info delete_replyThe delete_reply command deletes messages from your Inbox. It takes one parameter:
The response is a dictionary with one item:
For example: client.delete_reply(message_info['message_id']) client.delete_reply(['123','456']) check_numberThe check_number command provides country and pricing information for a phone number. It takes one parameter:
The response is a dictionary keyed on the phone numbers, with each value containing:
For example: response = client.check_number('44123456789')
info = response['44123456789']
country = info['country']
credits = info['price']or: response = client.check_number(['44123456789', '27123456789']) Callback URLsThe TextMagic API website explains how to set up Callback URLs. A Callback URL is used by the TextMagic system to send notifications of:
Notification is implemented as a POST request to the defined callback URL. callback_messageWhen a notification is received you can call callback_message, passing it the POST parameters as a dictionary. It responds with either a StatusCallbackResponse or a ReplyCallbackResponse. StatusCallbackResponseThis is a notification of the success or failure of message delivery. It is a dictionary with keys:
ReplyCallbackResponseThis is a notification of an incoming SMS. It is a dictionary with keys:
ErrorsA TextMagicError is raised when an error response is received from the TextMagic server. The list of error codes and messages is available at http://api.textmagic.com/https-api/api-error-codes. |