@@ -72,11 +72,11 @@ class APIClient(object):
72
72
"""
73
73
74
74
resources = {
75
- 'scopes' : {
75
+ 'scopes' : {
76
76
'live' : {
77
77
'products' : {
78
78
'websites' : {
79
- 'resources' : {
79
+ 'resources' : {
80
80
'button' : '/button' ,
81
81
'feedback' : '/button/:id/feedback' ,
82
82
'campaign' : '/campaign' ,
@@ -87,13 +87,13 @@ class APIClient(object):
87
87
}
88
88
},
89
89
'email' : {
90
- 'resources' : {
90
+ 'resources' : {
91
91
'button' : '/button' ,
92
92
'feedback' : '/button/:id/feedback'
93
93
}
94
94
},
95
95
'apps' : {
96
- 'resources' : {
96
+ 'resources' : {
97
97
'app' : '' ,
98
98
'feedback' : '/:id/feedback' ,
99
99
'campaign' : '/campaign' ,
@@ -238,12 +238,9 @@ def send_signed_request(self, scope):
238
238
# Send the request.
239
239
request_url = self .host + scope + '?' + canonical_querystring
240
240
r = requests .get (self .host_protocol + request_url , headers = headers )
241
+ r .raise_for_status ()
241
242
242
- if r .status_code != 200 :
243
- return r
244
- else :
245
- return r .json ()
246
-
243
+ return r .json ()
247
244
248
245
def check_resource_validity (self , scope , product , resource ):
249
246
"""Checks whether the resource exists
@@ -287,7 +284,7 @@ def handle_id(self, url, resource_id):
287
284
if resource_id == '' :
288
285
raise GeneralError ('invalid id' , 'Invalid resource ID' )
289
286
if resource_id == '*' :
290
- resource_id = '%2A'
287
+ resource_id = '%2A'
291
288
292
289
url = url .replace (':id' , str (resource_id ))
293
290
@@ -300,20 +297,17 @@ def item_iterator(self, url):
300
297
301
298
:type url: str
302
299
303
- :returns: An `generator` that yeilds the requested data.
300
+ :returns: A `generator` that yields the requested data.
304
301
:rtype: generator
302
+ :raises requests.exceptions.HTTPError: if an HTTP error occurred
305
303
"""
306
304
has_more = True
307
305
while has_more :
308
- try :
309
- results = self .send_signed_request (url )
310
- has_more = results ['hasMore' ]
311
- for item in results ['items' ]:
312
- yield item
313
- self .set_query_parameters ({'since' : results ['lastTimestamp' ]})
314
- except :
315
- return
316
-
306
+ results = self .send_signed_request (url )
307
+ has_more = results ['hasMore' ]
308
+ for item in results ['items' ]:
309
+ yield item
310
+ self .set_query_parameters ({'since' : results ['lastTimestamp' ]})
317
311
318
312
def get_resource (self , scope , product , resource , resource_id = None , iterate = False ):
319
313
"""Retrieves resources of the specified type
@@ -330,7 +324,7 @@ def get_resource(self, scope, product, resource, resource_id=None, iterate=False
330
324
:type resource_id: str
331
325
:type iterate: bool
332
326
333
- :returns: An `generator` that yeilds the requested data or a single resource
327
+ :returns: A `generator` that yields the requested data or a single resource
334
328
:rtype: generator or single resource
335
329
"""
336
330
url = self .handle_id (self .check_resource_validity (scope , product , resource ), resource_id )
0 commit comments