#!/usr/bin/python2.7

import json
import sys
import urllib

class FreeMobileSMS():

    def __init__(self, config="config.json"):
        self.baseURL = "https://smsapi.free-mobile.fr"
        self.route = "/sendmsg"
        self.file = config
        self.codes = [200, 400, 402, 403, 500]
        self.messages = ["Message send", "Missing parameter", "Too much messages send", "Service not enable", "Server not available"]
        try:
            configFile = open(self.file)
            dataFile = json.load(configFile)
            self.login = dataFile["login"]
            self.token = dataFile["token"]
        except:
            raise Exception("Error with file " + self.file + "\n")

    def makeRoute(self, message):
        route = self.baseURL + self.route
        route += "?user=" + self.login
        route += "&pass=" + self.token
        route += "&msg=" + urllib.quote(message)
        return route

    def checkCode(self, code):
        index = self.codes.index(code)
        if index >= 0:
            return self.messages[index]
        else:
            return "Error message not found"

    def send(self, message):
        route = self.makeRoute(message)
        res = urllib.urlopen(route)
        code = int(res.getcode())
        message = self.checkCode(code)
        return code, message

def usage():
    print("Usage :")
    print("./sms.py [--config=file] message")

if __name__ == '__main__':
    if len(sys.argv) > 1:
        config = "config.json"
        for arg in sys.argv:
            if arg.startswith("--config="):
                tab = arg.split("=")
                if (len(tab) > 1 and len(tab[1])):
                    config = tab[1]
                    sys.argv.remove(arg)
                else:
                    usage()
                    sys.exit(1)
        sms = FreeMobileSMS(config)
        code, message = sms.send(sys.argv[1])
        print (str(code) + " " + message)
    else:
        usage()
        sys.exit(1)

#!/usr/bin/python2.7
# -*- coding: utf8 -*-

import json
import sys
import urllib

class FreeMobileSMS(object):

	def __init__(self, config_file="config.json"):
		self._URL = "https://smsapi.free-mobile.fr/sendmsg?user={0}&pass={1}&msg={2}"
		self._file = config
		self._codes = {
			200: "Message send",
			400: "Missing parameter",
			402: "Too much messages send",
			403: "Service not enable",
			500: "Server not available"
		}
		try:
			configFile = open(self._file)
			dataFile = json.load(configFile)
			self._login = dataFile["login"]
			self._token = dataFile["token"]
		except:
			raise Exception("Error with file " + self._file + "\n")

	def _makeRoute(self, message):
		return self._URL.format(self._login, self._token, urllib.quote(message))

	def _checkCode(self, code):
		if code in self._codes:
			return code, self._codes[code]
		else:
			return code, "Error message not found"

	def send(self, message):
		route = self._makeRoute(message)
		res = urllib.urlopen(route)
		return self._checkCode(int(res.getcode()))

def usage():
	print("Usage :")
	print("./sms.py [--config=file] message")

if __name__ == '__main__':
	if len(sys.argv) > 1:
		config = "config.json"
		for arg in sys.argv:
			if arg.startswith("--config="):
				tab = arg.split("=")
				if (len(tab) > 1 and len(tab[1])):
					config = tab[1]
					sys.argv.remove(arg)
				else:
					usage()
					sys.exit(1)
		sms = FreeMobileSMS(config)
		code, message = sms.send(sys.argv[1])
		print (str(code) + " " + message)
	else:
		usage()
		sys.exit(1)

Clean Class