Base class with shared HTTP request logic for API request contexts.
| 248 | |
| 249 | |
| 250 | class _BaseRequestContext: |
| 251 | """Base class with shared HTTP request logic for API request contexts.""" |
| 252 | |
| 253 | def __init__( |
| 254 | self, |
| 255 | base_url: str = "", |
| 256 | extra_headers: dict[str, str] | None = None, |
| 257 | timeout: float = 30.0, |
| 258 | max_redirects: int = 10, |
| 259 | fail_on_status_code: bool = False, |
| 260 | ) -> None: |
| 261 | self._base_url = base_url |
| 262 | self._extra_headers = extra_headers or {} |
| 263 | self._timeout = timeout |
| 264 | self._max_redirects = max_redirects |
| 265 | self._fail_on_status_code = fail_on_status_code |
| 266 | self._pool = urllib3.PoolManager() |
| 267 | |
| 268 | def get(self, url: str, **kwargs: Any) -> APIResponse: |
| 269 | """Send a GET request. |
| 270 | |
| 271 | Args: |
| 272 | url: The request URL (absolute or relative to base_url). |
| 273 | **kwargs: Optional arguments: headers, params, timeout, max_redirects, fail_on_status_code. |
| 274 | |
| 275 | Returns: |
| 276 | An APIResponse object. |
| 277 | """ |
| 278 | return self._fetch(url, "GET", **kwargs) |
| 279 | |
| 280 | def post(self, url: str, **kwargs: Any) -> APIResponse: |
| 281 | """Send a POST request. |
| 282 | |
| 283 | Args: |
| 284 | url: The request URL (absolute or relative to base_url). |
| 285 | **kwargs: Optional arguments: headers, params, data, form, |
| 286 | json_data, timeout, max_redirects, fail_on_status_code. |
| 287 | |
| 288 | Returns: |
| 289 | An APIResponse object. |
| 290 | """ |
| 291 | return self._fetch(url, "POST", **kwargs) |
| 292 | |
| 293 | def put(self, url: str, **kwargs: Any) -> APIResponse: |
| 294 | """Send a PUT request. |
| 295 | |
| 296 | Args: |
| 297 | url: The request URL (absolute or relative to base_url). |
| 298 | **kwargs: Optional arguments: headers, params, data, form, |
| 299 | json_data, timeout, max_redirects, fail_on_status_code. |
| 300 | |
| 301 | Returns: |
| 302 | An APIResponse object. |
| 303 | """ |
| 304 | return self._fetch(url, "PUT", **kwargs) |
| 305 | |
| 306 | def patch(self, url: str, **kwargs: Any) -> APIResponse: |
| 307 | """Send a PATCH request. |
no outgoing calls