Skip to content

Commit

Permalink
Merge pull request #73 from QSDZvonimir/objects_API
Browse files Browse the repository at this point in the history
Objects API
  • Loading branch information
qsoftdevelopment authored Aug 26, 2019
2 parents f009ed8 + bf024cc commit 47f8f3d
Show file tree
Hide file tree
Showing 102 changed files with 4,510 additions and 10 deletions.
29 changes: 28 additions & 1 deletion .pubnub.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
name: python
version: 4.1.5
version: 4.1.6
schema: 1
scm: github.com/pubnub/python
changelog:
- version: v4.1.6
date: Aug 24, 2019
changes:
- type: improvement
text: implement Objects API
- version: v4.1.5
date: Aug 9, 2019
changes:
Expand Down Expand Up @@ -168,8 +173,30 @@ features:
- SUBSCRIBE-WILDCARD
- SUBSCRIBE-PUBLISHER-UUID
- SUBSCRIBE-SIGNAL-LISTENER
- SUBSCRIBE-USER-LISTENER
- SUBSCRIBE-SPACE-LISTENER
- SUBSCRIBE-MEMBERSHIP-LISTENER
signal:
- SIGNAL-SEND
objects:
- OBJECTS-GET-USER
- OBJECTS-GET-USERS
- OBJECTS-CREATE-USER
- OBJECTS-UPDATE-USER
- OBJECTS-DELETE-USER
- OBJECTS-GET-SPACE
- OBJECTS-GET-SPACES
- OBJECTS-CREATE-SPACE
- OBJECTS-UPDATE-SPACE
- OBJECTS-DELETE-SPACE
- OBJECTS-GET-MEMBERSHIPS
- OBJECTS-JOIN-SPACES
- OBJECTS-UPDATE-MEMBERSHIPS
- OBJECTS-LEAVE-SPACES
- OBJECTS-GET-MEMBERS
- OBJECTS-ADD-MEMBERS
- OBJECTS-UPDATE-MEMBERS
- OBJECTS-REMOVE-MEMBERS

supported-platforms:
-
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## [4.1.6](https://github.com/pubnub/python/tree/v4.1.6)

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

- 🐛implement Objects API

## [4.1.5](https://github.com/pubnub/python/tree/v4.1.5)

