Added User.me() and Find.find_from_endpoint() class methods.

This commit is contained in:
2016-05-23 14:19:14 +02:00
parent 75d71b824f
commit 2d195c7cd3
2 changed files with 14 additions and 1 deletions

View File

@@ -141,9 +141,16 @@ class Find(Resource):
>>> Node.find("507f1f77bcf86cd799439011")
"""
url = utils.join_url(cls.path, str(resource_id))
return cls.find_from_endpoint(url, params=params, api=api)
@classmethod
def find_from_endpoint(cls, endpoint, params=None, api=None):
"""Locate resource from a custom endpoint."""
api = api or Api.Default()
url = utils.join_url(cls.path, str(resource_id))
url = endpoint
if params is not None:
cls._ensure_projections(params, cls.ensure_query_projections)
url = utils.join_url_params(url, params)

View File

@@ -19,3 +19,9 @@ class User(List, Find, Create, Post, Update, Delete):
return "https://www.gravatar.com/avatar/" + \
hashlib.md5(self.email.lower()).hexdigest() + \
"?" + urllib.urlencode(parameters)
@classmethod
def me(cls, params=None, api=None):
"""Returns info about the current user, identified by auth token."""
return cls.find_from_endpoint('/users/me', params=params, api=api)