Something went wrong. Try again.
A SpaceTraders Agent
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199const std = @import("std");
pub const fleet = @import("fleet.zig");
const st = @import("root.zig");const http = st.http;const Client = http.Client;const Response = st.http.Response;
const models = st.models;const Wrapper = models.Wrapper;const Query = models.Query;
pub fn account(client: *Client) !Response(models.accounts.AccountWrapper) { return client.request( Wrapper(models.accounts.AccountWrapper), "/my/account", .{}, .{ .auth = .agent }, );}
pub fn info(client: *Client) !http.RawResponse(models.Info) { return client.request( models.Info, "/", .{}, .{ .auth = .none }, );}
pub const agent = struct { pub fn register( client: *Client, symbol: []const u8, faction: models.factions.Symbol, ) !Response(models.agents.Register) { return client.postW( models.agents.Register, "/register", .{}, .{ .symbol = symbol, .faction = faction }, .account, ); }
pub fn list(client: *Client, opts: Query) !Response([]models.agents.Agent) { return client.getW( []models.agents.Agent, "/agents{f}", .{opts}, .agent, ); }
pub fn get(client: *Client, symbol: []const u8) !Response(models.agents.Agent) { return client.getW( models.agents.Agent, "/agents/{s}", .{symbol}, .agent, ); }
pub fn own(client: *Client) !Response(models.agents.Agent) { return client.getW( models.agents.Agent, "/my/agent", .{}, .agent, ); }};
pub const system = struct { const Symbol = models.systems.Symbol;
pub fn get(client: *Client, symbol: Symbol.System) !Response(models.systems.System) { return client.getW( models.systems.System, "/systems/{f}", .{symbol}, .agent, ); }
pub fn list(client: *Client, opts: Query) !Response([]models.systems.System) { return client.getW( []models.systems.System, "/systems{f}", .{opts}, .agent, ); }
pub fn waypoint( client: *Client, waypoint_symbol: Symbol.Waypoint, ) !Response(models.systems.Waypoint) { return client.getW( models.systems.Waypoint, "/systems/{f}/waypoints/{f}", .{ waypoint_symbol.system, waypoint_symbol }, .agent, ); }
pub const WaypointsFilter = struct { type: ?models.systems.Waypoint.Type = null, traits: []models.systems.Waypoint.Trait = &.{},
pub fn format(this: @This(), writer: *std.Io.Writer) std.Io.Writer.Error!void { if (this.type) |ty| { try writer.print("&type={s}", .{@tagName(ty)}); } if (this.traits.len > 0) { for (this.traits) |trait| { try writer.print("&traits={s}", .{@tagName(trait)}); } } } };
pub fn waypoints( client: *Client, symbol: Symbol.System, filter: WaypointsFilter, opts: Query, ) !Response([]models.systems.Waypoint) { return client.getW( []models.systems.Waypoint, "/systems/{f}/waypoints{f}{f}", .{ symbol, opts, filter }, .agent, ); }
pub fn construction( client: *Client, waypoint_symbol: Symbol.Waypoint, ) !Response(models.systems.Construction) { return client.getW( models.systems.Construction, "/systems/{f}/waypoints/{f}/construction", .{ waypoint_symbol.system, waypoint_symbol }, .agent, ); }
pub const SupplyConstruction = struct { shipSymbol: []const u8, tradeSymbol: models.inventory.AllItems.Combined, units: u64,
pub const Response = struct { construction: models.systems.ConstructionSite, cargo: models.inventory.Cargo, }; };
pub fn supplyConstruction( client: *Client, waypoint_symbol: Symbol.Waypoint, supply: SupplyConstruction, ) !Response(SupplyConstruction.Response) { return client.postW( SupplyConstruction.Response, "/systems/{f}/waypoints/{f}/supply-construction", .{ waypoint_symbol.system, waypoint_symbol }, supply, .agent, ); }
pub fn market( client: *Client, waypoint_symbol: Symbol.Waypoint, ) !Response(models.systems.Market) { return client.getW( models.systems.Market, "/systems/{f}/waypoints/{f}/market", .{ waypoint_symbol.system, waypoint_symbol }, .agent, ); }
pub fn shipyard( client: *Client, waypoint_symbol: Symbol.Waypoint, ) !Response(models.systems.Shipyard) { return client.getW( models.systems.Shipyard, "/systems/{f}/waypoints/{f}/shipyard", .{ waypoint_symbol.system, waypoint_symbol }, .agent, ); }};