Skip to content

Commit e4efc3b

Browse files
authored
Merge pull request #48 from PioneersHub/modify-pretalx-base-url
use base_url from config or default
2 parents e9fa9bd + 689b7d1 commit e4efc3b

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

docs/usage/pretalx.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,17 @@ api_version = "v2" # Use a different API version
3838

3939
The `api_version` setting is optional. If not specified in your `~/.pytanis/config.toml`, it will default to "v1". This version is sent in the `Pretalx-Version` header with each API request.
4040

41+
## API Base URL Configuration
42+
Similar to the `api_version` above, you can change the pretalx base url if needed:
43+
44+
```toml
45+
[Pretalx]
46+
api_token = "your-api-token"
47+
api_base_url = "https://pretalx.com/" # pretalx.com is the default value but you can change it here
48+
```
49+
50+
The `api_base_url` setting is optional.
51+
4152
## Advanced Usage
4253

4354
Find out more about the client's capabilities, e.g. throttling, by looking at Pytanis' reference of the [pretalx client module].

src/pytanis/config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ class PretalxCfg(BaseModel):
5353

5454
api_token: str
5555
api_version: str = 'v1'
56+
api_base_url: str = 'https://pretalx.com/'
5657
timeout: int | None = None
5758

5859

src/pytanis/pretalx/client.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,12 @@ def _get(self, endpoint: str, params: QueryParams | dict | None = None) -> Respo
108108
if (api_token := self._config.Pretalx.api_token) is not None:
109109
headers['Authorization'] = f'Token {api_token}'
110110

111-
url = URL('https://pretalx.com/').join(endpoint).copy_merge_params(params)
111+
# get the pretalx base URL (defaults to pretalx.com)
112+
base_url = self._config.Pretalx.api_base_url
113+
if not base_url.endswith('/'):
114+
base_url += '/'
115+
116+
url = URL(base_url).join(endpoint).copy_merge_params(params)
112117
_logger.info(f'GET: {url}')
113118
# we set the timeout to what is configured, otherwise 60 seconds as the Pretalx API is quite slow
114119
timeout = self._config.Pretalx.timeout if self._config.Pretalx.timeout else 60.0

0 commit comments

Comments
 (0)