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)