summaryrefslogtreecommitdiff
path: root/src/srht/client.c
diff options
context:
space:
mode:
authorGravatar Anshul Gupta <ansg191@anshulg.com> 2025-06-12 01:53:38 -0700
committerGravatar GitHub <noreply@github.com> 2025-06-12 01:53:38 -0700
commitc9adb09abc626cdcc35c345a635ad8c163fcff3e (patch)
tree93f78bf8e5910a044f96ed77aca498ac60ada804 /src/srht/client.c
parent179679633a9fc3317585167f86c87a7fe8394945 (diff)
parentb78875e2265339b58c7a67cc83e6db2988aa0d74 (diff)
downloadgithub-mirror-c9adb09abc626cdcc35c345a635ad8c163fcff3e.tar.gz
github-mirror-c9adb09abc626cdcc35c345a635ad8c163fcff3e.tar.zst
github-mirror-c9adb09abc626cdcc35c345a635ad8c163fcff3e.zip
Merge pull request #2 from ansg191/srht
Diffstat (limited to 'src/srht/client.c')
-rw-r--r--src/srht/client.c65
1 files changed, 65 insertions, 0 deletions
diff --git a/src/srht/client.c b/src/srht/client.c
new file mode 100644
index 0000000..b6d9a50
--- /dev/null
+++ b/src/srht/client.c
@@ -0,0 +1,65 @@
+//
+// Created by Anshul Gupta on 6/10/25.
+//
+
+#include "client.h"
+
+#include "queries/srht/srht_list_repos.h"
+
+#include "../buffer.h"
+
+int srht_list_user_repos(const gql_client *client, const char *username,
+ const char *cursor, struct srht_list_repos_res *res)
+{
+ int status = 0;
+ buffer_t buf = buffer_new(4096);
+
+ cJSON *args = cJSON_CreateObject();
+ if (!args) {
+ status = -1;
+ goto end;
+ }
+ cJSON_AddItemToObject(args, "username", cJSON_CreateString(username));
+
+ if (cursor != NULL)
+ cJSON_AddItemToObject(args, "cursor",
+ cJSON_CreateString(cursor));
+ else
+ cJSON_AddItemToObject(args, "cursor", cJSON_CreateNull());
+
+ const CURLcode ret =
+ gql_client_send(client, srht_list_repos, args, &buf);
+ if (ret != CURLE_OK) {
+ fprintf(stderr, "Failed to send request: %s\n",
+ curl_easy_strerror(ret));
+ status = -1;
+ goto end;
+ }
+
+ // Parse the response
+ cJSON *root = cJSON_Parse((const char *) buf.data);
+ if (!root) {
+ const char *err = cJSON_GetErrorPtr();
+ if (err)
+ fprintf(stderr, "Error parsing response: %s\n", err);
+ status = -1;
+ goto end;
+ }
+
+ // Check for errors
+ if (gql_handle_error(root) < 0) {
+ cJSON_Delete(root);
+ status = -1;
+ goto end;
+ }
+
+ // Convert json to struct
+ if (srht_list_repos_from_json(root, res) < 0) {
+ fprintf(stderr, "Failed to parse response\n");
+ status = -1;
+ }
+
+end:
+ buffer_free(buf);
+ return status;
+}