Skip to content

Commit 47f8f3d

Browse files
Merge pull request #73 from QSDZvonimir/objects_API
Objects API
2 parents f009ed8 + bf024cc commit 47f8f3d

File tree

102 files changed

+4510
-10
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

102 files changed

+4510
-10
lines changed

.pubnub.yml

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
name: python
2-
version: 4.1.5
2+
version: 4.1.6
33
schema: 1
44
scm: github.com/pubnub/python
55
changelog:
6+
- version: v4.1.6
7+
date: Aug 24, 2019
8+
changes:
9+
- type: improvement
10+
text: implement Objects API
611
- version: v4.1.5
712
date: Aug 9, 2019
813
changes:
@@ -168,8 +173,30 @@ features:
168173
- SUBSCRIBE-WILDCARD
169174
- SUBSCRIBE-PUBLISHER-UUID
170175
- SUBSCRIBE-SIGNAL-LISTENER
176+
- SUBSCRIBE-USER-LISTENER
177+
- SUBSCRIBE-SPACE-LISTENER
178+
- SUBSCRIBE-MEMBERSHIP-LISTENER
171179
signal:
172180
- SIGNAL-SEND
181+
objects:
182+
- OBJECTS-GET-USER
183+
- OBJECTS-GET-USERS
184+
- OBJECTS-CREATE-USER
185+
- OBJECTS-UPDATE-USER
186+
- OBJECTS-DELETE-USER
187+
- OBJECTS-GET-SPACE
188+
- OBJECTS-GET-SPACES
189+
- OBJECTS-CREATE-SPACE
190+
- OBJECTS-UPDATE-SPACE
191+
- OBJECTS-DELETE-SPACE
192+
- OBJECTS-GET-MEMBERSHIPS
193+
- OBJECTS-JOIN-SPACES
194+
- OBJECTS-UPDATE-MEMBERSHIPS
195+
- OBJECTS-LEAVE-SPACES
196+
- OBJECTS-GET-MEMBERS
197+
- OBJECTS-ADD-MEMBERS
198+
- OBJECTS-UPDATE-MEMBERS
199+
- OBJECTS-REMOVE-MEMBERS
173200

174201
supported-platforms:
175202
-

CHANGELOG.md

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

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

pubnub/callbacks.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,15 @@ def presence(self, pubnub, presence):
2525
def signal(self, pubnub, signal):
2626
pass
2727

28+
def user(self, pubnub, user):
29+
pass
30+
31+
def space(self, pubnub, space):
32+
pass
33+
34+
def membership(self, pubnub, membership):
35+
pass
36+
2837

2938
class ReconnectionCallback(object):
3039
@abstractmethod

pubnub/endpoints/membership/__init__.py

