Skip to content

Commit 4d795e0

Browse files
Merge pull request #74 from pubnub/develop
Release version
2 parents 9f67057 + f009ed8 commit 4d795e0

File tree

19 files changed

+368
-15
lines changed

19 files changed

+368
-15
lines changed

.pubnub.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
name: python
2-
version: 4.1.4
2+
version: 4.1.5
33
schema: 1
44
scm: github.com/pubnub/python
55
changelog:
6+
- version: v4.1.5
7+
date: Aug 9, 2019
8+
changes:
9+
- type: improvement
10+
text: implement Signal
611
- version: v4.1.4
712
date: Apr 10, 2019
813
changes:
@@ -162,6 +167,9 @@ features:
162167
- SUBSCRIBE-WITH-TIMETOKEN
163168
- SUBSCRIBE-WILDCARD
164169
- SUBSCRIBE-PUBLISHER-UUID
170+
- SUBSCRIBE-SIGNAL-LISTENER
171+
signal:
172+
- SIGNAL-SEND
165173

166174
supported-platforms:
167175
-

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## [4.1.5](https://github.com/pubnub/python/tree/v4.1.5)
2+
3+
[Full Changelog](https://github.com/pubnub/python/compare/v4.1.4...v4.1.5)
4+
5+
- 🐛implement signal
6+
17
## [4.1.4](https://github.com/pubnub/python/tree/v4.1.4)
28

39
[Full Changelog](https://github.com/pubnub/python/compare/v4.1.3...v4.1.4)

pubnub/callbacks.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ def message(self, pubnub, message):
2222
def presence(self, pubnub, presence):
2323
pass
2424

25+
def signal(self, pubnub, signal):
26+
pass
27+
2528

2629
class ReconnectionCallback(object):
2730
@abstractmethod

pubnub/endpoints/signal.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
from pubnub import utils
2+
from pubnub.endpoints.endpoint import Endpoint
3+
from pubnub.enums import HttpMethod, PNOperationType
4+
from pubnub.models.consumer.signal import PNSignalResult
5+
6+
7+
class Signal(Endpoint):
8+
SIGNAL_PATH = '/signal/%s/%s/0/%s/0/%s'
9+
10+
def __init__(self, pubnub):
11+
Endpoint.__init__(self, pubnub)
12+
self._channel = None
13+
self._message = None
14+
15+
def channel(self, channel):
16+
self._channel = str(channel)
17+
return self
18+
19+
def message(self, message):
20+
self._message = message
21+
return self
22+
23+
def build_path(self):
24+
stringified_message = utils.write_value_as_string(self._message)
25+
msg = utils.url_encode(stringified_message)
26+
return Signal.SIGNAL_PATH % (
27+
self.pubnub.config.publish_key, self.pubnub.config.subscribe_key,
28+
utils.url_encode(self._channel), msg
29+
)
30+
31+
def custom_params(self):
32+
return {}
33+
34+
def http_method(self):
35+
return HttpMethod.GET
36+
37+
def is_auth_required(self):
38+
return True
39+
40+
def validate_params(self):
41+
self.validate_subscribe_key()
42+
self.validate_publish_key()
43+
self.validate_channel()
44+
45+
def create_response(self, result): # pylint: disable=W0221
46+
return PNSignalResult(result)
47+
48+
def request_timeout(self):
49+
return self.pubnub.config.non_subscribe_request_timeout
50+
51+
def connect_timeout(self):
52+
return self.pubnub.config.connect_timeout
53+
54+
def operation_type(self):
55+
return PNOperationType.PNSignalOperation
56+
57+
def name(self):
58+
return "Signal"

pubnub/enums.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ class PNOperationType(object):
6161
PNHistoryDeleteOperation = 23
6262
PNMessageCountOperation = 24
6363
PNFireOperation = 25
64+
PNSignalOperation = 26
6465

6566

6667
class PNHeartbeatNotificationOptions(object):

pubnub/managers.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,10 @@ def announce_message(self, message):
203203
for callback in self._listeners:
204204
callback.message(self._pubnub, message)
205205

206+
def announce_signal(self, signal):
207+
for callback in self._listeners:
208+
callback.signal(self._pubnub, signal)
209+
206210
def announce_presence(self, presence):
207211
for callback in self._listeners:
208212
callback.presence(self._pubnub, presence)
@@ -446,6 +450,7 @@ def endpoint_name_for_operation(operation_type):
446450
PNOperationType.PNAccessManagerRevoke: 'pam',
447451

448452
PNOperationType.PNTimeOperation: 'pam',
453+
PNOperationType.PNSignalOperation: 'sig',
449454
}[operation_type]
450455

451456
return endpoint

pubnub/models/consumer/pubsub.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ def __init__(self, message, subscription, channel, timetoken, user_metadata=None
3232
self.publisher = publisher
3333

3434

35+
class PNSignalMessageResult(PNMessageResult):
36+
pass
37+
38+
3539
class PNPresenceEventResult(object):
3640
def __init__(self, event, uuid, timestamp, occupancy, subscription, channel,
3741
timetoken, state, user_metadata=None):

pubnub/models/consumer/signal.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class PNSignalResult(object):
2+
def __init__(self, result):
3+
"""
4+
Representation of signal server response
5+
6+
:param result: result of signal operation
7+
"""
8+
self.timetoken = result[2]
9+
self._result = result
10+
11+
def __str__(self):
12+
return "Signal success with timetoken %s" % self.timetoken

pubnub/models/server/subscribe.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,13 @@ def __init__(self):
3232
self.origination_timetoken = None
3333
self.publish_metadata = None
3434
self.only_channel_subscription = False
35+
self.is_signal = False
3536

3637
@classmethod
3738
def from_json(cls, json_input):
3839
message = SubscribeMessage()
39-
message.shard = json_input['a']
40+
if 'a' in json_input:
41+
message.shard = json_input['a']
4042
if 'b' in json_input:
4143
message.subscription_match = json_input['b']
4244
message.channel = json_input['c']
@@ -48,7 +50,8 @@ def from_json(cls, json_input):
4850
if 'o' in json_input:
4951
message.origination_timetoken = json_input['o']
5052
message.publish_metadata = PublishMetadata.from_json(json_input['p'])
51-
53+
if 'e' in json_input and json_input['e'] == 1:
54+
message.is_signal = True
5255
return message
5356

5457

pubnub/pubnub_core.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from .endpoints.presence.where_now import WhereNow
2525
from .endpoints.history_delete import HistoryDelete
2626
from .endpoints.message_count import MessageCount
27+
from .endpoints.signal import Signal
2728

2829
from .endpoints.push.add_channels_to_push import AddChannelsToPush
2930
from .endpoints.push.remove_channels_from_push import RemoveChannelsFromPush
@@ -165,6 +166,9 @@ def message_counts(self):
165166
def fire(self):
166167
return Fire(self)
167168

169+
def signal(self):
170+
return Signal(self)
171+
168172
def time(self):
169173
return Time(self)
170174

0 commit comments

Comments
 (0)