diff --git a/trovebox/api/api_action.py b/trovebox/api/api_action.py index a0f586c..f6b571e 100644 --- a/trovebox/api/api_action.py +++ b/trovebox/api/api_action.py @@ -3,12 +3,10 @@ api_action.py : Trovebox Action API Classes """ from trovebox.objects.action import Action from trovebox.objects.photo import Photo +from .api_base import ApiBase -class ApiAction(object): +class ApiAction(ApiBase): """ Definitions of /action/ API endpoints """ - def __init__(self, client): - self._client = client - def create(self, target, target_type=None, **kwds): """ Create a new action and return it. diff --git a/trovebox/api/api_album.py b/trovebox/api/api_album.py index 4326816..f767c8f 100644 --- a/trovebox/api/api_album.py +++ b/trovebox/api/api_album.py @@ -3,23 +3,18 @@ api_album.py : Trovebox Album API Classes """ from trovebox.objects.album import Album from trovebox import http +from .api_base import ApiBase -class ApiAlbums(object): +class ApiAlbums(ApiBase): """ Definitions of /albums/ API endpoints """ - def __init__(self, client): - self._client = client - def list(self, **kwds): """ Return a list of Album objects """ albums = self._client.get("/albums/list.json", **kwds)["result"] albums = http.result_to_list(albums) return [Album(self._client, album) for album in albums] -class ApiAlbum(object): +class ApiAlbum(ApiBase): """ Definitions of /album/ API endpoints """ - def __init__(self, client): - self._client = client - def create(self, name, **kwds): """ Create a new album and return it""" result = self._client.post("/album/create.json", diff --git a/trovebox/api/api_base.py b/trovebox/api/api_base.py new file mode 100644 index 0000000..3e906be --- /dev/null +++ b/trovebox/api/api_base.py @@ -0,0 +1,8 @@ +""" +api_base.py: Base class for all API classes +""" + +class ApiBase(object): + def __init__(self, client): + self._client = client + diff --git a/trovebox/api/api_photo.py b/trovebox/api/api_photo.py index b5f8512..e83e74e 100644 --- a/trovebox/api/api_photo.py +++ b/trovebox/api/api_photo.py @@ -6,6 +6,7 @@ import base64 from trovebox import http from trovebox.errors import TroveboxError from trovebox.objects.photo import Photo +from .api_base import ApiBase def extract_ids(photos): """ @@ -20,11 +21,8 @@ def extract_ids(photos): ids.append(photo) return ids -class ApiPhotos(object): +class ApiPhotos(ApiBase): """ Definitions of /photos/ API endpoints """ - def __init__(self, client): - self._client = client - def list(self, **kwds): """ Returns a list of Photo objects """ photos = self._client.get("/photos/list.json", **kwds)["result"] @@ -55,11 +53,8 @@ class ApiPhotos(object): raise TroveboxError("Delete response returned False") return True -class ApiPhoto(object): +class ApiPhoto(ApiBase): """ Definitions of /photo/ API endpoints """ - def __init__(self, client): - self._client = client - def delete(self, photo, **kwds): """ Delete a photo. diff --git a/trovebox/api/api_tag.py b/trovebox/api/api_tag.py index acd6fca..dd11b15 100644 --- a/trovebox/api/api_tag.py +++ b/trovebox/api/api_tag.py @@ -3,23 +3,18 @@ api_tag.py : Trovebox Tag API Classes """ from trovebox import http from trovebox.objects.tag import Tag +from .api_base import ApiBase -class ApiTags(object): +class ApiTags(ApiBase): """ Definitions of /tags/ API endpoints """ - def __init__(self, client): - self._client = client - def list(self, **kwds): """ Returns a list of Tag objects """ tags = self._client.get("/tags/list.json", **kwds)["result"] tags = http.result_to_list(tags) return [Tag(self._client, tag) for tag in tags] -class ApiTag(object): +class ApiTag(ApiBase): """ Definitions of /tag/ API endpoints """ - def __init__(self, client): - self._client = client - def create(self, tag, **kwds): """ Create a new tag.