Skip to content

Commit

Permalink
docs: docstrings for Server and ServerInfo (#1494)
Browse files Browse the repository at this point in the history
Co-authored-by: Jordan Woods <[email protected]>
  • Loading branch information
jorwoods and jorwoods authored Oct 11, 2024
1 parent 0efd735 commit f8728b2
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 3 deletions.
22 changes: 22 additions & 0 deletions tableauserverclient/models/server_info_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,28 @@


class ServerInfoItem:
"""
The ServerInfoItem class contains the build and version information for
Tableau Server. The server information is accessed with the
server_info.get() method, which returns an instance of the ServerInfo class.
Attributes
----------
product_version : str
Shows the version of the Tableau Server or Tableau Cloud
(for example, 10.2.0).
build_number : str
Shows the specific build number (for example, 10200.17.0329.1446).
rest_api_version : str
Shows the supported REST API version number. Note that this might be
different from the default value specified for the server, with the
Server.version attribute. To take advantage of new features, you should
query the server and set the Server.version to match the supported REST
API version number.
"""

def __init__(self, product_version, build_number, rest_api_version):
self._product_version = product_version
self._build_number = build_number
Expand Down
41 changes: 38 additions & 3 deletions tableauserverclient/server/endpoint/server_info_endpoint.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
from typing import Union

from .endpoint import Endpoint, api
from .exceptions import ServerResponseError
Expand All @@ -24,12 +25,46 @@ def __repr__(self):
return f"<Endpoint {self.serverInfo}>"

@property
def baseurl(self):
def baseurl(self) -> str:
return f"{self.parent_srv.baseurl}/serverInfo"

@api(version="2.4")
def get(self):
"""Retrieve the server info for the server. This is an unauthenticated call"""
def get(self) -> Union[ServerInfoItem, None]:
"""
Retrieve the build and version information for the server.
This method makes an unauthenticated call, so no sign in or
authentication token is required.
Returns
-------
:class:`~tableauserverclient.models.ServerInfoItem`
Raises
------
:class:`~tableauserverclient.exceptions.ServerInfoEndpointNotFoundError`
Raised when the server info endpoint is not found.
:class:`~tableauserverclient.exceptions.EndpointUnavailableError`
Raised when the server info endpoint is not available.
Examples
--------
>>> import tableauserverclient as TSC
>>> # create a instance of server
>>> server = TSC.Server('https://MY-SERVER')
>>> # set the version number > 2.3
>>> # the server_info.get() method works in 2.4 and later
>>> server.version = '2.5'
>>> s_info = server.server_info.get()
>>> print("\nServer info:")
>>> print("\tProduct version: {0}".format(s_info.product_version))
>>> print("\tREST API version: {0}".format(s_info.rest_api_version))
>>> print("\tBuild number: {0}".format(s_info.build_number))
"""
try:
server_response = self.get_unauthenticated_request(self.baseurl)
except ServerResponseError as e:
Expand Down
56 changes: 56 additions & 0 deletions tableauserverclient/server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,63 @@


class Server:
"""
In the Tableau REST API, the server (https://MY-SERVER/) is the base or core
of the URI that makes up the various endpoints or methods for accessing
resources on the server (views, workbooks, sites, users, data sources, etc.)
The TSC library provides a Server class that represents the server. You
create a server instance to sign in to the server and to call the various
methods for accessing resources.
The Server class contains the attributes that represent the server on
Tableau Server. After you create an instance of the Server class, you can
sign in to the server and call methods to access all of the resources on the
server.
Parameters
----------
server_address : str
Specifies the address of the Tableau Server or Tableau Cloud (for
example, https://MY-SERVER/).
use_server_version : bool
Specifies the version of the REST API to use (for example, '2.5'). When
you use the TSC library to call methods that access Tableau Server, the
version is passed to the endpoint as part of the URI
(https://MY-SERVER/api/2.5/). Each release of Tableau Server supports
specific versions of the REST API. New versions of the REST API are
released with Tableau Server. By default, the value of version is set to
'2.3', which corresponds to Tableau Server 10.0. You can view or set
this value. You might need to set this to a different value, for
example, if you want to access features that are supported by the server
and a later version of the REST API. For more information, see REST API
Versions.
Examples
--------
>>> import tableauserverclient as TSC
>>> # create a instance of server
>>> server = TSC.Server('https://MY-SERVER')
>>> # sign in, etc.
>>> # change the REST API version to match the server
>>> server.use_server_version()
>>> # or change the REST API version to match a specific version
>>> # for example, 2.8
>>> # server.version = '2.8'
"""

class PublishMode:
"""
Enumerates the options that specify what happens when you publish a
workbook or data source. The options are Overwrite, Append, or
CreateNew.
"""

Append = "Append"
Overwrite = "Overwrite"
CreateNew = "CreateNew"
Expand Down

0 comments on commit f8728b2

Please sign in to comment.