From cb46e185ba67eb479fbf852331188db67db8b477 Mon Sep 17 00:00:00 2001 From: Richard Monk Date: Tue, 22 Jul 2014 07:14:20 -0400 Subject: [PATCH] - Added two utility functions: - setPassword (allows user password resets) - restful (allows generic REST calls) --- simple_salesforce/api.py | 43 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/simple_salesforce/api.py b/simple_salesforce/api.py index b74bd05a..70292dff 100644 --- a/simple_salesforce/api.py +++ b/simple_salesforce/api.py @@ -149,6 +149,49 @@ def __getattr__(self, name): """ return SFType(name, self.session_id, self.sf_instance, self.sf_version, self.proxies) + # User utlity methods + def setPassword(self, user, password): + """Sets the password of a user + + Arguments: + + * user: the userID of the user to set + * password: the new password + """ + + url = self.base_url + 'sobjects/User/%s/password' % user + params = { 'NewPassword' : password, } + + result = self.request.get(url, headers=self.headers, params=params) + if result.status_code != 200: + raise SalesforceGeneralError(result.content) + json_result = result.json(object_pairs_hook=OrderedDict) + if len(json_result) == 0: + return None + else: + return json_result + + # Generic Rest Function + def restful(self,path,params): + """Allows you to make a direct REST call if you know the path + + Arguments: + + * path: The path of the request + Example: sobjects/User/ABC123/password' + * params: dict of parameters to pass to the path + """ + + url = self.base_url + path + result = self.request.get(url, headers=self.headers, params=params) + if result.status_code != 200: + raise SalesforceGeneralError(result.content) + json_result = result.json(object_pairs_hook=OrderedDict) + if len(json_result) == 0: + return None + else: + return json_result + # Search Functions def search(self, search): """Returns the result of a Salesforce search as a dict decoded from