Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 6 additions & 3 deletions demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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 #
Expand Down Expand Up @@ -352,6 +354,7 @@ def download_file(url):
shutil.copyfileobj(r.raw, f)
return filename


def print_header(text):
logger.info("**** {} ****".format(text))

Expand Down
5 changes: 3 additions & 2 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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']
Expand Down