Skip to content

Commit c8ccb8f

Browse files
ujjawal-gargjrconlin
authored andcommitted
fix flake8 errors
1 parent 203e48f commit c8ccb8f

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ WebPusher(subscription_info).send(data, headers)
4949
```
5050
to send for Chrome:
5151
```
52-
WebPusher(subscription_info).send(data, gcm_key, headers)
52+
WebPusher(subscription_info).send(data, headers, ttl, gcm_key)
5353
```
5454

5555
You can also simply encode the data to send later by calling

pywebpush/__init__.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import base64
66
import os
7+
78
import json
89
import http_ece
910
import pyelliptic
@@ -151,13 +152,13 @@ def encode(self, data):
151152
'body': encrypted,
152153
})
153154

154-
def send(self, data, gcm_key=None, reg_id=None, headers={}, ttl=0):
155+
def send(self, data, headers={}, ttl=0, gcm_key=None, reg_id=None):
155156
"""Encode and send the data to the Push Service.
156157
157158
:param data: A serialized block of data (see encode() ).
158-
:param gcm_key: API key obtained from the Google Developer Console.
159+
:param gcm_key: API key obtained from the Google Developer Console.
159160
Needed if endpoint is https://android.googleapis.com/gcm/send
160-
:param reg_id: registration id of the recipient. If not provided,
161+
:param reg_id: registration id of the recipient. If not provided,
161162
it will be extracted from the endpoint.
162163
:param headers: A dictionary containing any additional HTTP headers.
163164
:param ttl: The Time To Live in seconds for this message if the
@@ -179,12 +180,12 @@ def send(self, data, gcm_key=None, reg_id=None, headers={}, ttl=0):
179180
'encryption': "keyid=p256dh;salt=" +
180181
encoded['salt'].decode('utf8'),
181182
})
182-
183-
if self.subscription_info['endpoint'].startswith('https://android.googleapis.com/gcm/send'):
183+
gcm_endpoint = 'https://android.googleapis.com/gcm/send'
184+
if self.subscription_info['endpoint'].startswith(gcm_endpoint):
184185

185186
if not gcm_key:
186-
raise WebPushException("API key not provided for google gcm endpoint")
187-
endpoint = 'https://android.googleapis.com/gcm/send'
187+
raise WebPushException("API key not provided for gcm endpoint")
188+
endpoint = gcm_endpoint
188189
reg_ids = []
189190
if not reg_id:
190191
reg_id = self.subscription_info['endpoint'].rsplit('/', 1)[-1]
@@ -194,8 +195,8 @@ def send(self, data, gcm_key=None, reg_id=None, headers={}, ttl=0):
194195
data['raw_data'] = base64.b64encode(encoded.get('body'))
195196
encoded_data = json.dumps(data)
196197
headers.update({
197-
'Authorization': 'key='+gcm_key,
198-
'Content-Type': 'application/json',
198+
'Authorization': 'key='+gcm_key,
199+
'Content-Type': 'application/json',
199200
})
200201
else:
201202
encoded_data = encoded.get('body')

0 commit comments

Comments
 (0)