Skip to content

Commit d63ff9d

Browse files
authored
docs: numpy-style docstrings on Favorites endpoint (15 methods) (#1855)
* docs: numpy-style docstrings on Favorites endpoint (15 methods) Adds a class-level docstring plus 15 method docstrings on Favorites (get, add_favorite, 6x add_favorite_<type>, delete_favorite, 6x delete_favorite_<type>). Content ported from docs/api-ref.md's Favorites section on gh-pages so that the Sphinx pipeline in #1832 will produce equivalent output once wired up. Part of the api-ref -> Sphinx migration; see the migration audit report for the full list of methods still needing docstrings. Favorites was the largest single chunk in the "needs_docstring" bucket (15/41 methods). No behavior change. Docs only. * docs: address fresh-eyes review on Favorites docstrings - Class docstring: add missing "collections" FavoriteType (7, not 6). - add_favorite: drop misleading #add_workbook_to_favorites anchor on polymorphic method; link to Favorites Methods page root. - add_favorite_metric: add REST API link (#add_metric_to_favorites). - delete_favorite: add REST API link; polymorphic, so page root. - delete_favorite_metric: add REST API link; no per-type anchor exists, so page root. - delete_favorite_flow: fix anchor drift (#delete_flow_from_favorites -> #ref_delete_flow_from_favorites).
1 parent 1e8669f commit d63ff9d

1 file changed

Lines changed: 286 additions & 0 deletions

File tree

tableauserverclient/server/endpoint/favorites_endpoint.py

Lines changed: 286 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,52 @@
1717

1818

1919
class Favorites(Endpoint):
20+
"""Get, add, and remove favorites for a user.
21+
22+
Favorites can be workbooks, views, datasources, flows, projects, metrics,
23+
or collections. Retrieved favorites are stored on the target ``UserItem``
24+
object as a dictionary keyed by content type (e.g. ``"workbooks"``,
25+
``"views"``, ``"datasources"``, ``"flows"``, ``"projects"``, ``"metrics"``,
26+
``"collections"``), where each value is a list of the corresponding item
27+
objects.
28+
29+
REST API: https://help.tableau.com/current/api/rest_api/en-us/REST/rest_api_ref_favorites.htm
30+
"""
31+
2032
@property
2133
def baseurl(self) -> str:
2234
return f"{self.parent_srv.baseurl}/sites/{self.parent_srv.site_id}/favorites"
2335

2436
# Gets all favorites
2537
@api(version="2.5")
2638
def get(self, user_item: UserItem, req_options: RequestOptions | None = None) -> None:
39+
"""Populate the favorites on the specified user.
40+
41+
After calling this method, the favorites are available through
42+
``user_item.favorites``, keyed by content type.
43+
44+
REST API: `Get Favorites for User <https://help.tableau.com/current/api/rest_api/en-us/REST/rest_api_ref_favorites.htm#get_favorites_for_user>`_
45+
46+
Parameters
47+
----------
48+
user_item : UserItem
49+
The user for whom to retrieve favorites. The user's ``id`` attribute
50+
must be set.
51+
52+
req_options : RequestOptions, optional
53+
Request options such as page size and page number.
54+
55+
Returns
56+
-------
57+
None
58+
Favorites are populated on ``user_item.favorites``.
59+
60+
Examples
61+
--------
62+
>>> server.favorites.get(user_item)
63+
>>> for workbook in user_item.favorites["workbooks"]:
64+
... print(workbook.name)
65+
"""
2766
logger.info(f"Querying all favorites for user {user_item.name}")
2867
url = f"{self.baseurl}/{user_item.id}"
2968
server_response = self.get_request(url, req_options)
@@ -33,6 +72,32 @@ def get(self, user_item: UserItem, req_options: RequestOptions | None = None) ->
3372

3473
@api(version="3.15")
3574
def add_favorite(self, user_item: UserItem, content_type: str, item: TableauItem) -> "Response":
75+
"""Add a content item of any supported type to the user's favorites.
76+
77+
Type-specific helpers (``add_favorite_workbook``, ``add_favorite_view``,
78+
etc.) exist for each individual content type; this method is the
79+
polymorphic entry point.
80+
81+
REST API: `Favorites Methods <https://help.tableau.com/current/api/rest_api/en-us/REST/rest_api_ref_favorites.htm>`_
82+
83+
Parameters
84+
----------
85+
user_item : UserItem
86+
The user to add the favorite for.
87+
88+
content_type : str
89+
The type of content as a string (e.g. ``"workbook"``, ``"view"``,
90+
``"datasource"``, ``"flow"``, ``"project"``, ``"metric"``).
91+
92+
item : TableauItem
93+
The content item to favorite. Must have ``id`` and ``name``
94+
attributes.
95+
96+
Returns
97+
-------
98+
requests.Response
99+
The server response.
100+
"""
36101
url = f"{self.baseurl}/{user_item.id}"
37102
add_req = RequestFactory.Favorite.add_request(item.id, content_type, item.name)
38103
server_response = self.put_request(url, add_req)
@@ -41,41 +106,137 @@ def add_favorite(self, user_item: UserItem, content_type: str, item: TableauItem
41106

42107
@api(version="2.0")
43108
def add_favorite_workbook(self, user_item: UserItem, workbook_item: WorkbookItem) -> None:
109+
"""Add a workbook to the user's favorites.
110+
111+
REST API: `Add Workbook to Favorites <https://help.tableau.com/current/api/rest_api/en-us/REST/rest_api_ref_favorites.htm#add_workbook_to_favorites>`_
112+
113+
Parameters
114+
----------
115+
user_item : UserItem
116+
The user to add the favorite for.
117+
118+
workbook_item : WorkbookItem
119+
The workbook to add to favorites.
120+
121+
Returns
122+
-------
123+
None
124+
"""
44125
url = f"{self.baseurl}/{user_item.id}"
45126
add_req = RequestFactory.Favorite.add_workbook_req(workbook_item.id, workbook_item.name)
46127
server_response = self.put_request(url, add_req)
47128
logger.info(f"Favorited {workbook_item.name} for user (ID: {user_item.id})")
48129

49130
@api(version="2.0")
50131
def add_favorite_view(self, user_item: UserItem, view_item: ViewItem) -> None:
132+
"""Add a view to the user's favorites.
133+
134+
REST API: `Add View to Favorites <https://help.tableau.com/current/api/rest_api/en-us/REST/rest_api_ref_favorites.htm#add_view_to_favorites>`_
135+
136+
Parameters
137+
----------
138+
user_item : UserItem
139+
The user to add the favorite for.
140+
141+
view_item : ViewItem
142+
The view to add to favorites.
143+
144+
Returns
145+
-------
146+
None
147+
"""
51148
url = f"{self.baseurl}/{user_item.id}"
52149
add_req = RequestFactory.Favorite.add_view_req(view_item.id, view_item.name)
53150
server_response = self.put_request(url, add_req)
54151
logger.info(f"Favorited {view_item.name} for user (ID: {user_item.id})")
55152

56153
@api(version="2.3")
57154
def add_favorite_datasource(self, user_item: UserItem, datasource_item: DatasourceItem) -> None:
155+
"""Add a datasource to the user's favorites.
156+
157+
REST API: `Add Data Source to Favorites <https://help.tableau.com/current/api/rest_api/en-us/REST/rest_api_ref_favorites.htm#add_data_source_to_favorites>`_
158+
159+
Parameters
160+
----------
161+
user_item : UserItem
162+
The user to add the favorite for.
163+
164+
datasource_item : DatasourceItem
165+
The datasource to add to favorites.
166+
167+
Returns
168+
-------
169+
None
170+
"""
58171
url = f"{self.baseurl}/{user_item.id}"
59172
add_req = RequestFactory.Favorite.add_datasource_req(datasource_item.id, datasource_item.name)
60173
server_response = self.put_request(url, add_req)
61174
logger.info(f"Favorited {datasource_item.name} for user (ID: {user_item.id})")
62175

63176
@api(version="3.1")
64177
def add_favorite_project(self, user_item: UserItem, project_item: ProjectItem) -> None:
178+
"""Add a project to the user's favorites.
179+
180+
REST API: `Add Project to Favorites <https://help.tableau.com/current/api/rest_api/en-us/REST/rest_api_ref_favorites.htm#add_project_to_favorites>`_
181+
182+
Parameters
183+
----------
184+
user_item : UserItem
185+
The user to add the favorite for.
186+
187+
project_item : ProjectItem
188+
The project to add to favorites.
189+
190+
Returns
191+
-------
192+
None
193+
"""
65194
url = f"{self.baseurl}/{user_item.id}"
66195
add_req = RequestFactory.Favorite.add_project_req(project_item.id, project_item.name)
67196
server_response = self.put_request(url, add_req)
68197
logger.info(f"Favorited {project_item.name} for user (ID: {user_item.id})")
69198

70199
@api(version="3.3")
71200
def add_favorite_flow(self, user_item: UserItem, flow_item: FlowItem) -> None:
201+
"""Add a flow to the user's favorites.
202+
203+
REST API: `Add Flow to Favorites <https://help.tableau.com/current/api/rest_api/en-us/REST/rest_api_ref_favorites.htm#add_flow_to_favorites>`_
204+
205+
Parameters
206+
----------
207+
user_item : UserItem
208+
The user to add the favorite for.
209+
210+
flow_item : FlowItem
211+
The flow to add to favorites.
212+
213+
Returns
214+
-------
215+
None
216+
"""
72217
url = f"{self.baseurl}/{user_item.id}"
73218
add_req = RequestFactory.Favorite.add_flow_req(flow_item.id, flow_item.name)
74219
server_response = self.put_request(url, add_req)
75220
logger.info(f"Favorited {flow_item.name} for user (ID: {user_item.id})")
76221

77222
@api(version="3.3")
78223
def add_favorite_metric(self, user_item: UserItem, metric_item: MetricItem) -> None:
224+
"""Add a metric to the user's favorites.
225+
226+
REST API: `Add Metric to Favorites <https://help.tableau.com/current/api/rest_api/en-us/REST/rest_api_ref_favorites.htm#add_metric_to_favorites>`_
227+
228+
Parameters
229+
----------
230+
user_item : UserItem
231+
The user to add the favorite for.
232+
233+
metric_item : MetricItem
234+
The metric to add to favorites.
235+
236+
Returns
237+
-------
238+
None
239+
"""
79240
url = f"{self.baseurl}/{user_item.id}"
80241
add_req = RequestFactory.Favorite.add_request(metric_item.id, Resource.Metric, metric_item.name)
81242
server_response = self.put_request(url, add_req)
@@ -93,42 +254,167 @@ def add_favorite_metric(self, user_item: UserItem, metric_item: MetricItem) -> N
93254

94255
@api(version="3.15")
95256
def delete_favorite(self, user_item: UserItem, content_type: Resource, item: TableauItem) -> None:
257+
"""Remove a content item of any supported type from the user's favorites.
258+
259+
Type-specific helpers (``delete_favorite_workbook``,
260+
``delete_favorite_view``, etc.) exist for each individual content
261+
type; this method is the polymorphic entry point.
262+
263+
REST API: `Favorites Methods <https://help.tableau.com/current/api/rest_api/en-us/REST/rest_api_ref_favorites.htm>`_
264+
265+
Parameters
266+
----------
267+
user_item : UserItem
268+
The user to remove the favorite from.
269+
270+
content_type : Resource
271+
The ``Resource`` type of the content (e.g. ``Resource.Workbook``,
272+
``Resource.View``).
273+
274+
item : TableauItem
275+
The content item to remove from favorites. Must have an ``id``
276+
attribute.
277+
278+
Returns
279+
-------
280+
None
281+
282+
Examples
283+
--------
284+
>>> server.favorites.delete_favorite(user_item, TSC.Resource.Workbook, workbook_item)
285+
"""
96286
url = f"{self.baseurl}/{user_item.id}/{content_type}/{item.id}"
97287
logger.info(f"Removing favorite {content_type}({item.id}) for user (ID: {user_item.id})")
98288
self.delete_request(url)
99289

100290
@api(version="2.0")
101291
def delete_favorite_workbook(self, user_item: UserItem, workbook_item: WorkbookItem) -> None:
292+
"""Remove a workbook from the user's favorites.
293+
294+
REST API: `Delete Workbook from Favorites <https://help.tableau.com/current/api/rest_api/en-us/REST/rest_api_ref_favorites.htm#delete_workbook_from_favorites>`_
295+
296+
Parameters
297+
----------
298+
user_item : UserItem
299+
The user to remove the favorite from.
300+
301+
workbook_item : WorkbookItem
302+
The workbook to remove from favorites.
303+
304+
Returns
305+
-------
306+
None
307+
"""
102308
url = f"{self.baseurl}/{user_item.id}/workbooks/{workbook_item.id}"
103309
logger.info(f"Removing favorite workbook {workbook_item.id} for user (ID: {user_item.id})")
104310
self.delete_request(url)
105311

106312
@api(version="2.0")
107313
def delete_favorite_view(self, user_item: UserItem, view_item: ViewItem) -> None:
314+
"""Remove a view from the user's favorites.
315+
316+
REST API: `Delete View from Favorites <https://help.tableau.com/current/api/rest_api/en-us/REST/rest_api_ref_favorites.htm#delete_view_from_favorites>`_
317+
318+
Parameters
319+
----------
320+
user_item : UserItem
321+
The user to remove the favorite from.
322+
323+
view_item : ViewItem
324+
The view to remove from favorites.
325+
326+
Returns
327+
-------
328+
None
329+
"""
108330
url = f"{self.baseurl}/{user_item.id}/views/{view_item.id}"
109331
logger.info(f"Removing favorite view {view_item.id} for user (ID: {user_item.id})")
110332
self.delete_request(url)
111333

112334
@api(version="2.3")
113335
def delete_favorite_datasource(self, user_item: UserItem, datasource_item: DatasourceItem) -> None:
336+
"""Remove a datasource from the user's favorites.
337+
338+
REST API: `Delete Data Source from Favorites <https://help.tableau.com/current/api/rest_api/en-us/REST/rest_api_ref_favorites.htm#delete_data_source_from_favorites>`_
339+
340+
Parameters
341+
----------
342+
user_item : UserItem
343+
The user to remove the favorite from.
344+
345+
datasource_item : DatasourceItem
346+
The datasource to remove from favorites.
347+
348+
Returns
349+
-------
350+
None
351+
"""
114352
url = f"{self.baseurl}/{user_item.id}/datasources/{datasource_item.id}"
115353
logger.info(f"Removing favorite {datasource_item.id} for user (ID: {user_item.id})")
116354
self.delete_request(url)
117355

118356
@api(version="3.1")
119357
def delete_favorite_project(self, user_item: UserItem, project_item: ProjectItem) -> None:
358+
"""Remove a project from the user's favorites.
359+
360+
REST API: `Delete Project from Favorites <https://help.tableau.com/current/api/rest_api/en-us/REST/rest_api_ref_favorites.htm#delete_project_from_favorites>`_
361+
362+
Parameters
363+
----------
364+
user_item : UserItem
365+
The user to remove the favorite from.
366+
367+
project_item : ProjectItem
368+
The project to remove from favorites.
369+
370+
Returns
371+
-------
372+
None
373+
"""
120374
url = f"{self.baseurl}/{user_item.id}/projects/{project_item.id}"
121375
logger.info(f"Removing favorite project {project_item.id} for user (ID: {user_item.id})")
122376
self.delete_request(url)
123377

124378
@api(version="3.3")
125379
def delete_favorite_flow(self, user_item: UserItem, flow_item: FlowItem) -> None:
380+
"""Remove a flow from the user's favorites.
381+
382+
REST API: `Delete Flow from Favorites <https://help.tableau.com/current/api/rest_api/en-us/REST/rest_api_ref_favorites.htm#ref_delete_flow_from_favorites>`_
383+
384+
Parameters
385+
----------
386+
user_item : UserItem
387+
The user to remove the favorite from.
388+
389+
flow_item : FlowItem
390+
The flow to remove from favorites.
391+
392+
Returns
393+
-------
394+
None
395+
"""
126396
url = f"{self.baseurl}/{user_item.id}/flows/{flow_item.id}"
127397
logger.info(f"Removing favorite flow {flow_item.id} for user (ID: {user_item.id})")
128398
self.delete_request(url)
129399

130400
@api(version="3.15")
131401
def delete_favorite_metric(self, user_item: UserItem, metric_item: MetricItem) -> None:
402+
"""Remove a metric from the user's favorites.
403+
404+
REST API: `Favorites Methods <https://help.tableau.com/current/api/rest_api/en-us/REST/rest_api_ref_favorites.htm>`_
405+
406+
Parameters
407+
----------
408+
user_item : UserItem
409+
The user to remove the favorite from.
410+
411+
metric_item : MetricItem
412+
The metric to remove from favorites.
413+
414+
Returns
415+
-------
416+
None
417+
"""
132418
url = f"{self.baseurl}/{user_item.id}/metrics/{metric_item.id}"
133419
logger.info(f"Removing favorite metric {metric_item.id} for user (ID: {user_item.id})")
134420
self.delete_request(url)

0 commit comments

Comments
 (0)