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
3 changes: 3 additions & 0 deletions meorg_client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ def _make_request(
# Assemble the headers
_headers = self._merge_headers(headers)

# Attach the user agent
_headers['user-agent'] = mu.get_user_agent()

# Make the request, set it as the last response for future use
self.last_response = func(
url, data=data, json=json, headers=_headers, files=files, **kwargs
Expand Down
5 changes: 5 additions & 0 deletions meorg_client/tests/test_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,8 @@ def test_load_package_data():
"""Test load_package_data."""
result = mu.load_package_data("openapi.json")
assert isinstance(result, dict)


def test_get_user_agent():
"""Test get_user_agent."""
assert "meorg_client/" in mu.get_user_agent()
22 changes: 22 additions & 0 deletions meorg_client/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import os
from pathlib import Path
from importlib import resources
from . import _version
import platform


# Single argument decoding functions.
Expand Down Expand Up @@ -105,3 +107,23 @@ def get_uploaded_file_ids(response):

def is_dev_mode():
return os.getenv("MEORG_DEV_MODE", "0") == "1"


def get_user_agent() -> str:
"""Return the client's user agent to send along with the request.

Returns
-------
str
User agent.
"""
template = "{product}/{product_version} ({system_information})"
system_information = f"{platform.system()} {platform.machine()}"

directives = dict(
product="meorg_client",
product_version=_version.get_versions()["version"],
system_information=system_information,
)

return template.format(**directives)
Loading