Skip to content

Commit

Permalink
Merge pull request simple-salesforce#38 from rmonk/master
Browse files Browse the repository at this point in the history
- Added two utility functions:
  • Loading branch information
nickcatal committed Aug 7, 2014
2 parents b7e361e + cb46e18 commit 23f787d
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions simple_salesforce/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 23f787d

Please sign in to comment.