Skip to content

Commit f0e813c

Browse files
fix(python): expose user_agent on the config (generated)
algolia/api-clients-automation#4141 Co-authored-by: algolia-bot <[email protected]> Co-authored-by: Clément Vannicatte <[email protected]>
1 parent c3a05b9 commit f0e813c

File tree

20 files changed

+124
-20
lines changed

20 files changed

+124
-20
lines changed

algoliasearch/abtesting/client.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,10 @@ async def set_client_api_key(self, api_key: str) -> None:
132132
"""Sets a new API key to authenticate requests."""
133133
self._transporter.config.set_client_api_key(api_key)
134134

135+
async def add_user_agent(self, segment: str, version: Optional[str] = None) -> None:
136+
"""adds a segment to the default user agent, and update the headers sent with each requests as well"""
137+
self._transporter.config.add_user_agent(segment, version)
138+
135139
async def add_ab_tests_with_http_info(
136140
self,
137141
add_ab_tests_request: Union[AddABTestsRequest, dict[str, Any]],
@@ -977,6 +981,10 @@ def set_client_api_key(self, api_key: str) -> None:
977981
"""Sets a new API key to authenticate requests."""
978982
self._transporter.config.set_client_api_key(api_key)
979983

984+
def add_user_agent(self, segment: str, version: Optional[str] = None) -> None:
985+
"""adds a segment to the default user agent, and update the headers sent with each requests as well"""
986+
self._transporter.config.add_user_agent(segment, version)
987+
980988
def add_ab_tests_with_http_info(
981989
self,
982990
add_ab_tests_request: Union[AddABTestsRequest, dict[str, Any]],

algoliasearch/abtesting/config.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from os import environ
22
from typing import Optional
33

4+
from algoliasearch import __version__
45
from algoliasearch.http.base_config import BaseConfig
56
from algoliasearch.http.hosts import Host, HostsCollection
67
from algoliasearch.http.user_agent import UserAgent
@@ -15,7 +16,8 @@ def __init__(
1516
) -> None:
1617
super().__init__(app_id, api_key)
1718

18-
user_agent = UserAgent().add("Abtesting")
19+
self._user_agent = UserAgent()
20+
self.add_user_agent("Abtesting", __version__)
1921

2022
if app_id is None or not app_id:
2123
raise ValueError("`app_id` is missing.")
@@ -26,7 +28,7 @@ def __init__(
2628
self.headers = {
2729
"x-algolia-application-id": app_id,
2830
"x-algolia-api-key": api_key,
29-
"user-agent": user_agent.get(),
31+
"user-agent": self._user_agent.get(),
3032
"content-type": "application/json",
3133
}
3234

algoliasearch/analytics/client.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,10 @@ async def set_client_api_key(self, api_key: str) -> None:
172172
"""Sets a new API key to authenticate requests."""
173173
self._transporter.config.set_client_api_key(api_key)
174174

175+
async def add_user_agent(self, segment: str, version: Optional[str] = None) -> None:
176+
"""adds a segment to the default user agent, and update the headers sent with each requests as well"""
177+
self._transporter.config.add_user_agent(segment, version)
178+
175179
async def custom_delete_with_http_info(
176180
self,
177181
path: Annotated[
@@ -3207,6 +3211,10 @@ def set_client_api_key(self, api_key: str) -> None:
32073211
"""Sets a new API key to authenticate requests."""
32083212
self._transporter.config.set_client_api_key(api_key)
32093213

3214+
def add_user_agent(self, segment: str, version: Optional[str] = None) -> None:
3215+
"""adds a segment to the default user agent, and update the headers sent with each requests as well"""
3216+
self._transporter.config.add_user_agent(segment, version)
3217+
32103218
def custom_delete_with_http_info(
32113219
self,
32123220
path: Annotated[

algoliasearch/analytics/config.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from os import environ
22
from typing import Optional
33

4+
from algoliasearch import __version__
45
from algoliasearch.http.base_config import BaseConfig
56
from algoliasearch.http.hosts import Host, HostsCollection
67
from algoliasearch.http.user_agent import UserAgent
@@ -15,7 +16,8 @@ def __init__(
1516
) -> None:
1617
super().__init__(app_id, api_key)
1718

18-
user_agent = UserAgent().add("Analytics")
19+
self._user_agent = UserAgent()
20+
self.add_user_agent("Analytics", __version__)
1921

2022
if app_id is None or not app_id:
2123
raise ValueError("`app_id` is missing.")
@@ -26,7 +28,7 @@ def __init__(
2628
self.headers = {
2729
"x-algolia-application-id": app_id,
2830
"x-algolia-api-key": api_key,
29-
"user-agent": user_agent.get(),
31+
"user-agent": self._user_agent.get(),
3032
"content-type": "application/json",
3133
}
3234

algoliasearch/http/base_config.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from typing import Dict, Optional
33

44
from algoliasearch.http.hosts import HostsCollection
5+
from algoliasearch.http.user_agent import UserAgent
56

67

78
class BaseConfig:
@@ -27,9 +28,18 @@ def __init__(self, app_id: Optional[str] = None, api_key: Optional[str] = None):
2728
self.proxies: Optional[Dict[str, str]] = None
2829
self.hosts: Optional[HostsCollection] = None
2930

31+
self._user_agent: UserAgent = UserAgent()
32+
3033
def set_client_api_key(self, api_key: str) -> None:
3134
"""Sets a new API key to authenticate requests."""
3235
self.api_key = api_key
3336
if self.headers is None:
3437
self.headers = {}
3538
self.headers["x-algolia-api-key"] = api_key
39+
40+
def add_user_agent(self, segment: str, version: Optional[str] = None) -> None:
41+
"""adds a segment to the default user agent, and update the headers sent with each requests as well"""
42+
self._user_agent = self._user_agent.add(segment, version)
43+
44+
if self.headers is not None:
45+
self.headers["user-agent"] = self._user_agent.get()

algoliasearch/http/user_agent.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ def __init__(self) -> None:
1919
def get(self) -> str:
2020
return self.value
2121

22-
def add(self, segment: str, version: Optional[str] = __version__) -> Self:
23-
self.value += "; {} ({})".format(segment, version)
22+
def add(self, segment: str, version: Optional[str] = None) -> Self:
23+
self.value += "; {}".format(segment)
24+
25+
if version is not None:
26+
self.value += " ({})".format(version)
27+
2428
return self

algoliasearch/ingestion/client.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,10 @@ async def set_client_api_key(self, api_key: str) -> None:
209209
"""Sets a new API key to authenticate requests."""
210210
self._transporter.config.set_client_api_key(api_key)
211211

212+
async def add_user_agent(self, segment: str, version: Optional[str] = None) -> None:
213+
"""adds a segment to the default user agent, and update the headers sent with each requests as well"""
214+
self._transporter.config.add_user_agent(segment, version)
215+
212216
async def create_authentication_with_http_info(
213217
self,
214218
authentication_create: Union[AuthenticationCreate, dict[str, Any]],
@@ -4933,6 +4937,10 @@ def set_client_api_key(self, api_key: str) -> None:
49334937
"""Sets a new API key to authenticate requests."""
49344938
self._transporter.config.set_client_api_key(api_key)
49354939

4940+
def add_user_agent(self, segment: str, version: Optional[str] = None) -> None:
4941+
"""adds a segment to the default user agent, and update the headers sent with each requests as well"""
4942+
self._transporter.config.add_user_agent(segment, version)
4943+
49364944
def create_authentication_with_http_info(
49374945
self,
49384946
authentication_create: Union[AuthenticationCreate, dict[str, Any]],

algoliasearch/ingestion/config.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from os import environ
22
from typing import Optional
33

4+
from algoliasearch import __version__
45
from algoliasearch.http.base_config import BaseConfig
56
from algoliasearch.http.hosts import Host, HostsCollection
67
from algoliasearch.http.user_agent import UserAgent
@@ -12,7 +13,8 @@ def __init__(
1213
) -> None:
1314
super().__init__(app_id, api_key)
1415

15-
user_agent = UserAgent().add("Ingestion")
16+
self._user_agent = UserAgent()
17+
self.add_user_agent("Ingestion", __version__)
1618

1719
if app_id is None or not app_id:
1820
raise ValueError("`app_id` is missing.")
@@ -23,7 +25,7 @@ def __init__(
2325
self.headers = {
2426
"x-algolia-application-id": app_id,
2527
"x-algolia-api-key": api_key,
26-
"user-agent": user_agent.get(),
28+
"user-agent": self._user_agent.get(),
2729
"content-type": "application/json",
2830
}
2931

algoliasearch/insights/client.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,10 @@ async def set_client_api_key(self, api_key: str) -> None:
118118
"""Sets a new API key to authenticate requests."""
119119
self._transporter.config.set_client_api_key(api_key)
120120

121+
async def add_user_agent(self, segment: str, version: Optional[str] = None) -> None:
122+
"""adds a segment to the default user agent, and update the headers sent with each requests as well"""
123+
self._transporter.config.add_user_agent(segment, version)
124+
121125
async def custom_delete_with_http_info(
122126
self,
123127
path: Annotated[
@@ -653,6 +657,10 @@ def set_client_api_key(self, api_key: str) -> None:
653657
"""Sets a new API key to authenticate requests."""
654658
self._transporter.config.set_client_api_key(api_key)
655659

660+
def add_user_agent(self, segment: str, version: Optional[str] = None) -> None:
661+
"""adds a segment to the default user agent, and update the headers sent with each requests as well"""
662+
self._transporter.config.add_user_agent(segment, version)
663+
656664
def custom_delete_with_http_info(
657665
self,
658666
path: Annotated[

algoliasearch/insights/config.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from os import environ
22
from typing import Optional
33

4+
from algoliasearch import __version__
45
from algoliasearch.http.base_config import BaseConfig
56
from algoliasearch.http.hosts import Host, HostsCollection
67
from algoliasearch.http.user_agent import UserAgent
@@ -15,7 +16,8 @@ def __init__(
1516
) -> None:
1617
super().__init__(app_id, api_key)
1718

18-
user_agent = UserAgent().add("Insights")
19+
self._user_agent = UserAgent()
20+
self.add_user_agent("Insights", __version__)
1921

2022
if app_id is None or not app_id:
2123
raise ValueError("`app_id` is missing.")
@@ -26,7 +28,7 @@ def __init__(
2628
self.headers = {
2729
"x-algolia-application-id": app_id,
2830
"x-algolia-api-key": api_key,
29-
"user-agent": user_agent.get(),
31+
"user-agent": self._user_agent.get(),
3032
"content-type": "application/json",
3133
}
3234

0 commit comments

Comments
 (0)