From e7348d06468e5f5156e4bffbcaac78191b579277 Mon Sep 17 00:00:00 2001 From: Hugo Maingonnat Date: Thu, 16 May 2019 14:41:31 +0200 Subject: [PATCH 01/15] Added support for prefix user agent --- deepomatic/api/http_helper.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/deepomatic/api/http_helper.py b/deepomatic/api/http_helper.py index c5eb62c..a4f2422 100644 --- a/deepomatic/api/http_helper.py +++ b/deepomatic/api/http_helper.py @@ -39,7 +39,7 @@ class HTTPHelper(object): - def __init__(self, app_id, api_key, verify, host, version, check_query_parameters, user_agent_suffix='', pool_maxsize=20): + def __init__(self, app_id, api_key, verify, host, version, check_query_parameters, user_agent_prefix='', user_agent_suffix='', pool_maxsize=20): """ Init the HTTP helper with API key and secret """ @@ -71,8 +71,14 @@ def __init__(self, app_id, api_key, verify, host, version, check_query_parameter 'platform': platform.platform() } - self.user_agent = 'deepomatic-api/{package_version} requests/{requests_version} python/{python_version} platform/{platform}\ + if user_agent_prefix: + self.user_agent = user_agent_prefix + ' ' + else: + self.user_agent = '' + + self.user_agent += 'deepomatic-api/{package_version} requests/{requests_version} python/{python_version} platform/{platform}\ '.format(**user_agent_params) + if user_agent_suffix: self.user_agent += ' ' + user_agent_suffix From a199a82e479423a207db96e2e33d89e4a527f575 Mon Sep 17 00:00:00 2001 From: Hugo Maingonnat Date: Thu, 16 May 2019 14:49:33 +0200 Subject: [PATCH 02/15] Better init of http helper --- deepomatic/api/client.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/deepomatic/api/client.py b/deepomatic/api/client.py index e099eb8..e7c1c94 100644 --- a/deepomatic/api/client.py +++ b/deepomatic/api/client.py @@ -34,10 +34,11 @@ ############################################################################### + class Client(object): - def __init__(self, app_id=None, api_key=None, verify_ssl=None, check_query_parameters=True, host=None, version=API_VERSION, user_agent_suffix='', pool_maxsize=20): - self.http_helper = HTTPHelper(app_id, api_key, verify_ssl, host, version, check_query_parameters, user_agent_suffix, pool_maxsize) + def __init__(self, *args, **kwargs): + self.http_helper = HTTPHelper(*args, **kwargs) # /accounts From 5eec89b699404f9481a61c41d30fb1535f4fee08 Mon Sep 17 00:00:00 2001 From: Hugo Maingonnat Date: Thu, 16 May 2019 14:56:42 +0200 Subject: [PATCH 03/15] fixed parameters --- deepomatic/api/client.py | 6 ------ deepomatic/api/http_helper.py | 7 +++++-- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/deepomatic/api/client.py b/deepomatic/api/client.py index e7c1c94..f271f45 100644 --- a/deepomatic/api/client.py +++ b/deepomatic/api/client.py @@ -28,12 +28,6 @@ from deepomatic.api.resources.task import Task from deepomatic.api.resources.account import Account -############################################################################### - -API_VERSION = 0.7 - -############################################################################### - class Client(object): diff --git a/deepomatic/api/http_helper.py b/deepomatic/api/http_helper.py index a4f2422..83765b8 100644 --- a/deepomatic/api/http_helper.py +++ b/deepomatic/api/http_helper.py @@ -34,18 +34,19 @@ from deepomatic.api.version import __version__ API_HOST = 'https://api.deepomatic.com' +API_VERSION = 0.7 ############################################################################### class HTTPHelper(object): - def __init__(self, app_id, api_key, verify, host, version, check_query_parameters, user_agent_prefix='', user_agent_suffix='', pool_maxsize=20): + def __init__(self, app_id=None, api_key=None, verify_ssl=None, host=None, version=API_VERSION, check_query_parameters=True, user_agent_prefix='', user_agent_suffix='', pool_maxsize=20): """ Init the HTTP helper with API key and secret """ if host is None: host = os.getenv('DEEPOMATIC_API_URL', API_HOST) - if verify is None: + if verify_ssl is None: verify = os.getenv('DEEPOMATIC_API_VERIFY_TLS', '1') == '0' if app_id is None: app_id = os.getenv('DEEPOMATIC_APP_ID') @@ -87,6 +88,8 @@ def __init__(self, app_id, api_key, verify, host, version, check_query_parameter self.verify = verify self.host = host self.resource_prefix = host + version + + # This is only used in mixins, this should not stay here self.check_query_parameters = check_query_parameters headers = { From 9e32fd16f9a5628cb9e88b2945f4e853e3c1fcf1 Mon Sep 17 00:00:00 2001 From: Hugo Maingonnat Date: Thu, 16 May 2019 15:04:01 +0200 Subject: [PATCH 04/15] removed hardcoded package title --- deepomatic/api/http_helper.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/deepomatic/api/http_helper.py b/deepomatic/api/http_helper.py index 83765b8..69a7925 100644 --- a/deepomatic/api/http_helper.py +++ b/deepomatic/api/http_helper.py @@ -31,7 +31,7 @@ from six import string_types from deepomatic.api.exceptions import DeepomaticException, BadStatus -from deepomatic.api.version import __version__ +from deepomatic.api.version import __title__, __version__ API_HOST = 'https://api.deepomatic.com' API_VERSION = 0.7 @@ -66,6 +66,7 @@ def __init__(self, app_id=None, api_key=None, verify_ssl=None, host=None, versio python_version = "{0}.{1}.{2}".format(sys.version_info.major, sys.version_info.minor, sys.version_info.micro) user_agent_params = { + 'package_title': __title__, 'package_version': __version__, 'requests_version': requests.__version__, 'python_version': python_version, @@ -77,7 +78,7 @@ def __init__(self, app_id=None, api_key=None, verify_ssl=None, host=None, versio else: self.user_agent = '' - self.user_agent += 'deepomatic-api/{package_version} requests/{requests_version} python/{python_version} platform/{platform}\ + self.user_agent += '{package_title}/{package_version} requests/{requests_version} python/{python_version} platform/{platform}\ '.format(**user_agent_params) if user_agent_suffix: From 563ae97a6e6f298580441943f75bee0d474a4736 Mon Sep 17 00:00:00 2001 From: Hugo Maingonnat Date: Thu, 16 May 2019 15:55:21 +0200 Subject: [PATCH 05/15] Comment Client class --- deepomatic/api/client.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/deepomatic/api/client.py b/deepomatic/api/client.py index f271f45..1393d45 100644 --- a/deepomatic/api/client.py +++ b/deepomatic/api/client.py @@ -32,6 +32,36 @@ class Client(object): def __init__(self, *args, **kwargs): + """ + Constructs a Client class that will allow to send requests to Deepomatic API. + + :param app_id: App id for authentication. Defaults to `None`. + If `None` try to retrieve it from the env var `DEEPOMATIC_APP_ID`. + If it fails raise a `DeepomaticException`. + :type app_id: string + :param api_key: API key for authentication. Defaults to `None`. + If `None` try to retrieve it from the env var `DEEPOMATIC_API_KEY`. + If it fails raise a `DeepomaticException`. + :type api_key: string + :param verify_ssl (optional): whether to ask requests to verify the SSL certificate. + Defaults to `None`. If `None` try to get it from the env var `DEEPOMATIC_API_VERIFY_TLS`. + If not found it is set to True. + :type verify_ssl: bool + :param host (optional): API root URL + :type host: string + :param version (optional): API version + :type version: string + :param user_agent_prefix (optional): Allow to prefix the user agent + :type user_agent_prefix: string + :param user_agent_suffix (optional): Allow to suffix the user agent + :type user_agent_suffix: string + :param pool_maxsize (optional): Allow to set `requests.adapters.HTTPAdapter.pool_maxsize` for concurrent calls. + Defaults to 20. + :type pool_maxsize: int + + :return: :class:`Client` object + :rtype: deepomatic.api.client.Client + """ self.http_helper = HTTPHelper(*args, **kwargs) # /accounts From b778534684358c31ab516bfb16ac6aec4c37a1c4 Mon Sep 17 00:00:00 2001 From: Hugo Maingonnat Date: Thu, 16 May 2019 15:58:17 +0200 Subject: [PATCH 06/15] indent --- deepomatic/api/client.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/deepomatic/api/client.py b/deepomatic/api/client.py index 1393d45..ea50aeb 100644 --- a/deepomatic/api/client.py +++ b/deepomatic/api/client.py @@ -32,7 +32,7 @@ class Client(object): def __init__(self, *args, **kwargs): - """ + """ Constructs a Client class that will allow to send requests to Deepomatic API. :param app_id: App id for authentication. Defaults to `None`. @@ -61,7 +61,7 @@ def __init__(self, *args, **kwargs): :return: :class:`Client` object :rtype: deepomatic.api.client.Client - """ + """ self.http_helper = HTTPHelper(*args, **kwargs) # /accounts From f0cefaf1270f5cf69c5ef3ebad5c28e655c346c6 Mon Sep 17 00:00:00 2001 From: Hugo Maingonnat Date: Thu, 16 May 2019 16:00:57 +0200 Subject: [PATCH 07/15] dot --- deepomatic/api/client.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/deepomatic/api/client.py b/deepomatic/api/client.py index ea50aeb..e7c0339 100644 --- a/deepomatic/api/client.py +++ b/deepomatic/api/client.py @@ -47,13 +47,13 @@ def __init__(self, *args, **kwargs): Defaults to `None`. If `None` try to get it from the env var `DEEPOMATIC_API_VERIFY_TLS`. If not found it is set to True. :type verify_ssl: bool - :param host (optional): API root URL + :param host (optional): API root URL. :type host: string - :param version (optional): API version + :param version (optional): API version. :type version: string - :param user_agent_prefix (optional): Allow to prefix the user agent + :param user_agent_prefix (optional): Allow to prefix the user agent. :type user_agent_prefix: string - :param user_agent_suffix (optional): Allow to suffix the user agent + :param user_agent_suffix (optional): Allow to suffix the user agent. :type user_agent_suffix: string :param pool_maxsize (optional): Allow to set `requests.adapters.HTTPAdapter.pool_maxsize` for concurrent calls. Defaults to 20. From 60a5dc403ae52a5a80e6f3cbf3f5241413c37430 Mon Sep 17 00:00:00 2001 From: Hugo Maingonnat Date: Thu, 16 May 2019 16:15:32 +0200 Subject: [PATCH 08/15] Update deepomatic/api/client.py Co-Authored-By: Thomas Riccardi --- deepomatic/api/client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deepomatic/api/client.py b/deepomatic/api/client.py index e7c0339..069617c 100644 --- a/deepomatic/api/client.py +++ b/deepomatic/api/client.py @@ -33,7 +33,7 @@ class Client(object): def __init__(self, *args, **kwargs): """ - Constructs a Client class that will allow to send requests to Deepomatic API. + Constructs a Client to send requests to the Deepomatic API. :param app_id: App id for authentication. Defaults to `None`. If `None` try to retrieve it from the env var `DEEPOMATIC_APP_ID`. From 8d9aa9809e219023aca6b23e2cef48c1f6752221 Mon Sep 17 00:00:00 2001 From: Hugo Maingonnat Date: Thu, 16 May 2019 16:15:40 +0200 Subject: [PATCH 09/15] Update deepomatic/api/client.py Co-Authored-By: Thomas Riccardi --- deepomatic/api/client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deepomatic/api/client.py b/deepomatic/api/client.py index 069617c..78eabb4 100644 --- a/deepomatic/api/client.py +++ b/deepomatic/api/client.py @@ -35,7 +35,7 @@ def __init__(self, *args, **kwargs): """ Constructs a Client to send requests to the Deepomatic API. - :param app_id: App id for authentication. Defaults to `None`. + :param app_id: App ID for authentication. Defaults to `None`. If `None` try to retrieve it from the env var `DEEPOMATIC_APP_ID`. If it fails raise a `DeepomaticException`. :type app_id: string From 5148f130843ace3e7a4437cfb84223afda0a8237 Mon Sep 17 00:00:00 2001 From: Hugo Maingonnat Date: Thu, 16 May 2019 16:15:54 +0200 Subject: [PATCH 10/15] Update deepomatic/api/client.py Co-Authored-By: Thomas Riccardi --- deepomatic/api/client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deepomatic/api/client.py b/deepomatic/api/client.py index 78eabb4..7c2ac28 100644 --- a/deepomatic/api/client.py +++ b/deepomatic/api/client.py @@ -40,7 +40,7 @@ def __init__(self, *args, **kwargs): If it fails raise a `DeepomaticException`. :type app_id: string :param api_key: API key for authentication. Defaults to `None`. - If `None` try to retrieve it from the env var `DEEPOMATIC_API_KEY`. + If `None` try to retrieve it from the `DEEPOMATIC_API_KEY` environment variable. If it fails raise a `DeepomaticException`. :type api_key: string :param verify_ssl (optional): whether to ask requests to verify the SSL certificate. From c3a4ba2aec66c551a7d6a58a8bf4ff0308ebbd3b Mon Sep 17 00:00:00 2001 From: Hugo Maingonnat Date: Thu, 16 May 2019 16:16:05 +0200 Subject: [PATCH 11/15] Update deepomatic/api/client.py Co-Authored-By: Thomas Riccardi --- deepomatic/api/client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deepomatic/api/client.py b/deepomatic/api/client.py index 7c2ac28..e86d7c8 100644 --- a/deepomatic/api/client.py +++ b/deepomatic/api/client.py @@ -36,7 +36,7 @@ def __init__(self, *args, **kwargs): Constructs a Client to send requests to the Deepomatic API. :param app_id: App ID for authentication. Defaults to `None`. - If `None` try to retrieve it from the env var `DEEPOMATIC_APP_ID`. + If `None`, try to retrieve it from the `DEEPOMATIC_APP_ID` environment variable. If it fails raise a `DeepomaticException`. :type app_id: string :param api_key: API key for authentication. Defaults to `None`. From 89573837a965d70e010e91b901bb1ebfdf4cfa2b Mon Sep 17 00:00:00 2001 From: Hugo Maingonnat Date: Thu, 16 May 2019 16:16:21 +0200 Subject: [PATCH 12/15] Update deepomatic/api/client.py Co-Authored-By: Thomas Riccardi --- deepomatic/api/client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deepomatic/api/client.py b/deepomatic/api/client.py index e86d7c8..dc7f1f5 100644 --- a/deepomatic/api/client.py +++ b/deepomatic/api/client.py @@ -43,7 +43,7 @@ def __init__(self, *args, **kwargs): If `None` try to retrieve it from the `DEEPOMATIC_API_KEY` environment variable. If it fails raise a `DeepomaticException`. :type api_key: string - :param verify_ssl (optional): whether to ask requests to verify the SSL certificate. + :param verify_ssl (optional): whether to ask `requests` to verify the TLS/SSL certificates. Defaults to `None`. If `None` try to get it from the env var `DEEPOMATIC_API_VERIFY_TLS`. If not found it is set to True. :type verify_ssl: bool From 7c4d5cb0a7b1e78be130ed918a6e85f533cf4c8c Mon Sep 17 00:00:00 2001 From: Hugo Maingonnat Date: Thu, 16 May 2019 16:16:55 +0200 Subject: [PATCH 13/15] Update deepomatic/api/client.py Co-Authored-By: Thomas Riccardi --- deepomatic/api/client.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/deepomatic/api/client.py b/deepomatic/api/client.py index dc7f1f5..3dddc63 100644 --- a/deepomatic/api/client.py +++ b/deepomatic/api/client.py @@ -44,7 +44,8 @@ def __init__(self, *args, **kwargs): If it fails raise a `DeepomaticException`. :type api_key: string :param verify_ssl (optional): whether to ask `requests` to verify the TLS/SSL certificates. - Defaults to `None`. If `None` try to get it from the env var `DEEPOMATIC_API_VERIFY_TLS`. + Defaults to `None`. + If `None` try to get it from the `DEEPOMATIC_API_VERIFY_TLS` environment variable (`0`: False, `1`: True). If not found it is set to True. :type verify_ssl: bool :param host (optional): API root URL. From 70a3b1a151b178b8cc1cc716e3719526db31ac81 Mon Sep 17 00:00:00 2001 From: Hugo Maingonnat Date: Thu, 16 May 2019 16:17:28 +0200 Subject: [PATCH 14/15] Update deepomatic/api/client.py Co-Authored-By: Thomas Riccardi --- deepomatic/api/client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deepomatic/api/client.py b/deepomatic/api/client.py index 3dddc63..7c97132 100644 --- a/deepomatic/api/client.py +++ b/deepomatic/api/client.py @@ -56,7 +56,7 @@ def __init__(self, *args, **kwargs): :type user_agent_prefix: string :param user_agent_suffix (optional): Allow to suffix the user agent. :type user_agent_suffix: string - :param pool_maxsize (optional): Allow to set `requests.adapters.HTTPAdapter.pool_maxsize` for concurrent calls. + :param pool_maxsize (optional): Set `requests.adapters.HTTPAdapter.pool_maxsize` for concurrent calls. Defaults to 20. :type pool_maxsize: int From 128cec77baeae7083a8c23681983438f8e10cf94 Mon Sep 17 00:00:00 2001 From: Hugo Maingonnat Date: Thu, 16 May 2019 16:21:34 +0200 Subject: [PATCH 15/15] suggestions --- deepomatic/api/client.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/deepomatic/api/client.py b/deepomatic/api/client.py index 7c97132..b3bc902 100644 --- a/deepomatic/api/client.py +++ b/deepomatic/api/client.py @@ -52,9 +52,10 @@ def __init__(self, *args, **kwargs): :type host: string :param version (optional): API version. :type version: string - :param user_agent_prefix (optional): Allow to prefix the user agent. + :param user_agent_prefix (optional): Prefix the HTTP User-Agent. + It is recommended to declare your client via this parameter. Example: 'my-app/1.0.0'. :type user_agent_prefix: string - :param user_agent_suffix (optional): Allow to suffix the user agent. + :param user_agent_suffix (optional): Suffix the HTTP User-Agent. :type user_agent_suffix: string :param pool_maxsize (optional): Set `requests.adapters.HTTPAdapter.pool_maxsize` for concurrent calls. Defaults to 20.