diff --git a/README.md b/README.md index 8236022..b235ff0 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ Does not make any call to the server. from deepomatic.api.client import Client # If you don't have your credentials, contact us at support@deepomatic.com -client = Client(app_id, api_key) +client = Client(app_id, api_key, user_agent_prefix='my-app/1.0.0') ``` ### Client methods diff --git a/demo.py b/demo.py index 9b8f609..80bd644 100644 --- a/demo.py +++ b/demo.py @@ -8,6 +8,7 @@ import hashlib import requests +from deepomatic.api.version import __title__, __version__ from deepomatic.api.client import Client from deepomatic.api.inputs import ImageInput @@ -37,15 +38,16 @@ def demo(client=None): ######### # You can create a client in two ways: - # i) explicitly: you pass your APP_ID and API_KEY by calling `client = Client(app_id, api_key)` + # i) explicitly: you pass your APP_ID and API_KEY by calling `client = Client(app_id, api_key, user_agent_prefix='my-app/1.0.0')` # ii) implicitly: you define environment variables `DEEPOMATIC_APP_ID` and `DEEPOMATIC_API_KEY` - # and just call `client = Client()` + # and just call `client = Client(user_agent_prefix='my-app/1.0.0')` # + # In both ways `user_agent_prefix` parameter is optional but recommended to identify your app to the API # Here we actually use a mix of those two methods to illustrate: if client is None: app_id = os.getenv('DEEPOMATIC_APP_ID') api_key = os.getenv('DEEPOMATIC_API_KEY') - client = Client(app_id, api_key) # this would be equivalent to using `Client()` in this case. + client = Client(app_id, api_key, user_agent_prefix='{}-demo/{}'.format(__title__, __version__)) ################### # Public networks # @@ -352,6 +354,7 @@ def download_file(url): shutil.copyfileobj(r.raw, f) return filename + def print_header(text): logger.info("**** {} ****".format(text)) diff --git a/tests/test_client.py b/tests/test_client.py index 5ae30e8..86518cb 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -6,6 +6,7 @@ import hashlib import shutil import requests +from deepomatic.api.version import __title__, __version__ from deepomatic.api.client import Client from deepomatic.api.inputs import ImageInput from pytest_voluptuous import S @@ -42,7 +43,7 @@ def client(): api_host = os.getenv('DEEPOMATIC_API_URL') app_id = os.environ['DEEPOMATIC_APP_ID'] api_key = os.environ['DEEPOMATIC_API_KEY'] - yield Client(app_id, api_key, host=api_host) + yield Client(app_id, api_key, host=api_host, user_agent_prefix='{}-tests/{}'.format(__title__, __version__)) @pytest.fixture(scope='session') @@ -141,7 +142,7 @@ class TestClient(object): def test_headers(self, client): http_helper = client.http_helper session_headers = http_helper.session.headers - assert session_headers['User-Agent'].startswith('deepomatic-api/') + assert session_headers['User-Agent'].startswith('{}-tests/{} {}/{}'.format(__title__, __version__, __title__, __version__)) assert 'platform/' in session_headers['User-Agent'] assert 'python/' in session_headers['User-Agent'] assert session_headers['X-APP-ID']