From db89e0e129cc9f05147cebf517336fb5eafb542d Mon Sep 17 00:00:00 2001 From: Maxim Slipenko Date: Fri, 1 Dec 2023 11:05:18 +0300 Subject: [PATCH] finish yadisk_get_disk --- src/yadisk_get_disk.c | 34 ++++++++++++++++++++++++++++++++++ src/yadisk_get_disk.h | 31 +++++++++++++++++++++++++++++++ tests/app.c | 42 +++++++++++++++++++++++++++++++++++------- 3 files changed, 100 insertions(+), 7 deletions(-) diff --git a/src/yadisk_get_disk.c b/src/yadisk_get_disk.c index edd9d5c..d07282f 100644 --- a/src/yadisk_get_disk.c +++ b/src/yadisk_get_disk.c @@ -39,6 +39,40 @@ yadisk_code yadisk_get_disk(yadisk_api_client* client, yadisk_disk_info* info) GET_JSON_STRING(root, "reg_time", &(info->reg_time)); GET_JSON_BOOL(root, "is_paid", &(info->is_paid)); + json_object *user_object; + if (!json_object_object_get_ex(root, "user", &user_object)) + THROW_PARSE_JSON_ERROR + + GET_JSON_STRING(user_object, "reg_time", &(info->user.reg_time)); + GET_JSON_STRING(user_object, "display_name", &(info->user.display_name)); + GET_JSON_STRING(user_object, "uid", &(info->user.uid)); + GET_JSON_STRING(user_object, "country", &(info->user.country)); + GET_JSON_BOOL(user_object, "is_child", &(info->user.is_child)); + GET_JSON_STRING(user_object, "login", &(info->user.login)); + + json_object *system_folders; + if (!json_object_object_get_ex(root, "system_folders", &system_folders)) + THROW_PARSE_JSON_ERROR + + GET_JSON_STRING(system_folders, "odnoklassniki", &(info->system_folders.odnoklassniki)); + GET_JSON_STRING(system_folders, "google", &(info->system_folders.google)); + GET_JSON_STRING(system_folders, "instagram", &(info->system_folders.instagram)); + GET_JSON_STRING(system_folders, "vkontakte", &(info->system_folders.vkontakte)); + GET_JSON_STRING(system_folders, "attach", &(info->system_folders.attach)); + GET_JSON_STRING(system_folders, "mailru", &(info->system_folders.mailru)); + GET_JSON_STRING(system_folders, "downloads", &(info->system_folders.downloads)); + GET_JSON_STRING(system_folders, "applications", &(info->system_folders.applications)); + GET_JSON_STRING(system_folders, "facebook", &(info->system_folders.facebook)); + GET_JSON_STRING(system_folders, "social", &(info->system_folders.social)); + GET_JSON_STRING(system_folders, "messenger", &(info->system_folders.messenger)); + GET_JSON_STRING(system_folders, "calendar", &(info->system_folders.calendar)); + GET_JSON_STRING(system_folders, "photostream", &(info->system_folders.photostream)); + GET_JSON_STRING(system_folders, "screenshots", &(info->system_folders.screenshots)); + GET_JSON_STRING(system_folders, "scans", &(info->system_folders.scans)); + + GET_JSON_BOOL(root, "unlimited_autoupload_enabled", &(info->unlimited_autoupload_enabled)); + GET_JSON_UINT64(root, "revision", &(info->revision)); + json_object_put(root); diff --git a/src/yadisk_get_disk.h b/src/yadisk_get_disk.h index e9d3407..1dc7e7b 100644 --- a/src/yadisk_get_disk.h +++ b/src/yadisk_get_disk.h @@ -24,12 +24,43 @@ #include "yadisk_shared.h" +typedef struct { + const char* reg_time; + const char* display_name; + const char* uid; + const char* country; + int is_child; + const char* login; +} yadisk_user_info; + +typedef struct { + const char* odnoklassniki; + const char* google; + const char* instagram; + const char* vkontakte; + const char* attach; + const char* mailru; + const char* downloads; + const char* applications; + const char* facebook; + const char* social; + const char* messenger; + const char* calendar; + const char* photostream; + const char* screenshots; + const char* scans; +} yadisk_system_folders; + typedef struct yadisk_disk_info { unsigned long total_space; unsigned long trash_size; unsigned long used_space; int is_paid; const char* reg_time; + yadisk_system_folders system_folders; + yadisk_user_info user; + int unlimited_autoupload_enabled; + unsigned long revision; } yadisk_disk_info; yadisk_code yadisk_get_disk(yadisk_api_client* client, yadisk_disk_info* info); diff --git a/tests/app.c b/tests/app.c index 7f4f623..127e1ba 100644 --- a/tests/app.c +++ b/tests/app.c @@ -34,14 +34,42 @@ int main() .token = token }; - yadisk_disk_info yadisk_disk_info; - yadisk_get_disk(client, &yadisk_disk_info); + yadisk_disk_info info; + yadisk_get_disk(client, &info); - printf("Total disk size: %lu\n", yadisk_disk_info.total_space); - printf("Trash size: %lu\n", yadisk_disk_info.trash_size); - printf("Used space: %lu\n", yadisk_disk_info.used_space); - printf("Registration time: %s\n", yadisk_disk_info.reg_time); - printf("Is paid: %s\n", yadisk_disk_info.is_paid ? "Yes" : "No"); + printf("Total disk size: %lu\n", info.total_space); + printf("Trash size: %lu\n", info.trash_size); + printf("Used space: %lu\n", info.used_space); + printf("Registration time: %s\n", info.reg_time); + printf("Is paid: %s\n", info.is_paid ? "Yes" : "No"); + + printf("User Info:\n"); + printf(" Registration time: %s\n", info.user.reg_time); + printf(" Display Name: %s\n", info.user.display_name); + printf(" UID: %s\n", info.user.uid); + printf(" Country: %s\n", info.user.country); + printf(" Is Child: %s\n", info.user.is_child ? "Yes" : "No"); + printf(" Login: %s\n", info.user.login); + + printf("System Folders:\n"); + printf(" Odnoklassniki: %s\n", info.system_folders.odnoklassniki); + printf(" Google: %s\n", info.system_folders.google); + printf(" Instagram: %s\n", info.system_folders.instagram); + printf(" Vkontakte: %s\n", info.system_folders.vkontakte); + printf(" Attach: %s\n", info.system_folders.attach); + printf(" Mailru: %s\n", info.system_folders.mailru); + printf(" Downloads: %s\n", info.system_folders.downloads); + printf(" Applications: %s\n", info.system_folders.applications); + printf(" Facebook: %s\n", info.system_folders.facebook); + printf(" Social: %s\n", info.system_folders.social); + printf(" Messenger: %s\n", info.system_folders.messenger); + printf(" Calendar: %s\n", info.system_folders.calendar); + printf(" Photostream: %s\n", info.system_folders.photostream); + printf(" Screenshots: %s\n", info.system_folders.screenshots); + printf(" Scans: %s\n", info.system_folders.scans); + + printf("Unlimited Autoupload Enabled: %s\n", info.unlimited_autoupload_enabled ? "Yes" : "No"); + printf("Revision: %lu\n", info.revision); printf("=================\n");