Added photo next_previous option argument.
Moved options_string slash to the start of the string.
This commit is contained in:
parent
9507abdd08
commit
3a13d13c42
5 changed files with 44 additions and 26 deletions
|
@ -473,9 +473,14 @@ class TestPhotoNextPrevious(TestPhotos):
|
|||
{"next": [self.test_photos_dict[0]],
|
||||
"previous": [self.test_photos_dict[1]]})
|
||||
result = self.client.photo.next_previous(self.test_photos[0],
|
||||
options={"foo": "bar",
|
||||
"test1": "test2"},
|
||||
foo="bar")
|
||||
mock_get.assert_called_with("/photo/1a/nextprevious.json",
|
||||
foo="bar")
|
||||
# Dict elemet can be in any order
|
||||
self.assertIn(mock_get.call_args[0],
|
||||
[("/photo/1a/nextprevious/foo-bar/test1-test2.json",),
|
||||
("/photo/1a/nextprevious/test1-test2/foo-bar.json",)])
|
||||
self.assertEqual(mock_get.call_args[1], {"foo": "bar"})
|
||||
self.assertEqual(result["next"][0].get_fields(),
|
||||
self.test_photos_dict[0])
|
||||
self.assertEqual(result["previous"][0].get_fields(),
|
||||
|
@ -490,9 +495,15 @@ class TestPhotoNextPrevious(TestPhotos):
|
|||
mock_get.return_value = self._return_value(
|
||||
{"next": [self.test_photos_dict[0]],
|
||||
"previous": [self.test_photos_dict[1]]})
|
||||
result = self.client.photo.next_previous("1a", foo="bar")
|
||||
mock_get.assert_called_with("/photo/1a/nextprevious.json",
|
||||
foo="bar")
|
||||
result = self.client.photo.next_previous("1a",
|
||||
options={"foo": "bar",
|
||||
"test1": "test2"},
|
||||
foo="bar")
|
||||
# Dict elemet can be in any order
|
||||
self.assertIn(mock_get.call_args[0],
|
||||
[("/photo/1a/nextprevious/foo-bar/test1-test2.json",),
|
||||
("/photo/1a/nextprevious/test1-test2/foo-bar.json",)])
|
||||
self.assertEqual(mock_get.call_args[1], {"foo": "bar"})
|
||||
self.assertEqual(result["next"][0].get_fields(),
|
||||
self.test_photos_dict[0])
|
||||
self.assertEqual(result["previous"][0].get_fields(),
|
||||
|
@ -507,9 +518,14 @@ class TestPhotoNextPrevious(TestPhotos):
|
|||
mock_get.return_value = self._return_value(
|
||||
{"next": [self.test_photos_dict[0]],
|
||||
"previous": [self.test_photos_dict[1]]})
|
||||
result = self.test_photos[0].next_previous(foo="bar")
|
||||
mock_get.assert_called_with("/photo/1a/nextprevious.json",
|
||||
foo="bar")
|
||||
result = self.test_photos[0].next_previous(options={"foo": "bar",
|
||||
"test1": "test2"},
|
||||
foo="bar")
|
||||
# Dict elemet can be in any order
|
||||
self.assertIn(mock_get.call_args[0],
|
||||
[("/photo/1a/nextprevious/foo-bar/test1-test2.json",),
|
||||
("/photo/1a/nextprevious/test1-test2/foo-bar.json",)])
|
||||
self.assertEqual(mock_get.call_args[1], {"foo": "bar"})
|
||||
self.assertEqual(result["next"][0].get_fields(),
|
||||
self.test_photos_dict[0])
|
||||
self.assertEqual(result["previous"][0].get_fields(),
|
||||
|
|
|
@ -9,14 +9,14 @@ class ApiActivities(ApiBase):
|
|||
""" Definitions of /activities/ API endpoints """
|
||||
def list(self, options=None, **kwds):
|
||||
"""
|
||||
Endpoint: /activities/[<options>]/list.json
|
||||
Endpoint: /activities[/<options>]/list.json
|
||||
|
||||
Returns a list of Activity objects.
|
||||
The options parameter can be used to narrow down the activities.
|
||||
Eg: options={"type": "photo-upload"}
|
||||
"""
|
||||
option_string = self._build_option_string(options)
|
||||
activities = self._client.get("/activities/%slist.json" % option_string,
|
||||
activities = self._client.get("/activities%s/list.json" % option_string,
|
||||
**kwds)["result"]
|
||||
activities = self._result_to_list(activities)
|
||||
return [Activity(self._client, activity) for activity in activities]
|
||||
|
|
|
@ -16,7 +16,7 @@ class ApiBase(object):
|
|||
option_string = ""
|
||||
if options is not None:
|
||||
for key in options:
|
||||
option_string += "%s-%s/" % (key, options[key])
|
||||
option_string += "/%s-%s" % (key, options[key])
|
||||
return option_string
|
||||
|
||||
@staticmethod
|
||||
|
|
|
@ -10,26 +10,26 @@ class ApiPhotos(ApiBase):
|
|||
""" Definitions of /photos/ API endpoints """
|
||||
def list(self, options=None, **kwds):
|
||||
"""
|
||||
Endpoint: /photos/[<options>]/list.json
|
||||
Endpoint: /photos[/<options>]/list.json
|
||||
|
||||
Returns a list of Photo objects.
|
||||
The options parameter can be used to narrow down the list.
|
||||
Eg: options={"album": <album_id>}
|
||||
"""
|
||||
option_string = self._build_option_string(options)
|
||||
photos = self._client.get("/photos/%slist.json" % option_string,
|
||||
photos = self._client.get("/photos%s/list.json" % option_string,
|
||||
**kwds)["result"]
|
||||
photos = self._result_to_list(photos)
|
||||
return [Photo(self._client, photo) for photo in photos]
|
||||
|
||||
def share(self, options=None, **kwds):
|
||||
"""
|
||||
Endpoint: /photos/[<options>/share.json
|
||||
Endpoint: /photos[/<options>/share.json
|
||||
|
||||
Not currently implemented.
|
||||
"""
|
||||
option_string = self._build_option_string(options)
|
||||
return self._client.post("/photos/%sshare.json" % option_string,
|
||||
return self._client.post("/photos%s/share.json" % option_string,
|
||||
**kwds)["result"]
|
||||
|
||||
def delete(self, photos, **kwds):
|
||||
|
@ -138,7 +138,7 @@ class ApiPhoto(ApiBase):
|
|||
|
||||
def view(self, photo, options=None, **kwds):
|
||||
"""
|
||||
Endpoint: /photo/<id>/[<options>]/view.json
|
||||
Endpoint: /photo/<id>[/<options>]/view.json
|
||||
|
||||
Requests all properties of a photo.
|
||||
Can be used to obtain URLs for the photo at a particular size,
|
||||
|
@ -148,7 +148,7 @@ class ApiPhoto(ApiBase):
|
|||
Eg: options={"token": <token_data>}
|
||||
"""
|
||||
option_string = self._build_option_string(options)
|
||||
result = self._client.get("/photo/%s/%sview.json" %
|
||||
result = self._client.get("/photo/%s%s/view.json" %
|
||||
(self._extract_id(photo), option_string),
|
||||
**kwds)["result"]
|
||||
return Photo(self._client, result)
|
||||
|
@ -192,15 +192,18 @@ class ApiPhoto(ApiBase):
|
|||
raise NotImplementedError()
|
||||
|
||||
# TODO: Add options
|
||||
def next_previous(self, photo, **kwds):
|
||||
def next_previous(self, photo, options=None, **kwds):
|
||||
"""
|
||||
Endpoint: /photo/<id>/nextprevious.json
|
||||
Endpoint: /photo/<id>/nextprevious[/<options>].json
|
||||
|
||||
Returns a dict containing the next and previous photo lists
|
||||
(there may be more than one next/previous photo returned).
|
||||
The options parameter can be used to narrow down the photos
|
||||
Eg: options={"album": <album_id>}
|
||||
"""
|
||||
result = self._client.get("/photo/%s/nextprevious.json" %
|
||||
self._extract_id(photo),
|
||||
option_string = self._build_option_string(options)
|
||||
result = self._client.get("/photo/%s/nextprevious%s.json" %
|
||||
(self._extract_id(photo), option_string),
|
||||
**kwds)["result"]
|
||||
value = {}
|
||||
if "next" in result:
|
||||
|
|
|
@ -69,7 +69,7 @@ class Photo(TroveboxObject):
|
|||
|
||||
def view(self, options=None, **kwds):
|
||||
"""
|
||||
Endpoint: /photo/<id>/view.json
|
||||
Endpoint: /photo/<id>[/<options>]/view.json
|
||||
|
||||
Requests all properties of this photo.
|
||||
Can be used to obtain URLs for the photo at a particular size,
|
||||
|
@ -85,15 +85,14 @@ class Photo(TroveboxObject):
|
|||
""" Not implemented yet """
|
||||
raise NotImplementedError()
|
||||
|
||||
# TODO: Add options
|
||||
def next_previous(self, **kwds):
|
||||
def next_previous(self, options=None, **kwds):
|
||||
"""
|
||||
Endpoint: /photo/<id>/nextprevious.json
|
||||
Endpoint: /photo/<id>/nextprevious[/<options>].json
|
||||
|
||||
Returns a dict containing the next and previous photo lists
|
||||
(there may be more than one next/previous photo returned).
|
||||
"""
|
||||
return self._client.photo.next_previous(self, **kwds)
|
||||
return self._client.photo.next_previous(self, options, **kwds)
|
||||
|
||||
def transform(self, **kwds):
|
||||
"""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue