-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactored TableauServer for better modularity (#70)
Refactored TableauServer for better modularity
- Loading branch information
1 parent
94bca91
commit 8e7ed08
Showing
20 changed files
with
838 additions
and
735 deletions.
There are no files selected for viewing
This file contains 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 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 |
---|---|---|
|
@@ -4,4 +4,3 @@ requests | |
pandas | ||
tabulate | ||
pytest | ||
|
This file contains 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 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 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,5 +1,6 @@ | ||
from .scripts import cli | ||
from .tableau_file.tableau_file import TableauFileError, Datasource | ||
from .tableau_file import tableau_file_objects | ||
from .tableau_server.tableau_server import TableauConnectionError, TableauServer | ||
from .tableau_server.static import TableauConnectionError | ||
from .tableau_server.tableau_server import TableauServer | ||
from .tableau_server import tableau_server_objects |
This file contains 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 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 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 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 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 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 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,68 @@ | ||
from requests import Session | ||
from tableau_utilities.tableau_server.static import validate_response | ||
|
||
|
||
class Base: | ||
def __init__(self, parent): | ||
self.session: Session = parent.session | ||
self.user: str = parent.user | ||
self._pw: str = parent._pw | ||
self._personal_access_token_secret: str = parent._personal_access_token_secret | ||
self.personal_access_token_name: str = parent.personal_access_token_name | ||
self.host: str = parent.host | ||
self.site: str = parent.site | ||
self.api: float = parent.api | ||
self._auth_token = parent._auth_token | ||
self.url: str = parent.url | ||
self.get = parent.get if hasattr(parent, 'get') else None | ||
|
||
def _get(self, url, headers=None, **params): | ||
""" GET request for the Tableau REST API | ||
Args: | ||
url (str): URL endpoint for GET call | ||
headers (dict): GET call header | ||
Returns: The response content as a JSON dict | ||
""" | ||
|
||
res = self.session.get(url, headers=headers, **params) | ||
return validate_response(res) | ||
|
||
def _post(self, url, json=None, headers=None, **params): | ||
""" POST request for the Tableau REST API | ||
Args: | ||
url (str): URL endpoint for POST call | ||
json (dict): The POST call JSON payload | ||
headers (dict): POST call header | ||
Returns: The response content as a JSON dict | ||
""" | ||
res = self.session.post(url, json=json, headers=headers, **params) | ||
return validate_response(res) | ||
|
||
def _put(self, url, json=None, headers=None, **params): | ||
""" PUT request for the Tableau REST API | ||
Args: | ||
url (str): URL endpoint for PUT call | ||
json (dict): The PUT call JSON payload | ||
headers (dict): PUT call header | ||
Returns: The response content as a JSON dict | ||
""" | ||
res = self.session.put(url, json=json, headers=headers, **params) | ||
return validate_response(res) | ||
|
||
def _delete(self, url, headers=None, **params): | ||
""" DELETE request for the Tableau REST API | ||
Args: | ||
url (str): URL endpoint for DELETE call | ||
headers (dict): DELETE call header | ||
Returns: The response content as a JSON dict | ||
""" | ||
res = self.session.delete(url, headers=headers, **params) | ||
return validate_response(res) |
This file contains 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,43 @@ | ||
from requests import Session | ||
from tableau_utilities.tableau_server.base import Base | ||
|
||
|
||
class Create(Base): | ||
def __init__(self, parent): | ||
super().__init__(parent) | ||
|
||
def project(self, name, description='', content_permissions='LockedToProject'): | ||
""" Creates a project. | ||
Args: | ||
name (str): The name of the project | ||
description (str): The description of the project | ||
content_permissions (str): The content permissions, e.g. LockedToProject | ||
""" | ||
self._post( | ||
f'{self.url}/projects', | ||
{ | ||
'project': { | ||
'name': name, | ||
'description': description, | ||
'contentPermissions': content_permissions | ||
} | ||
} | ||
) | ||
|
||
def group(self, name, minimum_site_role='Viewer'): | ||
""" Creates a group. | ||
Args: | ||
name (str): The name of the Group | ||
minimum_site_role (str): The minimum site role of the group, e.g. Viewer | ||
""" | ||
self._post( | ||
f'{self.url}/groups', | ||
{ | ||
'group': { | ||
'name': name, | ||
'minimumSiteRole': minimum_site_role | ||
} | ||
} | ||
) |
Oops, something went wrong.