Skip to content

Commit

Permalink
Merge pull request #72 from domoinc/RequestTimeoutSupport
Browse files Browse the repository at this point in the history
Supporting a configurable request timeout configuration
  • Loading branch information
jeremydmorris authored Jan 28, 2022
2 parents 2914688 + 5672df1 commit dacdee8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 22 deletions.
6 changes: 4 additions & 2 deletions pydomo/Transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ class DomoAPITransport:
serialization and deserialization of objects.
"""

def __init__(self, client_id, client_secret, api_host, use_https, logger):
def __init__(self, client_id, client_secret, api_host, use_https, logger, request_timeout):
self.apiHost = self._build_apihost(api_host, use_https)
self.clientId = client_id
self.clientSecret = client_secret
self.logger = logger
self._renew_access_token()
self.request_timeout = request_timeout

@staticmethod
def _build_apihost(host, use_https):
Expand Down Expand Up @@ -68,7 +69,8 @@ def request(self, url, method, headers, params=None, body=None):
self.logger.debug('{} {} {}'.format(method, url, body))
request_args = {'method': method, 'url': url, 'headers': headers,
'params': params, 'data': body, 'stream': True}

if self.request_timeout:
request_args['timeout'] = self.request_timeout
response = requests.request(**request_args)
if response.status_code == requests.codes.UNAUTHORIZED:
self._renew_access_token()
Expand Down
42 changes: 22 additions & 20 deletions pydomo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,13 @@ def __init__(self, client_id, client_secret, api_host='api.domo.com', **kwargs):
else:
self.logger = parent_logger

timeout = kwargs.get('request_timeout', None)

if kwargs.get('log_level'):
self.logger.setLevel(kwargs['log_level'])
self.logger.debug("\n" + DOMO + "\n")

self.transport = DomoAPITransport(client_id, client_secret, api_host, kwargs.get('use_https', True), self.logger)
self.transport = DomoAPITransport(client_id, client_secret, api_host, kwargs.get('use_https', True), self.logger, request_timeout = timeout)
self.datasets = DataSetClient(self.transport, self.logger)
self.groups = GroupClient(self.transport, self.logger)
self.pages = PageClient(self.transport, self.logger)
Expand Down Expand Up @@ -137,7 +139,7 @@ def ds_list(self, df_output = True, per_page=50, offset=0, limit=0):
- `per_page`: results per page. Default 50 (int)
- `offset`: offset if you need to paginate results. Default 0 (int)
- `limit`: max ouput to return. If 0 then return all results on page. Default 0 (int)
:Returns:
list or pandas dataframe depending on parameters
Expand All @@ -148,7 +150,7 @@ def ds_list(self, df_output = True, per_page=50, offset=0, limit=0):
else:
out = DataFrame(list(l))
return out

def ds_query(self, dataset_id, query, return_data=True):
"""
Evaluate query and return dataset in a dataframe
Expand All @@ -161,7 +163,7 @@ def ds_query(self, dataset_id, query, return_data=True):
- `dataset_id`: id of a dataset (str)
- `query`: query object (dict)
- `return_data`: should the result be a dataframe. Default True (Boolean)
:Returns:
dict or pandas dataframe depending on parameters
"""
Expand All @@ -180,10 +182,10 @@ def ds_get(self, dataset_id):
:Parameters:
- `dataset_id`: id of a dataset (str)
:Returns:
pandas dataframe
"""
"""
csv_download = self.datasets.data_export(dataset_id, include_csv_header=True)

content = StringIO(csv_download)
Expand Down Expand Up @@ -232,14 +234,14 @@ def pdp_create(self, dataset_id, pdp_request):
, "not": false } ], "users": [ 27 ],"groups": [ ]}
:Parameters:
- `dataset_id`: id of the dataset PDP will be applied to (String) Required
- `dataset_id`: id of the dataset PDP will be applied to (String) Required
Policy Object:
- `name`: Name of the Policy (String) Required
- `filters[].column`: Name of the column to filter on (String) Required
- `filters[].column`: Name of the column to filter on (String) Required
- `filters[].not`: Determines if NOT is applied to the filter operation (Boolean) Required
- `filters[].operator`: Matching operator (EQUALS) (String) Required
- `filters[].values[]`: Values to filter on (String) Required
- `type`: Type of policy (user or system) (String) Required
- `filters[].operator`: Matching operator (EQUALS) (String) Required
- `filters[].values[]`: Values to filter on (String) Required
- `type`: Type of policy (user or system) (String) Required
- `users`: List of user IDs the policy applies to (array) Required
- `groups`: List of group IDs the policy applies to (array) Required
"""
Expand All @@ -252,7 +254,7 @@ def pdp_delete(self, dataset_id, policy_id):
>>> domo.pdp_delete('4405ff58-1957-45f0-82bd-914d989a3ea3', 35)
:Parameters:
- `dataset_id`: id of the dataset PDP will be applied to (String) Required
- `dataset_id`: id of the dataset PDP will be applied to (String) Required
- `policy_id`: id of the policy to delete (String) Required
"""
return self.datasets.delete_pdp(dataset_id, policy_id)
Expand All @@ -267,7 +269,7 @@ def pdp_list(self, dataset_id, df_output = True):
:Parameters:
- `dataset_id`: id of dataset with PDP policies (str) Required
- `df_output`: should the result be a dataframe. Default True (Boolean)
:Returns:
list or pandas dataframe depending on parameters
Expand Down Expand Up @@ -297,15 +299,15 @@ def pdp_update(self, dataset_id, policy_id, policy_update):
, "not": false } ], "users": [ 27 ],"groups": [ ]}
:Parameters:
- `dataset_id`: id of the dataset PDP will be applied to (String) Required
- `policy_id`: id of the PDP pollicy that will be updated (String) Required
- `dataset_id`: id of the dataset PDP will be applied to (String) Required
- `policy_id`: id of the PDP pollicy that will be updated (String) Required
Policy Object:
- `name`: Name of the Policy (String) Required
- `filters[].column`: Name of the column to filter on (String) Required
- `filters[].column`: Name of the column to filter on (String) Required
- `filters[].not`: Determines if NOT is applied to the filter operation (Boolean) Required
- `filters[].operator`: Matching operator (EQUALS) (String) Required
- `filters[].values[]`: Values to filter on (String) Required
- `type`: Type of policy (user or system) (String) Required
- `filters[].operator`: Matching operator (EQUALS) (String) Required
- `filters[].values[]`: Values to filter on (String) Required
- `type`: Type of policy (user or system) (String) Required
- `users`: List of user IDs the policy applies to (array) Required
- `groups`: List of group IDs the policy applies to (array) Required
"""
Expand Down Expand Up @@ -600,7 +602,7 @@ def accounts_list(self):
- `per_page`: results per page. Default 50 (int)
- `offset`: offset if you need to paginate results. Default 0 (int)
- `limit`: max ouput to return. If 0 then return all results on page. Default 0 (int)
:returns:
- A list of dicts (with nesting possible)
Expand Down

0 comments on commit dacdee8

Please sign in to comment.