Repository navigation
Backwards Compatibility
sudorandom edited this page Feb 1, 2013
·
1 revision
If you've been using the older Python client, you'll be happy to know that the old API is still currently working. However, you should deprecate use of the old stuff. Below is an example of the old API converted to the new one.
import SoftLayer.API client = SoftLayer.API.Client('SoftLayer_Account', None, 'username', 'api_key') client.set_object_mask({'ipAddresses' : None}) client.set_result_limit(10, offset=10) client.getObject()
... changes to ...
import SoftLayer client = SoftLayer.Client(username='username', api_key='api_key') client['Account'].getObject(mask="mask[ipAddresses]", limit=10, offset=0)
Below are examples of how the old usages to the new API.
Importing the module
# Old import SoftLayer.API # New import SoftLayer
Creating a client instance
# Old client = SoftLayer.API.Client('SoftLayer_Account', None, 'username', 'api_key') # New client = SoftLayer.Client(username='username', api_key='api_key') service = client['Account']
Making an API call
# Old client = SoftLayer.API.Client('SoftLayer_Account', None, 'username', 'api_key') client.getObject() # New client = SoftLayer.Client(username='username', api_key='api_key') client['Account'].getObject() # Optionally service = client['Account'] service.getObject()
Setting Object Mask
# Old client.set_object_mask({'ipAddresses' : None}) # New client['Account'].getObject(mask="mask[ipAddresses]")
Using Init Parameter
# Old client.set_init_parameter(1234) # New client['Account'].getObject(id=1234)
Setting Result Limit and Offset
# Old client.set_result_limit(10, offset=10) # New client['Account'].getObject(limit=10, offset=10)
Adding Additional Headers
# Old # These headers are persisted accross API calls client.add_header('header', 'value') # New # These headers are NOT persisted accross API calls client['Account'].getObject(headers={'header': 'value'})
Removing Additional Headers
# Old client.remove_header('header') # New client['Account'].getObject()
Adding Additional HTTP Headers
# Old client.add_raw_header('header', 'value') # New client['Account'].getObject(raw_headers={'header': 'value'})
Changing Authentication Credentials
# Old client.set_authentication('username', 'api_key') # New client.username = 'username' client.api_key = 'api_key'