Skip to content

Commit 008c49e

Browse files
Sebastian Molendapubnub-release-bot
andauthored
Add optional TTL parameter for publish (#152)
* Optional TTL in publish * Tests * PubNub SDK 7.1.0 release. Co-authored-by: PubNub Release Bot <[email protected]>
1 parent 9cffc1f commit 008c49e

File tree

8 files changed

+127
-6
lines changed

8 files changed

+127
-6
lines changed

.pubnub.yml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: python
2-
version: 7.0.2
2+
version: 7.1.0
33
schema: 1
44
scm: github.com/pubnub/python
55
sdks:
@@ -18,7 +18,7 @@ sdks:
1818
distributions:
1919
- distribution-type: library
2020
distribution-repository: package
21-
package-name: pubnub-7.0.2
21+
package-name: pubnub-7.1.0
2222
location: https://pypi.org/project/pubnub/
2323
supported-platforms:
2424
supported-operating-systems:
@@ -97,8 +97,8 @@ sdks:
9797
-
9898
distribution-type: library
9999
distribution-repository: git release
100-
package-name: pubnub-7.0.2
101-
location: https://github.com/pubnub/python/releases/download/7.0.2/pubnub-7.0.2.tar.gz
100+
package-name: pubnub-7.1.0
101+
location: https://github.com/pubnub/python/releases/download/7.1.0/pubnub-7.1.0.tar.gz
102102
supported-platforms:
103103
supported-operating-systems:
104104
Linux:
@@ -169,6 +169,11 @@ sdks:
169169
license-url: https://github.com/aio-libs/aiohttp/blob/master/LICENSE.txt
170170
is-required: Required
171171
changelog:
172+
- date: 2023-01-17
173+
version: 7.1.0
174+
changes:
175+
- type: feature
176+
text: "Add optional TTL parameter for publish endpoint."
172177
- date: 2022-11-24
173178
version: 7.0.2
174179
changes:

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## 7.1.0
2+
January 17 2023
3+
4+
#### Added
5+
- Add optional TTL parameter for publish endpoint.
6+
17
## 7.0.2
28
November 24 2022
39

pubnub/endpoints/pubsub/publish.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ def __init__(self, pubnub):
2121
self._meta = None
2222
self._replicate = None
2323
self._ptto = None
24+
self._ttl = None
2425

2526
def channel(self, channel):
2627
self._channel = str(channel)
@@ -49,6 +50,10 @@ def meta(self, meta):
4950
self._meta = meta
5051
return self
5152

53+
def ttl(self, ttl):
54+
self._ttl = ttl
55+
return self
56+
5257
def build_data(self):
5358
if self._use_post is True:
5459
cipher = self.pubnub.config.cipher_key
@@ -70,6 +75,9 @@ def encoded_params(self):
7075
def custom_params(self):
7176
params = TimeTokenOverrideMixin.custom_params(self)
7277

78+
if self._ttl:
79+
params['ttl'] = self._ttl
80+
7381
if self._meta:
7482
params['meta'] = utils.write_value_as_string(self._meta)
7583

pubnub/pubnub_core.py

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

8484
class PubNubCore:
8585
"""A base class for PubNub Python API implementations"""
86-
SDK_VERSION = "7.0.2"
86+
SDK_VERSION = "7.1.0"
8787
SDK_NAME = "PubNub-Python"
8888

8989
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='7.0.2',
5+
version='7.1.0',
66
description='PubNub Real-time push service in the cloud',
77
author='PubNub',
88
author_email='[email protected]',
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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/7.0.2
13+
method: GET
14+
uri: https://ps.pndsn.com/publish/pub-c-739aa0fc-3ed5-472b-af26-aca1b333ec52/sub-c-33f55052-190b-11e6-bfbc-02ee2ddab7fe/0/ch1/0/%22hi%22?seqn=1
15+
response:
16+
body:
17+
string: '[1,"Sent","16738723726258763"]'
18+
headers:
19+
Access-Control-Allow-Methods:
20+
- GET
21+
Access-Control-Allow-Origin:
22+
- '*'
23+
Cache-Control:
24+
- no-cache
25+
Connection:
26+
- keep-alive
27+
Content-Length:
28+
- '30'
29+
Content-Type:
30+
- text/javascript; charset="UTF-8"
31+
Date:
32+
- Mon, 16 Jan 2023 12:32:52 GMT
33+
status:
34+
code: 200
35+
message: OK
36+
version: 1
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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/7.0.2
13+
method: GET
14+
uri: https://ps.pndsn.com/publish/pub-c-739aa0fc-3ed5-472b-af26-aca1b333ec52/sub-c-33f55052-190b-11e6-bfbc-02ee2ddab7fe/0/ch1/0/%22hi%22?seqn=1&ttl=100
15+
response:
16+
body:
17+
string: '[1,"Sent","16738723727729716"]'
18+
headers:
19+
Access-Control-Allow-Methods:
20+
- GET
21+
Access-Control-Allow-Origin:
22+
- '*'
23+
Cache-Control:
24+
- no-cache
25+
Connection:
26+
- keep-alive
27+
Content-Length:
28+
- '30'
29+
Content-Type:
30+
- text/javascript; charset="UTF-8"
31+
Date:
32+
- Mon, 16 Jan 2023 12:32:52 GMT
33+
status:
34+
code: 200
35+
message: OK
36+
version: 1

tests/integrational/native_sync/test_publish.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,3 +341,33 @@ def test_single_quote_character_message_encoded_ok(self):
341341
.sync()
342342

343343
assert envelope
344+
345+
@pn_vcr.use_cassette('tests/integrational/fixtures/native_sync/publish/publish_ttl_0.yaml',
346+
filter_query_parameters=['uuid', 'pnsdk'])
347+
def test_publish_ttl_0(self):
348+
try:
349+
env = PubNub(pnconf).publish() \
350+
.channel("ch1") \
351+
.message("hi") \
352+
.ttl(0) \
353+
.sync()
354+
355+
assert isinstance(env.result, PNPublishResult)
356+
assert env.result.timetoken > 1
357+
except PubNubException as e:
358+
self.fail(e)
359+
360+
@pn_vcr.use_cassette('tests/integrational/fixtures/native_sync/publish/publish_ttl_100.yaml',
361+
filter_query_parameters=['uuid', 'pnsdk'])
362+
def test_publish_ttl_100(self):
363+
try:
364+
env = PubNub(pnconf).publish() \
365+
.channel("ch1") \
366+
.message("hi") \
367+
.ttl(100) \
368+
.sync()
369+
370+
assert isinstance(env.result, PNPublishResult)
371+
assert env.result.timetoken > 1
372+
except PubNubException as e:
373+
self.fail(e)

0 commit comments

Comments
 (0)