Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added edit functionality for sobjects and corrected the order in Readme.md #4

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pip install salesforce-python
```
from salesforce.client import Client

client = Client('CLIENT_KEY', 'CLIENT_SECRET', 'https://na50.salesforce.com/', 'v41.0') # Host must have trailing slash
client = Client('CLIENT_KEY', 'CLIENT_SECRET', 'v41.0', 'https://na50.salesforce.com/')
```

Get authorization url
Expand Down
9 changes: 9 additions & 0 deletions salesforce/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ class Client(object):
def __init__(self, client_id, client_secret, version, instance_url=None):
self.client_id = client_id
self.client_secret = client_secret
if instance_url[-1] == '/':
instance_url = instance_url[:-1]
self.instance_url = self.BASE_URL.format(instance_url)
self.rest_url = self.instance_url + '{}/'.format(version)
if version.startswith('v'):
Expand Down Expand Up @@ -96,6 +98,10 @@ def get_sobject(self, sobject):
@access_token_required
def create_sobject(self, sobject, data):
return self._post(self.rest_url + 'sobjects/{}/'.format(sobject), json=data)

@access_token_required
def edit_sobject(self, sobject, record_id, data):
return self._patch(self.rest_url + 'sobjects/{}/{}'.format(sobject, record_id), json=data)

@access_token_required
def get_sobject_describe(self, sobject):
Expand Down Expand Up @@ -151,6 +157,9 @@ def _post(self, url, **kwargs):

def _put(self, url, **kwargs):
return self._request('PUT', url, **kwargs)

def _patch(self, url, **kwargs):
return self._request('PATCH', url, **kwargs)

def _delete(self, url, **kwargs):
return self._request('DELETE', url, **kwargs)
Expand Down