Skip to content

Commit 11a2249

Browse files
PubNub SDK v4.6.1 release.
1 parent 1ece87c commit 11a2249

File tree

9 files changed

+95
-14
lines changed

9 files changed

+95
-14
lines changed

.pubnub.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
name: python
2-
version: 4.6.0
2+
version: 4.6.1
33
schema: 1
44
scm: github.com/pubnub/python
55
changelog:
6+
- version: v4.6.1
7+
date: Oct 27, 2020
8+
changes:
9+
-
10+
text: "Passing uuid to the get_state endpoint call added."
11+
type: bug
612
- version: v4.6.0
713
date: Oct 22, 2020
814
changes:

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## [v4.6.1](https://github.com/pubnub/python/releases/tag/v4.6.1)
2+
3+
[Full Changelog](https://github.com/pubnub/python/compare/v4.6.0...v4.6.1)
4+
5+
- 🐛 Passing uuid to the get_state endpoint call added.
6+
17
## [v4.6.0](https://github.com/pubnub/python/releases/tag/v4.6.0)
28

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

pubnub/endpoints/presence/get_state.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,27 @@
22
from pubnub.endpoints.endpoint import Endpoint
33
from pubnub.enums import HttpMethod, PNOperationType
44
from pubnub.models.consumer.presence import PNGetStateResult
5+
from pubnub.endpoints.validators import UUIDValidatorMixin
56

67

7-
class GetState(Endpoint):
8+
class GetState(Endpoint, UUIDValidatorMixin):
89
# /v2/presence/sub-key/<subscribe_key>/channel/<channel>/uuid/<uuid>/data?state=<state>
910
GET_STATE_PATH = "/v2/presence/sub-key/%s/channel/%s/uuid/%s"
1011

1112
def __init__(self, pubnub):
1213
Endpoint.__init__(self, pubnub)
1314
self._channels = []
1415
self._groups = []
16+
self._uuid = self.pubnub.uuid
1517

1618
def channels(self, channels):
1719
utils.extend_list(self._channels, channels)
1820
return self
1921

22+
def uuid(self, uuid):
23+
self._uuid = uuid
24+
return self
25+
2026
def channel_groups(self, channel_groups):
2127
utils.extend_list(self._groups, channel_groups)
2228
return self
@@ -33,16 +39,16 @@ def build_path(self):
3339
return GetState.GET_STATE_PATH % (
3440
self.pubnub.config.subscribe_key,
3541
utils.join_channels(self._channels),
36-
utils.url_encode(self.pubnub.uuid)
42+
utils.url_encode(self._uuid)
3743
)
3844

3945
def http_method(self):
4046
return HttpMethod.GET
4147

4248
def validate_params(self):
4349
self.validate_subscribe_key()
44-
4550
self.validate_channels_and_groups()
51+
self.validate_uuid()
4652

4753
def create_response(self, envelope):
4854
if len(self._channels) == 1 and len(self._groups) == 0:

pubnub/endpoints/presence/where_now.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
1-
import six
2-
31
from pubnub import utils
42
from pubnub.endpoints.endpoint import Endpoint
53
from pubnub.enums import HttpMethod, PNOperationType
6-
from pubnub.errors import PNERR_UUID_MISSING
7-
from pubnub.exceptions import PubNubException
84
from pubnub.models.consumer.presence import PNWhereNowResult
5+
from pubnub.endpoints.validators import UUIDValidatorMixin
96

107

11-
class WhereNow(Endpoint):
8+
class WhereNow(Endpoint, UUIDValidatorMixin):
129
# /v2/presence/sub-key/<subscribe_key>/uuid/<uuid>
1310
WHERE_NOW_PATH = "/v2/presence/sub-key/%s/uuid/%s"
1411

@@ -31,9 +28,7 @@ def http_method(self):
3128

3229
def validate_params(self):
3330
self.validate_subscribe_key()
34-
35-
if self._uuid is None or not isinstance(self._uuid, six.string_types):
36-
raise PubNubException(pn_error=PNERR_UUID_MISSING)
31+
self.validate_uuid()
3732

3833
def is_auth_required(self):
3934
return True

pubnub/endpoints/validators.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import six
2+
3+
from pubnub.errors import PNERR_UUID_MISSING
4+
from pubnub.exceptions import PubNubException
5+
6+
7+
class UUIDValidatorMixin:
8+
def validate_uuid(self):
9+
if self._uuid is None or not isinstance(self._uuid, six.string_types):
10+
raise PubNubException(pn_error=PNERR_UUID_MISSING)

pubnub/pubnub_core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363

6464
class PubNubCore:
6565
"""A base class for PubNub Python API implementations"""
66-
SDK_VERSION = "4.6.0"
66+
SDK_VERSION = "4.6.1"
6767
SDK_NAME = "PubNub-Python"
6868

6969
TIMESTAMP_DIVIDER = 1000

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
setup(
44
name='pubnub',
5-
version='4.6.0',
5+
version='4.6.1',
66
description='PubNub Real-time push service in the cloud',
77
author='PubNub',
88
author_email='[email protected]',
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
interactions:
2+
- request:
3+
body: null
4+
headers:
5+
Accept:
6+
- '*/*'
7+
Accept-Encoding:
8+
- gzip, deflate
9+
Connection:
10+
- keep-alive
11+
User-Agent:
12+
- PubNub-Python/4.6.0
13+
method: GET
14+
uri: https://ps.pndsn.com/v2/presence/sub-key/sub-c-33f55052-190b-11e6-bfbc-02ee2ddab7fe/channel/state-native-sync-ch/uuid/state-native-sync-uuid
15+
response:
16+
body:
17+
string: '{"status": 200, "message": "OK", "payload": {"count": 5, "name": "Alex"},
18+
"uuid": "state-native-sync-uuid", "channel": "state-native-sync-ch", "service":
19+
"Presence"}'
20+
headers:
21+
Accept-Ranges:
22+
- bytes
23+
Access-Control-Allow-Methods:
24+
- OPTIONS, GET, POST
25+
Access-Control-Allow-Origin:
26+
- '*'
27+
Age:
28+
- '0'
29+
Cache-Control:
30+
- no-cache
31+
Connection:
32+
- keep-alive
33+
Content-Length:
34+
- '165'
35+
Content-Type:
36+
- text/javascript; charset="UTF-8"
37+
Date:
38+
- Mon, 26 Oct 2020 16:37:28 GMT
39+
Server:
40+
- Pubnub Presence
41+
status:
42+
code: 200
43+
message: OK
44+
version: 1

tests/integrational/native_sync/test_state.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,17 @@ def test_super_call(self):
7878
assert env.result.channels[ch2]['name'] == "Alex"
7979
assert env.result.channels[ch1]['count'] == 5
8080
assert env.result.channels[ch2]['count'] == 5
81+
82+
@pn_vcr.use_cassette('tests/integrational/fixtures/native_sync/state/state_with_user_defined_uuid.yaml',
83+
filter_query_parameters=['uuid', 'pnsdk'], match_on=['state_object_in_query'])
84+
def test_get_state_passes_user_defined_uuid(self):
85+
ch = "state-native-sync-ch"
86+
pubnub = PubNub(pnconf_copy())
87+
pubnub.config.uuid = "test_uuid"
88+
client_uuid = "state-native-sync-uuid"
89+
90+
envelope = pubnub.get_state().channels(ch).uuid(client_uuid).sync()
91+
92+
assert isinstance(envelope.result, PNGetStateResult)
93+
assert envelope.result.channels[ch]['name'] == "Alex"
94+
assert envelope.result.channels[ch]['count'] == 5

0 commit comments

Comments
 (0)