diff --git a/pillarsdk/resource.py b/pillarsdk/resource.py index 61b7ca5..c25f3d9 100644 --- a/pillarsdk/resource.py +++ b/pillarsdk/resource.py @@ -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) diff --git a/pillarsdk/users.py b/pillarsdk/users.py index 4e457b4..c0fae5a 100755 --- a/pillarsdk/users.py +++ b/pillarsdk/users.py @@ -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)