コード例 #1
0
    def test_create_pattern(self):
        http_client = Mock()

        http_client.post.return_value = Response(
            json.loads(r'''
        {
            "status": "OK",
            "code": 200,
            "message": "Ok",
            "data": {
                "pattern": {
                    "code": "6gr7ngjmhi",
                    "status": "pending",
                    "message": "%name% is awesome",
                    "is_shared": false
                }
            }
        }
        '''))

        sms = Client("", http_client)
        sms.create_pattern(r"%name% is awesome", False)

        http_client.post.assert_called_once_with("/v1/messages/patterns", {
            "pattern": r"%name% is awesome",
            "is_shared": False,
        })
コード例 #2
0
    def test_send_pattern(self):
        http_client = Mock()

        http_client.post.return_value = Response(
            json.loads(r'''
        {
            "status": "OK",
            "code": "OK",
            "message": "Ok",
            "data": {
                "bulk_id": 70671101
            }
        }
        '''))

        sms = Client("", http_client)
        bulk_id = sms.send_pattern("6gr7ngjmhi", "9810001", "+98912xxxxxxx",
                                   {"name": "IPPanel"})

        http_client.post.assert_called_once_with(
            "/v1/messages/patterns/send", {
                "pattern_code": "6gr7ngjmhi",
                "originator": "9810001",
                "recipient": "+98912xxxxxxx",
                "values": {
                    "name": "IPPanel"
                },
            })

        self.assertEqual(bulk_id, 70671101)
コード例 #3
0
    def test_message_get(self):
        http_client = Mock()
        http_client.get.return_value = Response(
            json.loads(r'''
        {
            "status": "OK",
            "code": 200,
            "message": "Ok",
            "data": {
                "message": {
                "bulk_id": 70671101,
                "number": "+9850002",
                "message": "Hello from me",
                "status": "active",
                "type": "webservice",
                "confirm_state": "",
                "created_at": "2019-12-07T13:34:06Z",
                "sent_at": "2019-12-07T13:34:06Z",
                "recipients_count": 1,
                "valid_recipients_count": 0,
                "page": 1,
                "cost": 0,
                "payback_cost": 0,
                "description": ""
                }
            }
        }
        '''))

        sms = Client("", http_client)
        message = sms.get_message(70671101)

        self.assertEqual(message.bulk_id, 70671101)
コード例 #4
0
    def test_fetch_statuses(self):
        http_client = Mock()
        http_client.get.return_value = Response(
            json.loads(r'''
        {
            "status": "OK",
            "code": "OK",
            "message": "Ok",
            "data": {
                "recipients": [
                    {
                        "recipient": "+98912xxxxxxx",
                        "status": "delivered"
                    }
                ]
            },
            "meta": {
                "total": 1,
                "pages": 1,
                "limit": 1,
                "page": 0,
                "prev": null,
                "next": null
            }
        }
        '''))

        sms = Client("", http_client)
        statuses, pagination_info = sms.fetch_statuses(52738671, 0, 10)

        self.assertEqual(len(statuses), 1)
        self.assertEqual(statuses[0].recipient, "+98912xxxxxxx")
        self.assertEqual(statuses[0].status, "delivered")

        self.assertEqual(pagination_info.total, 1)
コード例 #5
0
    def test_fetch_inbox_messages(self):
        http_client = Mock()
        http_client.get.return_value = Response(
            json.loads(r'''
        {
            "status": "OK",
            "code": 200,
            "message": "Ok",
            "data": {
                "messages": [
                    {
                        "number": "+9810001",
                        "message": "Hello",
                        "sender": "+98912xxxxxxx",
                        "time": "2019-12-17T23:02:10Z",
                        "type": "normal"
                    },
                    {
                        "number": "+9810001",
                        "message": "Test",
                        "sender": "+98913xxxxxxx",
                        "time": "2019-12-17T23:01:59Z",
                        "type": "normal"
                    }
                ]
            },
            "meta": {
                "total": 2,
                "pages": 1,
                "limit": 2,
                "page": 0,
                "prev": null,
                "next": null
            }
        }
        '''))

        sms = Client("", http_client)
        messages, pagination_info = sms.fetch_inbox(0, 2)

        self.assertEqual(len(messages), 2)
        self.assertEqual(messages[0].number, "+9810001")
        self.assertEqual(messages[0].message, "Hello")
        self.assertEqual(messages[0].sender, "+98912xxxxxxx")
        self.assertEqual(messages[0].time, "2019-12-17T23:02:10Z")
        self.assertEqual(messages[0].type, "normal")

        self.assertEqual(pagination_info.total, 2)
