-
Notifications
You must be signed in to change notification settings - Fork 421
/
webhooks_endpoint.py
70 lines (57 loc) · 2.77 KB
/
webhooks_endpoint.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import logging
from .endpoint import Endpoint, api
from tableauserverclient.server import RequestFactory
from tableauserverclient.models import WebhookItem, PaginationItem
from tableauserverclient.helpers.logging import logger
from typing import List, Optional, TYPE_CHECKING, Tuple
if TYPE_CHECKING:
from ..server import Server
from ..request_options import RequestOptions
class Webhooks(Endpoint):
def __init__(self, parent_srv: "Server") -> None:
super(Webhooks, self).__init__(parent_srv)
@property
def baseurl(self) -> str:
return "{0}/sites/{1}/webhooks".format(self.parent_srv.baseurl, self.parent_srv.site_id)
@api(version="3.6")
def get(self, req_options: Optional["RequestOptions"] = None) -> Tuple[List[WebhookItem], PaginationItem]:
logger.info("Querying all Webhooks on site")
url = self.baseurl
server_response = self.get_request(url, req_options)
all_webhook_items = WebhookItem.from_response(server_response.content, self.parent_srv.namespace)
pagination_item = PaginationItem.from_single_page_list(all_webhook_items)
return all_webhook_items, pagination_item
@api(version="3.6")
def get_by_id(self, webhook_id: str) -> WebhookItem:
if not webhook_id:
error = "Webhook ID undefined."
raise ValueError(error)
logger.info("Querying single webhook (ID: {0})".format(webhook_id))
url = "{0}/{1}".format(self.baseurl, webhook_id)
server_response = self.get_request(url)
return WebhookItem.from_response(server_response.content, self.parent_srv.namespace)[0]
@api(version="3.6")
def delete(self, webhook_id: str) -> None:
if not webhook_id:
error = "Webhook ID undefined."
raise ValueError(error)
url = "{0}/{1}".format(self.baseurl, webhook_id)
self.delete_request(url)
logger.info("Deleted single webhook (ID: {0})".format(webhook_id))
@api(version="3.6")
def create(self, webhook_item: WebhookItem) -> WebhookItem:
url = self.baseurl
create_req = RequestFactory.Webhook.create_req(webhook_item)
server_response = self.post_request(url, create_req)
new_webhook = WebhookItem.from_response(server_response.content, self.parent_srv.namespace)[0]
logger.info("Created new webhook (ID: {0})".format(new_webhook.id))
return new_webhook
@api(version="3.6")
def test(self, webhook_id: str):
if not webhook_id:
error = "Webhook ID undefined."
raise ValueError(error)
url = "{0}/{1}/test".format(self.baseurl, webhook_id)
testOutcome = self.get_request(url)
logger.info("Testing webhook (ID: {0} returned {1})".format(webhook_id, testOutcome))
return testOutcome