Move api_ classes to be members of OpenPhoto (eg: client.photos_list --> client.photos.list)
This commit is contained in:
parent
8307dca454
commit
21c38c53cb
4 changed files with 107 additions and 72 deletions
|
@ -1,8 +1,20 @@
|
||||||
from openphoto_http import OpenPhotoHttp, OpenPhotoError, OpenPhotoDuplicateError
|
from openphoto_http import OpenPhotoHttp, OpenPhotoError, OpenPhotoDuplicateError
|
||||||
from api_photo import ApiPhoto
|
import api_photo
|
||||||
from api_tag import ApiTag
|
import api_tag
|
||||||
from api_album import ApiAlbum
|
import api_album
|
||||||
|
|
||||||
class OpenPhoto(OpenPhotoHttp, ApiPhoto, ApiTag, ApiAlbum):
|
class OpenPhoto(OpenPhotoHttp):
|
||||||
""" Client library for OpenPhoto """
|
""" Client library for OpenPhoto """
|
||||||
pass
|
def __init__(self, host,
|
||||||
|
consumer_key='', consumer_secret='',
|
||||||
|
token='', token_secret=''):
|
||||||
|
OpenPhotoHttp.__init__(self, host,
|
||||||
|
consumer_key, consumer_secret,
|
||||||
|
token, token_secret)
|
||||||
|
|
||||||
|
self.photos = api_photo.ApiPhotos(self)
|
||||||
|
self.photo = api_photo.ApiPhoto(self)
|
||||||
|
self.tags = api_tag.ApiTags(self)
|
||||||
|
self.tag = api_tag.ApiTag(self)
|
||||||
|
self.albums = api_album.ApiAlbums(self)
|
||||||
|
self.album = api_album.ApiAlbum(self)
|
||||||
|
|
|
@ -1,33 +1,40 @@
|
||||||
from openphoto_http import OpenPhotoHttp, OpenPhotoError
|
from openphoto_http import OpenPhotoHttp, OpenPhotoError
|
||||||
from objects import Album
|
from objects import Album
|
||||||
|
|
||||||
class ApiAlbum(OpenPhotoHttp):
|
class ApiAlbums:
|
||||||
def album_create(self, name, **kwds):
|
def __init__(self, client):
|
||||||
""" Create a new album and return it"""
|
self._client = client
|
||||||
result = self.post("/album/create.json", name=name, **kwds)["result"]
|
|
||||||
return Album(self, result)
|
|
||||||
|
|
||||||
def album_delete(self, album_id, **kwds):
|
def list(self, **kwds):
|
||||||
|
""" Return a list of Album objects """
|
||||||
|
results = self._client.get("/albums/list.json", **kwds)["result"]
|
||||||
|
return [Album(self._client, album) for album in results]
|
||||||
|
|
||||||
|
class ApiAlbum:
|
||||||
|
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", name=name, **kwds)["result"]
|
||||||
|
return Album(self._client, result)
|
||||||
|
|
||||||
|
def delete(self, album, **kwds):
|
||||||
""" Delete an album """
|
""" Delete an album """
|
||||||
album = Album(self, {"id": album_id})
|
album = Album(self._client, {"id": album})
|
||||||
album.delete(**kwds)
|
album.delete(**kwds)
|
||||||
|
|
||||||
def album_form(self, album_id, **kwds):
|
def form(self, album, **kwds):
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
def album_add_photos(self, album_id, photo_ids, **kwds):
|
def add_photos(self, album, photos, **kwds):
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
def album_remove_photos(self, album_id, photo_ids, **kwds):
|
def remove_photos(self, album, photos, **kwds):
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
def albums_list(self, **kwds):
|
def update(self, album, **kwds):
|
||||||
""" Return a list of Album objects """
|
|
||||||
results = self.get("/albums/list.json", **kwds)["result"]
|
|
||||||
return [Album(self, album) for album in results]
|
|
||||||
|
|
||||||
def album_update(self, album_id, **kwds):
|
|
||||||
""" Update an album """
|
""" Update an album """
|
||||||
album = Album(self, {"id": album_id})
|
album = Album(self._client, {"id": album})
|
||||||
album.update(**kwds)
|
album.update(**kwds)
|
||||||
# Don't return the album, since the API doesn't give us the modified album
|
# Don't return the album, since the API doesn't give us the modified album
|
||||||
|
|
|
@ -3,77 +3,85 @@ import base64
|
||||||
from openphoto_http import OpenPhotoHttp, OpenPhotoError
|
from openphoto_http import OpenPhotoHttp, OpenPhotoError
|
||||||
from objects import Photo
|
from objects import Photo
|
||||||
|
|
||||||
class ApiPhoto(OpenPhotoHttp):
|
class ApiPhotos:
|
||||||
def photo_delete(self, photo_id, **kwds):
|
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"]
|
||||||
|
photos = self._client._result_to_list(photos)
|
||||||
|
return [Photo(self._client, photo) for photo in photos]
|
||||||
|
|
||||||
|
def update(self, photos, **kwds):
|
||||||
|
""" Updates a list of photos """
|
||||||
|
if not self._client.post("/photos/update.json", ids=photos, **kwds)["result"]:
|
||||||
|
raise OpenPhotoError("Update response returned False")
|
||||||
|
|
||||||
|
def delete(self, photos, **kwds):
|
||||||
|
""" Deletes a list of photos """
|
||||||
|
if not self._client.post("/photos/delete.json", ids=photos, **kwds)["result"]:
|
||||||
|
raise OpenPhotoError("Delete response returned False")
|
||||||
|
|
||||||
|
|
||||||
|
class ApiPhoto:
|
||||||
|
def __init__(self, client):
|
||||||
|
self._client = client
|
||||||
|
|
||||||
|
def delete(self, photo, **kwds):
|
||||||
""" Delete a photo """
|
""" Delete a photo """
|
||||||
photo = Photo(self, {"id": photo_id})
|
photo = Photo(self._client, {"id": photo})
|
||||||
photo.delete(**kwds)
|
photo.delete(**kwds)
|
||||||
|
|
||||||
def photo_edit(self, photo_id, **kwds):
|
def edit(self, photo, **kwds):
|
||||||
""" Returns an HTML form to edit a photo """
|
""" Returns an HTML form to edit a photo """
|
||||||
photo = Photo(self, {"id": photo_id})
|
photo = Photo(self._client, {"id": photo})
|
||||||
return photo.edit(**kwds)
|
return photo.edit(**kwds)
|
||||||
|
|
||||||
def photo_replace(self, photo_id, photo_file, **kwds):
|
def replace(self, photo, photo_file, **kwds):
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
def photo_replace_encoded(self, photo_id, photo_file, **kwds):
|
def replace_encoded(self, photo, photo_file, **kwds):
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
def photo_update(self, photo_id, **kwds):
|
def update(self, photo, **kwds):
|
||||||
"""
|
"""
|
||||||
Update a photo with the specified parameters.
|
Update a photo with the specified parameters.
|
||||||
Returns the updated photo object
|
Returns the updated photo object
|
||||||
"""
|
"""
|
||||||
photo = Photo(self, {"id": photo_id})
|
photo = Photo(self._client, {"id": photo})
|
||||||
photo.update(**kwds)
|
photo.update(**kwds)
|
||||||
return photo
|
return photo
|
||||||
|
|
||||||
def photo_view(self, photo_id, **kwds):
|
def view(self, photo, **kwds):
|
||||||
"""
|
"""
|
||||||
Used to view the photo at a particular size.
|
Used to view the photo at a particular size.
|
||||||
Returns the requested photo object
|
Returns the requested photo object
|
||||||
"""
|
"""
|
||||||
photo = Photo(self, {"id": photo_id})
|
photo = Photo(self._client, {"id": photo})
|
||||||
photo.view(**kwds)
|
photo.view(**kwds)
|
||||||
return photo
|
return photo
|
||||||
|
|
||||||
def photos_list(self, **kwds):
|
def upload(self, photo_file, **kwds):
|
||||||
""" Returns a list of Photo objects """
|
raise NotImplementedError("Use upload_encoded instead.")
|
||||||
photos = self.get("/photos/list.json", **kwds)["result"]
|
|
||||||
photos = self._result_to_list(photos)
|
|
||||||
return [Photo(self, photo) for photo in photos]
|
|
||||||
|
|
||||||
def photos_update(self, photo_ids, **kwds):
|
def upload_encoded(self, photo_file, **kwds):
|
||||||
""" Updates a list of photos """
|
|
||||||
if not self.post("/photos/update.json", ids=photo_ids, **kwds)["result"]:
|
|
||||||
raise OpenPhotoError("Update response returned False")
|
|
||||||
|
|
||||||
def photos_delete(self, photo_ids, **kwds):
|
|
||||||
""" Deletes a list of photos """
|
|
||||||
if not self.post("/photos/delete.json", ids=photo_ids, **kwds)["result"]:
|
|
||||||
raise OpenPhotoError("Delete response returned False")
|
|
||||||
|
|
||||||
def photo_upload(self, photo_file, **kwds):
|
|
||||||
raise NotImplementedError("Use photo_upload_encoded instead.")
|
|
||||||
|
|
||||||
def photo_upload_encoded(self, photo_file, **kwds):
|
|
||||||
""" Base64-encodes and uploads the specified file """
|
""" Base64-encodes and uploads the specified file """
|
||||||
encoded_photo = base64.b64encode(open(photo_file, "rb").read())
|
encoded_photo = base64.b64encode(open(photo_file, "rb").read())
|
||||||
result = self.post("/photo/upload.json", photo=encoded_photo,
|
result = self._client.post("/photo/upload.json", photo=encoded_photo,
|
||||||
**kwds)["result"]
|
**kwds)["result"]
|
||||||
return Photo(self, result)
|
return Photo(self._client, result)
|
||||||
|
|
||||||
def photo_dynamic_url(self, photo_id, **kwds):
|
def dynamic_url(self, photo, **kwds):
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
def photo_next_previous(self, photo_id, **kwds):
|
def next_previous(self, photo, **kwds):
|
||||||
"""
|
"""
|
||||||
Returns a dict containing the next and previous photo objects,
|
Returns a dict containing the next and previous photo objects,
|
||||||
given a photo in the middle.
|
given a photo in the middle.
|
||||||
"""
|
"""
|
||||||
photo = Photo(self, {"id": photo_id})
|
photo = Photo(self._client, {"id": photo})
|
||||||
return photo.next_previous(**kwds)
|
return photo.next_previous(**kwds)
|
||||||
|
|
||||||
def photo_transform(self, photo_id, **kwds):
|
def transform(self, photo, **kwds):
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
|
@ -1,25 +1,33 @@
|
||||||
from openphoto_http import OpenPhotoHttp, OpenPhotoError
|
from openphoto_http import OpenPhotoHttp, OpenPhotoError
|
||||||
from objects import Tag
|
from objects import Tag
|
||||||
|
|
||||||
class ApiTag(OpenPhotoHttp):
|
class ApiTags:
|
||||||
def tag_create(self, tag_id, **kwds):
|
def __init__(self, client):
|
||||||
""" Create a new tag and return it """
|
self._client = client
|
||||||
result = self.post("/tag/create.json", tag=tag_id, **kwds)["result"]
|
|
||||||
return Tag(self, result)
|
|
||||||
|
|
||||||
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 """
|
""" Delete a tag """
|
||||||
tag = Tag(self, {"id": tag_id})
|
tag = Tag(self._client, {"id": tag})
|
||||||
tag.delete(**kwds)
|
tag.delete(**kwds)
|
||||||
|
|
||||||
def tag_update(self, tag_id, **kwds):
|
def update(self, tag, **kwds):
|
||||||
""" Update a tag """
|
""" Update a tag """
|
||||||
tag = Tag(self, {"id": tag_id})
|
tag = Tag(self._client, {"id": tag})
|
||||||
tag.update(**kwds)
|
tag.update(**kwds)
|
||||||
return tag
|
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]
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue