Move api_ classes to be members of OpenPhoto (eg: client.photos_list --> client.photos.list)

This commit is contained in:
sneakypete81 2012-09-02 09:02:18 +01:00
parent 8307dca454
commit 21c38c53cb
4 changed files with 107 additions and 72 deletions

View file

@ -1,25 +1,33 @@
from openphoto_http import OpenPhotoHttp, OpenPhotoError
from objects import Tag
class ApiTag(OpenPhotoHttp):
def tag_create(self, tag_id, **kwds):
""" Create a new tag and return it """
result = self.post("/tag/create.json", tag=tag_id, **kwds)["result"]
return Tag(self, result)
class ApiTags:
def __init__(self, client):
self._client = client
def tag_delete(self, tag_id, **kwds):
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 and return it """
result = self._client.post("/tag/create.json", tag=tag, **kwds)["result"]
return Tag(self._client, result)
def delete(self, tag, **kwds):
""" Delete a tag """
tag = Tag(self, {"id": tag_id})
tag = Tag(self._client, {"id": tag})
tag.delete(**kwds)
def tag_update(self, tag_id, **kwds):
def update(self, tag, **kwds):
""" Update a tag """
tag = Tag(self, {"id": tag_id})
tag = Tag(self._client, {"id": tag})
tag.update(**kwds)
return tag
def tags_list(self, **kwds):
""" Returns a list of Tag objects """
results = self.get("/tags/list.json", **kwds)["result"]
return [Tag(self, tag) for tag in results]