-
Notifications
You must be signed in to change notification settings - Fork 448
Add webhooks #523
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
Merged
Merged
Add webhooks #523
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
82b4879
Fix a decreated warning in the tests
graysonarts 6b8d984
Dropping 2.7 support since it's EOLEOY
graysonarts d9e7657
fixes deprecated warning in test_requests.py
graysonarts ce0f6c4
fixes deprecated warning in test_datasource.py
graysonarts ead9e1a
fixed deprecated warning in test_workbook
graysonarts 8d6c5c4
Fixing incorrect version for publish_async
graysonarts f413df7
Fix deprecrated warning in test_regression_tests.py
graysonarts e68e07e
initial working version
graysonarts 1f4630a
removing print statements
graysonarts f4549e0
pep8 fixes in test
graysonarts 906b079
fixing pep8 failures in tableauserverclient
graysonarts 5786451
Make token optional if it's set in the environment
graysonarts c85d6f3
read events properly
graysonarts e608b8b
read events properly
graysonarts 6bc1371
fix request generation
graysonarts 61d6d8b
fix pep8 error
graysonarts 302263e
Tyler's feedback
graysonarts File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,6 @@ | ||
| dist: xenial | ||
| language: python | ||
| python: | ||
| - "2.7" | ||
| - "3.5" | ||
| - "3.6" | ||
| - "3.7" | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| import xml.etree.ElementTree as ET | ||
| from .exceptions import UnpopulatedPropertyError | ||
| from .property_decorators import property_not_nullable, property_is_boolean, property_is_materialized_views_config | ||
| from .tag_item import TagItem | ||
| from .view_item import ViewItem | ||
| from .permissions_item import PermissionsRule | ||
| from ..datetime_helpers import parse_datetime | ||
| import re | ||
|
|
||
|
|
||
| NAMESPACE_RE = re.compile(r'^{.*}') | ||
|
|
||
|
|
||
| def _parse_event(events): | ||
| event = events[0] | ||
| # Strip out the namespace from the tag name | ||
| return NAMESPACE_RE.sub('', event.tag) | ||
|
|
||
|
|
||
| class WebhookItem(object): | ||
| def __init__(self): | ||
| self._id = None | ||
| self.name = None | ||
| self.url = None | ||
| self._event = None | ||
| self.owner_id = None | ||
|
|
||
| def _set_values(self, id, name, url, event, owner_id): | ||
| if id is not None: | ||
| self._id = id | ||
| if name: | ||
| self.name = name | ||
| if url: | ||
| self.url = url | ||
| if event: | ||
| self.event = event | ||
| if owner_id: | ||
| self.owner_id = owner_id | ||
|
|
||
| @property | ||
| def id(self): | ||
| return self._id | ||
|
|
||
| @property | ||
| def event(self): | ||
| if self._event: | ||
| return self._event.replace("webhook-source-event-", "") | ||
| return None | ||
|
|
||
| @event.setter | ||
| def event(self, value): | ||
| self._event = "webhook-source-event-{}".format(value) | ||
|
|
||
| @classmethod | ||
| def from_response(cls, resp, ns): | ||
| all_webhooks_items = list() | ||
| parsed_response = ET.fromstring(resp) | ||
| all_webhooks_xml = parsed_response.findall('.//t:webhook', namespaces=ns) | ||
| for webhook_xml in all_webhooks_xml: | ||
| values = cls._parse_element(webhook_xml, ns) | ||
|
|
||
| webhook_item = cls() | ||
| webhook_item._set_values(*values) | ||
| all_webhooks_items.append(webhook_item) | ||
| return all_webhooks_items | ||
|
|
||
| @staticmethod | ||
| def _parse_element(webhook_xml, ns): | ||
| id = webhook_xml.get('id', None) | ||
| name = webhook_xml.get('name', None) | ||
|
|
||
| url = None | ||
| url_tag = webhook_xml.find('.//t:webhook-destination-http', namespaces=ns) | ||
| if url_tag is not None: | ||
| url = url_tag.get('url', None) | ||
|
|
||
| event = webhook_xml.findall('.//t:webhook-source/*', namespaces=ns) | ||
| if event is not None and len(event) > 0: | ||
| event = _parse_event(event) | ||
|
|
||
| owner_id = None | ||
| owner_tag = webhook_xml.find('.//t:owner', namespaces=ns) | ||
| if owner_tag is not None: | ||
| owner_id = owner_tag.get('id', None) | ||
|
|
||
| return id, name, url, event, owner_id | ||
|
|
||
| def __repr__(self): | ||
| return "<Webhook id={} name={} url={} event={}>".format(self.id, self.name, self.url, self.event) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| from .endpoint import Endpoint, api, parameter_added_in | ||
| from ...models import WebhookItem, PaginationItem | ||
| from .. import RequestFactory | ||
|
|
||
| import logging | ||
| logger = logging.getLogger('tableau.endpoint.webhooks') | ||
|
|
||
|
|
||
| class Webhooks(Endpoint): | ||
| def __init__(self, parent_srv): | ||
| super(Webhooks, self).__init__(parent_srv) | ||
|
|
||
| @property | ||
| def baseurl(self): | ||
| return "{0}/sites/{1}/webhooks".format(self.parent_srv.baseurl, self.parent_srv.site_id) | ||
|
|
||
| @api(version="3.6") | ||
| def get(self, req_options=None): | ||
| 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): | ||
| 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): | ||
| 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): | ||
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| <?xml version='1.0' encoding='UTF-8'?> | ||
| <tsResponse xmlns="http://tableau.com/api" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://tableau.com/api http://tableau.com/api/ts-api-2.3.xsd"> | ||
| <webhook id="webhook-id" name="webhook-name"> | ||
| <webhook-source> | ||
| <webhook-source-api-event-name/> | ||
| </webhook-source> | ||
| <webhook-destination> | ||
| <webhook-destination-http method="POST" url="url"/> | ||
| </webhook-destination> | ||
| <owner id="webhook_owner_luid" name="webhook_owner_name"/> | ||
| </webhook> | ||
| </tsResponse> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| <tsRequest><webhook name="webhook-name"><webhook-source><webhook-source-event-api-event-name /></webhook-source><webhook-destination><webhook-destination-http method="POST" url="url" /></webhook-destination></webhook></tsRequest> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| <?xml version='1.0' encoding='UTF-8'?> | ||
| <tsResponse xmlns="http://tableau.com/api" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://tableau.com/api http://tableau.com/api/ts-api-2.3.xsd"> | ||
| <webhooks> | ||
| <webhook id="webhook-id" name="webhook-name"> | ||
| <webhook-source> | ||
| <webhook-source-event-datasource-created /> | ||
| </webhook-source> | ||
| <webhook-destination> | ||
| <webhook-destination-http method="POST" url="url"/> | ||
| </webhook-destination> | ||
| <owner id="webhook_owner_luid" name="webhook_owner_name"/> | ||
| </webhook> | ||
| </webhooks> | ||
| </tsResponse> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.