|
10 | 10 |
|
11 | 11 | class NoNonPaginatedVersionError(Exception):
|
12 | 12 | """Raised when a non-paginated of a paginated-only method is called."""
|
13 |
| - pass |
14 |
| - |
15 |
| -@wrapt.decorator |
16 |
| -def has_paginated_version(method, instance, args, kwargs): |
17 |
| - def paginated(*args, limit=None, offset=None, direction=None): |
18 |
| - print("PAGINATED METHOD", method) |
19 |
| - print("PAGINATED ARGS", args) |
20 |
| - data = { |
21 |
| - 'limit': 20 if limit is None else limit, |
22 |
| - 'offset': 0 if offset is None else offset, |
23 |
| - 'direction': 'asc' if direction is None else direction, |
24 |
| - } |
25 |
| - return method(*args, data=data) |
26 |
| - setattr(instance.verbose, method.__name__, paginated) |
27 |
| - return method |
28 | 13 |
|
29 | 14 | def endpoint(endpoint_url):
|
| 15 | + """Decorator for API methods. Denotes the URL endpoint.""" |
30 | 16 | @wrapt.decorator
|
31 | 17 | def wrapper(method, instance, args, kwargs):
|
32 | 18 | return instance.request(endpoint_url, *method(*args, **kwargs))
|
33 | 19 | return wrapper
|
34 | 20 |
|
35 | 21 | class PaginatedMethod:
|
| 22 | + """Object representing a method that has a POST paginated version (with |
| 23 | + args like limit, offset, direction) as well as optionally a GET |
| 24 | + non-paginated version. The GET version is accessed by calling the object as |
| 25 | + if it were a method. The POST version is accessed by calling the `verbose` |
| 26 | + attribute. |
| 27 | + """ |
36 | 28 | def __init__(self, method: Callable, verbose_only: bool = False):
|
37 | 29 | self._method = method
|
38 | 30 | self._verbose_only = verbose_only
|
@@ -219,12 +211,9 @@ def tag_pages(self, tag: str):
|
219 | 211 | @endpoint("tag/pages")
|
220 | 212 | def _tags_pages(self, tags: Union[List[int], List[str]], operator: str = 'and', *, data):
|
221 | 213 | """
|
222 |
| - str[] `tags`: A list of tag names, finds all page IDs that match the |
223 |
| - condition. |
224 |
| - int[] `tags`: A list of SCUTTLE tag IDs, finds all page IDs that match |
225 |
| - the condition. |
226 |
| - str `operator`: 'and' or 'or'; defines the condition when specifying |
227 |
| - multiple tags. |
| 214 | + str[] `tags`: A list of tag names. |
| 215 | + int[] `tags`: A list of SCUTTLE tag IDs. |
| 216 | + str `operator`: 'and' or 'or'; defines how tags are combined. |
228 | 217 | """
|
229 | 218 | if isinstance(tags, str):
|
230 | 219 | raise TypeError("`tags` must be a list of at least one tag; use tag_pages() for a single tag name")
|
|
0 commit comments