[Full Changelog](https://github.com/pubnub/python/compare/v4.1.4...v4.1.5)
Expand Down
9 changes: 9 additions & 0 deletions pubnub/callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@ def presence(self, pubnub, presence):
def signal(self, pubnub, signal):
pass

def user(self, pubnub, user):
pass

def space(self, pubnub, space):
pass

def membership(self, pubnub, membership):
pass


class ReconnectionCallback(object):
@abstractmethod
Expand Down
Empty file.
100 changes: 100 additions & 0 deletions pubnub/endpoints/membership/get_members.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import six

from pubnub import utils
from pubnub.endpoints.endpoint import Endpoint
from pubnub.models.consumer.membership import PNGetMembersResult
from pubnub.enums import HttpMethod, PNOperationType
from pubnub.exceptions import PubNubException


class GetMembers(Endpoint):
GET_MEMBERS_PATH = '/v1/objects/%s/spaces/%s/users'
MAX_LIMIT = 100

def __init__(self, pubnub):
Endpoint.__init__(self, pubnub)
self._start = None
self._end = None
self._limit = GetMembers.MAX_LIMIT
self._count = False
self._include = None
self._space_id = None

def space_id(self, space_id):
assert isinstance(space_id, six.string_types)
self._space_id = space_id
return self

def start(self, start):
assert isinstance(start, six.string_types)
self._start = start
return self

def end(self, end):
assert isinstance(end, six.string_types)
self._end = end
return self

def limit(self, limit):
assert isinstance(limit, six.integer_types)
self._limit = limit
return self

def count(self, count):
self._count = bool(count)
return self

def include(self, data):
self._include = data
return self

def custom_params(self):
params = {}

if self._start is not None:
params['start'] = self._start

if self._end is not None and self._start is None:
params['end'] = self._end

if self._count is True:
params['count'] = True

if self._limit != GetMembers.MAX_LIMIT:
params['limit'] = self._limit

if self._include:
params['include'] = utils.join_items(self._include)

return params

def build_path(self):
if self._space_id is None:
raise PubNubException('Provide space_id.')
return GetMembers.GET_MEMBERS_PATH % (self.pubnub.config.subscribe_key, self._space_id)

def http_method(self):
return HttpMethod.GET

def is_auth_required(self):
return True

def validate_params(self):
self.validate_subscribe_key()
if self._space_id is None:
raise PubNubException('Provide space_id.')

def create_response(self, envelope): # pylint: disable=W0221
return PNGetMembersResult(envelope)

def request_timeout(self):
return self.pubnub.config.non_subscribe_request_timeout

def connect_timeout(self):
return self.pubnub.config.connect_timeout

def operation_type(self):
return PNOperationType.PNGetMembersOperation

def name(self):
return 'Get members'
100 changes: 100 additions & 0 deletions pubnub/endpoints/membership/get_space_memberships.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import six

from pubnub import utils
from pubnub.endpoints.endpoint import Endpoint
from pubnub.models.consumer.membership import PNGetSpaceMembershipsResult
from pubnub.enums import HttpMethod, PNOperationType
from pubnub.exceptions import PubNubException


class GetSpaceMemberships(Endpoint):
GET_SPACE_MEMBERSHIPS_PATH = '/v1/objects/%s/users/%s/spaces'
MAX_LIMIT = 100

def __init__(self, pubnub):
Endpoint.__init__(self, pubnub)
self._start = None
self._end = None
self._limit = GetSpaceMemberships.MAX_LIMIT
self._count = False
self._include = None
self._user_id = None

def user_id(self, user_id):
assert isinstance(user_id, six.string_types)
self._user_id = user_id
return self

def start(self, start):
assert isinstance(start, six.string_types)
self._start = start
return self

def end(self, end):
assert isinstance(end, six.string_types)
self._end = end
return self

def limit(self, limit):
assert isinstance(limit, six.integer_types)
self._limit = limit
return self

def count(self, count):
self._count = bool(count)
return self

def include(self, data):
self._include = data
return self

def custom_params(self):
params = {}

if self._start is not None:
params['start'] = self._start

if self._end is not None and self._start is None:
params['end'] = self._end

if self._count is True:
params['count'] = True

if self._limit != GetSpaceMemberships.MAX_LIMIT:
params['limit'] = self._limit

if self._include:
params['include'] = utils.join_items(self._include)

return params

def build_path(self):
if self._user_id is None:
raise PubNubException('Provide user_id.')
return GetSpaceMemberships.GET_SPACE_MEMBERSHIPS_PATH % (self.pubnub.config.subscribe_key, self._user_id)

def http_method(self):
return HttpMethod.GET

def is_auth_required(self):
return True

def validate_params(self):
self.validate_subscribe_key()
if self._user_id is None:
raise PubNubException('Provide user_id.')

def create_response(self, envelope): # pylint: disable=W0221
return PNGetSpaceMembershipsResult(envelope)

def request_timeout(self):
return self.pubnub.config.non_subscribe_request_timeout

def connect_timeout(self):
return self.pubnub.config.connect_timeout

def operation_type(self):
return PNOperationType.PNGetSpaceMembershipsOperation

def name(self):
return 'Get space membership'
110 changes: 110 additions & 0 deletions pubnub/endpoints/membership/manage_members.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
import six

from pubnub import utils
from pubnub.endpoints.endpoint import Endpoint
from pubnub.models.consumer.membership import PNManageMembersResult
from pubnub.enums import HttpMethod, PNOperationType
from pubnub.exceptions import PubNubException


class ManageMembers(Endpoint):
MANAGE_MEMBERS_PATH = '/v1/objects/%s/spaces/%s/users'
MAX_LIMIT = 100

def __init__(self, pubnub):
Endpoint.__init__(self, pubnub)
self._start = None
self._end = None
self._limit = ManageMembers.MAX_LIMIT
self._count = False
self._include = None
self._space_id = None
self._data = None

def space_id(self, space_id):
assert isinstance(space_id, six.string_types)
self._space_id = space_id
return self

def start(self, start):
assert isinstance(start, six.string_types)
self._start = start
return self

def end(self, end):
assert isinstance(end, six.string_types)
self._end = end
return self

def limit(self, limit):
assert isinstance(limit, six.integer_types)
self._limit = limit
return self

def count(self, count):
self._count = bool(count)
return self

def include(self, data):
self._include = data
return self

def data(self, data):
assert isinstance(data, dict)
self._data = data
return self

def build_data(self):
if self._data is not None:
return utils.write_value_as_string(self._data)

def custom_params(self):
params = {}

if self._start is not None:
params['start'] = self._start

if self._end is not None and self._start is None:
params['end'] = self._end

if self._count is True:
params['count'] = True

if self._limit != ManageMembers.MAX_LIMIT:
params['limit'] = self._limit

if self._include:
params['include'] = utils.join_items(self._include)

return params

def build_path(self):
if self._space_id is None:
raise PubNubException('Provide space_id.')
return ManageMembers.MANAGE_MEMBERS_PATH % (self.pubnub.config.subscribe_key, self._space_id)

def http_method(self):
return HttpMethod.PATCH

def is_auth_required(self):
return True

def validate_params(self):
self.validate_subscribe_key()
if self._space_id is None:
raise PubNubException('Provide space_id.')

def create_response(self, envelope): # pylint: disable=W0221
return PNManageMembersResult(envelope)

def request_timeout(self):
return self.pubnub.config.non_subscribe_request_timeout

def connect_timeout(self):
return self.pubnub.config.connect_timeout

def operation_type(self):
return PNOperationType.PNManageMembersOperation

def name(self):
return 'Update members'
Loading

0 comments on commit 47f8f3d

Please sign in to comment.