1. EXAMPLE CODE

This section shows sample usage in various environments.

1.1 Python 2.7 using httplib

import sys
import httplib
import urllib
import base64

URL = "smartreplypath.spirius.com"
PORT = 55001
CREDENTIALS = base64.b64encode("Username:Password")

def send_replypath_sms_v1(dest, message):
  try:
    encoded_dest = urllib.quote_plus(dest)
    encoded_mess = urllib.quote_plus(message)
    h = httplib.HTTPSConnection(URL, PORT, timeout=10)
    query = "/v1/replypath/sendsms/%s/%s" % (encoded_dest, encoded_mess)
    h.putrequest("GET", query)
    h.putheader("Accept", "application/json")
    h.putheader("Authorization", "Basic " + CREDENTIALS)
    h.endheaders()
    r = h.getresponse()
    if (r.status != 200):
        return ("%d %s") % (r.status, r.reason)	

    return r.read()
      
  except Exception, e:
    sys.stderr.write(str(e))
      
  finally:
    if (h is not None):
        h.close()
      
print send_replypath_sms_v1("+46123456789", "Hello world")

1.2 Python 2.7 using urllib2

import sys
import httplib
import urllib
import urllib2
import base64

URL = "https://smartreplypath.spirius.com:55001/v1/replypath/sendsms?"
CREDENTIALS = base64.b64encode("Username:Password")

def send_replypath_sms_v2(dest, message):
  try:
    params = { 'To': dest, 'Msg': message }
    encoded_params = urllib.urlencode(params)
    request = urllib2.Request(URL + encoded_params)
    request.add_header("Authorization", "Basic %s" % CREDENTIALS)
    response = urllib2.urlopen(request)
    return  response.read()
  
  except urllib2.HTTPError, error:
    return error.read()
  
  except Exception, e:
    sys.stderr.write(str(e))
    return ""


print send_replypath_sms_v2("+46123456789", "Hello world")

1.3 Python 2.7 using Requests (and urllib3)

Requests 1

import sys
import requests

URL = "https://smartreplypath.spirius.com:55001/v1/replypath/sendsms"
USER = "Username"
PASS = "Password"

def send_replypath_sms_v3(dest, message):
  try:
    _params = { 'To': dest, 'Msg': message }
    r = requests.get(URL, params=_params, auth=(USER,PASS), timeout=10)
    return r.text

  except Exception, e:
    sys.stderr.write(str(e))
    return ""

print send_replypath_sms_v3("+46123456789", "Hello world")