Skip to content

Commit 3295aaa

Browse files
committed
denote alt url for examples, mostly for meeee
1 parent dda7bc8 commit 3295aaa

4 files changed

Lines changed: 12 additions & 11 deletions

File tree

examples/basic_usage.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88

99
async def main(token: str, base_url: str):
10-
async with stackcoin.Client(base_url=base_url, token=token) as client:
10+
async with stackcoin.Client(token, base_url=base_url) as client:
1111
# Who am I?
1212
me = await client.get_me()
1313
print(f"Logged in as {me.username} with balance {me.balance} STK")
@@ -43,5 +43,7 @@ async def main(token: str, base_url: str):
4343
print("Token is required")
4444
exit(1)
4545

46+
# Can be omitted to hit production (https://stackcoin.world).
47+
# Set STACKCOIN_BASE_URL for local development, e.g. http://localhost:4000
4648
base_url = os.getenv("STACKCOIN_BASE_URL", "https://stackcoin.world")
4749
asyncio.run(main(token, base_url))

examples/simple_cli.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,18 +126,20 @@ async def main():
126126
print("Token is required")
127127
return
128128

129+
# Can be omitted to hit production (https://stackcoin.world).
130+
# Set STACKCOIN_BASE_URL for local development, e.g. http://localhost:4000
129131
base_url = os.getenv("STACKCOIN_BASE_URL", "https://stackcoin.world")
130132
ws_url = os.getenv("STACKCOIN_WS_URL",
131133
base_url.replace("https://", "wss://")
132134
.replace("http://", "ws://")
133135
+ "/ws")
134136

135-
async with stackcoin.Client(base_url=base_url, token=token) as client:
137+
async with stackcoin.Client(token, base_url=base_url) as client:
136138
me = await client.get_me()
137139
print(f"Connected to {base_url} as {me.username} ({me.balance} STK)")
138140

139141
# Set up gateway for live events
140-
gateway = stackcoin.Gateway(ws_url=ws_url, token=token)
142+
gateway = stackcoin.Gateway(token, ws_url=ws_url)
141143

142144
@gateway.on("transfer.completed")
143145
async def on_transfer(event: stackcoin.TransferCompletedEvent):

stackcoin/stackcoin/client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,16 @@ class Client:
3535
3636
Usage::
3737
38-
async with Client("https://stackcoin.example.com", token="sk-...") as client:
38+
async with Client(token="sk-...") as client:
3939
me = await client.get_me()
4040
print(me.username, me.balance)
4141
"""
4242

4343
def __init__(
4444
self,
45-
base_url: str,
4645
token: str,
4746
*,
47+
base_url: str = "https://stackcoin.world",
4848
timeout: float = 10.0,
4949
) -> None:
5050
self._http = httpx.AsyncClient(

stackcoin/stackcoin/gateway.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,7 @@ class Gateway:
1616
1717
Usage::
1818
19-
gateway = stackcoin.Gateway(
20-
ws_url="ws://localhost:4000/ws",
21-
token="...",
22-
)
19+
gateway = stackcoin.Gateway(token="...")
2320
2421
@gateway.on("request.accepted")
2522
async def handle_accepted(event: stackcoin.RequestAcceptedEvent):
@@ -30,12 +27,12 @@ async def handle_accepted(event: stackcoin.RequestAcceptedEvent):
3027

3128
def __init__(
3229
self,
33-
ws_url: str,
3430
token: str,
31+
*,
32+
ws_url: str = "wss://stackcoin.world/ws",
3533
last_event_id: int = 0,
3634
on_event_id: Callable[[int], None] | None = None,
3735
):
38-
# ws_url should be the full websocket URL like "ws://localhost:4000/ws"
3936
self._ws_url = ws_url.rstrip("/")
4037
self._token = token
4138
self._handlers: dict[str, list[EventHandler]] = {}

0 commit comments

Comments
 (0)