
The object classes are now simple wrappers. Improve parameter testing, by passing foo="bar" where possible.
38 lines
1 KiB
Python
38 lines
1 KiB
Python
"""
|
|
api_base.py: Base class for all API classes
|
|
"""
|
|
|
|
class ApiBase(object):
|
|
""" Base class for all API objects """
|
|
def __init__(self, client):
|
|
self._client = client
|
|
|
|
@staticmethod
|
|
def _build_filter_string(filters):
|
|
"""
|
|
:param filters: dictionary containing the filters
|
|
:returns: filter_string formatted for an API endpoint
|
|
"""
|
|
filter_string = ""
|
|
if filters is not None:
|
|
for filt in filters:
|
|
filter_string += "%s-%s/" % (filt, filters[filt])
|
|
return filter_string
|
|
|
|
@staticmethod
|
|
def _extract_id(obj):
|
|
""" Return obj.id, or obj if the object doesn't have an ID """
|
|
try:
|
|
return obj.id
|
|
except AttributeError:
|
|
return obj
|
|
|
|
@staticmethod
|
|
def _result_to_list(result):
|
|
""" Handle the case where the result contains no items """
|
|
if not result:
|
|
return []
|
|
if "totalRows" in result[0] and result[0]["totalRows"] == 0:
|
|
return []
|
|
else:
|
|
return result
|