diff --git a/README.rst b/README.rst index 4b5f55ca..1383bdde 100644 --- a/README.rst +++ b/README.rst @@ -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://.salesforce.com/services/data//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 ------------------- diff --git a/simple_salesforce/api.py b/simple_salesforce/api.py index 1c7e4818..a8c555c0 100644 --- a/simple_salesforce/api.py +++ b/simple_salesforce/api.py @@ -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') @@ -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" @@ -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):