Skip to content

Commit 85bf04a

Browse files
committed
Added Deprecation for Client.add_raw_header() + replacement implementation
1 parent 028c472 commit 85bf04a

3 files changed

Lines changed: 58 additions & 29 deletions

File tree

README.md

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -157,61 +157,70 @@ service = client['Account']
157157
service.getObject()
158158
```
159159

160-
**Adding Additional Headers**
160+
**Setting Object Mask**
161161
```python
162162
# Old
163-
# These headers are persisted accross API calls
164-
client.add_header('header', 'value')
163+
client.set_object_mask({'updates' : None})
165164

166165
# New
167-
# These headers are NOT persisted accross API calls
168-
client['Account'].getObject(headers={'header': 'value'})
166+
client['Account'].getObject(mask={'updates' : None})
169167
```
170168

171-
**Removing Additional Headers**
169+
**Using Init Parameter**
172170
```python
173171
# Old
174-
client.remove_header('header')
172+
client.set_init_parameter(1234)
175173

176174
# New
177-
client['Account'].getObject()
175+
client['Account'].getObject(id=1234)
178176
```
179177

180-
**Changing Authentication Credentials**
178+
**Setting Result Limit and Offset**
181179
```python
182180
# Old
183-
client.set_authentication('username', 'api_key')
181+
client.set_result_limit(10, offset=10)
184182

185183
# New
186-
client.username = 'username'
187-
client.api_key = 'api_key'
184+
client['Account'].getObject(limit=10, offset=10)
188185
```
189186

190-
**Using Init Parameter**
187+
**Adding Additional Headers**
191188
```python
192189
# Old
193-
client.set_init_parameter(1234)
190+
# These headers are persisted accross API calls
191+
client.add_header('header', 'value')
194192

195193
# New
196-
client['Account'].getObject(id=1234)
194+
# These headers are NOT persisted accross API calls
195+
client['Account'].getObject(headers={'header': 'value'})
197196
```
198197

199-
**Setting Object Mask**
198+
**Removing Additional Headers**
200199
```python
201200
# Old
202-
client.set_object_mask({'updates' : None})
201+
client.remove_header('header')
203202

204203
# New
205-
client['Account'].getObject(mask={'updates' : None})
204+
client['Account'].getObject()
206205
```
207206

208-
**Setting Result Limit and Offset**
207+
**Adding Additional HTTP Headers**
209208
```python
210209
# Old
211-
client.set_result_limit(10, offset=10)
210+
client.add_raw_header('header', 'value')
212211

