11import os
2- from typing import Any , override
2+ from typing import Any
33
4- from httpx import URL , AsyncClient , AsyncHTTPTransport , HTTPError , HTTPStatusError , Response
5- from httpx ._client import USE_CLIENT_DEFAULT , UseClientDefault # noqa: PLC2701
6- from httpx ._types import ( # noqa: WPS235
7- AuthTypes ,
8- CookieTypes ,
9- HeaderTypes ,
10- QueryParamTypes ,
11- RequestContent ,
12- RequestData ,
13- RequestExtensions ,
14- RequestFiles ,
15- TimeoutTypes ,
4+ from httpx import (
5+ AsyncClient ,
6+ AsyncHTTPTransport ,
7+ HTTPError ,
8+ HTTPStatusError ,
169)
1710
1811from mpt_api_client .exceptions import MPTError , transform_http_status_exception
12+ from mpt_api_client .http .types import (
13+ HeaderTypes ,
14+ QueryParam ,
15+ RequestFiles ,
16+ Response ,
17+ )
1918
2019
21- class AsyncHTTPClient ( AsyncClient ) :
20+ class AsyncHTTPClient :
2221 """Async HTTP client for interacting with SoftwareOne Marketplace Platform API."""
2322
2423 def __init__ (
@@ -49,43 +48,49 @@ def __init__(
4948 "Authorization" : f"Bearer { api_token } " ,
5049 "Accept" : "application/json" ,
5150 }
52- super (). __init__ (
51+ self . httpx_client = AsyncClient (
5352 base_url = base_url ,
5453 headers = base_headers ,
5554 timeout = timeout ,
5655 transport = AsyncHTTPTransport (retries = retries ),
5756 )
5857
59- @override
6058 async def request ( # noqa: WPS211
6159 self ,
6260 method : str ,
63- url : URL | str ,
61+ url : str ,
6462 * ,
65- content : RequestContent | None = None , # noqa: WPS110
66- data : RequestData | None = None , # noqa: WPS110
6763 files : RequestFiles | None = None ,
6864 json : Any | None = None ,
69- params : QueryParamTypes | None = None , # noqa: WPS110
65+ query_params : QueryParam | None = None ,
7066 headers : HeaderTypes | None = None ,
71- cookies : CookieTypes | None = None ,
72- auth : AuthTypes | UseClientDefault | None = USE_CLIENT_DEFAULT ,
73- follow_redirects : bool | UseClientDefault = USE_CLIENT_DEFAULT ,
74- timeout : TimeoutTypes | UseClientDefault = USE_CLIENT_DEFAULT ,
75- extensions : RequestExtensions | None = None ,
7667 ) -> Response :
68+ """Perform an HTTP request.
69+
70+ Args:
71+ method: HTTP method.
72+ url: URL to send the request to.
73+ files: Request files.
74+ json: Request JSON data.
75+ query_params: Query parameters.
76+ headers: Request headers.
77+
78+ Returns:
79+ Response object.
80+
81+ Raises:
82+ MPTError: If the request fails.
83+ MPTApiError: If the response contains an error.
84+ MPTHttpError: If the response contains an HTTP error.
85+ """
7786 try :
78- response = await super () .request (
87+ response = await self . httpx_client .request (
7988 method ,
8089 url ,
81- content = content ,
82- data = data ,
8390 files = files ,
8491 json = json ,
85- params = params ,
92+ params = query_params ,
8693 headers = headers ,
87- cookies = cookies ,
88- auth = auth ,
8994 )
9095 except HTTPError as err :
9196 raise MPTError (f"HTTP Error: { err } " ) from err
@@ -94,4 +99,8 @@ async def request( # noqa: WPS211
9499 response .raise_for_status ()
95100 except HTTPStatusError as http_status_exception :
96101 raise transform_http_status_exception (http_status_exception ) from http_status_exception
97- return response
102+ return Response (
103+ headers = dict (response .headers ),
104+ status_code = response .status_code ,
105+ content = response .content ,
106+ )
0 commit comments