diff --git a/custom_templates/client.py.jinja b/custom_templates/client.py.jinja index 7057c5e..7bc7375 100644 --- a/custom_templates/client.py.jinja +++ b/custom_templates/client.py.jinja @@ -1,32 +1,57 @@ import base64 import ssl import warnings -from typing import Dict, Union +from typing import Any, Dict, Optional, Union + +import httpx +from attrs import evolve class Client: - """A class for keeping track of data related to the API + """A Client which has been authenticated for use on secured endpoints + + The following are accepted as keyword arguments and will be used to construct httpx Clients internally: + + ``base_url``: The base URL for the API, all requests are made to a relative path to this URL + + ``cookies``: A dictionary of cookies to be sent with every request + + ``headers``: A dictionary of headers to be sent with every request + + ``timeout``: The maximum amount of a time a request can take. API functions will raise + httpx.TimeoutException if this is exceeded. + + ``verify_ssl``: Whether or not to verify the SSL certificate of the API server. This should be True in production, + but can be set to False for testing purposes. + + ``follow_redirects``: Whether or not to follow redirects. Default value is False. + + ``httpx_args``: A dictionary of additional arguments to be passed to the ``httpx.Client`` and ``httpx.AsyncClient`` constructor. + Attributes: - cookies: A dictionary of cookies to be sent with every request - headers: A dictionary of headers to be sent with every request - timeout: The maximum amount of a time in seconds a request can take. API functions will raise - httpx.TimeoutException if this is exceeded. - verify_ssl: Whether or not to verify the SSL certificate of the API server. This should be True in production, - but can be set to False for testing purposes. raise_on_unexpected_status: Whether or not to raise an errors.UnexpectedStatus if the API returns a - status code that was not documented in the source OpenAPI document. - http2: Whether or not to use http2, enabled by default. + status code that was not documented in the source OpenAPI document. Can also be provided as a keyword + argument to the constructor. + token: The token to use for authentication + prefix: The prefix to use for the Authorization header + auth_header_name: The name of the Authorization header """ - cookies = {} + raise_on_unexpected_status: bool + _base_url: str = "https://ftc-api.firstinspires.org" + cookies: Dict[str, str] = {} headers: Dict[str, str] = {} - timeout: float = 5.0 + timeout: Optional[httpx.Timeout] = None verify_ssl: Union[str, bool, ssl.SSLContext] = True - raise_on_unexpected_status: bool = False + follow_redirects: bool = False + httpx_args: Dict[str, Any] = {} + _client: Optional[httpx.Client] = None + _async_client: Optional[httpx.AsyncClient] = None + + token: str prefix: str = "Basic" auth_header_name: str = "Authorization" - http2 = True def __init__(self, token=None, username="", authorization_key=""): if token is not None: @@ -37,19 +62,98 @@ class Client: base64_bytes = base64.b64encode(token_bytes) self.token = base64_bytes.decode("ascii") - def get_headers(self) -> Dict[str, str]: - auth_header_value = f"{self.prefix} {self.token}" if self.prefix else self.token - """Get headers to be used in authenticated endpoints""" - return {self.auth_header_name: auth_header_value, **self.headers} + def with_headers(self, headers: Dict[str, str]) -> "Client": + """Get a new client matching this one with additional headers""" + if self._client is not None: + self._client.headers.update(headers) + if self._async_client is not None: + self._async_client.headers.update(headers) + return evolve(self, headers={**self.headers, **headers}) - def get_cookies(self) -> Dict[str, str]: - return {**self.cookies} + def with_cookies(self, cookies: Dict[str, str]) -> "Client": + """Get a new client matching this one with additional cookies""" + if self._client is not None: + self._client.cookies.update(cookies) + if self._async_client is not None: + self._async_client.cookies.update(cookies) + return evolve(self, cookies={**self.cookies, **cookies}) - def get_timeout(self) -> float: - return self.timeout + def with_timeout(self, timeout: httpx.Timeout) -> "Client": + """Get a new client matching this one with a new timeout (in seconds)""" + if self._client is not None: + self._client.timeout = timeout + if self._async_client is not None: + self._async_client.timeout = timeout + return evolve(self, timeout=timeout) + + def set_httpx_client(self, client: httpx.Client) -> "Client": + """Manually the underlying httpx.Client + + **NOTE**: This will override any other settings on the client, including cookies, headers, and timeout. + """ + self._client = client + return self + + def get_httpx_client(self) -> httpx.Client: + """Get the underlying httpx.Client, constructing a new one if not previously set""" + if self._client is None: + self.headers[self.auth_header_name] = f"{self.prefix} {self.token}" if self.prefix else self.token + self._client = httpx.Client( + base_url=self._base_url, + cookies=self.cookies, + headers=self.headers, + timeout=self.timeout, + verify=self.verify_ssl, + follow_redirects=self.follow_redirects, + **self.httpx_args, + ) + return self._client + + def __enter__(self) -> "Client": + """Enter a context manager for self.client—you cannot enter twice (see httpx docs)""" + self.get_httpx_client().__enter__() + return self + + def __exit__(self, *args: Any, **kwargs: Any) -> None: + """Exit a context manager for internal httpx.Client (see httpx docs)""" + self.get_httpx_client().__exit__(*args, **kwargs) + + def set_async_httpx_client(self, async_client: httpx.AsyncClient) -> "Client": + """Manually the underlying httpx.AsyncClient + + **NOTE**: This will override any other settings on the client, including cookies, headers, and timeout. + """ + self._async_client = async_client + return self + + def get_async_httpx_client(self) -> httpx.AsyncClient: + """Get the underlying httpx.AsyncClient, constructing a new one if not previously set""" + if self._async_client is None: + self.headers[self.auth_header_name] = f"{self.prefix} {self.token}" if self.prefix else self.token + self._async_client = httpx.AsyncClient( + base_url=self._base_url, + cookies=self.cookies, + headers=self.headers, + timeout=self.timeout, + verify=self.verify_ssl, + follow_redirects=self.follow_redirects, + **self.httpx_args, + ) + return self._async_client + + async def __aenter__(self) -> "Client": + """Enter a context manager for underlying httpx.AsyncClient—you cannot enter twice (see httpx docs)""" + await self.get_async_httpx_client().__aenter__() + return self + + async def __aexit__(self, *args: Any, **kwargs: Any) -> None: + """Exit a context manager for underlying httpx.AsyncClient (see httpx docs)""" + await self.get_async_httpx_client().__aexit__(*args, **kwargs) class AuthenticatedClient(Client): """Deprecated, use Client instead, as it has equivalent functionality, will be removed v1.0.0""" - warnings.warn("Will be removed v1.0.0 switch to Client because the functionality has been merged.", - DeprecationWarning) + + warnings.warn( + "Will be removed v1.0.0 switch to Client because the functionality has been merged.", DeprecationWarning + ) diff --git a/custom_templates/endpoint_macros.py.jinja b/custom_templates/endpoint_macros.py.jinja new file mode 100644 index 0000000..a9256d9 --- /dev/null +++ b/custom_templates/endpoint_macros.py.jinja @@ -0,0 +1,185 @@ +{% from "property_templates/helpers.jinja" import guarded_statement %} +{% from "helpers.jinja" import safe_docstring %} + +{% macro header_params(endpoint) %} +{% if endpoint.header_parameters %} +headers = {} + {% for parameter in endpoint.header_parameters.values() %} + {% import "property_templates/" + parameter.template as param_template %} + {% if param_template.transform_header %} + {% set expression = param_template.transform_header(parameter.python_name) %} + {% else %} + {% set expression = parameter.python_name %} + {% endif %} + {% set statement = 'headers["' + parameter.name + '"]' + " = " + expression %} +{{ guarded_statement(parameter, parameter.python_name, statement) }} + {% endfor %} +{% endif %} +{% endmacro %} + +{% macro cookie_params(endpoint) %} +cookies = {} +{% if endpoint.cookie_parameters %} + {% for parameter in endpoint.cookie_parameters.values() %} + {% if parameter.required %} +cookies["{{ parameter.name}}"] = {{ parameter.python_name }} + {% else %} +if {{ parameter.python_name }} is not UNSET: + cookies["{{ parameter.name}}"] = {{ parameter.python_name }} + {% endif %} + {% endfor %} +{% endif %} +{% endmacro %} + + +{% macro query_params(endpoint) %} +{% if endpoint.query_parameters %} +params: Dict[str, Any] = {} +{% for property in endpoint.query_parameters.values() %} + {% set destination = property.python_name %} + {% import "property_templates/" + property.template as prop_template %} + {% if prop_template.transform %} + {% set destination = "json_" + property.python_name %} +{{ prop_template.transform(property, property.python_name, destination) }} + {% endif %} + {%- if not property.json_is_dict %} +params["{{ property.name }}"] = {{ destination }} + {% else %} +{{ guarded_statement(property, destination, "params.update(" + destination + ")") }} + {% endif %} + + +{% endfor %} + +params = {k: v for k, v in params.items() if v is not UNSET and v is not None} +{% endif %} +{% endmacro %} + +{% macro json_body(endpoint) %} +{% if endpoint.json_body %} + {% set property = endpoint.json_body %} + {% set destination = "json_" + property.python_name %} + {% import "property_templates/" + property.template as prop_template %} + {% if prop_template.transform %} +{{ prop_template.transform(property, property.python_name, destination) }} + {% else %} +{{ destination }} = {{ property.python_name }} + {% endif %} +{% endif %} +{% endmacro %} + +{% macro multipart_body(endpoint) %} +{% if endpoint.multipart_body %} + {% set property = endpoint.multipart_body %} + {% set destination = "multipart_" + property.python_name %} + {% import "property_templates/" + property.template as prop_template %} + {% if prop_template.transform_multipart %} +{{ prop_template.transform_multipart(property, property.python_name, destination) }} + {% endif %} +{% endif %} +{% endmacro %} + +{# The all the kwargs passed into an endpoint (and variants thereof)) #} +{% macro arguments(endpoint, include_client=True) %} +{# path parameters #} +{% for parameter in endpoint.path_parameters.values() %} +{{ parameter.to_string() }}, +{% endfor %} +{% if include_client or ((endpoint.list_all_parameters() | length) > (endpoint.path_parameters | length)) %} +*, +{% endif %} +{# Proper client based on whether or not the endpoint requires authentication #} +{% if include_client %} +{% if endpoint.requires_security %} +client: Union[AuthenticatedClient, Client], +{% else %} +client: Union[AuthenticatedClient, Client], +{% endif %} +{% endif %} +{# Form data if any #} +{% if endpoint.form_body %} +form_data: {{ endpoint.form_body.get_type_string() }}, +{% endif %} +{# Multipart data if any #} +{% if endpoint.multipart_body %} +multipart_data: {{ endpoint.multipart_body.get_type_string() }}, +{% endif %} +{# JSON body if any #} +{% if endpoint.json_body %} +json_body: {{ endpoint.json_body.get_type_string() }}, +{% endif %} +{# query parameters #} +{% for parameter in endpoint.query_parameters.values() %} +{{ parameter.to_string() }}, +{% endfor %} +{% for parameter in endpoint.header_parameters.values() %} +{{ parameter.to_string() }}, +{% endfor %} +{# cookie parameters #} +{% for parameter in endpoint.cookie_parameters.values() %} +{{ parameter.to_string() }}, +{% endfor %} +{% endmacro %} + +{# Just lists all kwargs to endpoints as name=name for passing to other functions #} +{% macro kwargs(endpoint, include_client=True) %} +{% for parameter in endpoint.path_parameters.values() %} +{{ parameter.python_name }}={{ parameter.python_name }}, +{% endfor %} +{% if include_client %} +client=client, +{% endif %} +{% if endpoint.form_body %} +form_data=form_data, +{% endif %} +{% if endpoint.multipart_body %} +multipart_data=multipart_data, +{% endif %} +{% if endpoint.json_body %} +json_body=json_body, +{% endif %} +{% for parameter in endpoint.query_parameters.values() %} +{{ parameter.python_name }}={{ parameter.python_name }}, +{% endfor %} +{% for parameter in endpoint.header_parameters.values() %} +{{ parameter.python_name }}={{ parameter.python_name }}, +{% endfor %} +{% for parameter in endpoint.cookie_parameters.values() %} +{{ parameter.python_name }}={{ parameter.python_name }}, +{% endfor %} +{% endmacro %} + +{% macro docstring_content(endpoint, return_string, is_detailed) %} +{% if endpoint.summary %}{{ endpoint.summary | wordwrap(100)}} + +{% endif -%} +{%- if endpoint.description %} {{ endpoint.description | wordwrap(100) }} + +{% endif %} +{% if not endpoint.summary and not endpoint.description %} +{# Leave extra space so that Args or Returns isn't at the top #} + +{% endif %} +{% set all_parameters = endpoint.list_all_parameters() %} +{% if all_parameters %} +Args: + {% for parameter in all_parameters %} + {{ parameter.to_docstring() | wordwrap(90) | indent(8) }} + {% endfor %} + +{% endif %} +Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + +Returns: +{% if is_detailed %} + Response[{{ return_string }}] +{% else %} + {{ return_string }} +{% endif %} +{% endmacro %} + +{% macro docstring(endpoint, return_string, is_detailed) %} +{{ safe_docstring(docstring_content(endpoint, return_string, is_detailed)) }} +{% endmacro %} \ No newline at end of file diff --git a/custom_templates/endpoint_module.py.jinja b/custom_templates/endpoint_module.py.jinja deleted file mode 100644 index b5c5fc6..0000000 --- a/custom_templates/endpoint_module.py.jinja +++ /dev/null @@ -1,143 +0,0 @@ -from http import HTTPStatus -from typing import Any, Dict, List, Optional, Union, cast - -import httpx - -from ...client import AuthenticatedClient, Client -from ...types import Response, UNSET -from ... import errors - -{% for relative in endpoint.relative_imports %} -{{ relative }} -{% endfor %} - -{% from "endpoint_macros.py.jinja" import header_params, cookie_params, query_params, json_body, multipart_body, - arguments, client, kwargs, parse_response, docstring %} - -{% set return_string = endpoint.response_type() %} -{% set parsed_responses = (endpoint.responses | length > 0) and return_string != "Any" %} - -def _get_kwargs( - {{ arguments(endpoint) | indent(4) }} -) -> Dict[str, Any]: - url = "{}{{ endpoint.path }}".format( - "https://ftc-api.firstinspires.org" - {%- for parameter in endpoint.path_parameters.values() -%} - ,{{parameter.name}}={{parameter.python_name}} - {%- endfor -%} - ) - - headers: Dict[str, str] = client.get_headers() - cookies: Dict[str, Any] = client.get_cookies() - - {{ header_params(endpoint) | indent(4) }} - - {{ cookie_params(endpoint) | indent(4) }} - - {{ query_params(endpoint) | indent(4) }} - - {{ json_body(endpoint) | indent(4) }} - - {{ multipart_body(endpoint) | indent(4) }} - - return { - "method": "{{ endpoint.method }}", - "url": url, - "headers": headers, - "cookies": cookies, - "timeout": client.get_timeout(), - {% if endpoint.form_body %} - "data": form_data.to_dict(), - {% elif endpoint.multipart_body %} - "files": {{ "multipart_" + endpoint.multipart_body.python_name }}, - {% elif endpoint.json_body %} - "json": {{ "json_" + endpoint.json_body.python_name }}, - {% endif %} - {% if endpoint.query_parameters %} - "params": params, - {% endif %} - } - - -def _parse_response(*, client: Client, response: httpx.Response) -> Optional[{{ return_string }}]: - {% for response in endpoint.responses %} - if response.status_code == HTTPStatus.{{ response.status_code.name }}: - {% if parsed_responses %}{% import "property_templates/" + response.prop.template as prop_template %} - {% if prop_template.construct %} - {{ prop_template.construct(response.prop, response.source) | indent(8) }} - {% else %} - {{ response.prop.python_name }} = cast({{ response.prop.get_type_string() }}, {{ response.source }}) - {% endif %} - return {{ response.prop.python_name }} - {% else %} - return None - {% endif %} - {% endfor %} - if client.raise_on_unexpected_status: - raise errors.UnexpectedStatus(f"Unexpected status code: {response.status_code}") - else: - return None - - -def _build_response(*, client: Client, response: httpx.Response) -> Response[{{ return_string }}]: - return Response( - status_code=HTTPStatus(response.status_code), - content=response.content, - headers=response.headers, - parsed=_parse_response(client=client, response=response), - ) - - -def sync_detailed( - {{ arguments(endpoint) | indent(4) }} -) -> Response[{{ return_string }}]: - {{ docstring(endpoint, return_string) | indent(4) }} - - kwargs = _get_kwargs( - {{ kwargs(endpoint) }} - ) - - response = httpx.request( - verify=client.verify_ssl, - **kwargs, - ) - - return _build_response(client=client, response=response) - -{% if parsed_responses %} -def sync( - {{ arguments(endpoint) | indent(4) }} -) -> Optional[{{ return_string }}]: - {{ docstring(endpoint, return_string) | indent(4) }} - - return sync_detailed( - {{ kwargs(endpoint) }} - ).parsed -{% endif %} - -async def asyncio_detailed( - {{ arguments(endpoint) | indent(4) }} -) -> Response[{{ return_string }}]: - {{ docstring(endpoint, return_string) | indent(4) }} - - kwargs = _get_kwargs( - {{ kwargs(endpoint) }} - ) - - async with httpx.AsyncClient(verify=client.verify_ssl) as _client: - response = await _client.request( - **kwargs - ) - - return _build_response(client=client, response=response) - -{% if parsed_responses %} -async def asyncio( - {{ arguments(endpoint) | indent(4) }} -) -> Optional[{{ return_string }}]: - {{ docstring(endpoint, return_string) | indent(4) }} - - return (await asyncio_detailed( - {{ kwargs(endpoint) }} - )).parsed -{% endif %} \ No newline at end of file diff --git a/custom_templates/pyproject.toml.jinja b/custom_templates/pyproject.toml.jinja deleted file mode 100644 index d79d531..0000000 --- a/custom_templates/pyproject.toml.jinja +++ /dev/null @@ -1,26 +0,0 @@ -[project] -name = "ftc_api" -description = "A python client to access the FIRST Tech Challenge API" -authors = [ - { name = "Ashwin Naren", email = "arihant2math@gmail.com" } -] -license = {file = "LICENSE"} -readme = "README.md" -version = "0.1.1" -dependencies = [ - "httpx", "python-dateutil", "attrs" -] -keywords = ["ftc"] -requires-python = ">=3.7" - -[project.optional-dependencies] -dev = [ - "black", "sphinx", "furo" -] - -[build-system] -requires = ["setuptools"] -build-backend = "setuptools.build_meta" - -[tool.setuptools] -packages = ["ftc_api", "ftc_api.api", "ftc_api.models"] diff --git a/ftc_api/api/alliance_selection/get_v_2_0_season_alliances_event_code.py b/ftc_api/api/alliance_selection/get_v_2_0_season_alliances_event_code.py index 39dd176..28163c7 100644 --- a/ftc_api/api/alliance_selection/get_v_2_0_season_alliances_event_code.py +++ b/ftc_api/api/alliance_selection/get_v_2_0_season_alliances_event_code.py @@ -12,27 +12,20 @@ def _get_kwargs( season: int, event_code: Optional[str], - *, - client: AuthenticatedClient, ) -> Dict[str, Any]: - url = "{}/v2.0/{season}/alliances/{eventCode}".format( - "https://ftc-api.firstinspires.org", season=season, eventCode=event_code - ) - - headers: Dict[str, str] = client.get_headers() - cookies: Dict[str, Any] = client.get_cookies() + pass return { "method": "get", - "url": url, - "headers": headers, - "cookies": cookies, - "timeout": client.get_timeout(), + "url": "/v2.0/{season}/alliances/{eventCode}".format( + season=season, + eventCode=event_code, + ), } def _parse_response( - *, client: Client, response: httpx.Response + *, client: Union[AuthenticatedClient, Client], response: httpx.Response ) -> Optional[Union[AllianceSelection, Any]]: if response.status_code == HTTPStatus.OK: response_200 = AllianceSelection.from_dict(response.json()) @@ -42,13 +35,13 @@ def _parse_response( response_401 = cast(Any, None) return response_401 if client.raise_on_unexpected_status: - raise errors.UnexpectedStatus(f"Unexpected status code: {response.status_code}") + raise errors.UnexpectedStatus(response.status_code, response.content) else: return None def _build_response( - *, client: Client, response: httpx.Response + *, client: Union[AuthenticatedClient, Client], response: httpx.Response ) -> Response[Union[AllianceSelection, Any]]: return Response( status_code=HTTPStatus(response.status_code), @@ -84,11 +77,9 @@ def sync_detailed( kwargs = _get_kwargs( season=season, event_code=event_code, - client=client, ) - response = httpx.request( - verify=client.verify_ssl, + response = client.get_httpx_client().request( **kwargs, ) @@ -115,7 +106,7 @@ def sync( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[AllianceSelection, Any]] + Union[AllianceSelection, Any] """ return sync_detailed( @@ -151,11 +142,9 @@ async def asyncio_detailed( kwargs = _get_kwargs( season=season, event_code=event_code, - client=client, ) - async with httpx.AsyncClient(verify=client.verify_ssl) as _client: - response = await _client.request(**kwargs) + response = await client.get_async_httpx_client().request(**kwargs) return _build_response(client=client, response=response) @@ -180,7 +169,7 @@ async def asyncio( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[AllianceSelection, Any]] + Union[AllianceSelection, Any] """ return ( diff --git a/ftc_api/api/alliance_selection/get_v_2_0_season_alliances_event_code_selection.py b/ftc_api/api/alliance_selection/get_v_2_0_season_alliances_event_code_selection.py index 225825b..494f4fa 100644 --- a/ftc_api/api/alliance_selection/get_v_2_0_season_alliances_event_code_selection.py +++ b/ftc_api/api/alliance_selection/get_v_2_0_season_alliances_event_code_selection.py @@ -12,27 +12,20 @@ def _get_kwargs( season: int, event_code: Optional[str], - *, - client: AuthenticatedClient, ) -> Dict[str, Any]: - url = "{}/v2.0/{season}/alliances/{eventCode}/selection".format( - "https://ftc-api.firstinspires.org", season=season, eventCode=event_code - ) - - headers: Dict[str, str] = client.get_headers() - cookies: Dict[str, Any] = client.get_cookies() + pass return { "method": "get", - "url": url, - "headers": headers, - "cookies": cookies, - "timeout": client.get_timeout(), + "url": "/v2.0/{season}/alliances/{eventCode}/selection".format( + season=season, + eventCode=event_code, + ), } def _parse_response( - *, client: Client, response: httpx.Response + *, client: Union[AuthenticatedClient, Client], response: httpx.Response ) -> Optional[Union[AllianceSelectionDetails, Any]]: if response.status_code == HTTPStatus.OK: response_200 = AllianceSelectionDetails.from_dict(response.json()) @@ -42,13 +35,13 @@ def _parse_response( response_401 = cast(Any, None) return response_401 if client.raise_on_unexpected_status: - raise errors.UnexpectedStatus(f"Unexpected status code: {response.status_code}") + raise errors.UnexpectedStatus(response.status_code, response.content) else: return None def _build_response( - *, client: Client, response: httpx.Response + *, client: Union[AuthenticatedClient, Client], response: httpx.Response ) -> Response[Union[AllianceSelectionDetails, Any]]: return Response( status_code=HTTPStatus(response.status_code), @@ -84,11 +77,9 @@ def sync_detailed( kwargs = _get_kwargs( season=season, event_code=event_code, - client=client, ) - response = httpx.request( - verify=client.verify_ssl, + response = client.get_httpx_client().request( **kwargs, ) @@ -115,7 +106,7 @@ def sync( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[AllianceSelectionDetails, Any]] + Union[AllianceSelectionDetails, Any] """ return sync_detailed( @@ -151,11 +142,9 @@ async def asyncio_detailed( kwargs = _get_kwargs( season=season, event_code=event_code, - client=client, ) - async with httpx.AsyncClient(verify=client.verify_ssl) as _client: - response = await _client.request(**kwargs) + response = await client.get_async_httpx_client().request(**kwargs) return _build_response(client=client, response=response) @@ -180,7 +169,7 @@ async def asyncio( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[AllianceSelectionDetails, Any]] + Union[AllianceSelectionDetails, Any] """ return ( diff --git a/ftc_api/api/awards/get_v2_0_season_awards_list.py b/ftc_api/api/awards/get_v2_0_season_awards_list.py index 8db19ff..9ee3b0d 100644 --- a/ftc_api/api/awards/get_v2_0_season_awards_list.py +++ b/ftc_api/api/awards/get_v2_0_season_awards_list.py @@ -11,27 +11,19 @@ def _get_kwargs( season: int, - *, - client: AuthenticatedClient, ) -> Dict[str, Any]: - url = "{}/v2.0/{season}/awards/list".format( - "https://ftc-api.firstinspires.org", season=season - ) - - headers: Dict[str, str] = client.get_headers() - cookies: Dict[str, Any] = client.get_cookies() + pass return { "method": "get", - "url": url, - "headers": headers, - "cookies": cookies, - "timeout": client.get_timeout(), + "url": "/v2.0/{season}/awards/list".format( + season=season, + ), } def _parse_response( - *, client: Client, response: httpx.Response + *, client: Union[AuthenticatedClient, Client], response: httpx.Response ) -> Optional[Union[Any, AwardList]]: if response.status_code == HTTPStatus.OK: response_200 = AwardList.from_dict(response.json()) @@ -41,13 +33,13 @@ def _parse_response( response_401 = cast(Any, None) return response_401 if client.raise_on_unexpected_status: - raise errors.UnexpectedStatus(f"Unexpected status code: {response.status_code}") + raise errors.UnexpectedStatus(response.status_code, response.content) else: return None def _build_response( - *, client: Client, response: httpx.Response + *, client: Union[AuthenticatedClient, Client], response: httpx.Response ) -> Response[Union[Any, AwardList]]: return Response( status_code=HTTPStatus(response.status_code), @@ -82,11 +74,9 @@ def sync_detailed( kwargs = _get_kwargs( season=season, - client=client, ) - response = httpx.request( - verify=client.verify_ssl, + response = client.get_httpx_client().request( **kwargs, ) @@ -113,7 +103,7 @@ def sync( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[Any, AwardList]] + Union[Any, AwardList] """ return sync_detailed( @@ -147,11 +137,9 @@ async def asyncio_detailed( kwargs = _get_kwargs( season=season, - client=client, ) - async with httpx.AsyncClient(verify=client.verify_ssl) as _client: - response = await _client.request(**kwargs) + response = await client.get_async_httpx_client().request(**kwargs) return _build_response(client=client, response=response) @@ -176,7 +164,7 @@ async def asyncio( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[Any, AwardList]] + Union[Any, AwardList] """ return ( diff --git a/ftc_api/api/awards/get_v_2_0_season_awards_event_code.py b/ftc_api/api/awards/get_v_2_0_season_awards_event_code.py index 9d766ca..263cba1 100644 --- a/ftc_api/api/awards/get_v_2_0_season_awards_event_code.py +++ b/ftc_api/api/awards/get_v_2_0_season_awards_event_code.py @@ -13,15 +13,9 @@ def _get_kwargs( season: int, event_code: Optional[str] = "", *, - client: AuthenticatedClient, team_number: Union[Unset, None, int] = 0, ) -> Dict[str, Any]: - url = "{}/v2.0/{season}/awards/{eventCode}".format( - "https://ftc-api.firstinspires.org", season=season, eventCode=event_code - ) - - headers: Dict[str, str] = client.get_headers() - cookies: Dict[str, Any] = client.get_cookies() + pass params: Dict[str, Any] = {} params["teamNumber"] = team_number @@ -30,16 +24,16 @@ def _get_kwargs( return { "method": "get", - "url": url, - "headers": headers, - "cookies": cookies, - "timeout": client.get_timeout(), + "url": "/v2.0/{season}/awards/{eventCode}".format( + season=season, + eventCode=event_code, + ), "params": params, } def _parse_response( - *, client: Client, response: httpx.Response + *, client: Union[AuthenticatedClient, Client], response: httpx.Response ) -> Optional[Union[Any, AwardAssignmentList]]: if response.status_code == HTTPStatus.OK: response_200 = AwardAssignmentList.from_dict(response.json()) @@ -49,13 +43,13 @@ def _parse_response( response_401 = cast(Any, None) return response_401 if client.raise_on_unexpected_status: - raise errors.UnexpectedStatus(f"Unexpected status code: {response.status_code}") + raise errors.UnexpectedStatus(response.status_code, response.content) else: return None def _build_response( - *, client: Client, response: httpx.Response + *, client: Union[AuthenticatedClient, Client], response: httpx.Response ) -> Response[Union[Any, AwardAssignmentList]]: return Response( status_code=HTTPStatus(response.status_code), @@ -99,12 +93,10 @@ def sync_detailed( kwargs = _get_kwargs( season=season, event_code=event_code, - client=client, team_number=team_number, ) - response = httpx.request( - verify=client.verify_ssl, + response = client.get_httpx_client().request( **kwargs, ) @@ -139,7 +131,7 @@ def sync( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[Any, AwardAssignmentList]] + Union[Any, AwardAssignmentList] """ return sync_detailed( @@ -184,12 +176,10 @@ async def asyncio_detailed( kwargs = _get_kwargs( season=season, event_code=event_code, - client=client, team_number=team_number, ) - async with httpx.AsyncClient(verify=client.verify_ssl) as _client: - response = await _client.request(**kwargs) + response = await client.get_async_httpx_client().request(**kwargs) return _build_response(client=client, response=response) @@ -222,7 +212,7 @@ async def asyncio( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[Any, AwardAssignmentList]] + Union[Any, AwardAssignmentList] """ return ( diff --git a/ftc_api/api/awards/get_v_2_0_season_awards_event_code_team_number.py b/ftc_api/api/awards/get_v_2_0_season_awards_event_code_team_number.py index 7e8b37f..5f77c8f 100644 --- a/ftc_api/api/awards/get_v_2_0_season_awards_event_code_team_number.py +++ b/ftc_api/api/awards/get_v_2_0_season_awards_event_code_team_number.py @@ -13,30 +13,21 @@ def _get_kwargs( season: int, event_code: Optional[str] = "", team_number: int = 0, - *, - client: AuthenticatedClient, ) -> Dict[str, Any]: - url = "{}/v2.0/{season}/awards/{eventCode}/{teamNumber}".format( - "https://ftc-api.firstinspires.org", - season=season, - eventCode=event_code, - teamNumber=team_number, - ) - - headers: Dict[str, str] = client.get_headers() - cookies: Dict[str, Any] = client.get_cookies() + pass return { "method": "get", - "url": url, - "headers": headers, - "cookies": cookies, - "timeout": client.get_timeout(), + "url": "/v2.0/{season}/awards/{eventCode}/{teamNumber}".format( + season=season, + eventCode=event_code, + teamNumber=team_number, + ), } def _parse_response( - *, client: Client, response: httpx.Response + *, client: Union[AuthenticatedClient, Client], response: httpx.Response ) -> Optional[Union[Any, AwardAssignmentList]]: if response.status_code == HTTPStatus.OK: response_200 = AwardAssignmentList.from_dict(response.json()) @@ -46,13 +37,13 @@ def _parse_response( response_401 = cast(Any, None) return response_401 if client.raise_on_unexpected_status: - raise errors.UnexpectedStatus(f"Unexpected status code: {response.status_code}") + raise errors.UnexpectedStatus(response.status_code, response.content) else: return None def _build_response( - *, client: Client, response: httpx.Response + *, client: Union[AuthenticatedClient, Client], response: httpx.Response ) -> Response[Union[Any, AwardAssignmentList]]: return Response( status_code=HTTPStatus(response.status_code), @@ -97,11 +88,9 @@ def sync_detailed( season=season, event_code=event_code, team_number=team_number, - client=client, ) - response = httpx.request( - verify=client.verify_ssl, + response = client.get_httpx_client().request( **kwargs, ) @@ -136,7 +125,7 @@ def sync( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[Any, AwardAssignmentList]] + Union[Any, AwardAssignmentList] """ return sync_detailed( @@ -182,11 +171,9 @@ async def asyncio_detailed( season=season, event_code=event_code, team_number=team_number, - client=client, ) - async with httpx.AsyncClient(verify=client.verify_ssl) as _client: - response = await _client.request(**kwargs) + response = await client.get_async_httpx_client().request(**kwargs) return _build_response(client=client, response=response) @@ -219,7 +206,7 @@ async def asyncio( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[Any, AwardAssignmentList]] + Union[Any, AwardAssignmentList] """ return ( diff --git a/ftc_api/api/awards/get_v_2_0_season_awards_team_number.py b/ftc_api/api/awards/get_v_2_0_season_awards_team_number.py index 8edb762..d4f8132 100644 --- a/ftc_api/api/awards/get_v_2_0_season_awards_team_number.py +++ b/ftc_api/api/awards/get_v_2_0_season_awards_team_number.py @@ -13,15 +13,9 @@ def _get_kwargs( season: int, team_number: int = 0, *, - client: AuthenticatedClient, event_code: Union[Unset, None, str] = "", ) -> Dict[str, Any]: - url = "{}/v2.0/{season}/awards/{teamNumber}".format( - "https://ftc-api.firstinspires.org", season=season, teamNumber=team_number - ) - - headers: Dict[str, str] = client.get_headers() - cookies: Dict[str, Any] = client.get_cookies() + pass params: Dict[str, Any] = {} params["eventCode"] = event_code @@ -30,16 +24,16 @@ def _get_kwargs( return { "method": "get", - "url": url, - "headers": headers, - "cookies": cookies, - "timeout": client.get_timeout(), + "url": "/v2.0/{season}/awards/{teamNumber}".format( + season=season, + teamNumber=team_number, + ), "params": params, } def _parse_response( - *, client: Client, response: httpx.Response + *, client: Union[AuthenticatedClient, Client], response: httpx.Response ) -> Optional[Union[Any, AwardAssignmentList]]: if response.status_code == HTTPStatus.OK: response_200 = AwardAssignmentList.from_dict(response.json()) @@ -49,13 +43,13 @@ def _parse_response( response_401 = cast(Any, None) return response_401 if client.raise_on_unexpected_status: - raise errors.UnexpectedStatus(f"Unexpected status code: {response.status_code}") + raise errors.UnexpectedStatus(response.status_code, response.content) else: return None def _build_response( - *, client: Client, response: httpx.Response + *, client: Union[AuthenticatedClient, Client], response: httpx.Response ) -> Response[Union[Any, AwardAssignmentList]]: return Response( status_code=HTTPStatus(response.status_code), @@ -99,12 +93,10 @@ def sync_detailed( kwargs = _get_kwargs( season=season, team_number=team_number, - client=client, event_code=event_code, ) - response = httpx.request( - verify=client.verify_ssl, + response = client.get_httpx_client().request( **kwargs, ) @@ -139,7 +131,7 @@ def sync( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[Any, AwardAssignmentList]] + Union[Any, AwardAssignmentList] """ return sync_detailed( @@ -184,12 +176,10 @@ async def asyncio_detailed( kwargs = _get_kwargs( season=season, team_number=team_number, - client=client, event_code=event_code, ) - async with httpx.AsyncClient(verify=client.verify_ssl) as _client: - response = await _client.request(**kwargs) + response = await client.get_async_httpx_client().request(**kwargs) return _build_response(client=client, response=response) @@ -222,7 +212,7 @@ async def asyncio( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[Any, AwardAssignmentList]] + Union[Any, AwardAssignmentList] """ return ( diff --git a/ftc_api/api/general/get_v2_0.py b/ftc_api/api/general/get_v2_0.py index 7069a2d..499b816 100644 --- a/ftc_api/api/general/get_v2_0.py +++ b/ftc_api/api/general/get_v2_0.py @@ -1,47 +1,38 @@ from http import HTTPStatus -from typing import Any, Dict, Optional +from typing import Any, Dict, Optional, Union import httpx from ... import errors -from ...client import Client +from ...client import AuthenticatedClient, Client from ...models.api_information import APIInformation from ...types import Response -def _get_kwargs( - *, - client: Client, -) -> Dict[str, Any]: - url = "{}/v2.0".format("https://ftc-api.firstinspires.org") - - headers: Dict[str, str] = client.get_headers() - cookies: Dict[str, Any] = client.get_cookies() +def _get_kwargs() -> Dict[str, Any]: + pass return { "method": "get", - "url": url, - "headers": headers, - "cookies": cookies, - "timeout": client.get_timeout(), + "url": "/v2.0", } def _parse_response( - *, client: Client, response: httpx.Response + *, client: Union[AuthenticatedClient, Client], response: httpx.Response ) -> Optional[APIInformation]: if response.status_code == HTTPStatus.OK: response_200 = APIInformation.from_dict(response.json()) return response_200 if client.raise_on_unexpected_status: - raise errors.UnexpectedStatus(f"Unexpected status code: {response.status_code}") + raise errors.UnexpectedStatus(response.status_code, response.content) else: return None def _build_response( - *, client: Client, response: httpx.Response + *, client: Union[AuthenticatedClient, Client], response: httpx.Response ) -> Response[APIInformation]: return Response( status_code=HTTPStatus(response.status_code), @@ -53,7 +44,7 @@ def _build_response( def sync_detailed( *, - client: Client, + client: Union[AuthenticatedClient, Client], ) -> Response[APIInformation]: """API Index @@ -67,12 +58,9 @@ def sync_detailed( Response[APIInformation] """ - kwargs = _get_kwargs( - client=client, - ) + kwargs = _get_kwargs() - response = httpx.request( - verify=client.verify_ssl, + response = client.get_httpx_client().request( **kwargs, ) @@ -81,7 +69,7 @@ def sync_detailed( def sync( *, - client: Client, + client: Union[AuthenticatedClient, Client], ) -> Optional[APIInformation]: """API Index @@ -92,7 +80,7 @@ def sync( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[APIInformation] + APIInformation """ return sync_detailed( @@ -102,7 +90,7 @@ def sync( async def asyncio_detailed( *, - client: Client, + client: Union[AuthenticatedClient, Client], ) -> Response[APIInformation]: """API Index @@ -116,19 +104,16 @@ async def asyncio_detailed( Response[APIInformation] """ - kwargs = _get_kwargs( - client=client, - ) + kwargs = _get_kwargs() - async with httpx.AsyncClient(verify=client.verify_ssl) as _client: - response = await _client.request(**kwargs) + response = await client.get_async_httpx_client().request(**kwargs) return _build_response(client=client, response=response) async def asyncio( *, - client: Client, + client: Union[AuthenticatedClient, Client], ) -> Optional[APIInformation]: """API Index @@ -139,7 +124,7 @@ async def asyncio( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[APIInformation] + APIInformation """ return ( diff --git a/ftc_api/api/leagues/get_v2_0_season_leagues.py b/ftc_api/api/leagues/get_v2_0_season_leagues.py index 4c6cc50..926ead7 100644 --- a/ftc_api/api/leagues/get_v2_0_season_leagues.py +++ b/ftc_api/api/leagues/get_v2_0_season_leagues.py @@ -12,16 +12,10 @@ def _get_kwargs( season: int, *, - client: AuthenticatedClient, region_code: Union[Unset, None, str] = UNSET, league_code: Union[Unset, None, str] = UNSET, ) -> Dict[str, Any]: - url = "{}/v2.0/{season}/leagues".format( - "https://ftc-api.firstinspires.org", season=season - ) - - headers: Dict[str, str] = client.get_headers() - cookies: Dict[str, Any] = client.get_cookies() + pass params: Dict[str, Any] = {} params["regionCode"] = region_code @@ -32,16 +26,15 @@ def _get_kwargs( return { "method": "get", - "url": url, - "headers": headers, - "cookies": cookies, - "timeout": client.get_timeout(), + "url": "/v2.0/{season}/leagues".format( + season=season, + ), "params": params, } def _parse_response( - *, client: Client, response: httpx.Response + *, client: Union[AuthenticatedClient, Client], response: httpx.Response ) -> Optional[Union[Any, LeagueList]]: if response.status_code == HTTPStatus.OK: response_200 = LeagueList.from_dict(response.json()) @@ -51,13 +44,13 @@ def _parse_response( response_401 = cast(Any, None) return response_401 if client.raise_on_unexpected_status: - raise errors.UnexpectedStatus(f"Unexpected status code: {response.status_code}") + raise errors.UnexpectedStatus(response.status_code, response.content) else: return None def _build_response( - *, client: Client, response: httpx.Response + *, client: Union[AuthenticatedClient, Client], response: httpx.Response ) -> Response[Union[Any, LeagueList]]: return Response( status_code=HTTPStatus(response.status_code), @@ -97,13 +90,11 @@ def sync_detailed( kwargs = _get_kwargs( season=season, - client=client, region_code=region_code, league_code=league_code, ) - response = httpx.request( - verify=client.verify_ssl, + response = client.get_httpx_client().request( **kwargs, ) @@ -135,7 +126,7 @@ def sync( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[Any, LeagueList]] + Union[Any, LeagueList] """ return sync_detailed( @@ -176,13 +167,11 @@ async def asyncio_detailed( kwargs = _get_kwargs( season=season, - client=client, region_code=region_code, league_code=league_code, ) - async with httpx.AsyncClient(verify=client.verify_ssl) as _client: - response = await _client.request(**kwargs) + response = await client.get_async_httpx_client().request(**kwargs) return _build_response(client=client, response=response) @@ -212,7 +201,7 @@ async def asyncio( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[Any, LeagueList]] + Union[Any, LeagueList] """ return ( diff --git a/ftc_api/api/leagues/get_v_2_0_season_leagues_members_region_code_league_code.py b/ftc_api/api/leagues/get_v_2_0_season_leagues_members_region_code_league_code.py index b5d6246..0111dcc 100644 --- a/ftc_api/api/leagues/get_v_2_0_season_leagues_members_region_code_league_code.py +++ b/ftc_api/api/leagues/get_v_2_0_season_leagues_members_region_code_league_code.py @@ -13,30 +13,21 @@ def _get_kwargs( season: int, region_code: Optional[str], league_code: Optional[str], - *, - client: AuthenticatedClient, ) -> Dict[str, Any]: - url = "{}/v2.0/{season}/leagues/members/{regionCode}/{leagueCode}".format( - "https://ftc-api.firstinspires.org", - season=season, - regionCode=region_code, - leagueCode=league_code, - ) - - headers: Dict[str, str] = client.get_headers() - cookies: Dict[str, Any] = client.get_cookies() + pass return { "method": "get", - "url": url, - "headers": headers, - "cookies": cookies, - "timeout": client.get_timeout(), + "url": "/v2.0/{season}/leagues/members/{regionCode}/{leagueCode}".format( + season=season, + regionCode=region_code, + leagueCode=league_code, + ), } def _parse_response( - *, client: Client, response: httpx.Response + *, client: Union[AuthenticatedClient, Client], response: httpx.Response ) -> Optional[Union[Any, LeagueMembers]]: if response.status_code == HTTPStatus.OK: response_200 = LeagueMembers.from_dict(response.json()) @@ -46,13 +37,13 @@ def _parse_response( response_401 = cast(Any, None) return response_401 if client.raise_on_unexpected_status: - raise errors.UnexpectedStatus(f"Unexpected status code: {response.status_code}") + raise errors.UnexpectedStatus(response.status_code, response.content) else: return None def _build_response( - *, client: Client, response: httpx.Response + *, client: Union[AuthenticatedClient, Client], response: httpx.Response ) -> Response[Union[Any, LeagueMembers]]: return Response( status_code=HTTPStatus(response.status_code), @@ -91,11 +82,9 @@ def sync_detailed( season=season, region_code=region_code, league_code=league_code, - client=client, ) - response = httpx.request( - verify=client.verify_ssl, + response = client.get_httpx_client().request( **kwargs, ) @@ -124,7 +113,7 @@ def sync( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[Any, LeagueMembers]] + Union[Any, LeagueMembers] """ return sync_detailed( @@ -164,11 +153,9 @@ async def asyncio_detailed( season=season, region_code=region_code, league_code=league_code, - client=client, ) - async with httpx.AsyncClient(verify=client.verify_ssl) as _client: - response = await _client.request(**kwargs) + response = await client.get_async_httpx_client().request(**kwargs) return _build_response(client=client, response=response) @@ -195,7 +182,7 @@ async def asyncio( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[Any, LeagueMembers]] + Union[Any, LeagueMembers] """ return ( diff --git a/ftc_api/api/leagues/get_v_2_0_season_leagues_rankings_region_code_league_code.py b/ftc_api/api/leagues/get_v_2_0_season_leagues_rankings_region_code_league_code.py index 2bc2970..40f3e10 100644 --- a/ftc_api/api/leagues/get_v_2_0_season_leagues_rankings_region_code_league_code.py +++ b/ftc_api/api/leagues/get_v_2_0_season_leagues_rankings_region_code_league_code.py @@ -13,30 +13,21 @@ def _get_kwargs( season: int, region_code: Optional[str], league_code: Optional[str], - *, - client: AuthenticatedClient, ) -> Dict[str, Any]: - url = "{}/v2.0/{season}/leagues/rankings/{regionCode}/{leagueCode}".format( - "https://ftc-api.firstinspires.org", - season=season, - regionCode=region_code, - leagueCode=league_code, - ) - - headers: Dict[str, str] = client.get_headers() - cookies: Dict[str, Any] = client.get_cookies() + pass return { "method": "get", - "url": url, - "headers": headers, - "cookies": cookies, - "timeout": client.get_timeout(), + "url": "/v2.0/{season}/leagues/rankings/{regionCode}/{leagueCode}".format( + season=season, + regionCode=region_code, + leagueCode=league_code, + ), } def _parse_response( - *, client: Client, response: httpx.Response + *, client: Union[AuthenticatedClient, Client], response: httpx.Response ) -> Optional[Union[Any, EventRankingList]]: if response.status_code == HTTPStatus.OK: response_200 = EventRankingList.from_dict(response.json()) @@ -46,13 +37,13 @@ def _parse_response( response_401 = cast(Any, None) return response_401 if client.raise_on_unexpected_status: - raise errors.UnexpectedStatus(f"Unexpected status code: {response.status_code}") + raise errors.UnexpectedStatus(response.status_code, response.content) else: return None def _build_response( - *, client: Client, response: httpx.Response + *, client: Union[AuthenticatedClient, Client], response: httpx.Response ) -> Response[Union[Any, EventRankingList]]: return Response( status_code=HTTPStatus(response.status_code), @@ -92,11 +83,9 @@ def sync_detailed( season=season, region_code=region_code, league_code=league_code, - client=client, ) - response = httpx.request( - verify=client.verify_ssl, + response = client.get_httpx_client().request( **kwargs, ) @@ -126,7 +115,7 @@ def sync( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[Any, EventRankingList]] + Union[Any, EventRankingList] """ return sync_detailed( @@ -167,11 +156,9 @@ async def asyncio_detailed( season=season, region_code=region_code, league_code=league_code, - client=client, ) - async with httpx.AsyncClient(verify=client.verify_ssl) as _client: - response = await _client.request(**kwargs) + response = await client.get_async_httpx_client().request(**kwargs) return _build_response(client=client, response=response) @@ -199,7 +186,7 @@ async def asyncio( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[Any, EventRankingList]] + Union[Any, EventRankingList] """ return ( diff --git a/ftc_api/api/match_results/get_v_2_0_season_scores_event_code_tournament_level.py b/ftc_api/api/match_results/get_v_2_0_season_scores_event_code_tournament_level.py index 7f20abf..4113163 100644 --- a/ftc_api/api/match_results/get_v_2_0_season_scores_event_code_tournament_level.py +++ b/ftc_api/api/match_results/get_v_2_0_season_scores_event_code_tournament_level.py @@ -15,25 +15,14 @@ def _get_kwargs( season: int, event_code: Optional[str], - tournament_level: Optional[ - GetV20SeasonScoresEventCodeTournamentLevelTournamentLevel - ], + tournament_level: Optional[GetV20SeasonScoresEventCodeTournamentLevelTournamentLevel], *, - client: AuthenticatedClient, team_number: Union[Unset, None, int] = UNSET, match_number: Union[Unset, None, int] = UNSET, start: Union[Unset, None, int] = 0, end: Union[Unset, None, int] = 999, ) -> Dict[str, Any]: - url = "{}/v2.0/{season}/scores/{eventCode}/{tournamentLevel}".format( - "https://ftc-api.firstinspires.org", - season=season, - eventCode=event_code, - tournamentLevel=tournament_level, - ) - - headers: Dict[str, str] = client.get_headers() - cookies: Dict[str, Any] = client.get_cookies() + pass params: Dict[str, Any] = {} params["teamNumber"] = team_number @@ -48,16 +37,17 @@ def _get_kwargs( return { "method": "get", - "url": url, - "headers": headers, - "cookies": cookies, - "timeout": client.get_timeout(), + "url": "/v2.0/{season}/scores/{eventCode}/{tournamentLevel}".format( + season=season, + eventCode=event_code, + tournamentLevel=tournament_level, + ), "params": params, } def _parse_response( - *, client: Client, response: httpx.Response + *, client: Union[AuthenticatedClient, Client], response: httpx.Response ) -> Optional[Union[Any, MatchScoreList]]: if response.status_code == HTTPStatus.OK: response_200 = MatchScoreList.from_dict(response.json()) @@ -67,13 +57,13 @@ def _parse_response( response_401 = cast(Any, None) return response_401 if client.raise_on_unexpected_status: - raise errors.UnexpectedStatus(f"Unexpected status code: {response.status_code}") + raise errors.UnexpectedStatus(response.status_code, response.content) else: return None def _build_response( - *, client: Client, response: httpx.Response + *, client: Union[AuthenticatedClient, Client], response: httpx.Response ) -> Response[Union[Any, MatchScoreList]]: return Response( status_code=HTTPStatus(response.status_code), @@ -86,9 +76,7 @@ def _build_response( def sync_detailed( season: int, event_code: Optional[str], - tournament_level: Optional[ - GetV20SeasonScoresEventCodeTournamentLevelTournamentLevel - ], + tournament_level: Optional[GetV20SeasonScoresEventCodeTournamentLevelTournamentLevel], *, client: AuthenticatedClient, team_number: Union[Unset, None, int] = UNSET, @@ -124,15 +112,13 @@ def sync_detailed( season=season, event_code=event_code, tournament_level=tournament_level, - client=client, team_number=team_number, match_number=match_number, start=start, end=end, ) - response = httpx.request( - verify=client.verify_ssl, + response = client.get_httpx_client().request( **kwargs, ) @@ -142,9 +128,7 @@ def sync_detailed( def sync( season: int, event_code: Optional[str], - tournament_level: Optional[ - GetV20SeasonScoresEventCodeTournamentLevelTournamentLevel - ], + tournament_level: Optional[GetV20SeasonScoresEventCodeTournamentLevelTournamentLevel], *, client: AuthenticatedClient, team_number: Union[Unset, None, int] = UNSET, @@ -173,7 +157,7 @@ def sync( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[Any, MatchScoreList]] + Union[Any, MatchScoreList] """ return sync_detailed( @@ -191,9 +175,7 @@ def sync( async def asyncio_detailed( season: int, event_code: Optional[str], - tournament_level: Optional[ - GetV20SeasonScoresEventCodeTournamentLevelTournamentLevel - ], + tournament_level: Optional[GetV20SeasonScoresEventCodeTournamentLevelTournamentLevel], *, client: AuthenticatedClient, team_number: Union[Unset, None, int] = UNSET, @@ -229,15 +211,13 @@ async def asyncio_detailed( season=season, event_code=event_code, tournament_level=tournament_level, - client=client, team_number=team_number, match_number=match_number, start=start, end=end, ) - async with httpx.AsyncClient(verify=client.verify_ssl) as _client: - response = await _client.request(**kwargs) + response = await client.get_async_httpx_client().request(**kwargs) return _build_response(client=client, response=response) @@ -245,9 +225,7 @@ async def asyncio_detailed( async def asyncio( season: int, event_code: Optional[str], - tournament_level: Optional[ - GetV20SeasonScoresEventCodeTournamentLevelTournamentLevel - ], + tournament_level: Optional[GetV20SeasonScoresEventCodeTournamentLevelTournamentLevel], *, client: AuthenticatedClient, team_number: Union[Unset, None, int] = UNSET, @@ -276,7 +254,7 @@ async def asyncio( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[Any, MatchScoreList]] + Union[Any, MatchScoreList] """ return ( diff --git a/ftc_api/api/rankings/get_v_2_0_season_rankings_event_code.py b/ftc_api/api/rankings/get_v_2_0_season_rankings_event_code.py index fe2b999..7524736 100644 --- a/ftc_api/api/rankings/get_v_2_0_season_rankings_event_code.py +++ b/ftc_api/api/rankings/get_v_2_0_season_rankings_event_code.py @@ -13,16 +13,10 @@ def _get_kwargs( season: int, event_code: Optional[str], *, - client: AuthenticatedClient, team_number: Union[Unset, None, int] = 0, top: Union[Unset, None, int] = 0, ) -> Dict[str, Any]: - url = "{}/v2.0/{season}/rankings/{eventCode}".format( - "https://ftc-api.firstinspires.org", season=season, eventCode=event_code - ) - - headers: Dict[str, str] = client.get_headers() - cookies: Dict[str, Any] = client.get_cookies() + pass params: Dict[str, Any] = {} params["teamNumber"] = team_number @@ -33,16 +27,16 @@ def _get_kwargs( return { "method": "get", - "url": url, - "headers": headers, - "cookies": cookies, - "timeout": client.get_timeout(), + "url": "/v2.0/{season}/rankings/{eventCode}".format( + season=season, + eventCode=event_code, + ), "params": params, } def _parse_response( - *, client: Client, response: httpx.Response + *, client: Union[AuthenticatedClient, Client], response: httpx.Response ) -> Optional[Union[Any, EventRankingList]]: if response.status_code == HTTPStatus.OK: response_200 = EventRankingList.from_dict(response.json()) @@ -52,13 +46,13 @@ def _parse_response( response_401 = cast(Any, None) return response_401 if client.raise_on_unexpected_status: - raise errors.UnexpectedStatus(f"Unexpected status code: {response.status_code}") + raise errors.UnexpectedStatus(response.status_code, response.content) else: return None def _build_response( - *, client: Client, response: httpx.Response + *, client: Union[AuthenticatedClient, Client], response: httpx.Response ) -> Response[Union[Any, EventRankingList]]: return Response( status_code=HTTPStatus(response.status_code), @@ -101,13 +95,11 @@ def sync_detailed( kwargs = _get_kwargs( season=season, event_code=event_code, - client=client, team_number=team_number, top=top, ) - response = httpx.request( - verify=client.verify_ssl, + response = client.get_httpx_client().request( **kwargs, ) @@ -141,7 +133,7 @@ def sync( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[Any, EventRankingList]] + Union[Any, EventRankingList] """ return sync_detailed( @@ -186,13 +178,11 @@ async def asyncio_detailed( kwargs = _get_kwargs( season=season, event_code=event_code, - client=client, team_number=team_number, top=top, ) - async with httpx.AsyncClient(verify=client.verify_ssl) as _client: - response = await _client.request(**kwargs) + response = await client.get_async_httpx_client().request(**kwargs) return _build_response(client=client, response=response) @@ -224,7 +214,7 @@ async def asyncio( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[Any, EventRankingList]] + Union[Any, EventRankingList] """ return ( diff --git a/ftc_api/api/schedule/get_v_2_0_season_schedule_event_code_tournament_level_hybrid.py b/ftc_api/api/schedule/get_v_2_0_season_schedule_event_code_tournament_level_hybrid.py index cd7a5bb..6a630a0 100644 --- a/ftc_api/api/schedule/get_v_2_0_season_schedule_event_code_tournament_level_hybrid.py +++ b/ftc_api/api/schedule/get_v_2_0_season_schedule_event_code_tournament_level_hybrid.py @@ -15,23 +15,12 @@ def _get_kwargs( season: int, event_code: Optional[str], - tournament_level: Optional[ - GetV20SeasonScheduleEventCodeTournamentLevelHybridTournamentLevel - ], + tournament_level: Optional[GetV20SeasonScheduleEventCodeTournamentLevelHybridTournamentLevel], *, - client: AuthenticatedClient, start: Union[Unset, None, int] = 0, end: Union[Unset, None, int] = 999, ) -> Dict[str, Any]: - url = "{}/v2.0/{season}/schedule/{eventCode}/{tournamentLevel}/hybrid".format( - "https://ftc-api.firstinspires.org", - season=season, - eventCode=event_code, - tournamentLevel=tournament_level, - ) - - headers: Dict[str, str] = client.get_headers() - cookies: Dict[str, Any] = client.get_cookies() + pass params: Dict[str, Any] = {} params["start"] = start @@ -42,16 +31,17 @@ def _get_kwargs( return { "method": "get", - "url": url, - "headers": headers, - "cookies": cookies, - "timeout": client.get_timeout(), + "url": "/v2.0/{season}/schedule/{eventCode}/{tournamentLevel}/hybrid".format( + season=season, + eventCode=event_code, + tournamentLevel=tournament_level, + ), "params": params, } def _parse_response( - *, client: Client, response: httpx.Response + *, client: Union[AuthenticatedClient, Client], response: httpx.Response ) -> Optional[Union[Any, HybridSchedule]]: if response.status_code == HTTPStatus.OK: response_200 = HybridSchedule.from_dict(response.json()) @@ -61,13 +51,13 @@ def _parse_response( response_401 = cast(Any, None) return response_401 if client.raise_on_unexpected_status: - raise errors.UnexpectedStatus(f"Unexpected status code: {response.status_code}") + raise errors.UnexpectedStatus(response.status_code, response.content) else: return None def _build_response( - *, client: Client, response: httpx.Response + *, client: Union[AuthenticatedClient, Client], response: httpx.Response ) -> Response[Union[Any, HybridSchedule]]: return Response( status_code=HTTPStatus(response.status_code), @@ -80,9 +70,7 @@ def _build_response( def sync_detailed( season: int, event_code: Optional[str], - tournament_level: Optional[ - GetV20SeasonScheduleEventCodeTournamentLevelHybridTournamentLevel - ], + tournament_level: Optional[GetV20SeasonScheduleEventCodeTournamentLevelHybridTournamentLevel], *, client: AuthenticatedClient, start: Union[Unset, None, int] = 0, @@ -115,13 +103,11 @@ def sync_detailed( season=season, event_code=event_code, tournament_level=tournament_level, - client=client, start=start, end=end, ) - response = httpx.request( - verify=client.verify_ssl, + response = client.get_httpx_client().request( **kwargs, ) @@ -131,9 +117,7 @@ def sync_detailed( def sync( season: int, event_code: Optional[str], - tournament_level: Optional[ - GetV20SeasonScheduleEventCodeTournamentLevelHybridTournamentLevel - ], + tournament_level: Optional[GetV20SeasonScheduleEventCodeTournamentLevelHybridTournamentLevel], *, client: AuthenticatedClient, start: Union[Unset, None, int] = 0, @@ -159,7 +143,7 @@ def sync( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[Any, HybridSchedule]] + Union[Any, HybridSchedule] """ return sync_detailed( @@ -175,9 +159,7 @@ def sync( async def asyncio_detailed( season: int, event_code: Optional[str], - tournament_level: Optional[ - GetV20SeasonScheduleEventCodeTournamentLevelHybridTournamentLevel - ], + tournament_level: Optional[GetV20SeasonScheduleEventCodeTournamentLevelHybridTournamentLevel], *, client: AuthenticatedClient, start: Union[Unset, None, int] = 0, @@ -210,13 +192,11 @@ async def asyncio_detailed( season=season, event_code=event_code, tournament_level=tournament_level, - client=client, start=start, end=end, ) - async with httpx.AsyncClient(verify=client.verify_ssl) as _client: - response = await _client.request(**kwargs) + response = await client.get_async_httpx_client().request(**kwargs) return _build_response(client=client, response=response) @@ -224,9 +204,7 @@ async def asyncio_detailed( async def asyncio( season: int, event_code: Optional[str], - tournament_level: Optional[ - GetV20SeasonScheduleEventCodeTournamentLevelHybridTournamentLevel - ], + tournament_level: Optional[GetV20SeasonScheduleEventCodeTournamentLevelHybridTournamentLevel], *, client: AuthenticatedClient, start: Union[Unset, None, int] = 0, @@ -252,7 +230,7 @@ async def asyncio( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[Any, HybridSchedule]] + Union[Any, HybridSchedule] """ return ( diff --git a/ftc_api/api/season_data/get_v2_0_season.py b/ftc_api/api/season_data/get_v2_0_season.py index 83e668a..d16c33e 100644 --- a/ftc_api/api/season_data/get_v2_0_season.py +++ b/ftc_api/api/season_data/get_v2_0_season.py @@ -11,25 +11,19 @@ def _get_kwargs( season: int, - *, - client: AuthenticatedClient, ) -> Dict[str, Any]: - url = "{}/v2.0/{season}".format("https://ftc-api.firstinspires.org", season=season) - - headers: Dict[str, str] = client.get_headers() - cookies: Dict[str, Any] = client.get_cookies() + pass return { "method": "get", - "url": url, - "headers": headers, - "cookies": cookies, - "timeout": client.get_timeout(), + "url": "/v2.0/{season}".format( + season=season, + ), } def _parse_response( - *, client: Client, response: httpx.Response + *, client: Union[AuthenticatedClient, Client], response: httpx.Response ) -> Optional[Union[Any, SeasonSummary]]: if response.status_code == HTTPStatus.OK: response_200 = SeasonSummary.from_dict(response.json()) @@ -39,13 +33,13 @@ def _parse_response( response_401 = cast(Any, None) return response_401 if client.raise_on_unexpected_status: - raise errors.UnexpectedStatus(f"Unexpected status code: {response.status_code}") + raise errors.UnexpectedStatus(response.status_code, response.content) else: return None def _build_response( - *, client: Client, response: httpx.Response + *, client: Union[AuthenticatedClient, Client], response: httpx.Response ) -> Response[Union[Any, SeasonSummary]]: return Response( status_code=HTTPStatus(response.status_code), @@ -77,11 +71,9 @@ def sync_detailed( kwargs = _get_kwargs( season=season, - client=client, ) - response = httpx.request( - verify=client.verify_ssl, + response = client.get_httpx_client().request( **kwargs, ) @@ -105,7 +97,7 @@ def sync( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[Any, SeasonSummary]] + Union[Any, SeasonSummary] """ return sync_detailed( @@ -136,11 +128,9 @@ async def asyncio_detailed( kwargs = _get_kwargs( season=season, - client=client, ) - async with httpx.AsyncClient(verify=client.verify_ssl) as _client: - response = await _client.request(**kwargs) + response = await client.get_async_httpx_client().request(**kwargs) return _build_response(client=client, response=response) @@ -162,7 +152,7 @@ async def asyncio( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[Any, SeasonSummary]] + Union[Any, SeasonSummary] """ return ( diff --git a/ftc_api/api/season_data/get_v2_0_season_events.py b/ftc_api/api/season_data/get_v2_0_season_events.py index d7d66c2..d1bee4e 100644 --- a/ftc_api/api/season_data/get_v2_0_season_events.py +++ b/ftc_api/api/season_data/get_v2_0_season_events.py @@ -12,16 +12,10 @@ def _get_kwargs( season: int, *, - client: AuthenticatedClient, event_code: Union[Unset, None, str] = "0", team_number: Union[Unset, None, int] = 0, ) -> Dict[str, Any]: - url = "{}/v2.0/{season}/events".format( - "https://ftc-api.firstinspires.org", season=season - ) - - headers: Dict[str, str] = client.get_headers() - cookies: Dict[str, Any] = client.get_cookies() + pass params: Dict[str, Any] = {} params["eventCode"] = event_code @@ -32,16 +26,15 @@ def _get_kwargs( return { "method": "get", - "url": url, - "headers": headers, - "cookies": cookies, - "timeout": client.get_timeout(), + "url": "/v2.0/{season}/events".format( + season=season, + ), "params": params, } def _parse_response( - *, client: Client, response: httpx.Response + *, client: Union[AuthenticatedClient, Client], response: httpx.Response ) -> Optional[Union[Any, EventList]]: if response.status_code == HTTPStatus.OK: response_200 = EventList.from_dict(response.json()) @@ -51,13 +44,13 @@ def _parse_response( response_401 = cast(Any, None) return response_401 if client.raise_on_unexpected_status: - raise errors.UnexpectedStatus(f"Unexpected status code: {response.status_code}") + raise errors.UnexpectedStatus(response.status_code, response.content) else: return None def _build_response( - *, client: Client, response: httpx.Response + *, client: Union[AuthenticatedClient, Client], response: httpx.Response ) -> Response[Union[Any, EventList]]: return Response( status_code=HTTPStatus(response.status_code), @@ -102,13 +95,11 @@ def sync_detailed( kwargs = _get_kwargs( season=season, - client=client, event_code=event_code, team_number=team_number, ) - response = httpx.request( - verify=client.verify_ssl, + response = client.get_httpx_client().request( **kwargs, ) @@ -145,7 +136,7 @@ def sync( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[Any, EventList]] + Union[Any, EventList] """ return sync_detailed( @@ -191,13 +182,11 @@ async def asyncio_detailed( kwargs = _get_kwargs( season=season, - client=client, event_code=event_code, team_number=team_number, ) - async with httpx.AsyncClient(verify=client.verify_ssl) as _client: - response = await _client.request(**kwargs) + response = await client.get_async_httpx_client().request(**kwargs) return _build_response(client=client, response=response) @@ -232,7 +221,7 @@ async def asyncio( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[Any, EventList]] + Union[Any, EventList] """ return ( diff --git a/ftc_api/api/season_data/get_v2_0_season_teams.py b/ftc_api/api/season_data/get_v2_0_season_teams.py index 28c4161..47edd94 100644 --- a/ftc_api/api/season_data/get_v2_0_season_teams.py +++ b/ftc_api/api/season_data/get_v2_0_season_teams.py @@ -12,18 +12,12 @@ def _get_kwargs( season: int, *, - client: AuthenticatedClient, team_number: Union[Unset, None, int] = 0, event_code: Union[Unset, None, str] = "0", state: Union[Unset, None, str] = "", page: Union[Unset, None, int] = 1, ) -> Dict[str, Any]: - url = "{}/v2.0/{season}/teams".format( - "https://ftc-api.firstinspires.org", season=season - ) - - headers: Dict[str, str] = client.get_headers() - cookies: Dict[str, Any] = client.get_cookies() + pass params: Dict[str, Any] = {} params["teamNumber"] = team_number @@ -38,16 +32,15 @@ def _get_kwargs( return { "method": "get", - "url": url, - "headers": headers, - "cookies": cookies, - "timeout": client.get_timeout(), + "url": "/v2.0/{season}/teams".format( + season=season, + ), "params": params, } def _parse_response( - *, client: Client, response: httpx.Response + *, client: Union[AuthenticatedClient, Client], response: httpx.Response ) -> Optional[Union[Any, TeamList]]: if response.status_code == HTTPStatus.OK: response_200 = TeamList.from_dict(response.json()) @@ -57,13 +50,13 @@ def _parse_response( response_401 = cast(Any, None) return response_401 if client.raise_on_unexpected_status: - raise errors.UnexpectedStatus(f"Unexpected status code: {response.status_code}") + raise errors.UnexpectedStatus(response.status_code, response.content) else: return None def _build_response( - *, client: Client, response: httpx.Response + *, client: Union[AuthenticatedClient, Client], response: httpx.Response ) -> Response[Union[Any, TeamList]]: return Response( status_code=HTTPStatus(response.status_code), @@ -82,7 +75,7 @@ def sync_detailed( state: Union[Unset, None, str] = "", page: Union[Unset, None, int] = 1, ) -> Response[Union[Any, TeamList]]: - """Team Listings + r"""Team Listings The team listings API returns all FTC official teams in a particular season. If specified, the `teamNumber` parameter will return only one result with the details of the requested `teamNumber`. @@ -111,15 +104,13 @@ def sync_detailed( kwargs = _get_kwargs( season=season, - client=client, team_number=team_number, event_code=event_code, state=state, page=page, ) - response = httpx.request( - verify=client.verify_ssl, + response = client.get_httpx_client().request( **kwargs, ) @@ -135,7 +126,7 @@ def sync( state: Union[Unset, None, str] = "", page: Union[Unset, None, int] = 1, ) -> Optional[Union[Any, TeamList]]: - """Team Listings + r"""Team Listings The team listings API returns all FTC official teams in a particular season. If specified, the `teamNumber` parameter will return only one result with the details of the requested `teamNumber`. @@ -159,7 +150,7 @@ def sync( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[Any, TeamList]] + Union[Any, TeamList] """ return sync_detailed( @@ -181,7 +172,7 @@ async def asyncio_detailed( state: Union[Unset, None, str] = "", page: Union[Unset, None, int] = 1, ) -> Response[Union[Any, TeamList]]: - """Team Listings + r"""Team Listings The team listings API returns all FTC official teams in a particular season. If specified, the `teamNumber` parameter will return only one result with the details of the requested `teamNumber`. @@ -210,15 +201,13 @@ async def asyncio_detailed( kwargs = _get_kwargs( season=season, - client=client, team_number=team_number, event_code=event_code, state=state, page=page, ) - async with httpx.AsyncClient(verify=client.verify_ssl) as _client: - response = await _client.request(**kwargs) + response = await client.get_async_httpx_client().request(**kwargs) return _build_response(client=client, response=response) @@ -232,7 +221,7 @@ async def asyncio( state: Union[Unset, None, str] = "", page: Union[Unset, None, int] = 1, ) -> Optional[Union[Any, TeamList]]: - """Team Listings + r"""Team Listings The team listings API returns all FTC official teams in a particular season. If specified, the `teamNumber` parameter will return only one result with the details of the requested `teamNumber`. @@ -256,7 +245,7 @@ async def asyncio( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[Any, TeamList]] + Union[Any, TeamList] """ return ( diff --git a/ftc_api/client.py b/ftc_api/client.py index 7f05761..7bc7375 100644 --- a/ftc_api/client.py +++ b/ftc_api/client.py @@ -1,32 +1,57 @@ import base64 import ssl import warnings -from typing import Dict, Union +from typing import Any, Dict, Optional, Union + +import httpx +from attrs import evolve class Client: - """A class for keeping track of data related to the API + """A Client which has been authenticated for use on secured endpoints + + The following are accepted as keyword arguments and will be used to construct httpx Clients internally: + + ``base_url``: The base URL for the API, all requests are made to a relative path to this URL + + ``cookies``: A dictionary of cookies to be sent with every request + + ``headers``: A dictionary of headers to be sent with every request + + ``timeout``: The maximum amount of a time a request can take. API functions will raise + httpx.TimeoutException if this is exceeded. + + ``verify_ssl``: Whether or not to verify the SSL certificate of the API server. This should be True in production, + but can be set to False for testing purposes. + + ``follow_redirects``: Whether or not to follow redirects. Default value is False. + + ``httpx_args``: A dictionary of additional arguments to be passed to the ``httpx.Client`` and ``httpx.AsyncClient`` constructor. + Attributes: - cookies: A dictionary of cookies to be sent with every request - headers: A dictionary of headers to be sent with every request - timeout: The maximum amount of a time in seconds a request can take. API functions will raise - httpx.TimeoutException if this is exceeded. - verify_ssl: Whether or not to verify the SSL certificate of the API server. This should be True in production, - but can be set to False for testing purposes. raise_on_unexpected_status: Whether or not to raise an errors.UnexpectedStatus if the API returns a - status code that was not documented in the source OpenAPI document. - http2: Whether or not to use http2, enabled by default. + status code that was not documented in the source OpenAPI document. Can also be provided as a keyword + argument to the constructor. + token: The token to use for authentication + prefix: The prefix to use for the Authorization header + auth_header_name: The name of the Authorization header """ - cookies = {} + raise_on_unexpected_status: bool + _base_url: str = "https://ftc-api.firstinspires.org" + cookies: Dict[str, str] = {} headers: Dict[str, str] = {} - timeout: float = 5.0 + timeout: Optional[httpx.Timeout] = None verify_ssl: Union[str, bool, ssl.SSLContext] = True - raise_on_unexpected_status: bool = False + follow_redirects: bool = False + httpx_args: Dict[str, Any] = {} + _client: Optional[httpx.Client] = None + _async_client: Optional[httpx.AsyncClient] = None + + token: str prefix: str = "Basic" auth_header_name: str = "Authorization" - http2 = True def __init__(self, token=None, username="", authorization_key=""): if token is not None: @@ -37,22 +62,98 @@ def __init__(self, token=None, username="", authorization_key=""): base64_bytes = base64.b64encode(token_bytes) self.token = base64_bytes.decode("ascii") - def get_headers(self) -> Dict[str, str]: - auth_header_value = f"{self.prefix} {self.token}" if self.prefix else self.token - """Get headers to be used in authenticated endpoints""" - return {self.auth_header_name: auth_header_value, **self.headers} + def with_headers(self, headers: Dict[str, str]) -> "Client": + """Get a new client matching this one with additional headers""" + if self._client is not None: + self._client.headers.update(headers) + if self._async_client is not None: + self._async_client.headers.update(headers) + return evolve(self, headers={**self.headers, **headers}) + + def with_cookies(self, cookies: Dict[str, str]) -> "Client": + """Get a new client matching this one with additional cookies""" + if self._client is not None: + self._client.cookies.update(cookies) + if self._async_client is not None: + self._async_client.cookies.update(cookies) + return evolve(self, cookies={**self.cookies, **cookies}) + + def with_timeout(self, timeout: httpx.Timeout) -> "Client": + """Get a new client matching this one with a new timeout (in seconds)""" + if self._client is not None: + self._client.timeout = timeout + if self._async_client is not None: + self._async_client.timeout = timeout + return evolve(self, timeout=timeout) + + def set_httpx_client(self, client: httpx.Client) -> "Client": + """Manually the underlying httpx.Client + + **NOTE**: This will override any other settings on the client, including cookies, headers, and timeout. + """ + self._client = client + return self + + def get_httpx_client(self) -> httpx.Client: + """Get the underlying httpx.Client, constructing a new one if not previously set""" + if self._client is None: + self.headers[self.auth_header_name] = f"{self.prefix} {self.token}" if self.prefix else self.token + self._client = httpx.Client( + base_url=self._base_url, + cookies=self.cookies, + headers=self.headers, + timeout=self.timeout, + verify=self.verify_ssl, + follow_redirects=self.follow_redirects, + **self.httpx_args, + ) + return self._client + + def __enter__(self) -> "Client": + """Enter a context manager for self.client—you cannot enter twice (see httpx docs)""" + self.get_httpx_client().__enter__() + return self + + def __exit__(self, *args: Any, **kwargs: Any) -> None: + """Exit a context manager for internal httpx.Client (see httpx docs)""" + self.get_httpx_client().__exit__(*args, **kwargs) + + def set_async_httpx_client(self, async_client: httpx.AsyncClient) -> "Client": + """Manually the underlying httpx.AsyncClient + + **NOTE**: This will override any other settings on the client, including cookies, headers, and timeout. + """ + self._async_client = async_client + return self + + def get_async_httpx_client(self) -> httpx.AsyncClient: + """Get the underlying httpx.AsyncClient, constructing a new one if not previously set""" + if self._async_client is None: + self.headers[self.auth_header_name] = f"{self.prefix} {self.token}" if self.prefix else self.token + self._async_client = httpx.AsyncClient( + base_url=self._base_url, + cookies=self.cookies, + headers=self.headers, + timeout=self.timeout, + verify=self.verify_ssl, + follow_redirects=self.follow_redirects, + **self.httpx_args, + ) + return self._async_client - def get_cookies(self) -> Dict[str, str]: - return {**self.cookies} + async def __aenter__(self) -> "Client": + """Enter a context manager for underlying httpx.AsyncClient—you cannot enter twice (see httpx docs)""" + await self.get_async_httpx_client().__aenter__() + return self - def get_timeout(self) -> float: - return self.timeout + async def __aexit__(self, *args: Any, **kwargs: Any) -> None: + """Exit a context manager for underlying httpx.AsyncClient (see httpx docs)""" + await self.get_async_httpx_client().__aexit__(*args, **kwargs) class AuthenticatedClient(Client): """Deprecated, use Client instead, as it has equivalent functionality, will be removed v1.0.0""" warnings.warn( - "Will be removed v1.0.0 switch to Client because the functionality has been merged.", - DeprecationWarning, + "Will be removed v1.0.0 switch to Client because the functionality has been merged.", DeprecationWarning ) diff --git a/ftc_api/errors.py b/ftc_api/errors.py index a508e13..426f8a2 100644 --- a/ftc_api/errors.py +++ b/ftc_api/errors.py @@ -4,7 +4,11 @@ class UnexpectedStatus(Exception): """Raised by api functions when the response status an undocumented status and Client.raise_on_unexpected_status is True""" - ... + def __init__(self, status_code: int, content: bytes): + self.status_code = status_code + self.content = content + + super().__init__(f"Unexpected status code: {status_code}") __all__ = ["UnexpectedStatus"] diff --git a/ftc_api/models/__init__.py b/ftc_api/models/__init__.py index b4512c0..23d2c11 100644 --- a/ftc_api/models/__init__.py +++ b/ftc_api/models/__init__.py @@ -25,9 +25,7 @@ from .freight_frenzy_alliance_score_breakdown import FreightFrenzyAllianceScoreBreakdown from .freight_frenzy_alliance_score_details import FreightFrenzyAllianceScoreDetails from .freight_frenzy_remote_score_breakdown import FreightFrenzyRemoteScoreBreakdown -from .freight_frenzy_single_team_score_details import ( - FreightFrenzySingleTeamScoreDetails, -) +from .freight_frenzy_single_team_score_details import FreightFrenzySingleTeamScoreDetails from .ftc_event_level import FTCEventLevel from .geometry import Geometry from .geometry_factory import GeometryFactory diff --git a/ftc_api/models/alliance.py b/ftc_api/models/alliance.py index 25098d6..4b4acaa 100644 --- a/ftc_api/models/alliance.py +++ b/ftc_api/models/alliance.py @@ -1,13 +1,13 @@ from typing import Any, Dict, Type, TypeVar, Union -import attr +from attrs import define as _attrs_define from ..types import UNSET, Unset T = TypeVar("T", bound="Alliance") -@attr.s(auto_attribs=True) +@_attrs_define class Alliance: """ Attributes: diff --git a/ftc_api/models/alliance_selection.py b/ftc_api/models/alliance_selection.py index 9af92fa..1231761 100644 --- a/ftc_api/models/alliance_selection.py +++ b/ftc_api/models/alliance_selection.py @@ -1,6 +1,6 @@ from typing import TYPE_CHECKING, Any, Dict, List, Type, TypeVar, Union -import attr +from attrs import define as _attrs_define from ..types import UNSET, Unset @@ -11,7 +11,7 @@ T = TypeVar("T", bound="AllianceSelection") -@attr.s(auto_attribs=True) +@_attrs_define class AllianceSelection: """ Attributes: diff --git a/ftc_api/models/alliance_selection_details.py b/ftc_api/models/alliance_selection_details.py index df946d6..5d8d5e9 100644 --- a/ftc_api/models/alliance_selection_details.py +++ b/ftc_api/models/alliance_selection_details.py @@ -1,6 +1,6 @@ from typing import TYPE_CHECKING, Any, Dict, List, Type, TypeVar, Union -import attr +from attrs import define as _attrs_define from ..types import UNSET, Unset @@ -11,7 +11,7 @@ T = TypeVar("T", bound="AllianceSelectionDetails") -@attr.s(auto_attribs=True) +@_attrs_define class AllianceSelectionDetails: """ Attributes: diff --git a/ftc_api/models/api_information.py b/ftc_api/models/api_information.py index 5536dbe..1786594 100644 --- a/ftc_api/models/api_information.py +++ b/ftc_api/models/api_information.py @@ -1,13 +1,13 @@ from typing import Any, Dict, Type, TypeVar, Union -import attr +from attrs import define as _attrs_define from ..types import UNSET, Unset T = TypeVar("T", bound="APIInformation") -@attr.s(auto_attribs=True) +@_attrs_define class APIInformation: """ Attributes: diff --git a/ftc_api/models/auto_navigated_status.py b/ftc_api/models/auto_navigated_status.py index 6bd6401..2113524 100644 --- a/ftc_api/models/auto_navigated_status.py +++ b/ftc_api/models/auto_navigated_status.py @@ -2,11 +2,11 @@ class AutoNavigatedStatus(str, Enum): - NONE = "NONE" - IN_STORAGE = "IN_STORAGE" COMPLETELY_IN_STORAGE = "COMPLETELY_IN_STORAGE" - IN_WAREHOUSE = "IN_WAREHOUSE" COMPLETELY_IN_WAREHOUSE = "COMPLETELY_IN_WAREHOUSE" + IN_STORAGE = "IN_STORAGE" + IN_WAREHOUSE = "IN_WAREHOUSE" + NONE = "NONE" def __str__(self) -> str: return str(self.value) diff --git a/ftc_api/models/auto_navigation.py b/ftc_api/models/auto_navigation.py index 3249217..afd4fff 100644 --- a/ftc_api/models/auto_navigation.py +++ b/ftc_api/models/auto_navigation.py @@ -3,8 +3,8 @@ class AutoNavigation(str, Enum): NONE = "NONE" - SUBSTATION_TERMINAL = "SUBSTATION_TERMINAL" SIGNAL_ZONE = "SIGNAL_ZONE" + SUBSTATION_TERMINAL = "SUBSTATION_TERMINAL" def __str__(self) -> str: return str(self.value) diff --git a/ftc_api/models/award.py b/ftc_api/models/award.py index cc1cbe9..ac4869a 100644 --- a/ftc_api/models/award.py +++ b/ftc_api/models/award.py @@ -1,13 +1,13 @@ from typing import Any, Dict, Type, TypeVar, Union -import attr +from attrs import define as _attrs_define from ..types import UNSET, Unset T = TypeVar("T", bound="Award") -@attr.s(auto_attribs=True) +@_attrs_define class Award: """ Attributes: diff --git a/ftc_api/models/award_assignment.py b/ftc_api/models/award_assignment.py index 1c8d1f8..933a130 100644 --- a/ftc_api/models/award_assignment.py +++ b/ftc_api/models/award_assignment.py @@ -1,13 +1,13 @@ from typing import Any, Dict, Type, TypeVar, Union -import attr +from attrs import define as _attrs_define from ..types import UNSET, Unset T = TypeVar("T", bound="AwardAssignment") -@attr.s(auto_attribs=True) +@_attrs_define class AwardAssignment: """ Attributes: diff --git a/ftc_api/models/award_assignment_list.py b/ftc_api/models/award_assignment_list.py index cb95a37..674d6fd 100644 --- a/ftc_api/models/award_assignment_list.py +++ b/ftc_api/models/award_assignment_list.py @@ -1,6 +1,6 @@ from typing import TYPE_CHECKING, Any, Dict, List, Type, TypeVar, Union -import attr +from attrs import define as _attrs_define from ..types import UNSET, Unset @@ -11,7 +11,7 @@ T = TypeVar("T", bound="AwardAssignmentList") -@attr.s(auto_attribs=True) +@_attrs_define class AwardAssignmentList: """ Attributes: diff --git a/ftc_api/models/award_list.py b/ftc_api/models/award_list.py index 7224ead..480267f 100644 --- a/ftc_api/models/award_list.py +++ b/ftc_api/models/award_list.py @@ -1,6 +1,6 @@ from typing import TYPE_CHECKING, Any, Dict, List, Type, TypeVar, Union -import attr +from attrs import define as _attrs_define from ..types import UNSET, Unset @@ -11,7 +11,7 @@ T = TypeVar("T", bound="AwardList") -@attr.s(auto_attribs=True) +@_attrs_define class AwardList: """ Attributes: diff --git a/ftc_api/models/coordinate.py b/ftc_api/models/coordinate.py index e42bd08..5eff9c9 100644 --- a/ftc_api/models/coordinate.py +++ b/ftc_api/models/coordinate.py @@ -1,13 +1,13 @@ from typing import Any, Dict, Type, TypeVar, Union -import attr +from attrs import define as _attrs_define from ..types import UNSET, Unset T = TypeVar("T", bound="Coordinate") -@attr.s(auto_attribs=True) +@_attrs_define class Coordinate: """ Attributes: diff --git a/ftc_api/models/coordinate_equality_comparer.py b/ftc_api/models/coordinate_equality_comparer.py index 57b1b00..c25b2e7 100644 --- a/ftc_api/models/coordinate_equality_comparer.py +++ b/ftc_api/models/coordinate_equality_comparer.py @@ -1,11 +1,11 @@ from typing import Any, Dict, Type, TypeVar -import attr +from attrs import define as _attrs_define T = TypeVar("T", bound="CoordinateEqualityComparer") -@attr.s(auto_attribs=True) +@_attrs_define class CoordinateEqualityComparer: """ """ diff --git a/ftc_api/models/coordinate_sequence.py b/ftc_api/models/coordinate_sequence.py index 8832d00..62002d2 100644 --- a/ftc_api/models/coordinate_sequence.py +++ b/ftc_api/models/coordinate_sequence.py @@ -1,6 +1,6 @@ from typing import Any, Dict, Type, TypeVar, Union -import attr +from attrs import define as _attrs_define from ..models.ordinates import Ordinates from ..types import UNSET, Unset @@ -8,7 +8,7 @@ T = TypeVar("T", bound="CoordinateSequence") -@attr.s(auto_attribs=True) +@_attrs_define class CoordinateSequence: """ Attributes: diff --git a/ftc_api/models/coordinate_sequence_factory.py b/ftc_api/models/coordinate_sequence_factory.py index f5e3414..3a932fb 100644 --- a/ftc_api/models/coordinate_sequence_factory.py +++ b/ftc_api/models/coordinate_sequence_factory.py @@ -1,6 +1,6 @@ from typing import Any, Dict, Type, TypeVar, Union -import attr +from attrs import define as _attrs_define from ..models.ordinates import Ordinates from ..types import UNSET, Unset @@ -8,7 +8,7 @@ T = TypeVar("T", bound="CoordinateSequenceFactory") -@attr.s(auto_attribs=True) +@_attrs_define class CoordinateSequenceFactory: """ Attributes: diff --git a/ftc_api/models/dimension.py b/ftc_api/models/dimension.py index 966cb1a..92adf69 100644 --- a/ftc_api/models/dimension.py +++ b/ftc_api/models/dimension.py @@ -2,11 +2,11 @@ class Dimension(str, Enum): - P = "P" - CURVE = "Curve" A = "A" COLLAPSE = "Collapse" + CURVE = "Curve" DONTCARE = "Dontcare" + P = "P" TRUE = "True" UNKNOWN = "Unknown" diff --git a/ftc_api/models/endgame_parked_status.py b/ftc_api/models/endgame_parked_status.py index 97b675b..aae18df 100644 --- a/ftc_api/models/endgame_parked_status.py +++ b/ftc_api/models/endgame_parked_status.py @@ -2,9 +2,9 @@ class EndgameParkedStatus(str, Enum): - NONE = "NONE" - IN_WAREHOUSE = "IN_WAREHOUSE" COMPLETELY_IN_WAREHOUSE = "COMPLETELY_IN_WAREHOUSE" + IN_WAREHOUSE = "IN_WAREHOUSE" + NONE = "NONE" def __str__(self) -> str: return str(self.value) diff --git a/ftc_api/models/envelope.py b/ftc_api/models/envelope.py index 291c0fe..01a5036 100644 --- a/ftc_api/models/envelope.py +++ b/ftc_api/models/envelope.py @@ -1,6 +1,6 @@ from typing import TYPE_CHECKING, Any, Dict, Type, TypeVar, Union -import attr +from attrs import define as _attrs_define from ..types import UNSET, Unset @@ -11,7 +11,7 @@ T = TypeVar("T", bound="Envelope") -@attr.s(auto_attribs=True) +@_attrs_define class Envelope: """ Attributes: diff --git a/ftc_api/models/event.py b/ftc_api/models/event.py index bccb27e..1aea132 100644 --- a/ftc_api/models/event.py +++ b/ftc_api/models/event.py @@ -1,7 +1,7 @@ import datetime from typing import TYPE_CHECKING, Any, Dict, List, Type, TypeVar, Union, cast -import attr +from attrs import define as _attrs_define from dateutil.parser import isoparse from ..types import UNSET, Unset @@ -13,7 +13,7 @@ T = TypeVar("T", bound="Event") -@attr.s(auto_attribs=True) +@_attrs_define class Event: """ Attributes: diff --git a/ftc_api/models/event_list.py b/ftc_api/models/event_list.py index 0e316e2..f260698 100644 --- a/ftc_api/models/event_list.py +++ b/ftc_api/models/event_list.py @@ -1,6 +1,6 @@ from typing import TYPE_CHECKING, Any, Dict, List, Type, TypeVar, Union -import attr +from attrs import define as _attrs_define from ..types import UNSET, Unset @@ -11,7 +11,7 @@ T = TypeVar("T", bound="EventList") -@attr.s(auto_attribs=True) +@_attrs_define class EventList: """ Attributes: diff --git a/ftc_api/models/event_ranking_list.py b/ftc_api/models/event_ranking_list.py index 968ebc9..1a3020d 100644 --- a/ftc_api/models/event_ranking_list.py +++ b/ftc_api/models/event_ranking_list.py @@ -1,6 +1,6 @@ from typing import TYPE_CHECKING, Any, Dict, List, Type, TypeVar, Union -import attr +from attrs import define as _attrs_define from ..types import UNSET, Unset @@ -11,7 +11,7 @@ T = TypeVar("T", bound="EventRankingList") -@attr.s(auto_attribs=True) +@_attrs_define class EventRankingList: """ Attributes: diff --git a/ftc_api/models/field_side.py b/ftc_api/models/field_side.py index 6c6c3ff..6a22263 100644 --- a/ftc_api/models/field_side.py +++ b/ftc_api/models/field_side.py @@ -2,8 +2,8 @@ class FieldSide(str, Enum): - SCORING_SIDE = "SCORING_SIDE" AUDIENCE_SIDE = "AUDIENCE_SIDE" + SCORING_SIDE = "SCORING_SIDE" def __str__(self) -> str: return str(self.value) diff --git a/ftc_api/models/freight_frenzy_alliance_score_breakdown.py b/ftc_api/models/freight_frenzy_alliance_score_breakdown.py index 7f2a9c1..4462288 100644 --- a/ftc_api/models/freight_frenzy_alliance_score_breakdown.py +++ b/ftc_api/models/freight_frenzy_alliance_score_breakdown.py @@ -1,6 +1,6 @@ from typing import Any, Dict, Type, TypeVar, Union -import attr +from attrs import define as _attrs_define from ..models.auto_navigated_status import AutoNavigatedStatus from ..models.barcode_element import BarcodeElement @@ -10,7 +10,7 @@ T = TypeVar("T", bound="FreightFrenzyAllianceScoreBreakdown") -@attr.s(auto_attribs=True) +@_attrs_define class FreightFrenzyAllianceScoreBreakdown: """ Attributes: @@ -149,9 +149,7 @@ def to_dict(self) -> Dict[str, Any]: auto_navigation_points = self.auto_navigation_points auto_freight_points = self.auto_freight_points auto_bonus_points = self.auto_bonus_points - driver_controlled_alliance_hub_points = ( - self.driver_controlled_alliance_hub_points - ) + driver_controlled_alliance_hub_points = self.driver_controlled_alliance_hub_points driver_controlled_shared_hub_points = self.driver_controlled_shared_hub_points driver_controlled_storage_points = self.driver_controlled_storage_points endgame_delivery_points = self.endgame_delivery_points @@ -192,9 +190,7 @@ def to_dict(self) -> Dict[str, Any]: if auto_freight_3 is not UNSET: field_dict["autoFreight3"] = auto_freight_3 if driver_controlled_storage_freight is not UNSET: - field_dict[ - "driverControlledStorageFreight" - ] = driver_controlled_storage_freight + field_dict["driverControlledStorageFreight"] = driver_controlled_storage_freight if driver_controlled_freight_1 is not UNSET: field_dict["driverControlledFreight1"] = driver_controlled_freight_1 if driver_controlled_freight_2 is not UNSET: @@ -228,17 +224,11 @@ def to_dict(self) -> Dict[str, Any]: if auto_bonus_points is not UNSET: field_dict["autoBonusPoints"] = auto_bonus_points if driver_controlled_alliance_hub_points is not UNSET: - field_dict[ - "driverControlledAllianceHubPoints" - ] = driver_controlled_alliance_hub_points + field_dict["driverControlledAllianceHubPoints"] = driver_controlled_alliance_hub_points if driver_controlled_shared_hub_points is not UNSET: - field_dict[ - "driverControlledSharedHubPoints" - ] = driver_controlled_shared_hub_points + field_dict["driverControlledSharedHubPoints"] = driver_controlled_shared_hub_points if driver_controlled_storage_points is not UNSET: - field_dict[ - "driverControlledStoragePoints" - ] = driver_controlled_storage_points + field_dict["driverControlledStoragePoints"] = driver_controlled_storage_points if endgame_delivery_points is not UNSET: field_dict["endgameDeliveryPoints"] = endgame_delivery_points if alliance_balanced_points is not UNSET: @@ -309,9 +299,7 @@ def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: auto_freight_3 = d.pop("autoFreight3", UNSET) - driver_controlled_storage_freight = d.pop( - "driverControlledStorageFreight", UNSET - ) + driver_controlled_storage_freight = d.pop("driverControlledStorageFreight", UNSET) driver_controlled_freight_1 = d.pop("driverControlledFreight1", UNSET) @@ -355,13 +343,9 @@ def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: auto_bonus_points = d.pop("autoBonusPoints", UNSET) - driver_controlled_alliance_hub_points = d.pop( - "driverControlledAllianceHubPoints", UNSET - ) + driver_controlled_alliance_hub_points = d.pop("driverControlledAllianceHubPoints", UNSET) - driver_controlled_shared_hub_points = d.pop( - "driverControlledSharedHubPoints", UNSET - ) + driver_controlled_shared_hub_points = d.pop("driverControlledSharedHubPoints", UNSET) driver_controlled_storage_points = d.pop("driverControlledStoragePoints", UNSET) diff --git a/ftc_api/models/freight_frenzy_alliance_score_details.py b/ftc_api/models/freight_frenzy_alliance_score_details.py index 8a9aa14..9bcf383 100644 --- a/ftc_api/models/freight_frenzy_alliance_score_details.py +++ b/ftc_api/models/freight_frenzy_alliance_score_details.py @@ -1,20 +1,18 @@ from typing import TYPE_CHECKING, Any, Dict, List, Type, TypeVar, Union -import attr +from attrs import define as _attrs_define from ..models.ftc_event_level import FTCEventLevel from ..types import UNSET, Unset if TYPE_CHECKING: - from ..models.freight_frenzy_alliance_score_breakdown import ( - FreightFrenzyAllianceScoreBreakdown, - ) + from ..models.freight_frenzy_alliance_score_breakdown import FreightFrenzyAllianceScoreBreakdown T = TypeVar("T", bound="FreightFrenzyAllianceScoreDetails") -@attr.s(auto_attribs=True) +@_attrs_define class FreightFrenzyAllianceScoreDetails: """ Attributes: @@ -67,9 +65,7 @@ def to_dict(self) -> Dict[str, Any]: @classmethod def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: - from ..models.freight_frenzy_alliance_score_breakdown import ( - FreightFrenzyAllianceScoreBreakdown, - ) + from ..models.freight_frenzy_alliance_score_breakdown import FreightFrenzyAllianceScoreBreakdown d = src_dict.copy() _match_level = d.pop("matchLevel", UNSET) @@ -88,9 +84,7 @@ def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: alliances = [] _alliances = d.pop("alliances", UNSET) for alliances_item_data in _alliances or []: - alliances_item = FreightFrenzyAllianceScoreBreakdown.from_dict( - alliances_item_data - ) + alliances_item = FreightFrenzyAllianceScoreBreakdown.from_dict(alliances_item_data) alliances.append(alliances_item) diff --git a/ftc_api/models/freight_frenzy_remote_score_breakdown.py b/ftc_api/models/freight_frenzy_remote_score_breakdown.py index 501eb75..4f8086d 100644 --- a/ftc_api/models/freight_frenzy_remote_score_breakdown.py +++ b/ftc_api/models/freight_frenzy_remote_score_breakdown.py @@ -1,6 +1,6 @@ from typing import Any, Dict, Type, TypeVar, Union -import attr +from attrs import define as _attrs_define from ..models.auto_navigated_status import AutoNavigatedStatus from ..models.barcode_element import BarcodeElement @@ -10,7 +10,7 @@ T = TypeVar("T", bound="FreightFrenzyRemoteScoreBreakdown") -@attr.s(auto_attribs=True) +@_attrs_define class FreightFrenzyRemoteScoreBreakdown: """ Attributes: @@ -115,9 +115,7 @@ def to_dict(self) -> Dict[str, Any]: auto_navigation_points = self.auto_navigation_points auto_freight_points = self.auto_freight_points auto_bonus_points = self.auto_bonus_points - driver_controlled_alliance_hub_points = ( - self.driver_controlled_alliance_hub_points - ) + driver_controlled_alliance_hub_points = self.driver_controlled_alliance_hub_points driver_controlled_storage_points = self.driver_controlled_storage_points endgame_delivery_points = self.endgame_delivery_points alliance_balanced_points = self.alliance_balanced_points @@ -148,9 +146,7 @@ def to_dict(self) -> Dict[str, Any]: if auto_freight_3 is not UNSET: field_dict["autoFreight3"] = auto_freight_3 if driver_controlled_storage_freight is not UNSET: - field_dict[ - "driverControlledStorageFreight" - ] = driver_controlled_storage_freight + field_dict["driverControlledStorageFreight"] = driver_controlled_storage_freight if driver_controlled_freight_1 is not UNSET: field_dict["driverControlledFreight1"] = driver_controlled_freight_1 if driver_controlled_freight_2 is not UNSET: @@ -178,13 +174,9 @@ def to_dict(self) -> Dict[str, Any]: if auto_bonus_points is not UNSET: field_dict["autoBonusPoints"] = auto_bonus_points if driver_controlled_alliance_hub_points is not UNSET: - field_dict[ - "driverControlledAllianceHubPoints" - ] = driver_controlled_alliance_hub_points + field_dict["driverControlledAllianceHubPoints"] = driver_controlled_alliance_hub_points if driver_controlled_storage_points is not UNSET: - field_dict[ - "driverControlledStoragePoints" - ] = driver_controlled_storage_points + field_dict["driverControlledStoragePoints"] = driver_controlled_storage_points if endgame_delivery_points is not UNSET: field_dict["endgameDeliveryPoints"] = endgame_delivery_points if alliance_balanced_points is not UNSET: @@ -235,9 +227,7 @@ def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: auto_freight_3 = d.pop("autoFreight3", UNSET) - driver_controlled_storage_freight = d.pop( - "driverControlledStorageFreight", UNSET - ) + driver_controlled_storage_freight = d.pop("driverControlledStorageFreight", UNSET) driver_controlled_freight_1 = d.pop("driverControlledFreight1", UNSET) @@ -270,9 +260,7 @@ def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: auto_bonus_points = d.pop("autoBonusPoints", UNSET) - driver_controlled_alliance_hub_points = d.pop( - "driverControlledAllianceHubPoints", UNSET - ) + driver_controlled_alliance_hub_points = d.pop("driverControlledAllianceHubPoints", UNSET) driver_controlled_storage_points = d.pop("driverControlledStoragePoints", UNSET) diff --git a/ftc_api/models/freight_frenzy_single_team_score_details.py b/ftc_api/models/freight_frenzy_single_team_score_details.py index 7384141..8f871ab 100644 --- a/ftc_api/models/freight_frenzy_single_team_score_details.py +++ b/ftc_api/models/freight_frenzy_single_team_score_details.py @@ -1,20 +1,18 @@ from typing import TYPE_CHECKING, Any, Dict, Type, TypeVar, Union -import attr +from attrs import define as _attrs_define from ..models.ftc_event_level import FTCEventLevel from ..types import UNSET, Unset if TYPE_CHECKING: - from ..models.freight_frenzy_remote_score_breakdown import ( - FreightFrenzyRemoteScoreBreakdown, - ) + from ..models.freight_frenzy_remote_score_breakdown import FreightFrenzyRemoteScoreBreakdown T = TypeVar("T", bound="FreightFrenzySingleTeamScoreDetails") -@attr.s(auto_attribs=True) +@_attrs_define class FreightFrenzySingleTeamScoreDetails: """ Attributes: @@ -60,9 +58,7 @@ def to_dict(self) -> Dict[str, Any]: @classmethod def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: - from ..models.freight_frenzy_remote_score_breakdown import ( - FreightFrenzyRemoteScoreBreakdown, - ) + from ..models.freight_frenzy_remote_score_breakdown import FreightFrenzyRemoteScoreBreakdown d = src_dict.copy() _match_level = d.pop("matchLevel", UNSET) diff --git a/ftc_api/models/ftc_event_level.py b/ftc_api/models/ftc_event_level.py index 651ca03..277c3c0 100644 --- a/ftc_api/models/ftc_event_level.py +++ b/ftc_api/models/ftc_event_level.py @@ -2,11 +2,11 @@ class FTCEventLevel(str, Enum): + FINAL = "FINAL" OTHER = "OTHER" + PLAYOFF = "PLAYOFF" QUALIFICATION = "QUALIFICATION" SEMIFINAL = "SEMIFINAL" - FINAL = "FINAL" - PLAYOFF = "PLAYOFF" def __str__(self) -> str: return str(self.value) diff --git a/ftc_api/models/geometry.py b/ftc_api/models/geometry.py index 55544b3..4eb393d 100644 --- a/ftc_api/models/geometry.py +++ b/ftc_api/models/geometry.py @@ -1,6 +1,6 @@ from typing import TYPE_CHECKING, Any, Dict, List, Type, TypeVar, Union -import attr +from attrs import define as _attrs_define from ..models.dimension import Dimension from ..models.ogc_geometry_type import OgcGeometryType @@ -17,7 +17,7 @@ T = TypeVar("T", bound="Geometry") -@attr.s(auto_attribs=True) +@_attrs_define class Geometry: """ Attributes: diff --git a/ftc_api/models/geometry_factory.py b/ftc_api/models/geometry_factory.py index f6d4670..6740146 100644 --- a/ftc_api/models/geometry_factory.py +++ b/ftc_api/models/geometry_factory.py @@ -1,6 +1,6 @@ from typing import TYPE_CHECKING, Any, Dict, Type, TypeVar, Union -import attr +from attrs import define as _attrs_define from ..types import UNSET, Unset @@ -13,7 +13,7 @@ T = TypeVar("T", bound="GeometryFactory") -@attr.s(auto_attribs=True) +@_attrs_define class GeometryFactory: """ Attributes: @@ -74,9 +74,7 @@ def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: if isinstance(_coordinate_sequence_factory, Unset): coordinate_sequence_factory = UNSET else: - coordinate_sequence_factory = CoordinateSequenceFactory.from_dict( - _coordinate_sequence_factory - ) + coordinate_sequence_factory = CoordinateSequenceFactory.from_dict(_coordinate_sequence_factory) srid = d.pop("srid", UNSET) diff --git a/ftc_api/models/geometry_overlay.py b/ftc_api/models/geometry_overlay.py index f073412..06a0010 100644 --- a/ftc_api/models/geometry_overlay.py +++ b/ftc_api/models/geometry_overlay.py @@ -1,11 +1,11 @@ from typing import Any, Dict, Type, TypeVar -import attr +from attrs import define as _attrs_define T = TypeVar("T", bound="GeometryOverlay") -@attr.s(auto_attribs=True) +@_attrs_define class GeometryOverlay: """ """ diff --git a/ftc_api/models/get_v20_season_schedule_event_code_tournament_level_hybrid_tournament_level.py b/ftc_api/models/get_v20_season_schedule_event_code_tournament_level_hybrid_tournament_level.py index 400c308..b924139 100644 --- a/ftc_api/models/get_v20_season_schedule_event_code_tournament_level_hybrid_tournament_level.py +++ b/ftc_api/models/get_v20_season_schedule_event_code_tournament_level_hybrid_tournament_level.py @@ -2,8 +2,8 @@ class GetV20SeasonScheduleEventCodeTournamentLevelHybridTournamentLevel(str, Enum): - QUAL = "qual" PLAYOFF = "playoff" + QUAL = "qual" def __str__(self) -> str: return str(self.value) diff --git a/ftc_api/models/get_v20_season_scores_event_code_tournament_level_tournament_level.py b/ftc_api/models/get_v20_season_scores_event_code_tournament_level_tournament_level.py index 7e630b7..64d53db 100644 --- a/ftc_api/models/get_v20_season_scores_event_code_tournament_level_tournament_level.py +++ b/ftc_api/models/get_v20_season_scores_event_code_tournament_level_tournament_level.py @@ -2,8 +2,8 @@ class GetV20SeasonScoresEventCodeTournamentLevelTournamentLevel(str, Enum): - QUAL = "qual" PLAYOFF = "playoff" + QUAL = "qual" def __str__(self) -> str: return str(self.value) diff --git a/ftc_api/models/hybrid_schedule.py b/ftc_api/models/hybrid_schedule.py index 8f1ae45..793f88e 100644 --- a/ftc_api/models/hybrid_schedule.py +++ b/ftc_api/models/hybrid_schedule.py @@ -1,6 +1,6 @@ from typing import TYPE_CHECKING, Any, Dict, List, Type, TypeVar, Union -import attr +from attrs import define as _attrs_define from ..types import UNSET, Unset @@ -11,7 +11,7 @@ T = TypeVar("T", bound="HybridSchedule") -@attr.s(auto_attribs=True) +@_attrs_define class HybridSchedule: """ Attributes: diff --git a/ftc_api/models/hybrid_schedule_match.py b/ftc_api/models/hybrid_schedule_match.py index 47dfd10..21d7815 100644 --- a/ftc_api/models/hybrid_schedule_match.py +++ b/ftc_api/models/hybrid_schedule_match.py @@ -1,7 +1,7 @@ import datetime from typing import TYPE_CHECKING, Any, Dict, List, Type, TypeVar, Union -import attr +from attrs import define as _attrs_define from dateutil.parser import isoparse from ..types import UNSET, Unset @@ -13,7 +13,7 @@ T = TypeVar("T", bound="HybridScheduleMatch") -@attr.s(auto_attribs=True) +@_attrs_define class HybridScheduleMatch: """ Attributes: @@ -67,15 +67,11 @@ def to_dict(self) -> Dict[str, Any]: actual_start_time: Union[Unset, None, str] = UNSET if not isinstance(self.actual_start_time, Unset): - actual_start_time = ( - self.actual_start_time.isoformat() if self.actual_start_time else None - ) + actual_start_time = self.actual_start_time.isoformat() if self.actual_start_time else None post_result_time: Union[Unset, None, str] = UNSET if not isinstance(self.post_result_time, Unset): - post_result_time = ( - self.post_result_time.isoformat() if self.post_result_time else None - ) + post_result_time = self.post_result_time.isoformat() if self.post_result_time else None score_red_final = self.score_red_final score_red_foul = self.score_red_foul diff --git a/ftc_api/models/hybrid_schedule_team.py b/ftc_api/models/hybrid_schedule_team.py index 9fb9ae6..b889889 100644 --- a/ftc_api/models/hybrid_schedule_team.py +++ b/ftc_api/models/hybrid_schedule_team.py @@ -1,13 +1,13 @@ from typing import Any, Dict, Type, TypeVar, Union -import attr +from attrs import define as _attrs_define from ..types import UNSET, Unset T = TypeVar("T", bound="HybridScheduleTeam") -@attr.s(auto_attribs=True) +@_attrs_define class HybridScheduleTeam: """ Attributes: diff --git a/ftc_api/models/junction_element.py b/ftc_api/models/junction_element.py index 625804a..71854bd 100644 --- a/ftc_api/models/junction_element.py +++ b/ftc_api/models/junction_element.py @@ -3,9 +3,9 @@ class JunctionElement(str, Enum): MY_CONE = "MY_CONE" - OTHER_CONE = "OTHER_CONE" MY_R1_BEACON = "MY_R1_BEACON" MY_R2_BEACON = "MY_R2_BEACON" + OTHER_CONE = "OTHER_CONE" OTHER_R1_BEACON = "OTHER_R1_BEACON" OTHER_R2_BEACON = "OTHER_R2_BEACON" diff --git a/ftc_api/models/league.py b/ftc_api/models/league.py index e73cfdc..68d6979 100644 --- a/ftc_api/models/league.py +++ b/ftc_api/models/league.py @@ -1,13 +1,13 @@ from typing import Any, Dict, Type, TypeVar, Union -import attr +from attrs import define as _attrs_define from ..types import UNSET, Unset T = TypeVar("T", bound="League") -@attr.s(auto_attribs=True) +@_attrs_define class League: """ Attributes: diff --git a/ftc_api/models/league_list.py b/ftc_api/models/league_list.py index 7a6e308..f281e7f 100644 --- a/ftc_api/models/league_list.py +++ b/ftc_api/models/league_list.py @@ -1,6 +1,6 @@ from typing import TYPE_CHECKING, Any, Dict, List, Type, TypeVar, Union -import attr +from attrs import define as _attrs_define from ..types import UNSET, Unset @@ -11,7 +11,7 @@ T = TypeVar("T", bound="LeagueList") -@attr.s(auto_attribs=True) +@_attrs_define class LeagueList: """ Attributes: diff --git a/ftc_api/models/league_members.py b/ftc_api/models/league_members.py index 835bff7..2ad2cf2 100644 --- a/ftc_api/models/league_members.py +++ b/ftc_api/models/league_members.py @@ -1,13 +1,13 @@ from typing import Any, Dict, List, Type, TypeVar, Union, cast -import attr +from attrs import define as _attrs_define from ..types import UNSET, Unset T = TypeVar("T", bound="LeagueMembers") -@attr.s(auto_attribs=True) +@_attrs_define class LeagueMembers: """ Attributes: diff --git a/ftc_api/models/match_result.py b/ftc_api/models/match_result.py index 687794c..c5323ca 100644 --- a/ftc_api/models/match_result.py +++ b/ftc_api/models/match_result.py @@ -1,7 +1,7 @@ import datetime from typing import TYPE_CHECKING, Any, Dict, List, Type, TypeVar, Union -import attr +from attrs import define as _attrs_define from dateutil.parser import isoparse from ..types import UNSET, Unset @@ -13,7 +13,7 @@ T = TypeVar("T", bound="MatchResult") -@attr.s(auto_attribs=True) +@_attrs_define class MatchResult: """ Attributes: @@ -51,9 +51,7 @@ class MatchResult: def to_dict(self) -> Dict[str, Any]: actual_start_time: Union[Unset, None, str] = UNSET if not isinstance(self.actual_start_time, Unset): - actual_start_time = ( - self.actual_start_time.isoformat() if self.actual_start_time else None - ) + actual_start_time = self.actual_start_time.isoformat() if self.actual_start_time else None description = self.description tournament_level = self.tournament_level @@ -67,9 +65,7 @@ def to_dict(self) -> Dict[str, Any]: score_blue_auto = self.score_blue_auto post_result_time: Union[Unset, None, str] = UNSET if not isinstance(self.post_result_time, Unset): - post_result_time = ( - self.post_result_time.isoformat() if self.post_result_time else None - ) + post_result_time = self.post_result_time.isoformat() if self.post_result_time else None teams: Union[Unset, None, List[Dict[str, Any]]] = UNSET if not isinstance(self.teams, Unset): diff --git a/ftc_api/models/match_result_list.py b/ftc_api/models/match_result_list.py index 6ca6553..85a7702 100644 --- a/ftc_api/models/match_result_list.py +++ b/ftc_api/models/match_result_list.py @@ -1,6 +1,6 @@ from typing import TYPE_CHECKING, Any, Dict, List, Type, TypeVar, Union -import attr +from attrs import define as _attrs_define from ..types import UNSET, Unset @@ -11,7 +11,7 @@ T = TypeVar("T", bound="MatchResultList") -@attr.s(auto_attribs=True) +@_attrs_define class MatchResultList: """ Attributes: diff --git a/ftc_api/models/match_result_team.py b/ftc_api/models/match_result_team.py index a0f5498..9f4957b 100644 --- a/ftc_api/models/match_result_team.py +++ b/ftc_api/models/match_result_team.py @@ -1,13 +1,13 @@ from typing import Any, Dict, Type, TypeVar, Union -import attr +from attrs import define as _attrs_define from ..types import UNSET, Unset T = TypeVar("T", bound="MatchResultTeam") -@attr.s(auto_attribs=True) +@_attrs_define class MatchResultTeam: """ Attributes: diff --git a/ftc_api/models/match_score_list.py b/ftc_api/models/match_score_list.py index 78c306d..b812b82 100644 --- a/ftc_api/models/match_score_list.py +++ b/ftc_api/models/match_score_list.py @@ -1,33 +1,23 @@ from typing import TYPE_CHECKING, Any, Dict, List, Type, TypeVar, Union -import attr +from attrs import define as _attrs_define from ..types import UNSET, Unset if TYPE_CHECKING: - from ..models.freight_frenzy_alliance_score_details import ( - FreightFrenzyAllianceScoreDetails, - ) - from ..models.freight_frenzy_single_team_score_details import ( - FreightFrenzySingleTeamScoreDetails, - ) + from ..models.freight_frenzy_alliance_score_details import FreightFrenzyAllianceScoreDetails + from ..models.freight_frenzy_single_team_score_details import FreightFrenzySingleTeamScoreDetails from ..models.power_play_alliance_score_details import PowerPlayAllianceScoreDetails - from ..models.power_play_single_team_score_details import ( - PowerPlaySingleTeamScoreDetails, - ) + from ..models.power_play_single_team_score_details import PowerPlaySingleTeamScoreDetails from ..models.sky_stone_score_details import SkyStoneScoreDetails - from ..models.ultimate_goal_alliance_score_details import ( - UltimateGoalAllianceScoreDetails, - ) - from ..models.ultimate_goal_single_team_score_details import ( - UltimateGoalSingleTeamScoreDetails, - ) + from ..models.ultimate_goal_alliance_score_details import UltimateGoalAllianceScoreDetails + from ..models.ultimate_goal_single_team_score_details import UltimateGoalSingleTeamScoreDetails T = TypeVar("T", bound="MatchScoreList") -@attr.s(auto_attribs=True) +@_attrs_define class MatchScoreList: """ Attributes: @@ -53,22 +43,12 @@ class MatchScoreList: ] = UNSET def to_dict(self) -> Dict[str, Any]: - from ..models.freight_frenzy_alliance_score_details import ( - FreightFrenzyAllianceScoreDetails, - ) - from ..models.freight_frenzy_single_team_score_details import ( - FreightFrenzySingleTeamScoreDetails, - ) - from ..models.power_play_alliance_score_details import ( - PowerPlayAllianceScoreDetails, - ) + from ..models.freight_frenzy_alliance_score_details import FreightFrenzyAllianceScoreDetails + from ..models.freight_frenzy_single_team_score_details import FreightFrenzySingleTeamScoreDetails + from ..models.power_play_alliance_score_details import PowerPlayAllianceScoreDetails from ..models.sky_stone_score_details import SkyStoneScoreDetails - from ..models.ultimate_goal_alliance_score_details import ( - UltimateGoalAllianceScoreDetails, - ) - from ..models.ultimate_goal_single_team_score_details import ( - UltimateGoalSingleTeamScoreDetails, - ) + from ..models.ultimate_goal_alliance_score_details import UltimateGoalAllianceScoreDetails + from ..models.ultimate_goal_single_team_score_details import UltimateGoalSingleTeamScoreDetails match_scores: Union[Unset, None, List[Dict[str, Any]]] = UNSET if not isinstance(self.match_scores, Unset): @@ -82,29 +62,19 @@ def to_dict(self) -> Dict[str, Any]: if isinstance(match_scores_item_data, SkyStoneScoreDetails): match_scores_item = match_scores_item_data.to_dict() - elif isinstance( - match_scores_item_data, UltimateGoalAllianceScoreDetails - ): + elif isinstance(match_scores_item_data, UltimateGoalAllianceScoreDetails): match_scores_item = match_scores_item_data.to_dict() - elif isinstance( - match_scores_item_data, UltimateGoalSingleTeamScoreDetails - ): + elif isinstance(match_scores_item_data, UltimateGoalSingleTeamScoreDetails): match_scores_item = match_scores_item_data.to_dict() - elif isinstance( - match_scores_item_data, FreightFrenzyAllianceScoreDetails - ): + elif isinstance(match_scores_item_data, FreightFrenzyAllianceScoreDetails): match_scores_item = match_scores_item_data.to_dict() - elif isinstance( - match_scores_item_data, FreightFrenzySingleTeamScoreDetails - ): + elif isinstance(match_scores_item_data, FreightFrenzySingleTeamScoreDetails): match_scores_item = match_scores_item_data.to_dict() - elif isinstance( - match_scores_item_data, PowerPlayAllianceScoreDetails - ): + elif isinstance(match_scores_item_data, PowerPlayAllianceScoreDetails): match_scores_item = match_scores_item_data.to_dict() else: @@ -121,25 +91,13 @@ def to_dict(self) -> Dict[str, Any]: @classmethod def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: - from ..models.freight_frenzy_alliance_score_details import ( - FreightFrenzyAllianceScoreDetails, - ) - from ..models.freight_frenzy_single_team_score_details import ( - FreightFrenzySingleTeamScoreDetails, - ) - from ..models.power_play_alliance_score_details import ( - PowerPlayAllianceScoreDetails, - ) - from ..models.power_play_single_team_score_details import ( - PowerPlaySingleTeamScoreDetails, - ) + from ..models.freight_frenzy_alliance_score_details import FreightFrenzyAllianceScoreDetails + from ..models.freight_frenzy_single_team_score_details import FreightFrenzySingleTeamScoreDetails + from ..models.power_play_alliance_score_details import PowerPlayAllianceScoreDetails + from ..models.power_play_single_team_score_details import PowerPlaySingleTeamScoreDetails from ..models.sky_stone_score_details import SkyStoneScoreDetails - from ..models.ultimate_goal_alliance_score_details import ( - UltimateGoalAllianceScoreDetails, - ) - from ..models.ultimate_goal_single_team_score_details import ( - UltimateGoalSingleTeamScoreDetails, - ) + from ..models.ultimate_goal_alliance_score_details import UltimateGoalAllianceScoreDetails + from ..models.ultimate_goal_single_team_score_details import UltimateGoalSingleTeamScoreDetails d = src_dict.copy() match_scores = [] @@ -168,9 +126,7 @@ def _parse_match_scores_item( try: if not isinstance(data, dict): raise TypeError() - match_scores_item_type_1 = ( - UltimateGoalAllianceScoreDetails.from_dict(data) - ) + match_scores_item_type_1 = UltimateGoalAllianceScoreDetails.from_dict(data) return match_scores_item_type_1 except: # noqa: E722 @@ -178,9 +134,7 @@ def _parse_match_scores_item( try: if not isinstance(data, dict): raise TypeError() - match_scores_item_type_2 = ( - UltimateGoalSingleTeamScoreDetails.from_dict(data) - ) + match_scores_item_type_2 = UltimateGoalSingleTeamScoreDetails.from_dict(data) return match_scores_item_type_2 except: # noqa: E722 @@ -188,9 +142,7 @@ def _parse_match_scores_item( try: if not isinstance(data, dict): raise TypeError() - match_scores_item_type_3 = ( - FreightFrenzyAllianceScoreDetails.from_dict(data) - ) + match_scores_item_type_3 = FreightFrenzyAllianceScoreDetails.from_dict(data) return match_scores_item_type_3 except: # noqa: E722 @@ -198,9 +150,7 @@ def _parse_match_scores_item( try: if not isinstance(data, dict): raise TypeError() - match_scores_item_type_4 = ( - FreightFrenzySingleTeamScoreDetails.from_dict(data) - ) + match_scores_item_type_4 = FreightFrenzySingleTeamScoreDetails.from_dict(data) return match_scores_item_type_4 except: # noqa: E722 @@ -208,18 +158,14 @@ def _parse_match_scores_item( try: if not isinstance(data, dict): raise TypeError() - match_scores_item_type_5 = PowerPlayAllianceScoreDetails.from_dict( - data - ) + match_scores_item_type_5 = PowerPlayAllianceScoreDetails.from_dict(data) return match_scores_item_type_5 except: # noqa: E722 pass if not isinstance(data, dict): raise TypeError() - match_scores_item_type_6 = PowerPlaySingleTeamScoreDetails.from_dict( - data - ) + match_scores_item_type_6 = PowerPlaySingleTeamScoreDetails.from_dict(data) return match_scores_item_type_6 diff --git a/ftc_api/models/nts_geometry_services.py b/ftc_api/models/nts_geometry_services.py index d425e21..442a33e 100644 --- a/ftc_api/models/nts_geometry_services.py +++ b/ftc_api/models/nts_geometry_services.py @@ -1,6 +1,6 @@ from typing import TYPE_CHECKING, Any, Dict, Type, TypeVar, Union -import attr +from attrs import define as _attrs_define from ..types import UNSET, Unset @@ -14,7 +14,7 @@ T = TypeVar("T", bound="NtsGeometryServices") -@attr.s(auto_attribs=True) +@_attrs_define class NtsGeometryServices: """ Attributes: @@ -28,9 +28,7 @@ class NtsGeometryServices: geometry_overlay: Union[Unset, "GeometryOverlay"] = UNSET coordinate_equality_comparer: Union[Unset, "CoordinateEqualityComparer"] = UNSET default_srid: Union[Unset, int] = UNSET - default_coordinate_sequence_factory: Union[ - Unset, "CoordinateSequenceFactory" - ] = UNSET + default_coordinate_sequence_factory: Union[Unset, "CoordinateSequenceFactory"] = UNSET default_precision_model: Union[Unset, "PrecisionModel"] = UNSET def to_dict(self) -> Dict[str, Any]: @@ -45,9 +43,7 @@ def to_dict(self) -> Dict[str, Any]: default_srid = self.default_srid default_coordinate_sequence_factory: Union[Unset, Dict[str, Any]] = UNSET if not isinstance(self.default_coordinate_sequence_factory, Unset): - default_coordinate_sequence_factory = ( - self.default_coordinate_sequence_factory.to_dict() - ) + default_coordinate_sequence_factory = self.default_coordinate_sequence_factory.to_dict() default_precision_model: Union[Unset, Dict[str, Any]] = UNSET if not isinstance(self.default_precision_model, Unset): @@ -62,9 +58,7 @@ def to_dict(self) -> Dict[str, Any]: if default_srid is not UNSET: field_dict["defaultSRID"] = default_srid if default_coordinate_sequence_factory is not UNSET: - field_dict[ - "defaultCoordinateSequenceFactory" - ] = default_coordinate_sequence_factory + field_dict["defaultCoordinateSequenceFactory"] = default_coordinate_sequence_factory if default_precision_model is not UNSET: field_dict["defaultPrecisionModel"] = default_precision_model @@ -90,15 +84,11 @@ def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: if isinstance(_coordinate_equality_comparer, Unset): coordinate_equality_comparer = UNSET else: - coordinate_equality_comparer = CoordinateEqualityComparer.from_dict( - _coordinate_equality_comparer - ) + coordinate_equality_comparer = CoordinateEqualityComparer.from_dict(_coordinate_equality_comparer) default_srid = d.pop("defaultSRID", UNSET) - _default_coordinate_sequence_factory = d.pop( - "defaultCoordinateSequenceFactory", UNSET - ) + _default_coordinate_sequence_factory = d.pop("defaultCoordinateSequenceFactory", UNSET) default_coordinate_sequence_factory: Union[Unset, CoordinateSequenceFactory] if isinstance(_default_coordinate_sequence_factory, Unset): default_coordinate_sequence_factory = UNSET diff --git a/ftc_api/models/ogc_geometry_type.py b/ftc_api/models/ogc_geometry_type.py index fc056f9..a8bbe5f 100644 --- a/ftc_api/models/ogc_geometry_type.py +++ b/ftc_api/models/ogc_geometry_type.py @@ -2,21 +2,21 @@ class OgcGeometryType(str, Enum): - POINT = "Point" - LINESTRING = "LineString" - POLYGON = "Polygon" - MULTIPOINT = "MultiPoint" - MULTILINESTRING = "MultiLineString" - MULTIPOLYGON = "MultiPolygon" - GEOMETRYCOLLECTION = "GeometryCollection" CIRCULARSTRING = "CircularString" COMPOUNDCURVE = "CompoundCurve" + CURVE = "Curve" CURVEPOLYGON = "CurvePolygon" + GEOMETRYCOLLECTION = "GeometryCollection" + LINESTRING = "LineString" MULTICURVE = "MultiCurve" + MULTILINESTRING = "MultiLineString" + MULTIPOINT = "MultiPoint" + MULTIPOLYGON = "MultiPolygon" MULTISURFACE = "MultiSurface" - CURVE = "Curve" - SURFACE = "Surface" + POINT = "Point" + POLYGON = "Polygon" POLYHEDRALSURFACE = "PolyhedralSurface" + SURFACE = "Surface" TIN = "TIN" def __str__(self) -> str: diff --git a/ftc_api/models/ordinates.py b/ftc_api/models/ordinates.py index a3c7fa9..9b66ba1 100644 --- a/ftc_api/models/ordinates.py +++ b/ftc_api/models/ordinates.py @@ -2,29 +2,17 @@ class Ordinates(str, Enum): - NONE = "None" - X = "X" - Y = "Y" - XY = "XY" - SPATIAL3 = "Spatial3" - XYZ = "XYZ" - SPATIAL4 = "Spatial4" - SPATIAL5 = "Spatial5" - SPATIAL6 = "Spatial6" - SPATIAL7 = "Spatial7" - SPATIAL8 = "Spatial8" - SPATIAL9 = "Spatial9" - SPATIAL10 = "Spatial10" - SPATIAL11 = "Spatial11" - SPATIAL12 = "Spatial12" - SPATIAL13 = "Spatial13" - SPATIAL14 = "Spatial14" - SPATIAL15 = "Spatial15" - SPATIAL16 = "Spatial16" + ALLMEASUREORDINATES = "AllMeasureOrdinates" + ALLORDINATES = "AllOrdinates" ALLSPATIALORDINATES = "AllSpatialOrdinates" MEASURE1 = "Measure1" - XYM = "XYM" - XYZM = "XYZM" + MEASURE10 = "Measure10" + MEASURE11 = "Measure11" + MEASURE12 = "Measure12" + MEASURE13 = "Measure13" + MEASURE14 = "Measure14" + MEASURE15 = "Measure15" + MEASURE16 = "Measure16" MEASURE2 = "Measure2" MEASURE3 = "Measure3" MEASURE4 = "Measure4" @@ -33,15 +21,27 @@ class Ordinates(str, Enum): MEASURE7 = "Measure7" MEASURE8 = "Measure8" MEASURE9 = "Measure9" - MEASURE10 = "Measure10" - MEASURE11 = "Measure11" - MEASURE12 = "Measure12" - MEASURE13 = "Measure13" - MEASURE14 = "Measure14" - MEASURE15 = "Measure15" - MEASURE16 = "Measure16" - ALLMEASUREORDINATES = "AllMeasureOrdinates" - ALLORDINATES = "AllOrdinates" + NONE = "None" + SPATIAL10 = "Spatial10" + SPATIAL11 = "Spatial11" + SPATIAL12 = "Spatial12" + SPATIAL13 = "Spatial13" + SPATIAL14 = "Spatial14" + SPATIAL15 = "Spatial15" + SPATIAL16 = "Spatial16" + SPATIAL3 = "Spatial3" + SPATIAL4 = "Spatial4" + SPATIAL5 = "Spatial5" + SPATIAL6 = "Spatial6" + SPATIAL7 = "Spatial7" + SPATIAL8 = "Spatial8" + SPATIAL9 = "Spatial9" + X = "X" + XY = "XY" + XYM = "XYM" + XYZ = "XYZ" + XYZM = "XYZM" + Y = "Y" def __str__(self) -> str: return str(self.value) diff --git a/ftc_api/models/point.py b/ftc_api/models/point.py index 48e8e19..789ad56 100644 --- a/ftc_api/models/point.py +++ b/ftc_api/models/point.py @@ -1,6 +1,6 @@ from typing import TYPE_CHECKING, Any, Dict, List, Type, TypeVar, Union -import attr +from attrs import define as _attrs_define from ..models.dimension import Dimension from ..models.ogc_geometry_type import OgcGeometryType @@ -18,7 +18,7 @@ T = TypeVar("T", bound="Point") -@attr.s(auto_attribs=True) +@_attrs_define class Point: """ Attributes: diff --git a/ftc_api/models/power_play_alliance_score_breakdown.py b/ftc_api/models/power_play_alliance_score_breakdown.py index 721a0b8..7109d67 100644 --- a/ftc_api/models/power_play_alliance_score_breakdown.py +++ b/ftc_api/models/power_play_alliance_score_breakdown.py @@ -1,6 +1,6 @@ from typing import Any, Dict, List, Type, TypeVar, Union, cast -import attr +from attrs import define as _attrs_define from ..models.auto_navigation import AutoNavigation from ..models.field_side import FieldSide @@ -10,7 +10,7 @@ T = TypeVar("T", bound="PowerPlayAllianceScoreBreakdown") -@attr.s(auto_attribs=True) +@_attrs_define class PowerPlayAllianceScoreBreakdown: """ Attributes: @@ -136,16 +136,10 @@ def to_dict(self) -> Dict[str, Any]: auto_junctions_item = [] for auto_junctions_item_item_data in auto_junctions_item_data: auto_junctions_item_item = [] - for ( - auto_junctions_item_item_item_data - ) in auto_junctions_item_item_data: - auto_junctions_item_item_item = ( - auto_junctions_item_item_item_data.value - ) + for auto_junctions_item_item_item_data in auto_junctions_item_item_data: + auto_junctions_item_item_item = auto_junctions_item_item_item_data.value - auto_junctions_item_item.append( - auto_junctions_item_item_item - ) + auto_junctions_item_item.append(auto_junctions_item_item_item) auto_junctions_item.append(auto_junctions_item_item) @@ -161,12 +155,8 @@ def to_dict(self) -> Dict[str, Any]: dc_junctions_item = [] for dc_junctions_item_item_data in dc_junctions_item_data: dc_junctions_item_item = [] - for ( - dc_junctions_item_item_item_data - ) in dc_junctions_item_item_data: - dc_junctions_item_item_item = ( - dc_junctions_item_item_item_data.value - ) + for dc_junctions_item_item_item_data in dc_junctions_item_item_data: + dc_junctions_item_item_item = dc_junctions_item_item_item_data.value dc_junctions_item_item.append(dc_junctions_item_item_item) @@ -331,9 +321,7 @@ def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: auto_junctions_item_item = [] _auto_junctions_item_item = auto_junctions_item_item_data for auto_junctions_item_item_item_data in _auto_junctions_item_item: - auto_junctions_item_item_item = JunctionElement( - auto_junctions_item_item_item_data - ) + auto_junctions_item_item_item = JunctionElement(auto_junctions_item_item_item_data) auto_junctions_item_item.append(auto_junctions_item_item_item) @@ -350,9 +338,7 @@ def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: dc_junctions_item_item = [] _dc_junctions_item_item = dc_junctions_item_item_data for dc_junctions_item_item_item_data in _dc_junctions_item_item: - dc_junctions_item_item_item = JunctionElement( - dc_junctions_item_item_item_data - ) + dc_junctions_item_item_item = JunctionElement(dc_junctions_item_item_item_data) dc_junctions_item_item.append(dc_junctions_item_item_item) diff --git a/ftc_api/models/power_play_alliance_score_details.py b/ftc_api/models/power_play_alliance_score_details.py index 0f7912d..1553042 100644 --- a/ftc_api/models/power_play_alliance_score_details.py +++ b/ftc_api/models/power_play_alliance_score_details.py @@ -1,20 +1,18 @@ from typing import TYPE_CHECKING, Any, Dict, List, Type, TypeVar, Union -import attr +from attrs import define as _attrs_define from ..models.ftc_event_level import FTCEventLevel from ..types import UNSET, Unset if TYPE_CHECKING: - from ..models.power_play_alliance_score_breakdown import ( - PowerPlayAllianceScoreBreakdown, - ) + from ..models.power_play_alliance_score_breakdown import PowerPlayAllianceScoreBreakdown T = TypeVar("T", bound="PowerPlayAllianceScoreDetails") -@attr.s(auto_attribs=True) +@_attrs_define class PowerPlayAllianceScoreDetails: """ Attributes: @@ -67,9 +65,7 @@ def to_dict(self) -> Dict[str, Any]: @classmethod def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: - from ..models.power_play_alliance_score_breakdown import ( - PowerPlayAllianceScoreBreakdown, - ) + from ..models.power_play_alliance_score_breakdown import PowerPlayAllianceScoreBreakdown d = src_dict.copy() _match_level = d.pop("matchLevel", UNSET) @@ -88,9 +84,7 @@ def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: alliances = [] _alliances = d.pop("alliances", UNSET) for alliances_item_data in _alliances or []: - alliances_item = PowerPlayAllianceScoreBreakdown.from_dict( - alliances_item_data - ) + alliances_item = PowerPlayAllianceScoreBreakdown.from_dict(alliances_item_data) alliances.append(alliances_item) diff --git a/ftc_api/models/power_play_remote_score_breakdown.py b/ftc_api/models/power_play_remote_score_breakdown.py index 4cefba8..06f71a4 100644 --- a/ftc_api/models/power_play_remote_score_breakdown.py +++ b/ftc_api/models/power_play_remote_score_breakdown.py @@ -1,11 +1,11 @@ from typing import Any, Dict, Type, TypeVar -import attr +from attrs import define as _attrs_define T = TypeVar("T", bound="PowerPlayRemoteScoreBreakdown") -@attr.s(auto_attribs=True) +@_attrs_define class PowerPlayRemoteScoreBreakdown: """ """ diff --git a/ftc_api/models/power_play_single_team_score_details.py b/ftc_api/models/power_play_single_team_score_details.py index 8ee3fe1..d590ed9 100644 --- a/ftc_api/models/power_play_single_team_score_details.py +++ b/ftc_api/models/power_play_single_team_score_details.py @@ -1,6 +1,6 @@ from typing import TYPE_CHECKING, Any, Dict, Type, TypeVar, Union -import attr +from attrs import define as _attrs_define from ..models.ftc_event_level import FTCEventLevel from ..types import UNSET, Unset @@ -12,7 +12,7 @@ T = TypeVar("T", bound="PowerPlaySingleTeamScoreDetails") -@attr.s(auto_attribs=True) +@_attrs_define class PowerPlaySingleTeamScoreDetails: """ Attributes: @@ -58,9 +58,7 @@ def to_dict(self) -> Dict[str, Any]: @classmethod def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: - from ..models.power_play_remote_score_breakdown import ( - PowerPlayRemoteScoreBreakdown, - ) + from ..models.power_play_remote_score_breakdown import PowerPlayRemoteScoreBreakdown d = src_dict.copy() _match_level = d.pop("matchLevel", UNSET) diff --git a/ftc_api/models/precision_model.py b/ftc_api/models/precision_model.py index 26e6b1f..e5f4bfa 100644 --- a/ftc_api/models/precision_model.py +++ b/ftc_api/models/precision_model.py @@ -1,6 +1,6 @@ from typing import Any, Dict, Type, TypeVar, Union -import attr +from attrs import define as _attrs_define from ..models.precision_models import PrecisionModels from ..types import UNSET, Unset @@ -8,7 +8,7 @@ T = TypeVar("T", bound="PrecisionModel") -@attr.s(auto_attribs=True) +@_attrs_define class PrecisionModel: """ Attributes: diff --git a/ftc_api/models/precision_models.py b/ftc_api/models/precision_models.py index 3b11313..1449c9e 100644 --- a/ftc_api/models/precision_models.py +++ b/ftc_api/models/precision_models.py @@ -2,9 +2,9 @@ class PrecisionModels(str, Enum): + FIXED = "Fixed" FLOATING = "Floating" FLOATINGSINGLE = "FloatingSingle" - FIXED = "Fixed" def __str__(self) -> str: return str(self.value) diff --git a/ftc_api/models/scheduled_match.py b/ftc_api/models/scheduled_match.py index b95d08b..5ea2cc5 100644 --- a/ftc_api/models/scheduled_match.py +++ b/ftc_api/models/scheduled_match.py @@ -1,7 +1,7 @@ import datetime from typing import TYPE_CHECKING, Any, Dict, List, Type, TypeVar, Union -import attr +from attrs import define as _attrs_define from dateutil.parser import isoparse from ..types import UNSET, Unset @@ -13,7 +13,7 @@ T = TypeVar("T", bound="ScheduledMatch") -@attr.s(auto_attribs=True) +@_attrs_define class ScheduledMatch: """ Attributes: diff --git a/ftc_api/models/scheduled_match_list.py b/ftc_api/models/scheduled_match_list.py index fb88913..c8f0c6e 100644 --- a/ftc_api/models/scheduled_match_list.py +++ b/ftc_api/models/scheduled_match_list.py @@ -1,6 +1,6 @@ from typing import TYPE_CHECKING, Any, Dict, List, Type, TypeVar, Union -import attr +from attrs import define as _attrs_define from ..types import UNSET, Unset @@ -11,7 +11,7 @@ T = TypeVar("T", bound="ScheduledMatchList") -@attr.s(auto_attribs=True) +@_attrs_define class ScheduledMatchList: """ Attributes: diff --git a/ftc_api/models/scheduled_match_team.py b/ftc_api/models/scheduled_match_team.py index 26b8ba3..7a351ab 100644 --- a/ftc_api/models/scheduled_match_team.py +++ b/ftc_api/models/scheduled_match_team.py @@ -1,13 +1,13 @@ from typing import Any, Dict, Type, TypeVar, Union -import attr +from attrs import define as _attrs_define from ..types import UNSET, Unset T = TypeVar("T", bound="ScheduledMatchTeam") -@attr.s(auto_attribs=True) +@_attrs_define class ScheduledMatchTeam: """ Attributes: diff --git a/ftc_api/models/season_summary.py b/ftc_api/models/season_summary.py index 2a943b9..1a5e6da 100644 --- a/ftc_api/models/season_summary.py +++ b/ftc_api/models/season_summary.py @@ -1,7 +1,7 @@ import datetime from typing import TYPE_CHECKING, Any, Dict, List, Type, TypeVar, Union -import attr +from attrs import define as _attrs_define from dateutil.parser import isoparse from ..types import UNSET, Unset @@ -13,7 +13,7 @@ T = TypeVar("T", bound="SeasonSummary") -@attr.s(auto_attribs=True) +@_attrs_define class SeasonSummary: """ Attributes: @@ -30,9 +30,7 @@ class SeasonSummary: kickoff: Union[Unset, None, datetime.datetime] = UNSET rookie_start: Union[Unset, int] = UNSET team_count: Union[Unset, int] = UNSET - frc_championships: Union[ - Unset, None, List["SummaryChampionshipDescription"] - ] = UNSET + frc_championships: Union[Unset, None, List["SummaryChampionshipDescription"]] = UNSET def to_dict(self) -> Dict[str, Any]: event_count = self.event_count @@ -73,9 +71,7 @@ def to_dict(self) -> Dict[str, Any]: @classmethod def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: - from ..models.summary_championship_description import ( - SummaryChampionshipDescription, - ) + from ..models.summary_championship_description import SummaryChampionshipDescription d = src_dict.copy() event_count = d.pop("eventCount", UNSET) @@ -98,9 +94,7 @@ def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: frc_championships = [] _frc_championships = d.pop("frcChampionships", UNSET) for frc_championships_item_data in _frc_championships or []: - frc_championships_item = SummaryChampionshipDescription.from_dict( - frc_championships_item_data - ) + frc_championships_item = SummaryChampionshipDescription.from_dict(frc_championships_item_data) frc_championships.append(frc_championships_item) diff --git a/ftc_api/models/selection.py b/ftc_api/models/selection.py index f942d6f..76e5e31 100644 --- a/ftc_api/models/selection.py +++ b/ftc_api/models/selection.py @@ -1,6 +1,6 @@ from typing import Any, Dict, Type, TypeVar, Union -import attr +from attrs import define as _attrs_define from ..models.selection_result import SelectionResult from ..types import UNSET, Unset @@ -8,7 +8,7 @@ T = TypeVar("T", bound="Selection") -@attr.s(auto_attribs=True) +@_attrs_define class Selection: """ Attributes: diff --git a/ftc_api/models/selection_result.py b/ftc_api/models/selection_result.py index 43bb394..91a5c2b 100644 --- a/ftc_api/models/selection_result.py +++ b/ftc_api/models/selection_result.py @@ -3,8 +3,8 @@ class SelectionResult(str, Enum): ACCEPT = "ACCEPT" - DECLINE = "DECLINE" CAPTAIN = "CAPTAIN" + DECLINE = "DECLINE" def __str__(self) -> str: return str(self.value) diff --git a/ftc_api/models/sky_stone_alliance_score_details.py b/ftc_api/models/sky_stone_alliance_score_details.py index 1bc2461..ca0ad31 100644 --- a/ftc_api/models/sky_stone_alliance_score_details.py +++ b/ftc_api/models/sky_stone_alliance_score_details.py @@ -1,6 +1,6 @@ from typing import Any, Dict, List, Type, TypeVar, Union -import attr +from attrs import define as _attrs_define from ..models.stone import Stone from ..types import UNSET, Unset @@ -8,7 +8,7 @@ T = TypeVar("T", bound="SkyStoneAllianceScoreDetails") -@attr.s(auto_attribs=True) +@_attrs_define class SkyStoneAllianceScoreDetails: """ Attributes: @@ -178,9 +178,7 @@ def to_dict(self) -> Dict[str, Any]: if navigation_points is not UNSET: field_dict["navigationPoints"] = navigation_points if driver_controlled_delivery_points is not UNSET: - field_dict[ - "driverControlledDeliveryPoints" - ] = driver_controlled_delivery_points + field_dict["driverControlledDeliveryPoints"] = driver_controlled_delivery_points if driver_controlled_placed_points is not UNSET: field_dict["driverControlledPlacedPoints"] = driver_controlled_placed_points if skyscraper_bonus_points is not UNSET: @@ -258,9 +256,7 @@ def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: navigation_points = d.pop("navigationPoints", UNSET) - driver_controlled_delivery_points = d.pop( - "driverControlledDeliveryPoints", UNSET - ) + driver_controlled_delivery_points = d.pop("driverControlledDeliveryPoints", UNSET) driver_controlled_placed_points = d.pop("driverControlledPlacedPoints", UNSET) diff --git a/ftc_api/models/sky_stone_score_details.py b/ftc_api/models/sky_stone_score_details.py index e7e8b53..a82fb63 100644 --- a/ftc_api/models/sky_stone_score_details.py +++ b/ftc_api/models/sky_stone_score_details.py @@ -1,6 +1,6 @@ from typing import TYPE_CHECKING, Any, Dict, List, Type, TypeVar, Union -import attr +from attrs import define as _attrs_define from ..models.ftc_event_level import FTCEventLevel from ..types import UNSET, Unset @@ -12,7 +12,7 @@ T = TypeVar("T", bound="SkyStoneScoreDetails") -@attr.s(auto_attribs=True) +@_attrs_define class SkyStoneScoreDetails: """ Attributes: @@ -60,9 +60,7 @@ def to_dict(self) -> Dict[str, Any]: @classmethod def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: - from ..models.sky_stone_alliance_score_details import ( - SkyStoneAllianceScoreDetails, - ) + from ..models.sky_stone_alliance_score_details import SkyStoneAllianceScoreDetails d = src_dict.copy() _match_level = d.pop("matchLevel", UNSET) diff --git a/ftc_api/models/stone.py b/ftc_api/models/stone.py index 89c7e07..772beb3 100644 --- a/ftc_api/models/stone.py +++ b/ftc_api/models/stone.py @@ -3,8 +3,8 @@ class Stone(str, Enum): NONE = "NONE" - STONE = "STONE" SKYSTONE = "SKYSTONE" + STONE = "STONE" def __str__(self) -> str: return str(self.value) diff --git a/ftc_api/models/summary_championship_description.py b/ftc_api/models/summary_championship_description.py index d1fee15..91e2d9e 100644 --- a/ftc_api/models/summary_championship_description.py +++ b/ftc_api/models/summary_championship_description.py @@ -1,7 +1,7 @@ import datetime from typing import Any, Dict, Type, TypeVar, Union -import attr +from attrs import define as _attrs_define from dateutil.parser import isoparse from ..types import UNSET, Unset @@ -9,7 +9,7 @@ T = TypeVar("T", bound="SummaryChampionshipDescription") -@attr.s(auto_attribs=True) +@_attrs_define class SummaryChampionshipDescription: """ Attributes: diff --git a/ftc_api/models/team.py b/ftc_api/models/team.py index 20fb266..6c605af 100644 --- a/ftc_api/models/team.py +++ b/ftc_api/models/team.py @@ -1,13 +1,13 @@ from typing import Any, Dict, Type, TypeVar, Union -import attr +from attrs import define as _attrs_define from ..types import UNSET, Unset T = TypeVar("T", bound="Team") -@attr.s(auto_attribs=True) +@_attrs_define class Team: """ Attributes: diff --git a/ftc_api/models/team_list.py b/ftc_api/models/team_list.py index b598491..0bedc57 100644 --- a/ftc_api/models/team_list.py +++ b/ftc_api/models/team_list.py @@ -1,6 +1,6 @@ from typing import TYPE_CHECKING, Any, Dict, List, Type, TypeVar, Union -import attr +from attrs import define as _attrs_define from ..types import UNSET, Unset @@ -11,7 +11,7 @@ T = TypeVar("T", bound="TeamList") -@attr.s(auto_attribs=True) +@_attrs_define class TeamList: """ Attributes: diff --git a/ftc_api/models/team_ranking.py b/ftc_api/models/team_ranking.py index 125dc2f..7cf4a48 100644 --- a/ftc_api/models/team_ranking.py +++ b/ftc_api/models/team_ranking.py @@ -1,13 +1,13 @@ from typing import Any, Dict, Type, TypeVar, Union -import attr +from attrs import define as _attrs_define from ..types import UNSET, Unset T = TypeVar("T", bound="TeamRanking") -@attr.s(auto_attribs=True) +@_attrs_define class TeamRanking: """ Attributes: diff --git a/ftc_api/models/ultimate_goal_alliance_score_breakdown.py b/ftc_api/models/ultimate_goal_alliance_score_breakdown.py index e4f8e3d..3635d9d 100644 --- a/ftc_api/models/ultimate_goal_alliance_score_breakdown.py +++ b/ftc_api/models/ultimate_goal_alliance_score_breakdown.py @@ -1,13 +1,13 @@ from typing import Any, Dict, Type, TypeVar, Union -import attr +from attrs import define as _attrs_define from ..types import UNSET, Unset T = TypeVar("T", bound="UltimateGoalAllianceScoreBreakdown") -@attr.s(auto_attribs=True) +@_attrs_define class UltimateGoalAllianceScoreBreakdown: """ Attributes: diff --git a/ftc_api/models/ultimate_goal_alliance_score_details.py b/ftc_api/models/ultimate_goal_alliance_score_details.py index 4d84636..5dfffed 100644 --- a/ftc_api/models/ultimate_goal_alliance_score_details.py +++ b/ftc_api/models/ultimate_goal_alliance_score_details.py @@ -1,20 +1,18 @@ from typing import TYPE_CHECKING, Any, Dict, List, Type, TypeVar, Union -import attr +from attrs import define as _attrs_define from ..models.ftc_event_level import FTCEventLevel from ..types import UNSET, Unset if TYPE_CHECKING: - from ..models.ultimate_goal_alliance_score_breakdown import ( - UltimateGoalAllianceScoreBreakdown, - ) + from ..models.ultimate_goal_alliance_score_breakdown import UltimateGoalAllianceScoreBreakdown T = TypeVar("T", bound="UltimateGoalAllianceScoreDetails") -@attr.s(auto_attribs=True) +@_attrs_define class UltimateGoalAllianceScoreDetails: """ Attributes: @@ -62,9 +60,7 @@ def to_dict(self) -> Dict[str, Any]: @classmethod def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: - from ..models.ultimate_goal_alliance_score_breakdown import ( - UltimateGoalAllianceScoreBreakdown, - ) + from ..models.ultimate_goal_alliance_score_breakdown import UltimateGoalAllianceScoreBreakdown d = src_dict.copy() _match_level = d.pop("matchLevel", UNSET) @@ -81,9 +77,7 @@ def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: alliances = [] _alliances = d.pop("alliances", UNSET) for alliances_item_data in _alliances or []: - alliances_item = UltimateGoalAllianceScoreBreakdown.from_dict( - alliances_item_data - ) + alliances_item = UltimateGoalAllianceScoreBreakdown.from_dict(alliances_item_data) alliances.append(alliances_item) diff --git a/ftc_api/models/ultimate_goal_single_team_breakdown.py b/ftc_api/models/ultimate_goal_single_team_breakdown.py index 5e1cd74..feff93a 100644 --- a/ftc_api/models/ultimate_goal_single_team_breakdown.py +++ b/ftc_api/models/ultimate_goal_single_team_breakdown.py @@ -1,13 +1,13 @@ from typing import Any, Dict, Type, TypeVar, Union -import attr +from attrs import define as _attrs_define from ..types import UNSET, Unset T = TypeVar("T", bound="UltimateGoalSingleTeamBreakdown") -@attr.s(auto_attribs=True) +@_attrs_define class UltimateGoalSingleTeamBreakdown: """ Attributes: diff --git a/ftc_api/models/ultimate_goal_single_team_score_details.py b/ftc_api/models/ultimate_goal_single_team_score_details.py index 166b940..23d8e06 100644 --- a/ftc_api/models/ultimate_goal_single_team_score_details.py +++ b/ftc_api/models/ultimate_goal_single_team_score_details.py @@ -1,20 +1,18 @@ from typing import TYPE_CHECKING, Any, Dict, Type, TypeVar, Union -import attr +from attrs import define as _attrs_define from ..models.ftc_event_level import FTCEventLevel from ..types import UNSET, Unset if TYPE_CHECKING: - from ..models.ultimate_goal_single_team_breakdown import ( - UltimateGoalSingleTeamBreakdown, - ) + from ..models.ultimate_goal_single_team_breakdown import UltimateGoalSingleTeamBreakdown T = TypeVar("T", bound="UltimateGoalSingleTeamScoreDetails") -@attr.s(auto_attribs=True) +@_attrs_define class UltimateGoalSingleTeamScoreDetails: """ Attributes: @@ -55,9 +53,7 @@ def to_dict(self) -> Dict[str, Any]: @classmethod def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: - from ..models.ultimate_goal_single_team_breakdown import ( - UltimateGoalSingleTeamBreakdown, - ) + from ..models.ultimate_goal_single_team_breakdown import UltimateGoalSingleTeamBreakdown d = src_dict.copy() _match_level = d.pop("matchLevel", UNSET) diff --git a/ftc_api/types.py b/ftc_api/types.py index 230efea..15700b8 100644 --- a/ftc_api/types.py +++ b/ftc_api/types.py @@ -1,12 +1,12 @@ """ Contains some shared types for properties """ from http import HTTPStatus -from typing import BinaryIO, Generic, MutableMapping, Optional, Tuple, TypeVar +from typing import BinaryIO, Generic, Literal, MutableMapping, Optional, Tuple, TypeVar -import attr +from attrs import define class Unset: - def __bool__(self) -> bool: + def __bool__(self) -> Literal[False]: return False @@ -15,7 +15,7 @@ def __bool__(self) -> bool: FileJsonType = Tuple[Optional[str], BinaryIO, Optional[str]] -@attr.s(auto_attribs=True) +@define class File: """Contains information for file uploads""" @@ -31,7 +31,7 @@ def to_tuple(self) -> FileJsonType: T = TypeVar("T") -@attr.s(auto_attribs=True) +@define class Response(Generic[T]): """A response from an endpoint""" diff --git a/pyproject.toml b/pyproject.toml index 524daaf..76628c6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,7 +6,7 @@ authors = [ ] license = { file = "LICENSE" } readme = "README.md" -version = "0.3.3" +version = "0.4.0" dependencies = [ "httpx[http2]", "python-dateutil", "attrs" ] diff --git a/source/quickstart.rst b/source/quickstart.rst index 6914281..aca86f1 100644 --- a/source/quickstart.rst +++ b/source/quickstart.rst @@ -26,7 +26,7 @@ Now call your endpoint and use your models: client = ftc_api.Client(username="test", authorization_key="****-****-****-****") my_data = get_v2_0_season.sync(client=client, season=2022) - print(my_data.game_name) # POWERPLAY + print(my_data.game_name) # CENTERSTAGE # or if you need more info (e.g. status_code) response = get_v2_0_season.sync_detailed(client=client, season=2022) print(response.headers) # server headers @@ -41,7 +41,7 @@ Or do the same thing with an async version: client = ftc_api.Client(username="your username here", authorization_key="****-****-****-****") my_data = await get_v2_0_season.asyncio(client=client, season=2022) - print(my_data.game_name) # POWERPLAY + print(my_data.game_name) # CENTERSTAGE # or if you need more info (e.g. status_code) response = await get_v2_0_season.asyncio(client=client, season=2022) print(response.headers) # server headers