Create API base class
This commit is contained in:
parent
6293a81d39
commit
0f6cbd58e0
5 changed files with 19 additions and 28 deletions
|
@ -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.
|
||||
|
|
|
@ -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",
|
||||
|
|
8
trovebox/api/api_base.py
Normal file
8
trovebox/api/api_base.py
Normal file
|
@ -0,0 +1,8 @@
|
|||
"""
|
||||
api_base.py: Base class for all API classes
|
||||
"""
|
||||
|
||||
class ApiBase(object):
|
||||
def __init__(self, client):
|
||||
self._client = client
|
||||
|
|
@ -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.
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue