A SpaceTraders Agent
1pub const fleet = @import("fleet.zig");
2
3const st = @import("root.zig");
4const http = st.http;
5const Client = http.Client;
6const Response = st.http.Response;
7
8const models = st.models;
9const Wrapper = models.Wrapper;
10const Query = models.Query;
11
12pub fn account(client: *Client) !Response(models.accounts.AccountWrapper) {
13 return client.request(
14 Wrapper(models.accounts.AccountWrapper),
15 "/my/account",
16 .{},
17 .{ .auth = .agent },
18 );
19}
20
21pub fn info(client: *Client) !http.RawResponse(models.Info) {
22 return client.request(
23 models.Info,
24 "/",
25 .{},
26 .{ .auth = .none },
27 );
28}
29
30pub const agent = struct {
31 pub fn register(
32 client: *Client,
33 symbol: []const u8,
34 faction: models.factions.Symbol,
35 ) !Response(models.agents.Register) {
36 return client.post(
37 Wrapper(models.agents.Register),
38 "/register",
39 .{},
40 .{ .symbol = symbol, .faction = faction },
41 .account,
42 );
43 }
44
45 pub fn list(client: *Client, opts: Query) !Response([]models.agents.Agent) {
46 return client.get(
47 Wrapper([]models.agents.Agent),
48 "/agents{f}",
49 .{opts},
50 .agent,
51 );
52 }
53
54 pub fn get(client: *Client, symbol: []const u8) !Response(models.agents.Agent) {
55 return client.get(
56 Wrapper(models.agents.Agent),
57 "/agents/{s}",
58 .{symbol},
59 .agent,
60 );
61 }
62
63 pub fn own(client: *Client) !Response(models.agents.Agent) {
64 return client.get(
65 Wrapper(models.agents.Agent),
66 "/my/agent",
67 .{},
68 .agent,
69 );
70 }
71};