Beispiel #1
0
    def schedule(self):
        """
        Method to schedule a SMS campaign to a specified date and time after the required mandatory parameters received
        from the user are validated.
        dlr_url, custom, unicode and flash are optional parameters.

        :return:object of SMSMessageResponse which would be used to return a specific response as per the user's
        requirements.
        """

        if Validate.message(self.message) and Validate.number(self.to) and \
                Validate.date_and_time_validation(self.datetime, self.format):
            correct_time = Validate.date_and_time_validation(
                self.datetime, self.format)
            url = '{}&method={}&message={}&to={}&sender={}&time={}'.format(
                BASEURL, SMSMessageRequest.SMS, self.message, self.to,
                SENDERID, correct_time)
            if self.dlr_url:
                url += '&dlrurl={}'.format(self.dlr_url)
            if self.custom:
                url += '&custom={}'.format(self.custom)
            if self.unicode:
                url += '&unicode={}'.format(self.unicode)
            if self.flash:
                url += '&flash={}'.format(self.flash)
            response = Klient(url).response()
            sms_message_response = SMSMessageResponse(response=response)
            return sms_message_response
Beispiel #2
0
    def send(self):
        """
        Method to send an SMS to a group of contacts.

        :return:groupResponse object which would be used to return a specific response as per user's requirements.
        """

        if Validate.group_name(self.group_name) and Validate.message(self.to):

            url = '{}&method={}&name={}&sender={}&message={}'.format(
                BASEURL, GroupRequest.GROUPS, self.group_name, SENDERID,
                self.message)
            response = Klient(url).response()
            group_response = GroupResponse(response=response)
            return group_response
Beispiel #3
0
    def credit_usage(self):
        """
        Method to check credit usage of the user(API key) between two valid dates entered by the user.

        :return:object of SMSMessageResponse which would be used to return a specific response as per the user's
        requirement.
        """

        if Validate.date_validation(self.from_date, self.format) and \
                Validate.date_validation(self.to_date, self.format):
            from_date = Validate.date_validation(self.from_date, self.format)
            to_date = Validate.date_validation(self.to_date, self.format)
            url = '{}&method={}&from={}&to={}'.format(BASEURL,
                                                      SMSMessageRequest.USAGE,
                                                      from_date, to_date)
            response = Klient(url).response()
            sms_message_response = SMSMessageResponse(response=response)
            return sms_message_response
Beispiel #4
0
    def edit(self):
        """
        Method to edit a scheduled SMS campaign after the mandatory parameters are validated and ID of the SMS campaign
        is entered correctly.

        :return:object of SMSMessageResponse which would be used to return a specific response as per the user's
        requirements.
        """

        if Validate.date_and_time_validation(self.datetime, self.format):
            correct_time = Validate.date_and_time_validation(
                self.datetime, self.format)
            url = '{}&groupid={}&time={}&task={}&method={}'.format(
                BASEURL, self.group_id, correct_time, SMSMessageRequest.MODIFY,
                SMSMessageRequest.SCHEDULE)
            response = Klient(url).response()
            sms_message_response = SMSMessageResponse(response=response)
            return sms_message_response
Beispiel #5
0
    def add(self):
        """
        Method to add contacts to an SMS group that already exists.
        full_name and email_id are optional parameters.

        :return:groupResponse object which would be used to return a specific response as per user's requirements.
        """

        if Validate.group_name(self.group_name) and Validate.number(self.to):
            url = '{}&method={}&number={}&name={}&action={}'.format(
                BASEURL, GroupRequest.GROUPS_REGISTER, self.to,
                self.group_name, GroupRequest.ADD)
            if self.full_name:
                url += '&fullname={}'.format(self.full_name)
            if self.email_id:
                url += '&email={}'.format(self.email_id)
            response = Klient(url).response()
            group_response = GroupResponse(response=response)
            return group_response
Beispiel #6
0
    def create(self):
        """
        Method to create a group of contacts having a unique name so that you can simply type the group name to send an
        SMS campaign.

        :return:groupResponse object which would be used to return a specific response as per user's requirements.
        """

        if Validate.group_name(self.group_name):

            url = '{}&method={}&task={}&app=1&data[name]={}'.format(
                BASEURL, GroupRequest.GROUPS_ADD, GroupRequest.SAVE,
                self.group_name)
            response = Klient(url).response()
            group_response = GroupResponse(response=response)
            return group_response