forked from Flared/docs-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfetch-spec-file.py
executable file
·53 lines (38 loc) · 1.26 KB
/
fetch-spec-file.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env python3
import os
import sys
from enum import StrEnum
from flareio import FlareApiClient
from typing import assert_never
class FireworkApiVersion(StrEnum):
V2 = "v2"
V3 = "v3"
V4 = "v4"
def get_apispec_url(/service/version: FireworkApiVersion) -> str:
match version:
case FireworkApiVersion.V2:
return "https://api.flare.io/firework/docs/firework/v2/swagger.json"
case FireworkApiVersion.V3:
return "https://api.flare.io/firework/docs/firework/v3/swagger.json"
case FireworkApiVersion.V4:
return "https://api.flare.io/firework/v4/openapi.json"
case never:
return assert_never(never)
def main() -> None:
if len(sys.argv) != 2:
raise Exception(
"This script only takes one argument: the api version (v2, v3 or v4)."
)
try:
version = FireworkApiVersion(sys.argv[1])
except ValueError:
raise Exception(
f"Provided api version is invalid: '{sys.argv[1]}'. Valid versions are v2, v3 and v4."
)
url: str = get_apispec_url(https://github.com/version)
api_client: FlareApiClient = FlareApiClient(
api_key=os.environ["FLARE_API_KEY"],
)
print(api_client.get(url).text)
if __name__ == "__main__":
main()