django-restit 4.2.99__py3-none-any.whl → 4.2.101__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
account/fcm/v1.py CHANGED
@@ -3,6 +3,12 @@ import time
3
3
  import jwt # PyJWT library
4
4
  import requests
5
5
  from objict import objict
6
+ from rest import log
7
+ from rest import settings
8
+
9
+
10
+ DEBUG_FCM = settings.get("DEBUG_FCM", False)
11
+ logger = log.getLogger("fcm", filename="fcm.log")
6
12
 
7
13
 
8
14
  def create_jwt(service_account_info):
@@ -49,6 +55,7 @@ def get_access_token(jwt_token):
49
55
  response_data = response.json()
50
56
  return response_data['access_token']
51
57
 
58
+
52
59
  class FirebaseNotifier:
53
60
  def __init__(self, service_account_info):
54
61
  """
@@ -81,7 +88,7 @@ class FirebaseNotifier:
81
88
  self.access_token = get_access_token(self.jwt_token)
82
89
  return self.access_token
83
90
 
84
- def send(self, registration_token, title, body, data=None):
91
+ def send(self, registration_token, title, body, data=None, **kwargs):
85
92
  """
86
93
  Send a notification to the specified registration token.
87
94
 
@@ -89,6 +96,8 @@ class FirebaseNotifier:
89
96
  :param title: Title of the notification.
90
97
  :param body: Body of the notification.
91
98
  :param data: Optional data payload to send along with the notification.
99
+
100
+ :param ttl: optional life of message in seconds
92
101
  :return: Response from the FCM server.
