Module aiogithubapi.models.response
GitHub response data class.
Expand source code
"""GitHub response data class."""
# pylint: disable=protected-access
from __future__ import annotations
from typing import Any, Dict, Generic
from aiohttp.client import ClientResponse
from yarl import URL
from ..const import GenericType, HttpStatusCode
from .base import GitHubDataModelBase
class GitHubResponseHeadersModel(GitHubDataModelBase):
"""GitHub response header model."""
access_control_allow_origin: str | None = None
access_control_expose_headers: str | None = None
cache_control: str | None = None
content_encoding: str | None = None
content_security_policy: str | None = None
content_length: str | None = None
content_type: str | None = None
date: str | None = None
etag: str | None = None
github_authentication_token_expiration: str | None = None
last_modified: str | None = None
link: str | None = None
referrer_policy: str | None = None
server: str | None = None
strict_transport_security: str | None = None
transfer_encoding: str | None = None
vary: str | None = None
retry_after: str | None = None
expect_ct: str | None = None
permissions_policy: str | None = None
x_accepted_oauth_scopes: str | None = None
x_commonmarker_version: str | None = None
x_content_type_options: str | None = None
x_frame_options: str | None = None
x_github_media_type: str | None = None
x_github_request_id: str | None = None
x_oauth_client_id: str | None = None
x_oauth_scopes: str | None = None
x_poll_interval: str | None = None
x_ratelimit_limit: str | None = None
x_ratelimit_remaining: str | None = None
x_ratelimit_reset: str | None = None
x_ratelimit_resource: str | None = None
x_ratelimit_used: str | None = None
x_xss_protection: str | None = None
class GitHubResponseModel(GitHubDataModelBase, Generic[GenericType]):
"""GitHub response data class."""
_process_data: bool = False
_raw_data: ClientResponse
_slugify_keys: bool = True
headers: GitHubResponseHeadersModel = None
status: HttpStatusCode = None
data: GenericType | None = None
def __post_init__(self):
"""Post init."""
self.headers = GitHubResponseHeadersModel(self._raw_data.headers)
self.status = self._raw_data.status
@property
def etag(self) -> str | None:
"""Return the ETag for this response."""
return self.headers.etag
@property
def pages(self) -> Dict[str, int]:
"""Return the pages for this response."""
return {
key: int(self._raw_data.links[key]["url"].query.get("page"))
for key in self._raw_data.links
}
@property
def is_last_page(self) -> bool:
"""Return True if this is the last page of results."""
if self.headers.link is None:
return True
return self.page_number == self.pages.get("last", self.page_number)
@property
def page_number(self) -> int:
"""Return the current page number."""
if self.headers.link is None:
return 1
if previous_page := self.pages.get("prev"):
return previous_page + 1
return 1
@property
def next_page_number(self) -> int | None:
"""Return the current page number."""
if self.headers.link is None:
return None
return self.pages.get("next", None)
@property
def last_page_number(self) -> int | None:
"""Return the current page number."""
if self.headers.link is None:
return None
return self.pages.get("last", None)
Classes
class GitHubResponseHeadersModel (data: Dict[str, Any])
-
GitHub response header model.
Init.
Expand source code
class GitHubResponseHeadersModel(GitHubDataModelBase): """GitHub response header model.""" access_control_allow_origin: str | None = None access_control_expose_headers: str | None = None cache_control: str | None = None content_encoding: str | None = None content_security_policy: str | None = None content_length: str | None = None content_type: str | None = None date: str | None = None etag: str | None = None github_authentication_token_expiration: str | None = None last_modified: str | None = None link: str | None = None referrer_policy: str | None = None server: str | None = None strict_transport_security: str | None = None transfer_encoding: str | None = None vary: str | None = None retry_after: str | None = None expect_ct: str | None = None permissions_policy: str | None = None x_accepted_oauth_scopes: str | None = None x_commonmarker_version: str | None = None x_content_type_options: str | None = None x_frame_options: str | None = None x_github_media_type: str | None = None x_github_request_id: str | None = None x_oauth_client_id: str | None = None x_oauth_scopes: str | None = None x_poll_interval: str | None = None x_ratelimit_limit: str | None = None x_ratelimit_remaining: str | None = None x_ratelimit_reset: str | None = None x_ratelimit_resource: str | None = None x_ratelimit_used: str | None = None x_xss_protection: str | None = None
Ancestors
Class variables
var access_control_allow_origin : str | None
var access_control_expose_headers : str | None
var cache_control : str | None
var content_encoding : str | None
var content_length : str | None
var content_security_policy : str | None
var content_type : str | None
var date : str | None
var etag : str | None
var expect_ct : str | None
var github_authentication_token_expiration : str | None
var last_modified : str | None
var link : str | None
var permissions_policy : str | None
var referrer_policy : str | None
var retry_after : str | None
var server : str | None
var strict_transport_security : str | None
var transfer_encoding : str | None
var vary : str | None
var x_accepted_oauth_scopes : str | None
var x_commonmarker_version : str | None
var x_content_type_options : str | None
var x_frame_options : str | None
var x_github_media_type : str | None
var x_github_request_id : str | None
var x_oauth_client_id : str | None
var x_oauth_scopes : str | None
var x_poll_interval : str | None
var x_ratelimit_limit : str | None
var x_ratelimit_remaining : str | None
var x_ratelimit_reset : str | None
var x_ratelimit_resource : str | None
var x_ratelimit_used : str | None
var x_xss_protection : str | None
Inherited members
class GitHubResponseModel (data: Dict[str, Any])
-
GitHub response data class.
Init.
Expand source code
class GitHubResponseModel(GitHubDataModelBase, Generic[GenericType]): """GitHub response data class.""" _process_data: bool = False _raw_data: ClientResponse _slugify_keys: bool = True headers: GitHubResponseHeadersModel = None status: HttpStatusCode = None data: GenericType | None = None def __post_init__(self): """Post init.""" self.headers = GitHubResponseHeadersModel(self._raw_data.headers) self.status = self._raw_data.status @property def etag(self) -> str | None: """Return the ETag for this response.""" return self.headers.etag @property def pages(self) -> Dict[str, int]: """Return the pages for this response.""" return { key: int(self._raw_data.links[key]["url"].query.get("page")) for key in self._raw_data.links } @property def is_last_page(self) -> bool: """Return True if this is the last page of results.""" if self.headers.link is None: return True return self.page_number == self.pages.get("last", self.page_number) @property def page_number(self) -> int: """Return the current page number.""" if self.headers.link is None: return 1 if previous_page := self.pages.get("prev"): return previous_page + 1 return 1 @property def next_page_number(self) -> int | None: """Return the current page number.""" if self.headers.link is None: return None return self.pages.get("next", None) @property def last_page_number(self) -> int | None: """Return the current page number.""" if self.headers.link is None: return None return self.pages.get("last", None)
Ancestors
- GitHubDataModelBase
- GitHubBase
- typing.Generic
Class variables
var data : GenericType | None
var headers : GitHubResponseHeadersModel
var status : HttpStatusCode
Instance variables
var etag : str | None
-
Return the ETag for this response.
Expand source code
@property def etag(self) -> str | None: """Return the ETag for this response.""" return self.headers.etag
var is_last_page : bool
-
Return True if this is the last page of results.
Expand source code
@property def is_last_page(self) -> bool: """Return True if this is the last page of results.""" if self.headers.link is None: return True return self.page_number == self.pages.get("last", self.page_number)
var last_page_number : int | None
-
Return the current page number.
Expand source code
@property def last_page_number(self) -> int | None: """Return the current page number.""" if self.headers.link is None: return None return self.pages.get("last", None)
var next_page_number : int | None
-
Return the current page number.
Expand source code
@property def next_page_number(self) -> int | None: """Return the current page number.""" if self.headers.link is None: return None return self.pages.get("next", None)
var page_number : int
-
Return the current page number.
Expand source code
@property def page_number(self) -> int: """Return the current page number.""" if self.headers.link is None: return 1 if previous_page := self.pages.get("prev"): return previous_page + 1 return 1
var pages : Dict[str, int]
-
Return the pages for this response.
Expand source code
@property def pages(self) -> Dict[str, int]: """Return the pages for this response.""" return { key: int(self._raw_data.links[key]["url"].query.get("page")) for key in self._raw_data.links }
Inherited members