diff --git a/usabilla.py b/usabilla.py index 49fe12f..4ec5abb 100644 --- a/usabilla.py +++ b/usabilla.py @@ -72,11 +72,11 @@ class APIClient(object): """ resources = { - 'scopes' : { + 'scopes': { 'live': { 'products': { 'websites': { - 'resources' : { + 'resources': { 'button': '/button', 'feedback': '/button/:id/feedback', 'campaign': '/campaign', @@ -87,13 +87,13 @@ class APIClient(object): } }, 'email': { - 'resources' : { + 'resources': { 'button': '/button', 'feedback': '/button/:id/feedback' } }, 'apps': { - 'resources' : { + 'resources': { 'app': '', 'feedback': '/:id/feedback', 'campaign': '/campaign', @@ -238,12 +238,9 @@ def send_signed_request(self, scope): # Send the request. request_url = self.host + scope + '?' + canonical_querystring r = requests.get(self.host_protocol + request_url, headers=headers) + r.raise_for_status() - if r.status_code != 200: - return r - else: - return r.json() - + return r.json() def check_resource_validity(self, scope, product, resource): """Checks whether the resource exists @@ -287,7 +284,7 @@ def handle_id(self, url, resource_id): if resource_id == '': raise GeneralError('invalid id', 'Invalid resource ID') if resource_id == '*': - resource_id = '%2A' + resource_id = '%2A' url = url.replace(':id', str(resource_id)) @@ -300,20 +297,16 @@ def item_iterator(self, url): :type url: str - :returns: An `generator` that yeilds the requested data. + :returns: A `generator` that yeilds the requested data. :rtype: generator """ has_more = True while has_more: - try: - results = self.send_signed_request(url) - has_more = results['hasMore'] - for item in results['items']: - yield item - self.set_query_parameters({'since': results['lastTimestamp']}) - except: - return - + results = self.send_signed_request(url) + has_more = results['hasMore'] + for item in results['items']: + yield item + self.set_query_parameters({'since': results['lastTimestamp']}) def get_resource(self, scope, product, resource, resource_id=None, iterate=False): """Retrieves resources of the specified type @@ -330,7 +323,7 @@ def get_resource(self, scope, product, resource, resource_id=None, iterate=False :type resource_id: str :type iterate: bool - :returns: An `generator` that yeilds the requested data or a single resource + :returns: An `generator` that yields the requested data or a single resource :rtype: generator or single resource """ url = self.handle_id(self.check_resource_validity(scope, product, resource), resource_id)