コード例 #6
0
ファイル: sms.py プロジェクト: safarzadeh-reza/Traccar
def processParagraph():

    client = Client("mSlhtsSZUVW0KdquNmHHewZLEpu33K0ZQ_DFx2R3acI=")

    try:
        bulk_id = client.send("+983000505", ["+989124499659"],
                              "Hello from python client!")
        print(bulk_id)
    except Error as e:
        print("Error handled => code: %s, message: %s" % (e.code, e.message))
        if e.code == ResponseCode.ErrUnprocessableEntity.value:
            for field in e.message:
                print("Field: %s , Errors: %s" % (field, e.message[field]))
    except HTTPError as e:
        print("Error handled => code: %s" % (e))

    return client
コード例 #7
0
ファイル: farazsms_service.py プロジェクト: zeyysh/intuitx
class FarazSMS(adaptor.Client):
    def __init__(self, excel_or_list, service, from_sender, to_receivers, subject, content,
                 templates, name):
        super().__init__(self, excel_or_list, service, from_sender, to_receivers, subject, content,
                         templates, name)

    def create(self):
        # self.sms = FarazClient(os.environ.get('FARAZ_API_KEY'))
        # self.from_sender = os.environ.get('FARAZ_NUMBER')
        # print(os.environ.get('FARAZ_API_KEY'))
        # print(os.environ.get('FARAZ_NUMBER'))
        self.sms = FarazClient("lE4WSCxzQlexOHiNj7Cdr1piDhpPE8vKFhUuSIeUSyM=")
        self.name = self.name
        self.content = self.content
        if type(self.to_receivers) is list:
            self.to_receivers = self.to_receivers
        else:
            self.to_receivers = [self.to_receivers]

    def send_with_service(self):
        print(self.to_receivers)
        print(self.content)
        try:
            bulk_id = self.sms.send(originator=self.from_sender,
                                    recipients=self.to_receivers,
                                    message=self.content)
            print('messages send successfully', bulk_id)
        except Error as e:
            print("Error handled => code: %s" % e.code)

    def create_template(self):
        self.template_for_all_services = self.template_for_all_services

    def send_with_template(self):
        print(self.to_receivers)
        print(self.name)

        for receiver, content, name in zip(self.to_receivers, self.template_for_all_services, self.name):
            try:
                bulk_id = self.sms.send(originator=self.from_sender,
                                        recipients=[receiver],
                                        message=content)
                print(f'messages send successfully to {name} -->bulk_id :{bulk_id}')
            except Error as e:
                print("Error handled => code: %s" % e.code)
コード例 #8
0
    def test_parse_exception(self):
        http_client = Mock()
        http_client.post.return_value = Response(
            json.loads(r'''
        {
            "status": "OK",
            "code": "OK",
            "message": "Ok",
            "data": {
                "bulk_idd": 70671101
            }
        }
        '''))

        sms = Client("", http_client)

        with self.assertRaises(ValueError):
            sms.send("9810001", ["98912xxxxxxx", "98913xxxxxxx"], "Hello")
コード例 #9
0
    def test_send_response_parse(self):
        http_client = Mock()
        http_client.post.return_value = Response(
            json.loads(r'''
        {
            "status": "OK",
            "code": "OK",
            "message": "Ok",
            "data": {
                "bulk_id": 70671101
            }
        }
        '''))

        sms = Client("", http_client)
        bulk_id = sms.send("9810001", ["98912xxxxxxx", "98913xxxxxxx"],
                           "Hello")

        self.assertEqual(bulk_id, 70671101)
コード例 #10
0
ファイル: utils.py プロジェクト: janantan/rousta
def send_sms(phoneNumber, code):
	client = Client(config.IPPANEL_API_KEY)

	pattern_values = {"code": code}
	try:
		bulk_id = client.send_pattern(
			config.SMS_PATTERN_CODE,	# pattern code
			config.SMS_ORIGINATOR,	  # originator
			phoneNumber,  # recipient
			pattern_values,  # pattern values
		)
		return(bulk_id)
	except Error as e:
		print("Error handled => code: %s, message: %s" % (e.code, e.message))
		if e.code == ResponseCode.ErrUnprocessableEntity.value:
			for field in e.message:
				print("Field: %s , Errors: %s" % (field, e.message[field]))
	except HTTPError as e:
		print("Error handled => code: %s" % (e))
	return (None)
