Ejemplo n.º 1
0
    def send_flash_sms(self, sms, header=None, data_format=None, is_legacy=None):
        if not data_format: data_format='json'
        if is_legacy == None: is_legacy=True

        client_correlator = sms.client_correlator
        if not client_correlator:
            client_correlator = mod_utils.get_random_alphanumeric_string()

        if data_format == "json":
            params = {
                    'address' : [
                        'tel:{0}'.format(sms.address)
                        ],
                    'clientCorrelator': client_correlator,
                    'senderAddress': sms.sender_address,
                    'outboundSMSFlashMessage' : {
                        'flashMessage' : sms.message
                        },
                    'senderName': 'tel:{0}'.format(sms.sender_address),
                    'receiptRequest' : {
                        'callbackData': sms.callback_data,
                        'notifyURL': sms.notify_url
                        }
                    }
        elif data_format == "url":
            params = {
                    'senderAddress': sms.sender_address,
                    'address': sms.address,
                    'flashMessage': sms.message,
                    'clientCorrelator': client_correlator,
                    'senderName': 'tel:{0}'.format(sms.sender_address),
                    }

            if sms.mo_response_key:
                params['moResponseKey'] = sms.mo_response_key

            if sms.notify_url:
                params['notifyURL'] = sms.notify_url

            if sms.callback_data:
                params['callbackData'] = sms.callback_data
        else:
            raise Exception("invalid asked data format (supported url or json")

        if is_legacy == True:
            tmp='/1/smsmessaging/outbound/{0}/requests'.format(sms.sender_address)
        else:
            tmp='/smsmessaging/v1/outbound/{0}/requests'.format(sms.sender_address)

        is_success, result = self.execute_POST(
                tmp,
                params = params,
                headers = header,
                data_format = data_format
        )

        if not is_success:
            return is_success

        return self.create_from_json(mod_models.ResourceReference, result, not is_success)
Ejemplo n.º 2
0
    def send_sms(self, sms, header=None, data_format=None, is_legacy=None):
        if not data_format: data_format = 'json'
        if is_legacy == None: is_legacy = True

        client_correlator = sms.client_correlator
        if not client_correlator:
            client_correlator = mod_utils.get_random_alphanumeric_string()

        if data_format == "json":
            params = {
                'address': ['tel:{0}'.format(sms.address)],
                'clientCorrelator': client_correlator,
                'senderAddress': sms.sender_address,
                'outboundSMSTextMessage': {
                    'message': sms.message
                },
                'senderName': 'tel:{0}'.format(sms.sender_address),
                'receiptRequest': {
                    'callbackData': sms.callback_data,
                    'notifyURL': sms.notify_url
                }
            }
        elif data_format == "url":
            params = {
                'senderAddress': sms.sender_address,
                'address': sms.address,
                'message': sms.message,
                'clientCorrelator': client_correlator,
                'senderName': 'tel:{0}'.format(sms.sender_address),
            }

            if sms.mo_response_key:
                params['moResponseKey'] = sms.mo_response_key

            if sms.notify_url:
                params['notifyURL'] = sms.notify_url

            if sms.callback_data:
                params['callbackData'] = sms.callback_data
        else:
            raise Exception("invalid asked data format (supported url or json")

        if is_legacy == True:
            tmp = '/1/smsmessaging/outbound/{0}/requests'.format(
                sms.sender_address)
        else:
            tmp = '/smsmessaging/v1/outbound/{0}/requests'.format(
                sms.sender_address)

        is_success, result = self.execute_POST(tmp,
                                               params=params,
                                               headers=header,
                                               data_format=data_format)

        if not is_success:
            return is_success

        return self.create_from_json(mod_models.ResourceReference, result,
                                     not is_success)
Ejemplo n.º 3
0
    def send_sms(self, sms, header=None, data_format=None):
        if not data_format: data_format='json'

        client_correlator = sms.client_correlator
        if not client_correlator:
            client_correlator = mod_utils.get_random_alphanumeric_string()

        if data_format == "json":
            params = {
                    'address' : [
                        'tel:{0}'.format(sms.address)
                        ],
                    'clientCorrelator': client_correlator,
                    'senderAddress': sms.sender_address,
                    'message' : sms.message,
                    'senderName': 'tel:{0}'.format(sms.sender_address),
                    'callbackData': sms.callback_data,
                    'notifyURL': sms.notify_url
                    }
        elif data_format == "url":
            params = {
                    'senderAddress': sms.sender_address,
                    'address': sms.address,
                    'message': sms.message,
                    'clientCorrelator': client_correlator,
                    'senderName': 'tel:{0}'.format(sms.sender_address),
                    }

            if sms.mo_response_key:
                params['moResponseKey'] = sms.mo_response_key

            if sms.notify_url:
                params['notifyURL'] = sms.notify_url
            if sms.callback_data:
                params['callbackData'] = sms.callback_data
        else:
            raise ValueError("invalid asked data format (supported url or json")

        is_success, result = self.execute_POST(
                '/1/smsmessaging/outbound/{0}/requests'.format(sms.sender_address),
                params = params,
                headers = header,
                data_format = data_format
        )

        return self.create_from_json(mod_models.ResourceReference, result, not is_success)
Ejemplo n.º 4
0
    def get_client_correlator(self, client_correlator=None):
        if client_correlator:
            return client_correlator;

        return mod_utils.get_random_alphanumeric_string()
Ejemplo n.º 5
0
    def get_client_correlator(self, client_correlator=None):
        if client_correlator:
            return client_correlator;

        return mod_utils.get_random_alphanumeric_string()