-
Notifications
You must be signed in to change notification settings - Fork 95
Adding a header parameters to the client constructor #771
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 7 commits
d79b5e4
7080052
e462013
b56a225
3dc0ddd
d403503
dce8fe0
95bd4bc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,8 @@ | ||
| from __future__ import annotations | ||
|
|
||
| import json | ||
| from typing import Any, Callable, Dict, List, Optional, Union | ||
| from functools import lru_cache | ||
| from typing import Any, Callable, Dict, List, Optional, Tuple, Union | ||
|
|
||
| import requests | ||
|
|
||
|
|
@@ -19,7 +20,7 @@ def __init__(self, config: Config) -> None: | |
| self.config = config | ||
| self.headers = { | ||
| "Authorization": f"Bearer {self.config.api_key}", | ||
| "User-Agent": qualified_version(), | ||
| "User-Agent": self._build_user_agent(config.client_agents), | ||
| } | ||
|
|
||
| def send_request( | ||
|
|
@@ -94,6 +95,14 @@ def delete( | |
| ) -> Any: | ||
| return self.send_request(requests.delete, path, body) | ||
|
|
||
| @lru_cache(maxsize=1) | ||
| def _build_user_agent(self, client_agents: Optional[Tuple[str]] = None) -> str: | ||
| user_agent = qualified_version() | ||
| if not client_agents: | ||
| return user_agent | ||
|
|
||
| return f"{user_agent};{';'.join(client_agents)}" | ||
|
|
||
|
||
| @staticmethod | ||
| def __to_json(request: requests.Response) -> Any: | ||
| if request.content == b"": | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No because
_build_user_agentshouldn't be part of the classThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason way is a bit hard to explain here, but this video does a really good job explaining it https://www.youtube.com/watch?v=sVjtp6tGo0g