Skip to content

Commit 1bc5dd5

Browse files
author
Teun Zengerink
committed
Remove whitespace
1 parent a9529a7 commit 1bc5dd5

2 files changed

Lines changed: 41 additions & 43 deletions

File tree

tests.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,5 +87,6 @@ def test_query_parameters(self):
8787
self.client.set_query_parameters(params)
8888
self.assertEqual(self.client.get_query_parameters(), 'limit=1&since=1235454')
8989

90+
9091
if __name__ == '__main__':
9192
unittest_main()

usabilla.py

Lines changed: 40 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -104,23 +104,23 @@ class APIClient(object):
104104
}
105105
}
106106
}
107-
107+
108108
""" Scope constants """
109109
SCOPE_LIVE = 'live'
110-
110+
111111
""" Product contants """
112112
PRODUCT_WEBSITES = 'websites'
113113
PRODUCT_EMAIL = 'email'
114114
PRODUCT_APPS = 'apps'
115-
115+
116116
""" Resource contants """
117117
RESOURCE_FEEDBACK = 'feedback'
118118
RESOURCE_APP = 'app'
119119
RESOURCE_BUTTON = 'button'
120-
RESOURCE_CAMPAIGN = 'campaign'
120+
RESOURCE_CAMPAIGN = 'campaign'
121121
RESOURCE_CAMPAIGN_RESULT = 'campaign_result'
122122
RESOURCE_CAMPAIGN_STATS = 'campaign_stats'
123-
RESOURCE_INPAGE = 'inpage'
123+
RESOURCE_INPAGE = 'inpage'
124124
RESOURCE_INPAGE_RESULT = 'inpage_result'
125125

126126
method = 'GET'
@@ -148,7 +148,7 @@ def set_query_parameters(self, parameters):
148148
:param parameters: A `dict` representing the query parameters to be used for the request.
149149
:type parameters: dict
150150
"""
151-
151+
152152
self.query_parameters = urllib.urlencode(OrderedDict(sorted(parameters.items())))
153153

154154
def get_query_parameters(self):
@@ -169,7 +169,7 @@ def send_signed_request(self, scope):
169169
:type scope: str
170170
171171
:returns: A `dict` of the data.
172-
:rtype: dict
172+
:rtype: dict
173173
"""
174174
if self.credentials.client_key is None or self.credentials.secret_key is None:
175175
raise GeneralError('Invalid Access Key.', 'The Access Key supplied is invalid.')
@@ -194,7 +194,7 @@ def send_signed_request(self, scope):
194194

195195
# Create payload hash (hash of the request body content).
196196
payload_hash = hashlib.sha256(''.encode('utf-8')).hexdigest()
197-
197+
198198
# Combine elements to create canonical request.
199199
canonical_request = '{method}\n{uri}\n{query}\n{can_headers}\n{signed_headers}\n{hash}'.format(
200200
method=self.method,
@@ -234,52 +234,52 @@ def send_signed_request(self, scope):
234234
)
235235

236236
headers = {'date': usbldate, 'Authorization': authorization_header}
237-
237+
238238
# Send the request.
239-
request_url = self.host + scope + '?' + canonical_querystring
239+
request_url = self.host + scope + '?' + canonical_querystring
240240
r = requests.get(self.host_protocol + request_url, headers=headers)
241-
242-
241+
242+
243243
if r.status_code != 200:
244244
return r
245245
else:
246246
return r.json()
247-
248247

249-
def check_resource_validity(self,scope,product,resource):
250-
"""Checks whether the resource exists
251-
248+
249+
def check_resource_validity(self, scope, product, resource):
250+
"""Checks whether the resource exists
251+
252252
:param scope: A `string` that specifies the resource scope
253253
:param product: A `string` that specifies the product type
254254
:param resource: A `string` that specifies the resource type
255-
255+
256256
:type scope: str
257257
:type product: str
258258
:type resource: str
259-
259+
260260
:returns: An `string` that represents the resource request url
261261
:rtype: string
262262
"""
263263
if scope not in self.resources['scopes'].keys():
264264
raise GeneralError('invalid scope', 'Invalid scope name')
265265
if product not in self.resources['scopes'][scope]['products'].keys():
266-
raise GeneralError('invalid product', 'Invalid product name')
266+
raise GeneralError('invalid product', 'Invalid product name')
267267
if resource not in self.resources['scopes'][scope]['products'][product]['resources'].keys():
268-
raise GeneralError('invalid resource', 'Invalid resource name')
269-
268+
raise GeneralError('invalid resource', 'Invalid resource name')
269+
270270
url = '/' + scope + '/' + product + self.resources['scopes'][scope]['products'][product]['resources'][resource]
271-
271+
272272
return url
273-
273+
274274
def handle_id(self,url,resource_id):
275275
"""Replaces the :id pattern in the url
276-
276+
277277
:param url: A `string` that specifies the resource request url
278278
:param resource_id: A `string` that specifies the resource id
279-
279+
280280
:type url: str
281281
:type resource_id: str
282-
282+
283283
:returns: An `string` that represents the resource request url
284284
:rtype: string
285285
"""
@@ -288,18 +288,18 @@ def handle_id(self,url,resource_id):
288288
raise GeneralError('invalid id', 'Invalid resource ID')
289289
if resource_id == '*':
290290
resource_id = '%2A'
291-
291+
292292
url = url.replace(':id', str(resource_id))
293-
293+
294294
return url
295-
295+
296296
def item_iterator(self, url):
297297
"""Get items using an iterator.
298-
298+
299299
:param url: A `string` that specifies the resource request url
300-
300+
301301
:type url: str
302-
302+
303303
:returns: An `generator` that yeilds the requested data.
304304
:rtype: generator
305305
"""
@@ -313,32 +313,29 @@ def item_iterator(self, url):
313313
self.set_query_parameters({'since': results['lastTimestamp']})
314314
except:
315315
return
316-
317-
316+
317+
318318
def get_resource(self, scope, product, resource, resource_id=None, iterate=False):
319319
"""Retrieves resources of the specified type
320-
320+
321321
:param scope: A `string` that specifies the resource scope
322322
:param product: A `string` that specifies the product type
323323
:param resource: A `string` that specifies the resource type
324324
:param resource_id: A `string` that specifies the resource id
325-
:param iterate: A `boolean` that specifies whether the you want to use an iterator
326-
325+
:param iterate: A `boolean` that specifies whether the you want to use an iterator
326+
327327
:type scope: str
328328
:type product: str
329329
:type resource: str
330330
:type resource_id: str
331-
:type iterate: bool
332-
331+
:type iterate: bool
332+
333333
:returns: An `generator` that yeilds the requested data or a single resource
334334
:rtype: generator or single resource
335335
"""
336336
url = self.handle_id(self.check_resource_validity(scope, product, resource), resource_id)
337-
337+
338338
if iterate:
339339
return self.item_iterator(url)
340340
else:
341341
return self.send_signed_request(url)
342-
343-
344-

0 commit comments

Comments
 (0)