Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: webhook docstrings #1530

Open
wants to merge 1 commit into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions tableauserverclient/models/webhook_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,39 @@ def _parse_event(events):


class WebhookItem:
"""
The WebhookItem represents the webhook resources on Tableau Server or
Tableau Cloud. This is the information that can be sent or returned in
response to a REST API request for webhooks.

Attributes
----------
id : Optional[str]
The identifier (luid) for the webhook. You need this value to query a
specific webhook with the get_by_id method or to delete a webhook with
the delete method.

name : Optional[str]
The name of the webhook. You must specify this when you create an
instance of the WebhookItem.

url : Optional[str]
The destination URL for the webhook. The webhook destination URL must
be https and have a valid certificate. You must specify this when you
create an instance of the WebhookItem.

event : Optional[str]
The name of the Tableau event that triggers your webhook.This is either
api-event-name or webhook-source-api-event-name: one of these is
required to create an instance of the WebhookItem. We recommend using
the api-event-name. The event name must be one of the supported events
listed in the Trigger Events table.
https://help.tableau.com/current/developer/webhooks/en-us/docs/webhooks-events-payload.html

owner_id : Optional[str]
The identifier (luid) of the user who owns the webhook.
"""

def __init__(self):
self._id: Optional[str] = None
self.name: Optional[str] = None
Expand Down
77 changes: 77 additions & 0 deletions tableauserverclient/server/endpoint/webhooks_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,21 @@ def baseurl(self) -> str:

@api(version="3.6")
def get(self, req_options: Optional["RequestOptions"] = None) -> tuple[list[WebhookItem], PaginationItem]:
"""
Returns a list of all webhooks on the site.

REST API: https://help.tableau.com/current/api/rest_api/en-us/REST/rest_api_ref.htm#list_webhooks_for_site

Parameters
----------
req_options : Optional[RequestOptions]
Filter and sorting options for the request.

Returns
-------
tuple[list[WebhookItem], PaginationItem]
A tuple of the list of webhooks and pagination item
"""
logger.info("Querying all Webhooks on site")
url = self.baseurl
server_response = self.get_request(url, req_options)
Expand All @@ -32,6 +47,21 @@ def get(self, req_options: Optional["RequestOptions"] = None) -> tuple[list[Webh

@api(version="3.6")
def get_by_id(self, webhook_id: str) -> WebhookItem:
"""
Returns information about a specified Webhook.

Rest API: https://help.tableau.com/current/api/rest_api/en-us/REST/rest_api_ref.htm#get_webhook

Parameters
----------
webhook_id : str
The ID of the webhook to query.

Returns
-------
WebhookItem
An object containing information about the webhook.
"""
if not webhook_id:
error = "Webhook ID undefined."
raise ValueError(error)
Expand All @@ -42,6 +72,20 @@ def get_by_id(self, webhook_id: str) -> WebhookItem:

@api(version="3.6")
def delete(self, webhook_id: str) -> None:
"""
Deletes a specified webhook.

REST API: https://help.tableau.com/current/api/rest_api/en-us/REST/rest_api_ref.htm#delete_webhook

Parameters
----------
webhook_id : str
The ID of the webhook to delete.

Returns
-------
None
"""
if not webhook_id:
error = "Webhook ID undefined."
raise ValueError(error)
Expand All @@ -51,6 +95,21 @@ def delete(self, webhook_id: str) -> None:

@api(version="3.6")
def create(self, webhook_item: WebhookItem) -> WebhookItem:
"""
Creates a new webhook on the site.

REST API: https://help.tableau.com/current/api/rest_api/en-us/REST/rest_api_ref.htm#create_webhook

Parameters
----------
webhook_item : WebhookItem
The webhook item to create.

Returns
-------
WebhookItem
An object containing information about the created webhook
"""
url = self.baseurl
create_req = RequestFactory.Webhook.create_req(webhook_item)
server_response = self.post_request(url, create_req)
Expand All @@ -61,6 +120,24 @@ def create(self, webhook_item: WebhookItem) -> WebhookItem:

@api(version="3.6")
def test(self, webhook_id: str):
"""
Tests the specified webhook. Sends an empty payload to the configured
destination URL of the webhook and returns the response from the server.
This is useful for testing, to ensure that things are being sent from
Tableau and received back as expected.

Rest API: https://help.tableau.com/current/api/rest_api/en-us/REST/rest_api_ref.htm#test_webhook

Parameters
----------
webhook_id : str
The ID of the webhook to test.

Returns
-------
XML Response

"""
if not webhook_id:
error = "Webhook ID undefined."
raise ValueError(error)
Expand Down
Loading