A SpaceTraders Agent

agent model + get/list requests

altagos.dev febe319b 19b97ed3

verified
+42
+1
src/st/models.zig
··· 1 1 pub const accounts = @import("models/accounts.zig"); 2 + pub const agents = @import("models/agents.zig"); 2 3 pub const factions = @import("models/factions.zig"); 3 4 4 5 pub const Info = @import("models/Info.zig");
+41
src/st/models/agents.zig
··· 1 + const st = @import("../root.zig"); 2 + const Client = st.http.Client; 3 + const Response = st.http.Response; 4 + const Wrapper = st.models.Wrapper; 5 + const Query = st.models.Query; 6 + const FactionSymbol = st.models.factions.Symbol; 7 + 8 + pub const Agent = struct { 9 + symbol: []const u8, 10 + headquarters: []const u8, 11 + credits: u64, 12 + startingFaction: FactionSymbol, 13 + shipCount: u64, 14 + }; 15 + 16 + pub fn list(client: *Client, opts: Query) !Response([]Agent) { 17 + return client.request( 18 + Wrapper([]Agent), 19 + "/agents?page={}&limit={}", 20 + .{ opts.page, opts.limit }, 21 + .{ .auth = .agent }, 22 + ); 23 + } 24 + 25 + pub fn get(client: *Client, symbol: []const u8) !Response(Agent) { 26 + return client.request( 27 + Wrapper(Agent), 28 + "/agents/{s}", 29 + .{symbol}, 30 + .{ .auth = .agent }, 31 + ); 32 + } 33 + 34 + pub fn own(client: *Client) !Response(Agent) { 35 + return client.request( 36 + Wrapper(Agent), 37 + "/my/agent", 38 + .{}, 39 + .{ .auth = .agent }, 40 + ); 41 + }