From 1ac92f29f57e7cff80a0b92f9e2323fefbd65aa5 Mon Sep 17 00:00:00 2001 From: Ivan Date: Thu, 25 Mar 2021 14:26:05 +0300 Subject: [PATCH] =?UTF-8?q?fix:=20=D0=BF=D0=BE=D1=81=D0=BB=D0=B5=20=D0=BE?= =?UTF-8?q?=D1=82=D0=BF=D1=80=D0=B0=D0=B2=D0=BA=D0=B8=20=D0=B2=D0=B5=D1=80?= =?UTF-8?q?=D0=BD=D1=83=D1=82=D1=8C=20=D0=B8=D0=BD=D1=84=D0=BE=D1=80=D0=BC?= =?UTF-8?q?=D0=B0=D1=86=D0=B8=D1=8E=20=D0=BF=D0=BE=20=D1=81=D0=BC=D1=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit BREAKING CHANGE: поменялась структура данных возвращаемых после отправки смс --- README.md | 13 ++++++++++--- smsru/service.py | 13 +++++++++---- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 11f4e96..23beabc 100644 --- a/README.md +++ b/README.md @@ -58,7 +58,9 @@ python manage.py send-sms-ru --phone +79888888888 --msg Тест ``` # Сигналы - - `smsru_call_back_sms(sender, instance, new_status)` - при обработке callback запроса, после изменения статуса сообщения + +- `smsru_call_back_sms(sender, instance, new_status)` - при обработке callback запроса, после изменения статуса + сообщения ```python from django.dispatch import receiver @@ -82,7 +84,9 @@ from smsru.service import SmsRuApi api = SmsRuApi() result = api.send_one_sms("+79888888888", "Test") # телефон и сообщение -# result: {'79888888888': True} +# result: { +# '79888888888': {'status': True, 'status_code': 100, 'sms_id': 0000-0000} +# } ``` Отправка на множество номеров, разных сообщений: @@ -95,7 +99,10 @@ result = api.send_multi_sms({ '+79888888888': 'test', '+79888888889': 'test 2', }) -# result: {'79888888888': True, '79888888889': True} +# result: { +# '79888888888': {'status': True, 'status_code': 100, 'sms_id': 0000-0000}, +# '79888888889': {'status': True, 'status_code': 100, 'sms_id': 0000-0000} +# } ``` Получить баланс и лимиты: diff --git a/smsru/service.py b/smsru/service.py index 850c797..f9a4470 100644 --- a/smsru/service.py +++ b/smsru/service.py @@ -62,11 +62,12 @@ def __request(self, url: str, post_param: dict) -> dict: return data def _sms_request(self, post_param: dict) -> dict: + mock_sms = {'status': False, 'status_code': None, 'sms_id': None} if 'to' in post_param: - return_result = {k: False for k in post_param['to'].split(',')} + return_result = {k: mock_sms for k in post_param['to'].split(',')} phone_msg = {k: post_param['msg'] for k in post_param['to'].split(',')} else: - return_result = {k: False for k, v in post_param['multi'].items()} + return_result = {k: mock_sms for k, v in post_param['multi'].items()} phone_msg = post_param['multi'] multi = post_param.pop('multi') for k, v in multi.items(): @@ -78,7 +79,11 @@ def _sms_request(self, post_param: dict) -> dict: if isinstance(data, dict): if data['status'] == 'OK' and data['status_code'] == 100: for phone, result in data['sms'].items(): - return_result[phone] = result['status_code'] == 100 + return_result[phone] = { + 'status': result['status_code'] == 100, + 'status_code': result['status_code'], + 'sms_id': result['sms_id'], + } itm = Log( phone=phone, @@ -137,7 +142,7 @@ def get_balance(self) -> float: data = self.__request(url, {}) if data['status_code'] != 100: raise Exception(data['status_text']) - + return data['balance'] def get_limit(self) -> dict: