-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.py
More file actions
41 lines (36 loc) · 1.22 KB
/
client.py
File metadata and controls
41 lines (36 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import os
from httpx import Client, HTTPTransport
class HTTPClient(Client):
"""Sync HTTP client for interacting with SoftwareOne Marketplace Platform API."""
def __init__(
self,
*,
base_url: str | None = None,
api_token: str | None = None,
timeout: float = 5.0,
retries: int = 0,
):
api_token = api_token or os.getenv("MPT_TOKEN")
if not api_token:
raise ValueError(
"API token is required. "
"Set it up as env variable MPT_TOKEN or pass it as `api_token` "
"argument to MPTClient."
)
base_url = base_url or os.getenv("MPT_URL")
if not base_url:
raise ValueError(
"Base URL is required. "
"Set it up as env variable MPT_URL or pass it as `base_url` "
"argument to MPTClient."
)
base_headers = {
"User-Agent": "swo-marketplace-client/1.0",
"Authorization": f"Bearer {api_token}",
}
super().__init__(
base_url=base_url,
headers=base_headers,
timeout=timeout,
transport=HTTPTransport(retries=retries),
)