93
102
  """
94
103
  access_token = self._get_access_token()
@@ -100,6 +109,18 @@ class FirebaseNotifier:
100
109
  if title and body:
101
110
  message["notification"] = dict(title=title, body=body)
102
111
  if data:
112
+ priority = kwargs.get("priority", None)
103
113
  message["data"] = data
114
+ if priority == "high":
115
+ message["android"] = dict(priority="high")
116
+ message["apns"] = dict(headers={"apns-priority": "10"})
117
+ else:
118
+ message["android"] = dict(priority="normal")
119
+ message["apns"] = dict(headers={"apns-priority": "5"})
104
120
  payload = dict(message=message)
105
- return requests.post(self.fcm_url, headers=headers, data=json.dumps(payload))
121
+ if DEBUG_FCM:
122
+ logger.info("request", payload)
123
+ resp = requests.post(self.fcm_url, headers=headers, data=json.dumps(payload))
124
+ if DEBUG_FCM:
125
+ logger.info("response", resp.json())
126
+ return resp
account/models/device.py CHANGED
@@ -137,6 +137,9 @@ class CloudCredentials(models.Model, rm.RestModel, rm.MetaDataModel):
137
137
  uuid = models.CharField(db_index=True, max_length=64, blank=True, null=True, default=None)
138
138
  state = models.IntegerField(db_index=True, default=1)
139
139
 
140
+ # specify the cloud provider class "account.fcm.v1.FirebaseNotifier"
141
+ # provider_class = models.CharField(max_length=255, null=True, default=None)
142
+
140
143
  credentials = rf.JSONField()
141
144
 
142
145
  _notifier = None
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: django-restit
3
- Version: 4.2.99
3
+ Version: 4.2.101
4
4
  Summary: A Rest Framework for DJANGO
5
5
  License: MIT
6
6
  Author: Ian Starnes
@@ -2,7 +2,7 @@ account/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
2
  account/admin.py,sha256=8MQ1gAgjpPUC_SGCVMwd7I8fqLetqcutLiasjssEPRY,1839
3
3
  account/fcm/__init__.py,sha256=lXuz5z0bL5TXqVdaXxiVr-4zF_Q1IZ8kPEkuYGb5eB0,17
4
4
  account/fcm/legacy.py,sha256=5WM5HAnjVPweT0oe3rBN9tBGHfC-DPa-e9luH3baT8Y,959
5
- account/fcm/v1.py,sha256=dMCHvDRgTrkkrfFocxuVvBo7sAzqonOO1IqVYp2B7Jk,3601
5
+ account/fcm/v1.py,sha256=dHoa7vBv-VAqP41DisJgFzvaYsCYmXpqBxftcfUAox8,4339
6
6
  account/migrations/0001_initial.py,sha256=PhYNDTiwjyUplErBmYc34ecynLIEJL2JuC02o8GCXes,15894
7
7
  account/migrations/0003_member_phone_number.py,sha256=auAJCfxsK-y3Veo0vwZfrIZxvwHYBjg5CpYRgCWghCQ,738
8
8
  account/migrations/0004_group_modified_alter_group_created.py,sha256=20iNFlUGtRCWUsxEqTJFRQKQ73z4REhfo-hGam8IHXY,551
@@ -25,7 +25,7 @@ account/migrations/0020_cloudcredentials_cloudcredentialsmetadata.py,sha256=mHwx
25
25
  account/migrations/0021_alter_cloudcredentials_group.py,sha256=zoFYmE-hd3uRGX6DRO9k-osPwH0jFeTU7S-pjCOtakk,561
26
26
  account/migrations/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
27
27
  account/models/__init__.py,sha256=cV_lMnT2vL_mjiYtT4hlcIHo52ocFbGSNVkOIHHLXZY,385
28
- account/models/device.py,sha256=v2kUx040cOvXHKLl98Vi-2qbZCGsVdQlX2Td4fg9CqA,5716
28
+ account/models/device.py,sha256=DDeYCX_6gNgSIvfkPaICtxVilZXcjZNSNDQNikGA9lc,5871
29
29
  account/models/feeds.py,sha256=vI7fG4ASY1M0Zjke24RdnfDcuWeATl_yR_25jPmT64g,2011
30
30
  account/models/group.py,sha256=mjWwePt3ogQUo9m0EhURMz0aBrVVx_0Drr0lNDESQio,22281
31
31
  account/models/legacy.py,sha256=zYdtv4LC0ooxPVqWM-uToPwV-lYWQLorSE6p6yn1xDw,2720
@@ -507,7 +507,7 @@ ws4redis/servers/uwsgi.py,sha256=VyhoCI1DnVFqBiJYHoxqn5Idlf6uJPHvfBKgkjs34mo,172
507
507
  ws4redis/settings.py,sha256=K0yBiLUuY81iDM4Yr-k8hbvjn5VVHu5zQhmMK8Dtz0s,1536
508
508
  ws4redis/utf8validator.py,sha256=S0OlfjeGRP75aO6CzZsF4oTjRQAgR17OWE9rgZdMBZA,5122
509
509
  ws4redis/websocket.py,sha256=R0TUyPsoVRD7Y_oU7w2I6NL4fPwiz5Vl94-fUkZgLHA,14848
510
- django_restit-4.2.99.dist-info/LICENSE.md,sha256=VHN4hhEeVOoFjtG-5fVv4jesA4SWi0Z-KgOzzN6a1ps,1068
511
- django_restit-4.2.99.dist-info/METADATA,sha256=ya7u4YtKVvZiqZd6VuERyv7neyhRQWRlIiyCLm8DYbo,7662
512
- django_restit-4.2.99.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
513
- django_restit-4.2.99.dist-info/RECORD,,
510
+ django_restit-4.2.101.dist-info/LICENSE.md,sha256=VHN4hhEeVOoFjtG-5fVv4jesA4SWi0Z-KgOzzN6a1ps,1068
511
+ django_restit-4.2.101.dist-info/METADATA,sha256=8k0GzJ6-pWg5Cjzo8JkcK7mHswnujmGX5zPpDaSjS58,7663
512
+ django_restit-4.2.101.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
513
+ django_restit-4.2.101.dist-info/RECORD,,