tangled
alpha
login
or
join now
altagos.dev
/
space
0
fork
atom
A SpaceTraders Agent
0
fork
atom
overview
issues
pulls
pipelines
separate api calls from models
altagos.dev
3 months ago
83aec082
84a9d7e7
verified
This commit was signed with the committer's
known signature
.
altagos.dev
SSH Key Fingerprint:
SHA256:UbTjEcCZlc6GzQWLCuDK3D//HESWD2xFPkzue9XMras=
0/1
build.yml
failed
20s
+75
-64
6 changed files
expand all
collapse all
unified
split
src
main.zig
st
api.zig
models
Info.zig
accounts.zig
agents.zig
root.zig
+2
-7
src/main.zig
···
5
5
const meta = @import("meta");
6
6
7
7
const st = @import("st");
8
8
-
const m = st.models;
8
8
+
const api = st.api;
9
9
const Client = st.http.Client;
10
10
-
const RawResponse = st.http.RawResponse;
11
11
-
const Response = st.http.Response;
12
12
-
13
13
-
const Info = st.models.Info;
14
14
-
const agents = st.models.agents;
15
10
16
11
const agent = @import("agent");
17
12
const Config = agent.config.Config;
···
31
26
// _ = io;
32
27
// _ = client;
33
28
34
34
-
var fleet_f = try st.fleet.listShips(client, .{});
29
29
+
var fleet_f = try api.fleet.listShips(client, .{});
35
30
defer _ = fleet_f.cancel(io) catch {};
36
31
37
32
const fleet = try fleet_f.await(io);
+72
src/st/api.zig
···
1
1
+
pub const fleet = @import("fleet.zig");
2
2
+
3
3
+
const st = @import("root.zig");
4
4
+
const http = st.http;
5
5
+
const Response = st.http.Response;
6
6
+
7
7
+
const models = st.models;
8
8
+
const Wrapper = models.Wrapper;
9
9
+
const Query = models.Query;
10
10
+
11
11
+
const Client = st.Client;
12
12
+
13
13
+
pub fn account(client: *Client) !Response(models.accounts.AccountWrapper) {
14
14
+
return client.request(
15
15
+
Wrapper(models.accounts.AccountWrapper),
16
16
+
"/my/account",
17
17
+
.{},
18
18
+
.{ .auth = .agent },
19
19
+
);
20
20
+
}
21
21
+
22
22
+
pub fn info(client: *Client) !http.RawResponse(models.Info) {
23
23
+
return client.request(
24
24
+
models.Info,
25
25
+
"/",
26
26
+
.{},
27
27
+
.{ .auth = .none },
28
28
+
);
29
29
+
}
30
30
+
31
31
+
pub const agent = struct {
32
32
+
pub fn register(
33
33
+
client: *Client,
34
34
+
symbol: []const u8,
35
35
+
faction: models.factions.Symbol,
36
36
+
) !Response(models.agents.Register) {
37
37
+
return client.post(
38
38
+
Wrapper(models.agents.Register),
39
39
+
"/register",
40
40
+
.{},
41
41
+
.{ .symbol = symbol, .faction = faction },
42
42
+
.account,
43
43
+
);
44
44
+
}
45
45
+
46
46
+
pub fn list(client: *Client, opts: Query) !Response([]models.agents.Agent) {
47
47
+
return client.get(
48
48
+
Wrapper([]models.agents.Agent),
49
49
+
"/agents{f}",
50
50
+
.{opts},
51
51
+
.agent,
52
52
+
);
53
53
+
}
54
54
+
55
55
+
pub fn get(client: *Client, symbol: []const u8) !Response(models.agents.Agent) {
56
56
+
return client.get(
57
57
+
Wrapper(models.agents.Agent),
58
58
+
"/agents/{s}",
59
59
+
.{symbol},
60
60
+
.agent,
61
61
+
);
62
62
+
}
63
63
+
64
64
+
pub fn own(client: *Client) !Response(models.agents.Agent) {
65
65
+
return client.get(
66
66
+
Wrapper(models.agents.Agent),
67
67
+
"/my/agent",
68
68
+
.{},
69
69
+
.agent,
70
70
+
);
71
71
+
}
72
72
+
};
-9
src/st/models/Info.zig
···
54
54
name: []const u8,
55
55
url: []const u8,
56
56
};
57
57
-
58
58
-
pub fn get(client: *Client) !RawResponse(Info) {
59
59
-
return client.request(
60
60
-
Info,
61
61
-
"/",
62
62
-
.{},
63
63
-
.{ .auth = .none },
64
64
-
);
65
65
-
}
-9
src/st/models/accounts.zig
···
13
13
token: ?[]const u8 = null,
14
14
createdAt: []const u8,
15
15
};
16
16
-
17
17
-
pub fn get(client: *Client) !Response(AccountWrapper) {
18
18
-
return client.request(
19
19
-
Wrapper(AccountWrapper),
20
20
-
"/my/account",
21
21
-
.{},
22
22
-
.{ .auth = .agent },
23
23
-
);
24
24
-
}
-37
src/st/models/agents.zig
···
24
24
contract: Contract,
25
25
ships: []Ship,
26
26
};
27
27
-
28
28
-
pub fn list(client: *Client, opts: Query) !Response([]Agent) {
29
29
-
return client.get(
30
30
-
Wrapper([]Agent),
31
31
-
"/agents{f}",
32
32
-
.{opts},
33
33
-
.agent,
34
34
-
);
35
35
-
}
36
36
-
37
37
-
pub fn get(client: *Client, symbol: []const u8) !Response(Agent) {
38
38
-
return client.get(
39
39
-
Wrapper(Agent),
40
40
-
"/agents/{s}",
41
41
-
.{symbol},
42
42
-
.agent,
43
43
-
);
44
44
-
}
45
45
-
46
46
-
pub fn own(client: *Client) !Response(Agent) {
47
47
-
return client.get(
48
48
-
Wrapper(Agent),
49
49
-
"/my/agent",
50
50
-
.{},
51
51
-
.agent,
52
52
-
);
53
53
-
}
54
54
-
55
55
-
pub fn register(client: *Client, symbol: []const u8, faction: FactionSymbol, email: ?[]const u8) !Response(Register) {
56
56
-
return client.post(
57
57
-
Wrapper(Register),
58
58
-
"/register",
59
59
-
.{},
60
60
-
.{ .symbol = symbol, .faction = faction, .email = email },
61
61
-
.account,
62
62
-
);
63
63
-
}
+1
-2
src/st/root.zig
···
1
1
+
pub const api = @import("api.zig");
1
2
pub const http = @import("http.zig");
2
3
pub const models = @import("models.zig");
3
3
-
4
4
-
pub const fleet = @import("fleet.zig");
5
4
6
5
test {
7
6
const testing = @import("std").testing;