Ejemplo n.º 1
0
def add_sms_user(send_name, mobile_number, optin):
    messages = get_sms_messages()
    if send_name not in messages:
        return

    sfmc.send_sms([mobile_number], messages[send_name])
    if optin:
        add_sms_user_optin.delay(mobile_number)
Ejemplo n.º 2
0
def add_sms_user(send_name, mobile_number, optin):
    messages = get_sms_messages()
    if send_name not in messages:
        return

    sfmc.send_sms([mobile_number], messages[send_name])
    if optin:
        add_sms_user_optin.delay(mobile_number)
Ejemplo n.º 3
0
    def test_messages_combined(self):
        """Messages returned should be a combo of the DB and constants.

        DB entries should override the contsants.
        """
        self.assertEqual(newsletters.get_sms_messages(), {
            'the-sheriff': 'REACTIONARY',
            'the-dude': 'YOURE_NOT_WRONG_WALTER',
            'the-walrus': 'SHUTUP_DONNIE',
        })
Ejemplo n.º 4
0
    def test_messages_combined(self):
        """Messages returned should be a combo of the DB and constants.

        DB entries should override the contsants.
        """
        self.assertEqual(
            newsletters.get_sms_messages(), {
                'the-sheriff': 'REACTIONARY',
                'the-dude': 'YOURE_NOT_WRONG_WALTER',
                'the-walrus': 'SHUTUP_DONNIE',
            })
Ejemplo n.º 5
0
def add_sms_user(send_name, mobile_number, optin):
    messages = get_sms_messages()
    if send_name not in messages:
        return
    et = ExactTargetRest()

    try:
        et.send_sms([mobile_number], messages[send_name])
    except ETRestError as error:
        return add_sms_user.retry(exc=error)

    if optin:
        add_sms_user_optin.delay(mobile_number)
Ejemplo n.º 6
0
def subscribe_sms(request):
    if 'mobile_number' not in request.POST:
        return HttpResponseJSON({
            'status': 'error',
            'desc': 'mobile_number is missing',
            'code': errors.BASKET_USAGE_ERROR,
        }, 400)

    messages = get_sms_messages()
    msg_name = request.POST.get('msg_name', 'SMS_Android')
    if msg_name not in messages:
        return HttpResponseJSON({
            'status': 'error',
            'desc': 'Invalid msg_name',
            'code': errors.BASKET_USAGE_ERROR,
        }, 400)

    mobile = request.POST['mobile_number']
    mobile = re.sub(r'\D+', '', mobile)
    if len(mobile) == 10:
        mobile = '1' + mobile
    elif len(mobile) != 11 or mobile[0] != '1':
        return HttpResponseJSON({
            'status': 'error',
            'desc': 'mobile_number must be a US number',
            'code': errors.BASKET_USAGE_ERROR,
        }, 400)

    # only rate limit numbers here so we don't rate limit errors.
    if is_ratelimited(request, group='news.views.subscribe_sms',
                      key=lambda x, y: '%s-%s' % (msg_name, mobile),
                      rate=PHONE_NUMBER_RATE_LIMIT, increment=True):
        raise Ratelimited()

    optin = request.POST.get('optin', 'N') == 'Y'

    add_sms_user.delay(msg_name, mobile, optin)
    return HttpResponseJSON({'status': 'ok'})
Ejemplo n.º 7
0
def subscribe_sms(request):
    if 'mobile_number' not in request.POST:
        return HttpResponseJSON({
            'status': 'error',
            'desc': 'mobile_number is missing',
            'code': errors.BASKET_USAGE_ERROR,
        }, 400)

    messages = get_sms_messages()
    msg_name = request.POST.get('msg_name', 'SMS_Android')
    if msg_name not in messages:
        return HttpResponseJSON({
            'status': 'error',
            'desc': 'Invalid msg_name',
            'code': errors.BASKET_USAGE_ERROR,
        }, 400)

    mobile = request.POST['mobile_number']
    mobile = re.sub(r'\D+', '', mobile)
    if len(mobile) == 10:
        mobile = '1' + mobile
    elif len(mobile) != 11 or mobile[0] != '1':
        return HttpResponseJSON({
            'status': 'error',
            'desc': 'mobile_number must be a US number',
            'code': errors.BASKET_USAGE_ERROR,
        }, 400)

    # only rate limit numbers here so we don't rate limit errors.
    if is_ratelimited(request, group='news.views.subscribe_sms',
                      key=lambda x, y: '%s-%s' % (msg_name, mobile),
                      rate=PHONE_NUMBER_RATE_LIMIT, increment=True):
        raise Ratelimited()

    optin = request.POST.get('optin', 'N') == 'Y'

    add_sms_user.delay(msg_name, mobile, optin)
    return HttpResponseJSON({'status': 'ok'})