Whitespace-only changes.
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
import six
2+
3+
from pubnub import utils
4+
from pubnub.endpoints.endpoint import Endpoint
5+
from pubnub.models.consumer.membership import PNGetMembersResult
6+
from pubnub.enums import HttpMethod, PNOperationType
7+
from pubnub.exceptions import PubNubException
8+
9+
10+
class GetMembers(Endpoint):
11+
GET_MEMBERS_PATH = '/v1/objects/%s/spaces/%s/users'
12+
MAX_LIMIT = 100
13+
14+
def __init__(self, pubnub):
15+
Endpoint.__init__(self, pubnub)
16+
self._start = None
17+
self._end = None
18+
self._limit = GetMembers.MAX_LIMIT
19+
self._count = False
20+
self._include = None
21+
self._space_id = None
22+
23+
def space_id(self, space_id):
24+
assert isinstance(space_id, six.string_types)
25+
self._space_id = space_id
26+
return self
27+
28+
def start(self, start):
29+
assert isinstance(start, six.string_types)
30+
self._start = start
31+
return self
32+
33+
def end(self, end):
34+
assert isinstance(end, six.string_types)
35+
self._end = end
36+
return self
37+
38+
def limit(self, limit):
39+
assert isinstance(limit, six.integer_types)
40+
self._limit = limit
41+
return self
42+
43+
def count(self, count):
44+
self._count = bool(count)
45+
return self
46+
47+
def include(self, data):
48+
self._include = data
49+
return self
50+
51+
def custom_params(self):
52+
params = {}
53+
54+
if self._start is not None:
55+
params['start'] = self._start
56+
57+
if self._end is not None and self._start is None:
58+
params['end'] = self._end
59+
60+
if self._count is True:
61+
params['count'] = True
62+
63+
if self._limit != GetMembers.MAX_LIMIT:
64+
params['limit'] = self._limit
65+
66+
if self._include:
67+
params['include'] = utils.join_items(self._include)
68+
69+
return params
70+
71+
def build_path(self):
72+
if self._space_id is None:
73+
raise PubNubException('Provide space_id.')
74+
return GetMembers.GET_MEMBERS_PATH % (self.pubnub.config.subscribe_key, self._space_id)
75+
76+
def http_method(self):
77+
return HttpMethod.GET
78+
79+
def is_auth_required(self):
80+
return True
81+
82+
def validate_params(self):
83+
self.validate_subscribe_key()
84+
if self._space_id is None:
85+
raise PubNubException('Provide space_id.')
86+
87+
def create_response(self, envelope): # pylint: disable=W0221
88+
return PNGetMembersResult(envelope)
89+
90+
def request_timeout(self):
91+
return self.pubnub.config.non_subscribe_request_timeout
92+
93+
def connect_timeout(self):
94+
return self.pubnub.config.connect_timeout
95+
96+
def operation_type(self):
97+
return PNOperationType.PNGetMembersOperation
98+
99+
def name(self):
100+
return 'Get members'
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
import six
2+
3+
from pubnub import utils
4+
from pubnub.endpoints.endpoint import Endpoint
5+
from pubnub.models.consumer.membership import PNGetSpaceMembershipsResult
6+
from pubnub.enums import HttpMethod, PNOperationType
7+
from pubnub.exceptions import PubNubException
8+
9+
10+
class GetSpaceMemberships(Endpoint):
11+
GET_SPACE_MEMBERSHIPS_PATH = '/v1/objects/%s/users/%s/spaces'
12+
MAX_LIMIT = 100
13+
14+
def __init__(self, pubnub):
15+
Endpoint.__init__(self, pubnub)
16+
self._start = None
17+
self._end = None
18+
self._limit = GetSpaceMemberships.MAX_LIMIT
19+
self._count = False
20+
self._include = None
21+
self._user_id = None
22+
23+
def user_id(self, user_id):
24+
assert isinstance(user_id, six.string_types)
25+
self._user_id = user_id
26+
return self
27+
28+
def start(self, start):
29+
assert isinstance(start, six.string_types)
30+
self._start = start
31+
return self
32+
33+
def end(self, end):
34+
assert isinstance(end, six.string_types)
35+
self._end = end
36+
return self
37+
38+
def limit(self, limit):
39+
assert isinstance(limit, six.integer_types)
40+
self._limit = limit
41+
return self
42+
43+
def count(self, count):
44+
self._count = bool(count)
45+
return self
46+
47+
def include(self, data):
48+
self._include = data
49+
return self
50+
51+
def custom_params(self):
52+
params = {}
53+
54+
if self._start is not None:
55+
params['start'] = self._start
56+
57+
if self._end is not None and self._start is None:
58+
params['end'] = self._end
59+
60+
if self._count is True:
61+
params['count'] = True
62+
63+
if self._limit != GetSpaceMemberships.MAX_LIMIT:
64+
params['limit'] = self._limit
65+
66+
if self._include:
67+
params['include'] = utils.join_items(self._include)
68+
69+
return params
70+
71+
def build_path(self):
72+
if self._user_id is None:
73+
raise PubNubException('Provide user_id.')
74+
return GetSpaceMemberships.GET_SPACE_MEMBERSHIPS_PATH % (self.pubnub.config.subscribe_key, self._user_id)
75+
76+
def http_method(self):
77+
return HttpMethod.GET
78+
79+
def is_auth_required(self):
80+
return True
81+
82+
def validate_params(self):
83+
self.validate_subscribe_key()
84+
if self._user_id is None:
85+
raise PubNubException('Provide user_id.')
86+
87+
def create_response(self, envelope): # pylint: disable=W0221
88+
return PNGetSpaceMembershipsResult(envelope)
89+
90+
def request_timeout(self):
91+
return self.pubnub.config.non_subscribe_request_timeout
92+
93+
def connect_timeout(self):
94+
return self.pubnub.config.connect_timeout
95+
96+
def operation_type(self):
97+
return PNOperationType.PNGetSpaceMembershipsOperation
98+
99+
def name(self):
100+
return 'Get space membership'
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
import six
2+
3+
from pubnub import utils
4+
from pubnub.endpoints.endpoint import Endpoint
5+
from pubnub.models.consumer.membership import PNManageMembersResult
6+
from pubnub.enums import HttpMethod, PNOperationType
7+
from pubnub.exceptions import PubNubException
8+
9+
10+
class ManageMembers(Endpoint):
11+
MANAGE_MEMBERS_PATH = '/v1/objects/%s/spaces/%s/users'
12+
MAX_LIMIT = 100
13+
14+
def __init__(self, pubnub):
15+
Endpoint.__init__(self, pubnub)
16+
self._start = None
17+
self._end = None
18+
self._limit = ManageMembers.MAX_LIMIT
19+
self._count = False
20+
self._include = None
21+
self._space_id = None
22+
self._data = None
23+
24+
def space_id(self, space_id):
25+
assert isinstance(space_id, six.string_types)
26+
self._space_id = space_id
27+
return self
28+
29+
def start(self, start):
30+
assert isinstance(start, six.string_types)
31+
self._start = start
32+
return self
33+
34+
def end(self, end):
35+
assert isinstance(end, six.string_types)
36+
self._end = end
37+
return self
38+
39+
def limit(self, limit):
40+
assert isinstance(limit, six.integer_types)
41+
self._limit = limit
42+
return self
43+
44+
def count(self, count):
45+
self._count = bool(count)
46+
return self
47+
48+
def include(self, data):
49+
self._include = data
50+
return self
51+
52+
def data(self, data):
53+
assert isinstance(data, dict)
54+
self._data = data
55+
return self
56+
57+
def build_data(self):
58+
if self._data is not None:
59+
return utils.write_value_as_string(self._data)
60+
61+
def custom_params(self):
62+
params = {}
63+
64+
if self._start is not None:
65+
params['start'] = self._start
66+
67+
if self._end is not None and self._start is None:
68+
params['end'] = self._end
69+
70+
if self._count is True:
71+
params['count'] = True
72+
73+
if self._limit != ManageMembers.MAX_LIMIT:
74+
params['limit'] = self._limit
75+
76+
if self._include:
77+
params['include'] = utils.join_items(self._include)
78+
79+
return params
80+
81+
def build_path(self):
82+
if self._space_id is None:
83+
raise PubNubException('Provide space_id.')
84+
return ManageMembers.MANAGE_MEMBERS_PATH % (self.pubnub.config.subscribe_key, self._space_id)
85+
86+
def http_method(self):
87+
return HttpMethod.PATCH
88+
89+
def is_auth_required(self):
90+
return True
91+
92+
def validate_params(self):
93+
self.validate_subscribe_key()
94+
if self._space_id is None:
95+
raise PubNubException('Provide space_id.')
96+
97+
def create_response(self, envelope): # pylint: disable=W0221
98+
return PNManageMembersResult(envelope)
99+
100+
def request_timeout(self):
101+
return self.pubnub.config.non_subscribe_request_timeout
102+
103+
def connect_timeout(self):
104+
return self.pubnub.config.connect_timeout
105+
106+
def operation_type(self):
107+
return PNOperationType.PNManageMembersOperation
108+
109+
def name(self):
110+
return 'Update members'

0 commit comments

Comments
 (0)