コード例 #1
0
    def test_group_message(self):
        cool = GroupMessage(self.api_key, self.api_secret)

        ## create group
        response = cool.create_group()
        group_id = response['group_id']
        self.assertIsNotNone(group_id)

        ## group list
        response = cool.get_group_list()
        self.assertIsNotNone(response['list'][0])

        ## add messages
        params = {
            'group_id': group_id,
            'to': '01000000000',
            'from': '01000000000',
            'text': 'TestGroupMessage'
        }
        response = cool.add_messages(params)
        self.assertIsNotNone(response['error_count'])

        ## add messages json
        params = [{
            "from": "01000000000",
            "to": "01000000001",
            "text": "TestGroupMessage"
        }, {
            "from": "01000000000",
            "to": "01000000002",
            "text": "TestGroupMessage"
        }]
        messages = json.dumps(params)
        response = cool.add_messages_json(group_id, messages)
        self.assertIsNotNone(response[0]['error_count'])

        ## get message list
        params = {'group_id': group_id}
        try:
            cool.get_message_list(params)
        except CoolsmsException as e:
            # 404는 메시지 내역이 없는 것이기 때문에 테스트 실패사유가 안됨
            if e.code == 404:
                pass

        ## delete messages
        message_id = 'TESTMESSAGEID'
        response = cool.delete_messages(group_id, message_id)
        self.assertIsNotNone(response['error_count'])

        ## send
        try:
            cool.send(group_id)
        except CoolsmsException as e:
            # 402는 잔액부족이기 때문에 테스트 실패사유가 안됨
            if e.code == 402:
                pass
コード例 #2
0
from sdk.api.group_message import GroupMessage
from sdk.exceptions import CoolsmsException

##  @brief This sample code demonstrate how to delete messages through CoolSMS Rest API
if __name__ == "__main__":

    # set api key, api secret
    api_key = "#ENTER_YOUR_OWN#"
    api_secret = "#ENTER_YOUR_OWN#"

    # group_id, message_ids are mandatory.
    group_id = "GID57A82D462CBBF"  # Group ID
    message_ids = "MID2738AWQIEQQ"  # Message IDs "MID29EII1913,MID1839231REE ..."

    cool = GroupMessage(api_key, api_secret)

    try:
        response = cool.delete_messages(group_id, message_ids)
        print("Success Count : %s" % response['success_count'])
        print("Error Count : %s" % response['error_count'])

        if "error_list" in response:
            print("Error List : %s" % response['error_list'])

    except CoolsmsException as e:
        print("Error Code : %s" % e.code)
        print("Error Message : %s" % e.msg)

    sys.exit()