From 735f0ff00859d9dda5e93be401c609653e1467a8 Mon Sep 17 00:00:00 2001 From: andromeda Date: Sun, 10 May 2026 00:45:25 +0200 Subject: client abstraction --- main.c3 | 30 +++++++++--------------------- 1 file changed, 9 insertions(+), 21 deletions(-) (limited to 'main.c3') 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; } -- cgit v1.3.1