psnawp_api.core.request_builder module#
Provides the HTTP request handling interface.
- class RequestBuilder(common_headers: RequestBuilderHeaders, rate_limit: Rate)[source]#
Bases:
objectHandles all the HTTP requests to PSN API and manages ratelimit.
- Variables:
common_headers (RequestBuilderHeaders) – Headers that will be passed in each HTTPs request.
session (LimiterSession) –
LimiterSessionobject with built-in rate limit capabilities. Limit is hardcoded to 300 requests per 15 minutes.
Note
This class is intended to be used via
Authenticator. If you want to override default headers for language and region, you may do so viapsnawp_api.psnawp.PSNAWP.__init__().Initialize Request Handler with default headers.
- Parameters:
common_headers – Default headers for the requests.
rate_limit – Controls pacing of HTTP requests to avoid service throttling.
- __init__(common_headers: RequestBuilderHeaders, rate_limit: Rate) None[source]#
Initialize Request Handler with default headers.
- Parameters:
common_headers – Default headers for the requests.
rate_limit – Controls pacing of HTTP requests to avoid service throttling.
- delete(**kwargs: Unpack[RequestOptions]) Response[source]#
Handles the DELETE requests and returns the requests.Response object.
- Parameters:
kwargs – The options for the DELETE request.
- Returns:
The Request Response Object.
- Raises:
PSNAWPBadRequestError – If the HTTP response status code is 400.
PSNAWPUnauthorizedError – If the HTTP response status code is 401.
PSNAWPForbiddenError – If the HTTP response status code is 403.
PSNAWPNotFoundError – If the HTTP response status code is 404.
PSNAWPNotAllowedError – If the HTTP response status code is 405.
PSNAWPTooManyRequestsError – If the HTTP response status code is 429.
PSNAWPClientError – If the HTTP response status code is in the 4xx range (excluding those listed above).
PSNAWPServerError – If the HTTP response status code is 500 or above.
- get(**kwargs: Unpack[RequestOptions]) Response[source]#
Handles the GET requests and returns the requests.Response object.
- Parameters:
kwargs – The options for the GET request.
- Returns:
The Request Response Object.
- Raises:
PSNAWPBadRequestError – If the HTTP response status code is 400.
PSNAWPUnauthorizedError – If the HTTP response status code is 401.
PSNAWPForbiddenError – If the HTTP response status code is 403.
PSNAWPNotFoundError – If the HTTP response status code is 404.
PSNAWPNotAllowedError – If the HTTP response status code is 405.
PSNAWPTooManyRequestsError – If the HTTP response status code is 429.
PSNAWPClientError – If the HTTP response status code is in the 4xx range (excluding those listed above).
PSNAWPServerError – If the HTTP response status code is 500 or above.
- head(**kwargs: Unpack[RequestOptions]) Response[source]#
Handles the HEAD requests and returns the requests.Response object.
- Parameters:
kwargs – The options for the HEAD request.
- Returns:
The Request Response Object.
- Raises:
PSNAWPBadRequestError – If the HTTP response status code is 400.
PSNAWPUnauthorizedError – If the HTTP response status code is 401.
PSNAWPForbiddenError – If the HTTP response status code is 403.
PSNAWPNotFoundError – If the HTTP response status code is 404.
PSNAWPNotAllowedError – If the HTTP response status code is 405.
PSNAWPTooManyRequestsError – If the HTTP response status code is 429.
PSNAWPClientError – If the HTTP response status code is in the 4xx range (excluding those listed above).
PSNAWPServerError – If the HTTP response status code is 500 or above.
- options(**kwargs: Unpack[RequestOptions]) Response[source]#
Handles the OPTIONS requests and returns the requests.Response object.
- Parameters:
kwargs – The options for the OPTIONS request.
- Returns:
The Request Response Object.
- Raises:
PSNAWPBadRequestError – If the HTTP response status code is 400.
PSNAWPUnauthorizedError – If the HTTP response status code is 401.
PSNAWPForbiddenError – If the HTTP response status code is 403.
PSNAWPNotFoundError – If the HTTP response status code is 404.
PSNAWPNotAllowedError – If the HTTP response status code is 405.
PSNAWPTooManyRequestsError – If the HTTP response status code is 429.
PSNAWPClientError – If the HTTP response status code is in the 4xx range (excluding those listed above).
PSNAWPServerError – If the HTTP response status code is 500 or above.
- patch(**kwargs: Unpack[RequestOptions]) Response[source]#
Handles the PATCH requests and returns the requests.Response object.
- Parameters:
kwargs – The options for the PATCH request.
- Returns:
The Request Response Object.
- Raises:
PSNAWPBadRequestError – If the HTTP response status code is 400.
PSNAWPUnauthorizedError – If the HTTP response status code is 401.
PSNAWPForbiddenError – If the HTTP response status code is 403.
PSNAWPNotFoundError – If the HTTP response status code is 404.
PSNAWPNotAllowedError – If the HTTP response status code is 405.
PSNAWPTooManyRequestsError – If the HTTP response status code is 429.
PSNAWPClientError – If the HTTP response status code is in the 4xx range (excluding those listed above).
PSNAWPServerError – If the HTTP response status code is 500 or above.
- post(**kwargs: Unpack[RequestOptions]) Response[source]#
Handles the POST requests and returns the requests.Response object.
- Parameters:
kwargs – The options for the POST request.
- Returns:
The Request Response Object.
- Raises:
PSNAWPBadRequestError – If the HTTP response status code is 400.
PSNAWPUnauthorizedError – If the HTTP response status code is 401.
PSNAWPForbiddenError – If the HTTP response status code is 403.
PSNAWPNotFoundError – If the HTTP response status code is 404.
PSNAWPNotAllowedError – If the HTTP response status code is 405.
PSNAWPTooManyRequestsError – If the HTTP response status code is 429.
PSNAWPClientError – If the HTTP response status code is in the 4xx range (excluding those listed above).
PSNAWPServerError – If the HTTP response status code is 500 or above.
- put(**kwargs: Unpack[RequestOptions]) Response[source]#
Handles the PUT requests and returns the requests.Response object.
- Parameters:
kwargs – The options for the PUT request.
- Returns:
The Request Response Object.
- Raises:
PSNAWPBadRequestError – If the HTTP response status code is 400.
PSNAWPUnauthorizedError – If the HTTP response status code is 401.
PSNAWPForbiddenError – If the HTTP response status code is 403.
PSNAWPNotFoundError – If the HTTP response status code is 404.
PSNAWPNotAllowedError – If the HTTP response status code is 405.
PSNAWPTooManyRequestsError – If the HTTP response status code is 429.
PSNAWPClientError – If the HTTP response status code is in the 4xx range (excluding those listed above).
PSNAWPServerError – If the HTTP response status code is 500 or above.
- request(method: str | bytes, **kwargs: Unpack[RequestOptions]) Response[source]#
Handles HTTP requests and returns the requests.Response object.
- Parameters:
method – The HTTP method to use for the request (e.g., GET, PATCH).
kwargs – The options for the HTTP request.
- Returns:
The Request Response Object.
- Raises:
PSNAWPBadRequestError – If the HTTP response status code is 400.
PSNAWPUnauthorizedError – If the HTTP response status code is 401.
PSNAWPForbiddenError – If the HTTP response status code is 403.
PSNAWPNotFoundError – If the HTTP response status code is 404.
PSNAWPNotAllowedError – If the HTTP response status code is 405.
PSNAWPTooManyRequestsError – If the HTTP response status code is 429.
PSNAWPClientError – If the HTTP response status code is in the 4xx range (excluding those listed above).
PSNAWPServerError – If the HTTP response status code is 500 or above.
- class RequestOptions[source]#
Bases:
TypedDictA typing stub for the options that can be passed to a requests request.
- auth: NotRequired[_Auth]#
- cert: NotRequired[_Cert]#
- cookies: NotRequired[RequestsCookieJar | _TextMapping]#
- data: NotRequired[_Data]#
- files: NotRequired[_Files]#
- headers: NotRequired[_TextMapping]#
- hooks: NotRequired[_HooksInput]#
- json: NotRequired[Any]#
- params: NotRequired[_Params]#
- proxies: NotRequired[_TextMapping]#
- timeout: NotRequired[_Timeout]#
- verify: NotRequired[_Verify]#
- response_checker(response: Response) None[source]#
Checks the HTTP(S) response and raises corresponding PSNAWP exceptions.
This function examines the status code of the HTTP response and raises PSNAWP exceptions based on error conditions.
- Parameters:
response (requests.Response) – The HTTP response object.
- Raises:
PSNAWPBadRequestError – If the HTTP response status code is 400.
PSNAWPUnauthorizedError – If the HTTP response status code is 401.
PSNAWPForbiddenError – If the HTTP response status code is 403.
PSNAWPNotFoundError – If the HTTP response status code is 404.
PSNAWPNotAllowedError – If the HTTP response status code is 405.
PSNAWPTooManyRequestsError – If the HTTP response status code is 429.
PSNAWPClientError – If the HTTP response status code is in the 4xx range (excluding those listed above).
PSNAWPServerError – If the HTTP response status code is 500 or above.