Skip to content

Commit

Permalink
fix: после отправки вернуть информацию по смс
Browse files Browse the repository at this point in the history
BREAKING CHANGE: поменялась структура данных возвращаемых после отправки смс
  • Loading branch information
iredun committed Mar 25, 2021
1 parent 50e67cc commit 1ac92f2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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}
# }
```

Отправка на множество номеров, разных сообщений:
Expand All @@ -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}
# }
```

Получить баланс и лимиты:
Expand Down
13 changes: 9 additions & 4 deletions smsru/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand All @@ -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,
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 1ac92f2

Please sign in to comment.