diff options
| author | andromeda <andromeda@lenovo> | 2026-05-10 00:45:25 +0200 |
|---|---|---|
| committer | andromeda <andromeda@lenovo> | 2026-05-10 00:45:25 +0200 |
| commit | 735f0ff00859d9dda5e93be401c609653e1467a8 (patch) | |
| tree | 85e15f690d82e99d491b12a5747d20e3c1478e6d /main.c3 | |
| parent | 1caa1bbdb8f474a1e404875e0f02464273dabb46 (diff) | |
client abstraction
Diffstat (limited to 'main.c3')
| -rw-r--r-- | main.c3 | 30 |
1 files changed, 9 insertions, 21 deletions
@@ -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; } |
