use service_clients
This commit is contained in:
parent
88d3f53dd8
commit
f67d201fca
6 changed files with 49 additions and 38 deletions
|
|
@ -12,7 +12,7 @@ from rest_framework.exceptions import APIException
|
|||
import uuid
|
||||
|
||||
from apps.users.constans import MAX_OTP_TRY, DEVELOPMENT_PHONE_NUMBERS
|
||||
from utils.notification_client import notification_client
|
||||
from utils.service_client import service_client
|
||||
|
||||
|
||||
class UserManager(BaseUserManager):
|
||||
|
|
@ -170,7 +170,7 @@ class User(AbstractUser):
|
|||
self.notify(sms_body)
|
||||
|
||||
def notify(self, body, notification_type='sms'):
|
||||
notification_client.notify(phone_number=self.phone_number, body=body)
|
||||
service_client.notify(phone_number=self.phone_number, body=body)
|
||||
|
||||
|
||||
def __str__(self):
|
||||
|
|
|
|||
|
|
@ -1,8 +1,5 @@
|
|||
#!/usr/bin/env bash
|
||||
# Deployment script
|
||||
apt install libmysqlclient-dev
|
||||
apt install libssl-dev
|
||||
apt install libcrypto++-dev
|
||||
apt install lsb-release
|
||||
apt install libmysqlclient-dev libssl-dev libcrypto++-dev lsb-release
|
||||
|
||||
python manage.py migrate
|
||||
|
|
|
|||
|
|
@ -176,7 +176,6 @@ MEDIA_URL = "/media/"
|
|||
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
|
||||
STATIC_URL = '/static/'
|
||||
|
||||
NOTIFICATIONS_SERVICE_URL = 'https://notifications.gooyal.com'
|
||||
CLIENT_ID = 'wDGC6ZtKXxUvVMP0tUg8DYbtgAD0It8o3TCWjY05'
|
||||
CLIENT_SECRET = 'NBmm8FCzKCYLhMIN3LQ7LoZ3nonnjLvQkVP96MYGAGc5LQSCmdOXbfWP8tdbPBihPOhqW3Fk96tpaQVM6NyJBQCS2qvigE9Vp2RaqKUPM6QhvGI3GT5itT6Rwv5iO4JX'
|
||||
ACCESS_TOKEN = 'Px7WLUKoynua6qJq5IkIG8Fn5dPLXq'
|
||||
NOTIFICATIONS_SERVICE_URL = config('NOTIFICATIONS_SERVICE_URL')
|
||||
CLIENT_ID = config('CLIENT_ID')
|
||||
CLIENT_SECRET = config('CLIENT_SECRET')
|
||||
|
|
|
|||
31
requirements.in
Normal file
31
requirements.in
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
# requirements.in
|
||||
django
|
||||
django-oauth-toolkit
|
||||
djangorestframework
|
||||
markdown
|
||||
django-filter
|
||||
django-cors-middleware
|
||||
|
||||
|
||||
##
|
||||
|
||||
pillow = "*"
|
||||
django-model-utils = "*"
|
||||
mysqlclient = "*"
|
||||
django-mysql = "*"
|
||||
python-decouple = "*"
|
||||
gunicorn = "*"
|
||||
gevent = "*"
|
||||
|
||||
|
||||
pip-tools
|
||||
python-decouple
|
||||
django-cors-middleware
|
||||
django-model-utils
|
||||
mysqlclient
|
||||
django-mysql
|
||||
kavenegar
|
||||
celery
|
||||
mp-model-helper @ git+https://mgit.mparsict.com/utils/mp-model-helper.git
|
||||
mp-api-helper @ git+https://mgit.mparsict.com/utils/mp-api-helper.git
|
||||
redis
|
||||
|
|
@ -1,28 +0,0 @@
|
|||
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}", )
|
||||
return {}
|
||||
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()
|
||||
12
utils/service_client.py
Normal file
12
utils/service_client.py
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
import requests
|
||||
from django.conf import settings
|
||||
|
||||
from service_clients import Client, AccountsClient
|
||||
|
||||
service_client = Client(
|
||||
client_id=settings.CLIENT_ID,
|
||||
client_secret=settings.CLIENT_SECRET,
|
||||
grant_type=AccountsClient.GRANT_CLIENT_CREDENTIALS
|
||||
)
|
||||
service_client.login(scopes=['notification.notification:submit'])
|
||||
|
||||
Loading…
Add table
Reference in a new issue