photo-python/openphoto/api_tag.py
sneakypete81 ba681cea89 Code tidyup after 2to3 conversion
Moved config parser into its own module
2013-05-25 11:33:41 +01:00

36 lines
1.1 KiB
Python

from openphoto.errors import *
from openphoto.objects import Tag
class ApiTags:
def __init__(self, client):
self._client = client
def list(self, **kwds):
""" Returns a list of Tag objects """
results = self._client.get("/tags/list.json", **kwds)["result"]
return [Tag(self._client, tag) for tag in results]
class ApiTag:
def __init__(self, client):
self._client = client
def create(self, tag, **kwds):
""" Create a new tag. The API returns true if the tag was sucessfully created """
return self._client.post("/tag/create.json", tag=tag, **kwds)["result"]
def delete(self, tag, **kwds):
"""
Delete a tag.
Returns True if successful.
Raises an OpenPhotoError if not.
"""
if not isinstance(tag, Tag):
tag = Tag(self._client, {"id": tag})
return tag.delete(**kwds)
def update(self, tag, **kwds):
""" Update a tag """
if not isinstance(tag, Tag):
tag = Tag(self._client, {"id": tag})
tag.update(**kwds)
return tag