Ejemplo n.º 1
0
def send(msg, delay=True, *args, **kwargs):
    """
    Sends a message via mach's API
    """
    context = {
        'phone_number': urllib.quote(msg.phone_number),
        'sender_id': urllib.quote(kwargs.get("sender_id", DEFAULT_SENDER_ID)),
    }
    encoding_param = ""
    try:
        text = msg.text.encode("iso-8859-1")
        context["message"] = clean_outgoing_sms_text(text)
    except UnicodeEncodeError:
        context["message"] = msg.text.encode("utf-16-be").encode("hex")
        encoding_param = "&encoding=ucs"
    url = "%s?%s%s" % (settings.SMS_GATEWAY_URL,
                       settings.SMS_GATEWAY_PARAMS % context, encoding_param)
    # just opening the url is enough to send the message
    # TODO, check response
    resp = urllib2.urlopen(url).read()
    msg.save()

    create_billable_for_sms(msg, API_ID, delay=delay, response=resp)

    return resp
Ejemplo n.º 2
0
def send(msg, delay=True):
    """
    Sends a message via mach's API
    """
    outgoing_sms_text = clean_outgoing_sms_text(msg.text)
    context = {
        'message': outgoing_sms_text,
        'phone_number': urllib.quote(msg.phone_number),
    }
    url = "%s?%s" % (settings.SMS_GATEWAY_URL, settings.SMS_GATEWAY_PARAMS % context)
    # just opening the url is enough to send the message
    # TODO, check response
    resp = urllib2.urlopen(url).read()
    msg.save()
    try:
        # attempt to bill client
        from hqbilling.tasks import bill_client_for_sms
        from hqbilling.models import MachSMSBillable
        if delay:
            bill_client_for_sms.delay(MachSMSBillable, msg.get_id, **dict(response=resp))
        else:
            bill_client_for_sms(MachSMSBillable, msg.get_id, **dict(response=resp))
    except Exception as e:
        logging.debug("MACH API contacted, errors in billing. Error: %s" % e)

    return resp
Ejemplo n.º 3
0
def send(msg, delay=True, *args, **kwargs):
    """
    Sends a message via mach's API
    """
    outgoing_sms_text = clean_outgoing_sms_text(msg.text)
    context = {
        'message': outgoing_sms_text,
        'phone_number': urllib.quote(msg.phone_number),
        'sender_id': urllib.quote(kwargs.get("sender_id", DEFAULT_SENDER_ID)),
    }
    url = "%s?%s" % (settings.SMS_GATEWAY_URL, settings.SMS_GATEWAY_PARAMS % context)
    # just opening the url is enough to send the message
    # TODO, check response
    resp = urllib2.urlopen(url).read()
    msg.save()

    create_billable_for_sms(msg, API_ID, delay=delay, response=resp)

    return resp
Ejemplo n.º 4
0
def send(msg, delay=True, *args, **kwargs):
    """
    Sends a message via mach's API
    """
    context = {
        'phone_number': urllib.quote(msg.phone_number),
        'sender_id': urllib.quote(kwargs.get("sender_id", DEFAULT_SENDER_ID)),
    }
    encoding_param = ""
    try:
        text = msg.text.encode("iso-8859-1")
        context["message"] = clean_outgoing_sms_text(text)
    except UnicodeEncodeError:
        context["message"] = msg.text.encode("utf-16-be").encode("hex")
        encoding_param = "&encoding=ucs"
    url = "%s?%s%s" % (settings.SMS_GATEWAY_URL, settings.SMS_GATEWAY_PARAMS % context, encoding_param)
    # just opening the url is enough to send the message
    # TODO, check response
    resp = urllib2.urlopen(url).read()
    msg.save()

    create_billable_for_sms(msg, API_ID, delay=delay, response=resp)

    return resp
Ejemplo n.º 5
0
 def testCleanOutgoingSMSText(self):
     text = u"+this is a test شسیبشسی"
     cleaned = clean_outgoing_sms_text(text)
     # make sure '+' and unicode get encoded for GET properly
     self.assertEquals(cleaned, "%2Bthis%20is%20a%20test%20%D8%B4%D8%B3%DB%8C%D8%A8%D8%B4%D8%B3%DB%8C")