Skip to content

Commit fc961f8

Browse files
committed
added templates and made everything accept Client rather than only AuthenticatedClient
1 parent 01cb6ea commit fc961f8

21 files changed

+206
-117
lines changed

CHANGELOG.md

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1-
# 0.0.2
2-
* Fixed numbering in pyproject.toml
3-
# 0.0.1
4-
* Changed default prefix of Authorization header to "Basic", which should be the default for the API
5-
* Fixed bug that caused double //s when requesting a api endpoint.
61
# 0.0.0
7-
* Initial Release
2+
* Initial Release
3+
### 0.0.1
4+
* Changed default prefix of Authorization header to "Basic", which should be the default for the API
5+
* Fixed bug that caused double //s when requesting an api endpoint.
6+
### 0.0.2
7+
* Fixed numbering in pyproject.toml
8+
## 0.1.0
9+
* Merged `Client` with `AuthenticatedClient` using `AuthenticatedClient` is now deprecated
10+
* Added support for creating a Client with a username and access key
11+
* Removed `attrs` as a dependency
12+
* Added support for [ftcstats](https://ftcstats.org)

custom_templates/client.py.jinja

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import base64
2+
import ssl
3+
from typing import Dict, Union
4+
5+
6+
class Client:
7+
"""A class for keeping track of data related to the API"""
8+
9+
cookies = {}
10+
headers: Dict[str, str] = {}
11+
timeout: float = 5.0
12+
verify_ssl: Union[str, bool, ssl.SSLContext] = True
13+
raise_on_unexpected_status: bool = False
14+
prefix: str = "Basic"
15+
auth_header_name: str = "Authorization"
16+
17+
def __init__(self, token=None, username="", authorization_key=""):
18+
if token is not None:
19+
self.token = token
20+
else:
21+
token = username + ":" + authorization_key
22+
token_bytes = token.encode("ascii")
23+
base64_bytes = base64.b64encode(token_bytes)
24+
self.token = base64_bytes.decode("ascii")
25+
26+
def get_headers(self) -> Dict[str, str]:
27+
auth_header_value = f"{self.prefix} {self.token}" if self.prefix else self.token
28+
"""Get headers to be used in authenticated endpoints"""
29+
return {self.auth_header_name: auth_header_value, **self.headers}
30+
31+
def get_cookies(self) -> Dict[str, str]:
32+
return {**self.cookies}
33+
34+
def get_timeout(self) -> float:
35+
return self.timeout
36+
37+
38+
class AuthenticatedClient(Client):
39+
"""Deprecated, use Client instead, as it has equivalent functionality, will be removed v1.0.0"""
40+
pass
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
""" A client library for accessing FTC Events API """
2+
from .client import AuthenticatedClient, Client
3+
4+
__all__ = (
5+
"AuthenticatedClient",
6+
"Client"
7+
)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
[project]
2+
name = "ftc_api"
3+
description = "A python client to access the FIRST Tech Challenge API"
4+
authors = [
5+
{name = "Ashwin Naren", email="arihant2math@gmail.com"}
6+
]
7+
license = {file = "LICENSE"}
8+
readme = "README.md"
9+
version = "0.1.0"
10+
dependencies = [
11+
"httpx", "python-dateutil"
12+
]
13+
keywords = ["ftc"]
14+
requires-python = ">=3.7"
15+
16+
[project.optional-dependencies]
17+
dev = [
18+
"black"
19+
]
20+
21+
[build-system]
22+
requires = ["setuptools"]
23+
build-backend = "setuptools.build_meta"
24+
25+
[tool.setuptools]
26+
packages = ["ftc_api"]

ftc_api/api/alliance_selection/get_v_2_0_season_alliances_event_code.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import httpx
55

66
from ... import errors
7-
from ...client import AuthenticatedClient, Client
7+
from ...client import Client
88
from ...models.alliance_selection import AllianceSelection
99
from ...types import Response
1010

@@ -13,7 +13,7 @@ def _get_kwargs(
1313
season: int,
1414
event_code: Optional[str],
1515
*,
16-
client: AuthenticatedClient,
16+
client: Client,
1717
) -> Dict[str, Any]:
1818
url = "{}/v2.0/{season}/alliances/{eventCode}".format("https://ftc-api.firstinspires.org", season=season, eventCode=event_code)
1919

@@ -56,7 +56,7 @@ def sync_detailed(
5656
season: int,
5757
event_code: Optional[str],
5858
*,
59-
client: AuthenticatedClient,
59+
client: Client,
6060
) -> Response[Union[AllianceSelection, Any]]:
6161
"""Event Alliances
6262
@@ -93,7 +93,7 @@ def sync(
9393
season: int,
9494
event_code: Optional[str],
9595
*,
96-
client: AuthenticatedClient,
96+
client: Client,
9797
) -> Optional[Union[AllianceSelection, Any]]:
9898
"""Event Alliances
9999
@@ -123,7 +123,7 @@ async def asyncio_detailed(
123123
season: int,
124124
event_code: Optional[str],
125125
*,
126-
client: AuthenticatedClient,
126+
client: Client,
127127
) -> Response[Union[AllianceSelection, Any]]:
128128
"""Event Alliances
129129
@@ -158,7 +158,7 @@ async def asyncio(
158158
season: int,
159159
event_code: Optional[str],
160160
*,
161-
client: AuthenticatedClient,
161+
client: Client,
162162
) -> Optional[Union[AllianceSelection, Any]]:
163163
"""Event Alliances
164164

ftc_api/api/alliance_selection/get_v_2_0_season_alliances_event_code_selection.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import httpx
55

66
from ... import errors
7-
from ...client import AuthenticatedClient, Client
7+
from ...client import Client
88
from ...models.alliance_selection_details import AllianceSelectionDetails
99
from ...types import Response
1010

@@ -13,7 +13,7 @@ def _get_kwargs(
1313
season: int,
1414
event_code: Optional[str],
1515
*,
16-
client: AuthenticatedClient,
16+
client: Client,
1717
) -> Dict[str, Any]:
1818
url = "{}/v2.0/{season}/alliances/{eventCode}/selection".format(
1919
"https://ftc-api.firstinspires.org", season=season, eventCode=event_code
@@ -58,7 +58,7 @@ def sync_detailed(
5858
season: int,
5959
event_code: Optional[str],
6060
*,
61-
client: AuthenticatedClient,
61+
client: Client,
6262
) -> Response[Union[AllianceSelectionDetails, Any]]:
6363
"""Alliance Selection Details
6464
@@ -95,7 +95,7 @@ def sync(
9595
season: int,
9696
event_code: Optional[str],
9797
*,
98-
client: AuthenticatedClient,
98+
client: Client,
9999
) -> Optional[Union[AllianceSelectionDetails, Any]]:
100100
"""Alliance Selection Details
101101
@@ -125,7 +125,7 @@ async def asyncio_detailed(
125125
season: int,
126126
event_code: Optional[str],
127127
*,
128-
client: AuthenticatedClient,
128+
client: Client,
129129
) -> Response[Union[AllianceSelectionDetails, Any]]:
130130
"""Alliance Selection Details
131131
@@ -160,7 +160,7 @@ async def asyncio(
160160
season: int,
161161
event_code: Optional[str],
162162
*,
163-
client: AuthenticatedClient,
163+
client: Client,
164164
) -> Optional[Union[AllianceSelectionDetails, Any]]:
165165
"""Alliance Selection Details
166166

ftc_api/api/awards/get_v2_0_season_awards_list.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44
import httpx
55

66
from ... import errors
7-
from ...client import AuthenticatedClient, Client
7+
from ...client import Client
88
from ...models.award_list import AwardList
99
from ...types import Response
1010

1111

1212
def _get_kwargs(
1313
season: int,
1414
*,
15-
client: AuthenticatedClient,
15+
client: Client,
1616
) -> Dict[str, Any]:
1717
url = "{}/v2.0/{season}/awards/list".format("https://ftc-api.firstinspires.org", season=season)
1818

@@ -54,7 +54,7 @@ def _build_response(*, client: Client, response: httpx.Response) -> Response[Uni
5454
def sync_detailed(
5555
season: int,
5656
*,
57-
client: AuthenticatedClient,
57+
client: Client,
5858
) -> Response[Union[Any, AwardList]]:
5959
"""Award Listings
6060
@@ -90,7 +90,7 @@ def sync_detailed(
9090
def sync(
9191
season: int,
9292
*,
93-
client: AuthenticatedClient,
93+
client: Client,
9494
) -> Optional[Union[Any, AwardList]]:
9595
"""Award Listings
9696
@@ -119,7 +119,7 @@ def sync(
119119
async def asyncio_detailed(
120120
season: int,
121121
*,
122-
client: AuthenticatedClient,
122+
client: Client,
123123
) -> Response[Union[Any, AwardList]]:
124124
"""Award Listings
125125
@@ -153,7 +153,7 @@ async def asyncio_detailed(
153153
async def asyncio(
154154
season: int,
155155
*,
156-
client: AuthenticatedClient,
156+
client: Client,
157157
) -> Optional[Union[Any, AwardList]]:
158158
"""Award Listings
159159

ftc_api/api/awards/get_v_2_0_season_awards_event_code.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import httpx
55

66
from ... import errors
7-
from ...client import AuthenticatedClient, Client
7+
from ...client import Client
88
from ...models.award_assignment_list import AwardAssignmentList
99
from ...types import UNSET, Response, Unset
1010

@@ -13,7 +13,7 @@ def _get_kwargs(
1313
season: int,
1414
event_code: Optional[str] = "",
1515
*,
16-
client: AuthenticatedClient,
16+
client: Client,
1717
team_number: Union[Unset, None, int] = 0,
1818
) -> Dict[str, Any]:
1919
url = "{}/v2.0/{season}/awards/{eventCode}".format("https://ftc-api.firstinspires.org", season=season, eventCode=event_code)
@@ -63,7 +63,7 @@ def sync_detailed(
6363
season: int,
6464
event_code: Optional[str] = "",
6565
*,
66-
client: AuthenticatedClient,
66+
client: Client,
6767
team_number: Union[Unset, None, int] = 0,
6868
) -> Response[Union[Any, AwardAssignmentList]]:
6969
"""Event Awards
@@ -109,7 +109,7 @@ def sync(
109109
season: int,
110110
event_code: Optional[str] = "",
111111
*,
112-
client: AuthenticatedClient,
112+
client: Client,
113113
team_number: Union[Unset, None, int] = 0,
114114
) -> Optional[Union[Any, AwardAssignmentList]]:
115115
"""Event Awards
@@ -148,7 +148,7 @@ async def asyncio_detailed(
148148
season: int,
149149
event_code: Optional[str] = "",
150150
*,
151-
client: AuthenticatedClient,
151+
client: Client,
152152
team_number: Union[Unset, None, int] = 0,
153153
) -> Response[Union[Any, AwardAssignmentList]]:
154154
"""Event Awards
@@ -192,7 +192,7 @@ async def asyncio(
192192
season: int,
193193
event_code: Optional[str] = "",
194194
*,
195-
client: AuthenticatedClient,
195+
client: Client,
196196
team_number: Union[Unset, None, int] = 0,
197197
) -> Optional[Union[Any, AwardAssignmentList]]:
198198
"""Event Awards

ftc_api/api/awards/get_v_2_0_season_awards_event_code_team_number.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import httpx
55

66
from ... import errors
7-
from ...client import AuthenticatedClient, Client
7+
from ...client import Client
88
from ...models.award_assignment_list import AwardAssignmentList
99
from ...types import Response
1010

@@ -14,7 +14,7 @@ def _get_kwargs(
1414
event_code: Optional[str] = "",
1515
team_number: int = 0,
1616
*,
17-
client: AuthenticatedClient,
17+
client: Client,
1818
) -> Dict[str, Any]:
1919
url = "{}/v2.0/{season}/awards/{eventCode}/{teamNumber}".format(
2020
"https://ftc-api.firstinspires.org", season=season, eventCode=event_code, teamNumber=team_number
@@ -60,7 +60,7 @@ def sync_detailed(
6060
event_code: Optional[str] = "",
6161
team_number: int = 0,
6262
*,
63-
client: AuthenticatedClient,
63+
client: Client,
6464
) -> Response[Union[Any, AwardAssignmentList]]:
6565
"""Event Awards
6666
@@ -106,7 +106,7 @@ def sync(
106106
event_code: Optional[str] = "",
107107
team_number: int = 0,
108108
*,
109-
client: AuthenticatedClient,
109+
client: Client,
110110
) -> Optional[Union[Any, AwardAssignmentList]]:
111111
"""Event Awards
112112
@@ -145,7 +145,7 @@ async def asyncio_detailed(
145145
event_code: Optional[str] = "",
146146
team_number: int = 0,
147147
*,
148-
client: AuthenticatedClient,
148+
client: Client,
149149
) -> Response[Union[Any, AwardAssignmentList]]:
150150
"""Event Awards
151151
@@ -189,7 +189,7 @@ async def asyncio(
189189
event_code: Optional[str] = "",
190190
team_number: int = 0,
191191
*,
192-
client: AuthenticatedClient,
192+
client: Client,
193193
) -> Optional[Union[Any, AwardAssignmentList]]:
194194
"""Event Awards
195195

0 commit comments

Comments
 (0)