summaryrefslogtreecommitdiff
path: root/main.c3
diff options
context:
space:
mode:
authorandromeda <andromeda@lenovo>2026-05-10 00:45:25 +0200
committerandromeda <andromeda@lenovo>2026-05-10 00:45:25 +0200
commit735f0ff00859d9dda5e93be401c609653e1467a8 (patch)
tree85e15f690d82e99d491b12a5747d20e3c1478e6d /main.c3
parent1caa1bbdb8f474a1e404875e0f02464273dabb46 (diff)
client abstraction
Diffstat (limited to 'main.c3')
-rw-r--r--main.c330
1 files changed, 9 insertions, 21 deletions
diff --git a/main.c3 b/main.c3
index 93ad23b..1a09cc5 100644
--- a/main.c3
+++ b/main.c3
@@ -22,33 +22,17 @@ import std::io;
import std::encoding::json;
import std::collections::object;
import curl;
+import radapi;
-char[10485760] response;
-usz response_len;
String url = "https://iris.radicle.network/api/v1";
-fn usz write_callback(char* buffer, usz size, usz nitems, void* outstream)
-{
- response[response_len..response_len+nitems-1] = buffer[..nitems-1];
- response_len += nitems;
- return nitems;
-}
-
-fn void get(Curl* c, String endpoint)
-{
- response_len = 0;
- curl::easy_setopt(c, CurlOption.URL, url.tconcat(endpoint));
- curl::easy_setopt(c, CurlOption.WRITEFUNCTION, &write_callback);
- CurlResult r = curl::easy_perform(c);
-}
-
fn int main(String[] args)
{
- Curl* c = curl::easy_init();
- get(c, "/repos?show=all&perPage=16384&page=0");
- curl::easy_cleanup(c);
+ Client* c = radapi::new_client(url);
+
+ c.request(Request.REPO_ROOT, "?show=all&perPage=16384&page=0");
- Object* j = json::tparse((String)response[..response_len], JsonFlavor.JSONC)!!;
+ Object* j = json::tparse(c.response())!!;
int i = 0;
while (i < j.array.len())
@@ -59,5 +43,9 @@ fn int main(String[] args)
i++;
}
+ c.request(Request.REPO, "", j.get_at(0).get_string("rid"))!!;
+
+ io::printn((String)c.buffer.[..c.buffer_index]);
+
return 0;
}