@@ -2187,6 +2187,50 @@ def patch(
21872187 )
21882188 return json .loads (result )
21892189
2190+ def patch_resource (
2191+ self ,
2192+ patch : Patch ,
2193+ branch = None ,
2194+ message = None ,
2195+ author = None ,
2196+ match_final_state = True ,
2197+ ):
2198+ """Apply the patch object to the given resource
2199+
2200+ Do not connect when using public API.
2201+
2202+ Returns
2203+ -------
2204+ dict
2205+ After object
2206+
2207+ Examples
2208+ --------
2209+ >>> client = Client("http://127.0.0.1:6363/")
2210+ >>> client.connect(user="admin", key="root", team="admin", db="some_db")
2211+ >>> patch_obj = Patch(json='{"name" : { "@op" : "ValueSwap", "@before" : "Jane", "@after": "Janine" }}')
2212+ >>> result = client.patch_resource(patch_obj,branch="main")
2213+ >>> print(result)
2214+ '["Person/Jane"]'"""
2215+ commit_info = self ._generate_commit (message , author )
2216+ request_dict = {
2217+ "patch" : patch .content ,
2218+ "message" : commit_info ["message" ],
2219+ "author" : commit_info ["author" ],
2220+ "match_final_state" : match_final_state
2221+ }
2222+ patch_url = self ._branch_base ("patch" , branch )
2223+
2224+ result = _finish_response (
2225+ self ._session .post (
2226+ patch_url ,
2227+ headers = self ._default_headers ,
2228+ json = request_dict ,
2229+ auth = self ._auth (),
2230+ )
2231+ )
2232+ return json .loads (result )
2233+
21902234 def clonedb (
21912235 self , clone_source : str , newid : str , description : Optional [str ] = None
21922236 ) -> None :
@@ -2954,7 +2998,7 @@ def _apply_url(self, branch: Optional[str] = None):
29542998 return self ._branch_base ("apply" , branch )
29552999
29563000 def _patch_url (self ):
2957- return self ._branch_base ( " patch")
3001+ return f" { self .api } / patch"
29583002
29593003 def _push_url (self ):
29603004 return self ._branch_base ("push" )
0 commit comments