-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
58 lines (46 loc) · 1.71 KB
/
main.py
File metadata and controls
58 lines (46 loc) · 1.71 KB
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
54
55
56
57
58
"""Artifacts MMO API demo - shows public and authenticated endpoints."""
import os
from client import Client
def main():
print("⚔️ Initializing Artifacts MMO Client...")
client = Client(base_url="https://api.artifactsmmo.com")
# Add auth middleware if token is available
token = os.environ.get("ARTIFACTS_TOKEN")
if token:
@client.middleware
def auth(request, call_next):
request.headers["Authorization"] = f"Bearer {token}"
return call_next(request)
# 1. Server status (public)
print("\n--- 1. Server Status ---")
res = client.GET("/")
if res.is_success:
data = res.data.get("data", {})
print(f"✅ Version: {data.get('version')} | Online: {data.get('characters_online')} players")
else:
print(f"❌ Failed: {res.error}")
# 2. List items (public)
print("\n--- 2. List Items ---")
res = client.GET("/items", page=1, size=5)
if res.is_success:
items = res.data.get("data", [])
print(f"✅ Found {res.data.get('total', '?')} items")
for item in items[:5]:
print(f" - {item['name']} ({item['code']})")
else:
print(f"❌ Failed: {res.error}")
# 3. My characters (requires auth)
if not token:
print("\n⚠️ Set ARTIFACTS_TOKEN to access authenticated endpoints")
return
print("\n--- 3. My Characters ---")
res = client.GET("/my/characters")
if res.is_success:
chars = res.data.get("data", [])
print(f"✅ Found {len(chars)} characters")
for char in chars:
print(f" - {char['name']} (Level {char['level']})")
else:
print(f"❌ Failed: {res.error}")
if __name__ == "__main__":
main()