accounts/utils/notification_client.py
2020-03-28 00:48:52 +04:30

28 lines
817 B
Python

import requests
from django.conf import settings
class NotificationClient():
def notify(self, phone_number, body):
data = {
'phone_number': phone_number,
'body': body
}
# data = json.dumps(data)
header = {
# "Content-Type": "application/json",
"charset": "utf-8"
}
header.setdefault("Authorization", f"Bearer {settings.ACCESS_TOKEN}", )
response = requests.request('post',
f'{settings.NOTIFICATIONS_SERVICE_URL}/notifications/',
headers=header,
json=data)
try:
return response.json()
except:
return response.text
notification_client = NotificationClient()