コード例 #11
0
ファイル: farazsms_service.py プロジェクト: zeyysh/intuitx
 def create(self):
     # self.sms = FarazClient(os.environ.get('FARAZ_API_KEY'))
     # self.from_sender = os.environ.get('FARAZ_NUMBER')
     # print(os.environ.get('FARAZ_API_KEY'))
     # print(os.environ.get('FARAZ_NUMBER'))
     self.sms = FarazClient("lE4WSCxzQlexOHiNj7Cdr1piDhpPE8vKFhUuSIeUSyM=")
     self.name = self.name
     self.content = self.content
     if type(self.to_receivers) is list:
         self.to_receivers = self.to_receivers
     else:
         self.to_receivers = [self.to_receivers]
コード例 #12
0
    def test_send_api_call(self):
        http_client = Mock()

        http_client.post.return_value = Response(
            json.loads(r'''
        {
            "status": "OK",
            "code": "OK",
            "message": "Ok",
            "data": {
                "bulk_id": 70671101
            }
        }
        '''))

        sms = Client("", http_client)
        sms.send("9810001", ["98912xxxxxxx", "98913xxxxxxx"], "Hello")

        http_client.post.assert_called_once_with(
            "/v1/messages", {
                "originator": "9810001",
                "recipients": ["98912xxxxxxx", "98913xxxxxxx"],
                "message": "Hello",
            })
コード例 #13
0
class Sms:
    def __init__(self):
        self.phone = "+9810009589"
        self.api_key = "w-_o3HD2Uz5D-UtibVcGj4q5R4_POJhpVeXrZC2NjZE="
        self.pattern_code = "e06081mqm5"
        self.client = Client(self.api_key)

    def send_code(self, verify_code, recipient_number):
        pattern_val = {'verify': str(verify_code)}
        try:
            resp = self.client.send_pattern(self.pattern_code, self.phone,
                                            recipient_number, pattern_val)
            return True, resp
        except Error as e:
            return ('error: {}'.format(e))
コード例 #14
0
class SMS:
    def __init__(self):
        api_key = "YMQm7ifbEWxFEcStuyBA7yppiRJFgLjBioWOxdU8P1c="
        self.sms = Client(api_key)

    def send(self, phone):
        code = opt_generator(5)

        pattern_values = {"code": code}
        bulk_id = self.sms.send_pattern(
            "4tprjx5g44",  # pattern code
            "+982000505",  # originator
            phone,  # recipient
            pattern_values,  # pattern values
        )
        print('Sent ', bulk_id)
        return code
コード例 #15
0
 def __init__(self):
     api_key = "YMQm7ifbEWxFEcStuyBA7yppiRJFgLjBioWOxdU8P1c="
     self.sms = Client(api_key)
コード例 #16
0
from ippanel import Client

api_key = "TkHglMm5LV49fr_SaxnT2vzr2eW7KFHT3VNXBxrIwAY="
sms = Client(api_key)
pattern_code = "3op4py8h7b"
phone_number = "+985000125475"


def otp_send(recipient, otp):
    pattern_values = {
        "otp": otp,
    }
    bulk_id = sms.send(
        phone_number,  # originator
        [recipient],  # recipients
        "کد تایید شما در وبسایت پسیکو: " + otp,
    )
    # bulk_id = sms.send_pattern(
    #     pattern_code,  # pattern code
    #     phone_number,  # originator
    #     recipient,  # recipient
    #     pattern_values,  # pattern Fvalues
    # )
コード例 #17
0
ファイル: send.py プロジェクト: tokyodevs/python-rest-sdk
from ippanel import Client, Error, HTTPError, ResponseCode

client = Client("YOUR-API-KEY")

try:
    bulk_id = client.send("+9810001", ["+98912xxxxxxx"],
                          "Hello from python client!")
    print(bulk_id)
except Error as e:
    print("Error handled => code: %s, message: %s" % (e.code, e.message))

    if e.code == ResponseCode.ErrUnprocessableEntity.value:
        for field in e.message:
            print("Field: %s , Errors: %s" % (field, e.message[field]))
except HTTPError as e:
    print("Error handled => code: %s" % (e))
コード例 #18
0
 def __init__(self):
     self.phone = "+9810009589"
     self.api_key = "w-_o3HD2Uz5D-UtibVcGj4q5R4_POJhpVeXrZC2NjZE="
     self.pattern_code = "e06081mqm5"
     self.client = Client(self.api_key)