From 2d195c7cd363e4e9f8d5d047a84c9fcd60cfc881 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Mon, 23 May 2016 14:19:14 +0200 Subject: [PATCH] Added User.me() and Find.find_from_endpoint() class methods. --- pillarsdk/resource.py | 9 ++++++++- pillarsdk/users.py | 6 ++++++ 2 files changed, 14 insertions(+), 1 deletion(-) 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)