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

Tooling pull request #1 #1

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
14 changes: 14 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,20 @@ You can read more about Apex on the `Force.com Apex Code Developer's Guide`_

.. _Force.com Apex Code Developer's Guide: http://www.salesforce.com/us/developer/docs/apexcode


Using Tooling API
-----------------

You can access the Metadata Tooling API using this library::

result = sf.tooling( 'query/?q=Select+id,ApexProfiling+from+TraceFlag' , {}))

This would call the endpoint ``https://<instance>.salesforce.com/services/data/<version>/tooling/`` with a query against the TraceFlag Tooling API object

You can read more about the Tooling API on the `Using Tooling REST API`_

.. _Using Tooling REST API: http://www.salesforce.com/us/developer/docs/api_tooling/Content/intro_rest_overview.htm

Additional Features
-------------------

Expand Down
26 changes: 25 additions & 1 deletion simple_salesforce/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def __init__(self, **kwargs):
"""

# Determine if the user passed in the optional version and/or sandbox kwargs
self.sf_version = kwargs.get('version', '29.0')
self.sf_version = kwargs.get('version', '32.0')
self.sandbox = kwargs.get('sandbox', False)
self.proxies = kwargs.get('proxies')

Expand Down Expand Up @@ -121,6 +121,9 @@ def __init__(self, **kwargs):
version=self.sf_version))
self.apex_url = ('https://{instance}/services/apexrest/'
.format(instance=self.sf_instance))
self.tool_url = ('https://{instance}/services/data/v{version}/tooling/'
.format(instance=self.sf_instance,
version=self.sf_version))

def describe(self):
url = self.base_url + "sobjects"
Expand Down Expand Up @@ -202,6 +205,27 @@ def restful(self,path,params):
return None
else:
return json_result

# Generic Tooling API Function
def tooling(self,path,params):
"""Allows you to make a direct Tooling REST call if you know the path

Arguments:

* path: The path of the request
Example: sobjects/User'
* params: dict of parameters to pass to the path
"""

url = self.tool_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):
Expand Down