From 3c39506014ab29bce26a3cbe258bf19a7ba604e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Thu, 28 Jul 2016 11:28:32 +0200 Subject: [PATCH] Allow PATCHing nodes. --- pillarsdk/nodes.py | 3 ++- pillarsdk/resource.py | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/pillarsdk/nodes.py b/pillarsdk/nodes.py index 5b83a8e..2e81b8a 100755 --- a/pillarsdk/nodes.py +++ b/pillarsdk/nodes.py @@ -9,13 +9,14 @@ from .resource import Post from .resource import Update from .resource import Delete from .resource import Replace +from .resource import Patch from .exceptions import ResourceNotFound from . import utils from .api import Api -class Node(List, Find, Create, Post, Update, Delete, Replace): +class Node(List, Find, Create, Post, Update, Delete, Replace, Patch): """Node class wrapping the REST nodes endpoint """ path = "nodes" diff --git a/pillarsdk/resource.py b/pillarsdk/resource.py index d1e1880..b447744 100644 --- a/pillarsdk/resource.py +++ b/pillarsdk/resource.py @@ -385,3 +385,20 @@ class Post(Resource): return cls(new_attributes, api=self.api)""" self.merge(new_attributes) return self.success() + + +class Patch(Resource): + def patch(self, patch, api=None): + """Patch a resource. + + Usage:: + + >>> node = Node.find('12345') + >>> node.patch({'op': 'upvote'}) + """ + + api = api or self.api + url = utils.join_url(self.path, self._id) + + result = api.patch(url, patch) + return Resource(result)