psnawp_api.core.request_builder module#

Provides the HTTP request handling interface.

class RequestBuilder(common_headers: RequestBuilderHeaders, rate_limit: Rate)[source]#

Bases: object

Handles 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) – LimiterSession object 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 via psnawp_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:
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:
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:
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:
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:
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:
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:
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:
class RequestOptions[source]#

Bases: TypedDict

A typing stub for the options that can be passed to a requests request.

allow_redirects: NotRequired[bool]#
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]#
stream: NotRequired[bool]#
timeout: NotRequired[_Timeout]#
url: str | bytes#
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: