def _make_api_object(self, response, model_type=None): blob = response.json() data = blob.get('data', None) # All valid responses have a "data" key. if data is None: raise build_api_error(response, blob) # Warn the user about each warning that was returned. warnings_data = blob.get('warnings', None) for warning_blob in warnings_data or []: message = "%s (%s)" % (warning_blob.get( 'message', ''), warning_blob.get('url', '')) warnings.warn(message, UserWarning) pagination = blob.get('pagination', None) kwargs = { 'response': response, 'pagination': pagination and new_api_object(None, pagination, APIObject), 'warnings': warnings_data and new_api_object(None, warnings_data, APIObject), } if isinstance(data, dict): obj = new_api_object(self, data, model_type, **kwargs) else: obj = APIObject(self, **kwargs) obj.data = new_api_object(self, data, model_type) return obj
def _make_api_object(self, response, model_type=None): blob = response.json() data = blob.get('data', None) # All valid responses have a "data" key. if data is None: raise build_api_error(response, blob) # Warn the user about each warning that was returned. warnings_data = blob.get('warnings', None) for warning_blob in warnings_data or []: message = "%s (%s)" % ( warning_blob.get('message', ''), warning_blob.get('url', '')) warnings.warn(message, UserWarning) pagination = blob.get('pagination', None) kwargs = { 'response': response, 'pagination': pagination and new_api_object(None, pagination, APIObject), 'warnings': warnings_data and new_api_object(None, warnings_data, APIObject) } if isinstance(data, dict): obj = new_api_object(self, data, model_type, **kwargs) else: obj = APIObject(self, **kwargs) obj.data = new_api_object(self, data, model_type) return obj