Renamed <object>._trovebox to <object>._client, to match API classes.
Changed _type to a class attribute.
This commit is contained in:
parent
3cfc090dd0
commit
7a7b43afc7
6 changed files with 66 additions and 67 deletions
|
@ -7,11 +7,12 @@ from .photo import Photo
|
|||
|
||||
class Action(TroveboxObject):
|
||||
""" Representation of an Action object """
|
||||
def __init__(self, trovebox, json_dict):
|
||||
_type = "action"
|
||||
|
||||
def __init__(self, client, json_dict):
|
||||
self.target = None
|
||||
self.target_type = None
|
||||
TroveboxObject.__init__(self, trovebox, json_dict)
|
||||
self._type = "action"
|
||||
TroveboxObject.__init__(self, client, json_dict)
|
||||
self._update_fields_with_objects()
|
||||
|
||||
def _update_fields_with_objects(self):
|
||||
|
@ -19,7 +20,7 @@ class Action(TroveboxObject):
|
|||
# Update the photo target with photo objects
|
||||
if self.target is not None:
|
||||
if self.target_type == "photo":
|
||||
self.target = Photo(self._trovebox, self.target)
|
||||
self.target = Photo(self._client, self.target)
|
||||
else:
|
||||
raise NotImplementedError("Actions can only be assigned to "
|
||||
"Photos")
|
||||
|
@ -32,8 +33,8 @@ class Action(TroveboxObject):
|
|||
Returns True if successful.
|
||||
Raises a TroveboxError if not.
|
||||
"""
|
||||
result = self._trovebox.post("/action/%s/delete.json" %
|
||||
self.id, **kwds)["result"]
|
||||
result = self._client.post("/action/%s/delete.json" %
|
||||
self.id, **kwds)["result"]
|
||||
if not result:
|
||||
raise TroveboxError("Delete response returned False")
|
||||
self._delete_fields()
|
||||
|
@ -46,7 +47,7 @@ class Action(TroveboxObject):
|
|||
Requests the full contents of the action.
|
||||
Updates the action's fields with the response.
|
||||
"""
|
||||
result = self._trovebox.get("/action/%s/view.json" %
|
||||
self.id, **kwds)["result"]
|
||||
result = self._client.get("/action/%s/view.json" %
|
||||
self.id, **kwds)["result"]
|
||||
self._replace_fields(result)
|
||||
self._update_fields_with_objects()
|
||||
|
|
|
@ -8,11 +8,12 @@ from .photo import Photo
|
|||
|
||||
class Activity(TroveboxObject):
|
||||
""" Representation of an Activity object """
|
||||
def __init__(self, trovebox, json_dict):
|
||||
_type = "activity"
|
||||
|
||||
def __init__(self, client, json_dict):
|
||||
self.data = None
|
||||
self.type = None
|
||||
TroveboxObject.__init__(self, trovebox, json_dict)
|
||||
self._type = "activity"
|
||||
TroveboxObject.__init__(self, client, json_dict)
|
||||
self._update_fields_with_objects()
|
||||
|
||||
def _update_fields_with_objects(self):
|
||||
|
@ -20,7 +21,7 @@ class Activity(TroveboxObject):
|
|||
# Update the data with photo objects
|
||||
if self.type is not None:
|
||||
if self.type.startswith("photo"):
|
||||
self.data = Photo(self._trovebox, self.data)
|
||||
self.data = Photo(self._client, self.data)
|
||||
else:
|
||||
raise NotImplementedError("Unrecognised activity type: %s"
|
||||
% self.type)
|
||||
|
@ -32,8 +33,8 @@ class Activity(TroveboxObject):
|
|||
Requests the full contents of the activity.
|
||||
Updates the activity's fields with the response.
|
||||
"""
|
||||
result = self._trovebox.get("/activity/%s/view.json" %
|
||||
self.id, **kwds)["result"]
|
||||
result = self._client.get("/activity/%s/view.json" %
|
||||
self.id, **kwds)["result"]
|
||||
|
||||
# TBD: Why is the result enclosed/encoded like this?
|
||||
result = result["0"]
|
||||
|
|
|
@ -7,11 +7,12 @@ from .photo import Photo
|
|||
|
||||
class Album(TroveboxObject):
|
||||
""" Representation of an Album object """
|
||||
def __init__(self, trovebox, json_dict):
|
||||
_type = "album"
|
||||
|
||||
def __init__(self, client, json_dict):
|
||||
self.photos = None
|
||||
self.cover = None
|
||||
TroveboxObject.__init__(self, trovebox, json_dict)
|
||||
self._type = "album"
|
||||
TroveboxObject.__init__(self, client, json_dict)
|
||||
self._update_fields_with_objects()
|
||||
|
||||
def _update_fields_with_objects(self):
|
||||
|
@ -19,7 +20,7 @@ class Album(TroveboxObject):
|
|||
# Update the cover with a photo object
|
||||
try:
|
||||
if isinstance(self.cover, dict):
|
||||
self.cover = Photo(self._trovebox, self.cover)
|
||||
self.cover = Photo(self._client, self.cover)
|
||||
except AttributeError:
|
||||
pass # No cover
|
||||
|
||||
|
@ -27,7 +28,7 @@ class Album(TroveboxObject):
|
|||
try:
|
||||
for i, photo in enumerate(self.photos):
|
||||
if isinstance(photo, dict):
|
||||
self.photos[i] = Photo(self._trovebox, photo)
|
||||
self.photos[i] = Photo(self._client, photo)
|
||||
except (AttributeError, TypeError):
|
||||
pass # No photos, or not a list
|
||||
|
||||
|
@ -38,17 +39,17 @@ class Album(TroveboxObject):
|
|||
Update the cover photo of this album.
|
||||
"""
|
||||
if not isinstance(photo, Photo):
|
||||
photo = Photo(self._trovebox, {"id": photo})
|
||||
photo = Photo(self._client, {"id": photo})
|
||||
|
||||
result = self._trovebox.post("/album/%s/cover/%s/update.json" %
|
||||
(self.id, photo.id),
|
||||
**kwds)["result"]
|
||||
result = self._client.post("/album/%s/cover/%s/update.json" %
|
||||
(self.id, photo.id),
|
||||
**kwds)["result"]
|
||||
|
||||
# API currently doesn't return the updated album
|
||||
# (frontend issue #1369)
|
||||
if isinstance(result, bool): # pragma: no cover
|
||||
result = self._trovebox.get("/album/%s/view.json" %
|
||||
self.id)["result"]
|
||||
result = self._client.get("/album/%s/view.json" %
|
||||
self.id)["result"]
|
||||
self._replace_fields(result)
|
||||
self._update_fields_with_objects()
|
||||
|
||||
|
@ -60,8 +61,8 @@ class Album(TroveboxObject):
|
|||
Returns True if successful.
|
||||
Raises a TroveboxError if not.
|
||||
"""
|
||||
result = self._trovebox.post("/album/%s/delete.json" %
|
||||
self.id, **kwds)["result"]
|
||||
result = self._client.post("/album/%s/delete.json" %
|
||||
self.id, **kwds)["result"]
|
||||
if not result:
|
||||
raise TroveboxError("Delete response returned False")
|
||||
self._delete_fields()
|
||||
|
@ -77,13 +78,13 @@ class Album(TroveboxObject):
|
|||
automatically.
|
||||
Updates the album's fields with the response.
|
||||
"""
|
||||
result = self._trovebox.album.add(self, objects, object_type, **kwds)
|
||||
result = self._client.album.add(self, objects, object_type, **kwds)
|
||||
|
||||
# API currently doesn't return the updated album
|
||||
# (frontend issue #1369)
|
||||
if isinstance(result, bool): # pragma: no cover
|
||||
result = self._trovebox.get("/album/%s/view.json" %
|
||||
self.id)["result"]
|
||||
result = self._client.get("/album/%s/view.json" %
|
||||
self.id)["result"]
|
||||
self._replace_fields(result)
|
||||
self._update_fields_with_objects()
|
||||
|
||||
|
@ -97,13 +98,13 @@ class Album(TroveboxObject):
|
|||
automatically.
|
||||
Updates the album's fields with the response.
|
||||
"""
|
||||
result = self._trovebox.album.remove(self, objects, object_type,
|
||||
**kwds)
|
||||
result = self._client.album.remove(self, objects, object_type,
|
||||
**kwds)
|
||||
# API currently doesn't return the updated album
|
||||
# (frontend issue #1369)
|
||||
if isinstance(result, bool): # pragma: no cover
|
||||
result = self._trovebox.get("/album/%s/view.json" %
|
||||
self.id)["result"]
|
||||
result = self._client.get("/album/%s/view.json" %
|
||||
self.id)["result"]
|
||||
self._replace_fields(result)
|
||||
self._update_fields_with_objects()
|
||||
|
||||
|
@ -113,13 +114,13 @@ class Album(TroveboxObject):
|
|||
|
||||
Updates this album with the specified parameters.
|
||||
"""
|
||||
result = self._trovebox.post("/album/%s/update.json" %
|
||||
self.id, **kwds)["result"]
|
||||
result = self._client.post("/album/%s/update.json" %
|
||||
self.id, **kwds)["result"]
|
||||
|
||||
# APIv1 doesn't return the updated album (frontend issue #937)
|
||||
if isinstance(result, bool): # pragma: no cover
|
||||
result = self._trovebox.get("/album/%s/view.json" %
|
||||
self.id)["result"]
|
||||
result = self._client.get("/album/%s/view.json" %
|
||||
self.id)["result"]
|
||||
|
||||
self._replace_fields(result)
|
||||
self._update_fields_with_objects()
|
||||
|
@ -131,7 +132,7 @@ class Album(TroveboxObject):
|
|||
Requests all properties of an album.
|
||||
Updates the album's fields with the response.
|
||||
"""
|
||||
result = self._trovebox.get("/album/%s/view.json" %
|
||||
self.id, **kwds)["result"]
|
||||
result = self._client.get("/album/%s/view.json" %
|
||||
self.id, **kwds)["result"]
|
||||
self._replace_fields(result)
|
||||
self._update_fields_with_objects()
|
||||
|
|
|
@ -6,9 +6,7 @@ from .trovebox_object import TroveboxObject
|
|||
|
||||
class Photo(TroveboxObject):
|
||||
""" Representation of a Photo object """
|
||||
def __init__(self, trovebox, json_dict):
|
||||
TroveboxObject.__init__(self, trovebox, json_dict)
|
||||
self._type = "photo"
|
||||
_type = "photo"
|
||||
|
||||
def delete(self, **kwds):
|
||||
"""
|
||||
|
@ -18,8 +16,8 @@ class Photo(TroveboxObject):
|
|||
Returns True if successful.
|
||||
Raises a TroveboxError if not.
|
||||
"""
|
||||
result = self._trovebox.post("/photo/%s/delete.json" %
|
||||
self.id, **kwds)["result"]
|
||||
result = self._client.post("/photo/%s/delete.json" %
|
||||
self.id, **kwds)["result"]
|
||||
if not result:
|
||||
raise TroveboxError("Delete response returned False")
|
||||
self._delete_fields()
|
||||
|
@ -41,8 +39,8 @@ class Photo(TroveboxObject):
|
|||
|
||||
Updates this photo with the specified parameters.
|
||||
"""
|
||||
result = self._trovebox.post("/photo/%s/update.json" %
|
||||
self.id, **kwds)["result"]
|
||||
result = self._client.post("/photo/%s/update.json" %
|
||||
self.id, **kwds)["result"]
|
||||
self._replace_fields(result)
|
||||
|
||||
# TODO: Add options
|
||||
|
@ -55,8 +53,8 @@ class Photo(TroveboxObject):
|
|||
by using the "returnSizes" parameter.
|
||||
Updates the photo's fields with the response.
|
||||
"""
|
||||
result = self._trovebox.get("/photo/%s/view.json" %
|
||||
self.id, **kwds)["result"]
|
||||
result = self._client.get("/photo/%s/view.json" %
|
||||
self.id, **kwds)["result"]
|
||||
self._replace_fields(result)
|
||||
|
||||
def dynamic_url(self, **kwds):
|
||||
|
@ -71,8 +69,8 @@ class Photo(TroveboxObject):
|
|||
Returns a dict containing the next and previous photo lists
|
||||
(there may be more than one next/previous photo returned).
|
||||
"""
|
||||
result = self._trovebox.get("/photo/%s/nextprevious.json" %
|
||||
self.id, **kwds)["result"]
|
||||
result = self._client.get("/photo/%s/nextprevious.json" %
|
||||
self.id, **kwds)["result"]
|
||||
value = {}
|
||||
if "next" in result:
|
||||
# Workaround for APIv1
|
||||
|
@ -81,7 +79,7 @@ class Photo(TroveboxObject):
|
|||
|
||||
value["next"] = []
|
||||
for photo in result["next"]:
|
||||
value["next"].append(Photo(self._trovebox, photo))
|
||||
value["next"].append(Photo(self._client, photo))
|
||||
|
||||
if "previous" in result:
|
||||
# Workaround for APIv1
|
||||
|
@ -90,7 +88,7 @@ class Photo(TroveboxObject):
|
|||
|
||||
value["previous"] = []
|
||||
for photo in result["previous"]:
|
||||
value["previous"].append(Photo(self._trovebox, photo))
|
||||
value["previous"].append(Photo(self._client, photo))
|
||||
|
||||
return value
|
||||
|
||||
|
@ -102,12 +100,12 @@ class Photo(TroveboxObject):
|
|||
eg. transform(photo, rotate=90)
|
||||
Updates the photo's fields with the response.
|
||||
"""
|
||||
result = self._trovebox.post("/photo/%s/transform.json" %
|
||||
self.id, **kwds)["result"]
|
||||
result = self._client.post("/photo/%s/transform.json" %
|
||||
self.id, **kwds)["result"]
|
||||
|
||||
# APIv1 doesn't return the transformed photo (frontend issue #955)
|
||||
if isinstance(result, bool): # pragma: no cover
|
||||
result = self._trovebox.get("/photo/%s/view.json" %
|
||||
self.id)["result"]
|
||||
result = self._client.get("/photo/%s/view.json" %
|
||||
self.id)["result"]
|
||||
|
||||
self._replace_fields(result)
|
||||
|
|
|
@ -11,9 +11,7 @@ from .trovebox_object import TroveboxObject
|
|||
|
||||
class Tag(TroveboxObject):
|
||||
""" Representation of a Tag object """
|
||||
def __init__(self, trovebox, json_dict):
|
||||
TroveboxObject.__init__(self, trovebox, json_dict)
|
||||
self._type = "tag"
|
||||
_type = "tag"
|
||||
|
||||
def delete(self, **kwds):
|
||||
"""
|
||||
|
@ -23,8 +21,8 @@ class Tag(TroveboxObject):
|
|||
Returns True if successful.
|
||||
Raises a TroveboxError if not.
|
||||
"""
|
||||
result = self._trovebox.post("/tag/%s/delete.json" %
|
||||
quote(self.id), **kwds)["result"]
|
||||
result = self._client.post("/tag/%s/delete.json" %
|
||||
quote(self.id), **kwds)["result"]
|
||||
if not result:
|
||||
raise TroveboxError("Delete response returned False")
|
||||
self._delete_fields()
|
||||
|
@ -37,8 +35,8 @@ class Tag(TroveboxObject):
|
|||
Updates this tag with the specified parameters.
|
||||
Returns the updated tag object.
|
||||
"""
|
||||
result = self._trovebox.post("/tag/%s/update.json" % quote(self.id),
|
||||
**kwds)["result"]
|
||||
result = self._client.post("/tag/%s/update.json" % quote(self.id),
|
||||
**kwds)["result"]
|
||||
self._replace_fields(result)
|
||||
|
||||
# def view(self, **kwds):
|
||||
|
|
|
@ -3,11 +3,11 @@ Base object supporting the storage of custom fields as attributes
|
|||
"""
|
||||
class TroveboxObject(object):
|
||||
""" Base object supporting the storage of custom fields as attributes """
|
||||
def __init__(self, trovebox, json_dict):
|
||||
self._type = "None"
|
||||
_type = "None"
|
||||
def __init__(self, client, json_dict):
|
||||
self.id = None
|
||||
self.name = None
|
||||
self._trovebox = trovebox
|
||||
self._client = client
|
||||
self._json_dict = json_dict
|
||||
self._set_fields(json_dict)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue