|
| 1 | +"""Interface to Plotly's /v2/folders endpoints.""" |
| 2 | +from __future__ import absolute_import |
| 3 | + |
| 4 | +from plotly.api.v2.utils import build_url, make_params, request |
| 5 | + |
| 6 | +RESOURCE = 'folders' |
| 7 | + |
| 8 | + |
| 9 | +def create(body): |
| 10 | + """ |
| 11 | + Create a new folder. |
| 12 | +
|
| 13 | + :param (dict) body: A mapping of body param names to values. |
| 14 | + :returns: (requests.Response) Returns response directly from requests. |
| 15 | +
|
| 16 | + """ |
| 17 | + url = build_url(RESOURCE) |
| 18 | + return request('post', url, json=body) |
| 19 | + |
| 20 | + |
| 21 | +def retrieve(fid, share_key=None): |
| 22 | + """ |
| 23 | + Retrieve a folder from Plotly. |
| 24 | +
|
| 25 | + :param (str) fid: The `{username}:{idlocal}` identifier. E.g. `foo:88`. |
| 26 | + :param (str) share_key: The secret key granting 'read' access if private. |
| 27 | + :returns: (requests.Response) Returns response directly from requests. |
| 28 | +
|
| 29 | + """ |
| 30 | + url = build_url(RESOURCE, id=fid) |
| 31 | + params = make_params(share_key=share_key) |
| 32 | + return request('get', url, params=params) |
| 33 | + |
| 34 | + |
| 35 | +def update(fid, body): |
| 36 | + """ |
| 37 | + Update a folder from Plotly. |
| 38 | +
|
| 39 | + :param (str) fid: The `{username}:{idlocal}` identifier. E.g. `foo:88`. |
| 40 | + :param (dict) body: A mapping of body param names to values. |
| 41 | + :returns: (requests.Response) Returns response directly from requests. |
| 42 | +
|
| 43 | + """ |
| 44 | + url = build_url(RESOURCE, id=fid) |
| 45 | + return request('put', url, json=body) |
| 46 | + |
| 47 | + |
| 48 | +def trash(fid): |
| 49 | + """ |
| 50 | + Soft-delete a folder from Plotly. (Can be undone with 'restore'). |
| 51 | +
|
| 52 | + This action is recursively done on files inside the folder. |
| 53 | +
|
| 54 | + :param (str) fid: The `{username}:{idlocal}` identifier. E.g. `foo:88`. |
| 55 | + :returns: (requests.Response) Returns response directly from requests. |
| 56 | +
|
| 57 | + """ |
| 58 | + url = build_url(RESOURCE, id=fid, route='trash') |
| 59 | + return request('post', url) |
| 60 | + |
| 61 | + |
| 62 | +def restore(fid): |
| 63 | + """ |
| 64 | + Restore a trashed folder from Plotly. See 'trash'. |
| 65 | +
|
| 66 | + This action is recursively done on files inside the folder. |
| 67 | +
|
| 68 | + :param (str) fid: The `{username}:{idlocal}` identifier. E.g. `foo:88`. |
| 69 | + :returns: (requests.Response) Returns response directly from requests. |
| 70 | +
|
| 71 | + """ |
| 72 | + url = build_url(RESOURCE, id=fid, route='restore') |
| 73 | + return request('post', url) |
| 74 | + |
| 75 | + |
| 76 | +def permanent_delete(fid): |
| 77 | + """ |
| 78 | + Permanently delete a trashed folder file from Plotly. See 'trash'. |
| 79 | +
|
| 80 | + This action is recursively done on files inside the folder. |
| 81 | +
|
| 82 | + :param (str) fid: The `{username}:{idlocal}` identifier. E.g. `foo:88`. |
| 83 | + :returns: (requests.Response) Returns response directly from requests. |
| 84 | +
|
| 85 | + """ |
| 86 | + url = build_url(RESOURCE, id=fid, route='permanent_delete') |
| 87 | + return request('delete', url) |
| 88 | + |
| 89 | + |
| 90 | +def lookup(path, parent=None, user=None, exists=None): |
| 91 | + """ |
| 92 | + Retrieve a folder file from Plotly without needing a fid. |
| 93 | +
|
| 94 | + :param (str) path: The '/'-delimited path specifying the file location. |
| 95 | + :param (int) parent: Parent id, an integer, which the path is relative to. |
| 96 | + :param (str) user: The username to target files for. Defaults to requestor. |
| 97 | + :param (bool) exists: If True, don't return the full file, just a flag. |
| 98 | + :returns: (requests.Response) Returns response directly from requests. |
| 99 | +
|
| 100 | + """ |
| 101 | + url = build_url(RESOURCE, route='lookup') |
| 102 | + params = make_params(path=path, parent=parent, user=user, exists=exists) |
| 103 | + return request('get', url, params=params) |
0 commit comments