213212
# New
214-
client['Account'].getObject(limit=10, offset=10)
213+
client['Account'].getObject(raw_headers={'header': 'value'})
214+
```
215+
216+
**Changing Authentication Credentials**
217+
```python
218+
# Old
219+
client.set_authentication('username', 'api_key')
220+
221+
# New
222+
client.username = 'username'
223+
client.api_key = 'api_key'
215224
```
216225

217226

SoftLayer/API.py

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,6 @@ class SoftLayerError(Exception):
4848

4949
class Client(object):
5050
"""A SoftLayer API client
51-
Clients are intended to be declared once per service and used for all calls
52-
made to that service.
5351
5452
:param service_name: The name of the SoftLayer API service to query.
5553
:param id: An optional object if if you're instantiating a particular
@@ -107,10 +105,14 @@ def __init__(self, service_name=None, id=None, username=None, api_key=None,
107105
self.timeout = timeout
108106

109107
def add_raw_header(self, name, value):
108+
""" Set HTTP headers for API calls
109+
.. deprecated:: 2.0.0
110+
"""
110111
self.transport.set_raw_header(name, value)
111112

112113
def add_header(self, name, value):
113-
""" Set a SoftLayer API call header; deprecated
114+
""" Set a SoftLayer API call header
115+
.. deprecated:: 2.0.0
114116
115117
:param name: The name of the header to add
116118
:param value: The header to add.
@@ -123,7 +125,8 @@ def add_header(self, name, value):
123125
self._headers[name] = value
124126

125127
def remove_header(self, name):
126-
""" Remove a SoftLayer API call header; deprecated
128+
""" Remove a SoftLayer API call header
129+
.. deprecated:: 2.0.0
127130
128131
:param name: The name of the header to remove.
129132
"""
@@ -133,6 +136,7 @@ def remove_header(self, name):
133136

134137
def set_authentication(self, username, api_key):
135138
""" Set user and key to authenticate a SoftLayer API call
139+
.. deprecated:: 2.0.0
136140
137141
Use this method if you wish to bypass the API_USER and API_KEY class
138142
constants and set custom authentication per API call.
@@ -150,7 +154,8 @@ def set_authentication(self, username, api_key):
150154
})
151155

152156
def set_init_parameter(self, id):
153-
""" Set an initialization parameter header; deprecated
157+
""" Set an initialization parameter header
158+
.. deprecated:: 2.0.0
154159
155160
Initialization parameters instantiate a SoftLayer API service object to
156161
act upon during your API method call. For instance, if your account has
@@ -169,7 +174,8 @@ def set_init_parameter(self, id):
169174
})
170175

171176
def set_object_mask(self, mask):
172-
""" Set an object mask to a SoftLayer API call; deprecated
177+
""" Set an object mask to a SoftLayer API call
178+
.. deprecated:: 2.0.0
173179
174180
Use an object mask to retrieve data related your API call's result.
175181
Object masks are skeleton objects, or strings that define nested
@@ -189,7 +195,8 @@ def set_object_mask(self, mask):
189195
self.add_header(header, {'mask': mask})
190196

191197
def set_result_limit(self, limit, offset=0):
192-
""" Set a result limit on a SoftLayer API call; deprecated
198+
""" Set a result limit on a SoftLayer API call
199+
.. deprecated:: 2.0.0
193200
194201
Many SoftLayer API methods return a group of results. These methods
195202
support a way to limit the number of results retrieved from the
@@ -229,6 +236,7 @@ def __call__(self, service, method, *args, **kwargs):
229236
objectmask = kwargs.get('mask')
230237
objectfilter = kwargs.get('filter')
231238
headers = kwargs.get('headers')
239+
raw_headers = kwargs.get('raw_headers')
232240
limit = kwargs.get('limit')
233241
offset = kwargs.get('offset', 0)
234242

@@ -239,6 +247,10 @@ def __call__(self, service, method, *args, **kwargs):
239247
'apiKey': self.api_key,
240248
}}
241249

250+
if raw_headers:
251+
for name, value in raw_headers.items():
252+
self.transport.set_raw_header(name, value)
253+
242254
if objectid is not None:
243255
headers[service + 'InitParameters'] = {'id': int(objectid)}
244256

@@ -272,6 +284,7 @@ def __call__(self, service, method, *args, **kwargs):
272284

273285
def __getattribute__(self, name):
274286
""" Attempt a SoftLayer API call
287+
.. deprecated:: 2.0.0
275288
276289
Use this as a catch-all so users can call SoftLayer API methods
277290
directly against their client object. If the property or method

SoftLayer/tests/basic_tests.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,9 @@ def test_non_secure_endpoint(self):
7777
self.assertIsInstance(client.transport,
7878
SoftLayer.API.ProxyTransport)
7979

80-
def test_set_raw_header(self):
80+
81+
class ClientMethods(unittest.TestCase):
82+
def test_set_raw_header_old(self):
8183
client = SoftLayer.Client(
8284
username='doesnotexist',
8385
api_key='issurelywrong'
@@ -191,11 +193,15 @@ def test_complex(self, m):
191193
client = SoftLayer.Client(username='doesnotexist',
192194
api_key='issurelywrong')
193195

196+
client.transport = MagicMock()
197+
194198
return_value = client['SERVICE'].METHOD(1234,
195199
id=5678,
196200
mask={'object': {'attribute': ''}},
201+
raw_headers={'RAW': 'HEADER'},
197202
filter={'TYPE': {'obj': {'attribute': '^= prefix'}}},
198203
limit=9, offset=10)
204+
199205
m.return_value.METHOD.assert_called_with({
200206
'headers': {
201207
'SoftLayer_SERVICEObjectMask': {
@@ -209,6 +215,7 @@ def test_complex(self, m):
209215
'resultLimit': {'limit': 9, 'offset': 10}}}, 1234)
210216

211217
self.assertEquals(m.return_value.METHOD(), return_value)
218+
client.transport.set_raw_header.assert_called_with("RAW", "HEADER")
212219

213220

214221
class UnauthedUser(unittest.TestCase):

0 commit comments

Comments
 (0)