finish yadisk_get_disk

This commit is contained in:
Maxim Slipenko 2023-12-01 11:05:18 +03:00
parent b0cdcabe1a
commit db89e0e129
3 changed files with 100 additions and 7 deletions

View File

@ -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_STRING(root, "reg_time", &(info->reg_time));
GET_JSON_BOOL(root, "is_paid", &(info->is_paid)); 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); json_object_put(root);

View File

@ -24,12 +24,43 @@
#include "yadisk_shared.h" #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 { typedef struct yadisk_disk_info {
unsigned long total_space; unsigned long total_space;
unsigned long trash_size; unsigned long trash_size;
unsigned long used_space; unsigned long used_space;
int is_paid; int is_paid;
const char* reg_time; const char* reg_time;
yadisk_system_folders system_folders;
yadisk_user_info user;
int unlimited_autoupload_enabled;
unsigned long revision;
} yadisk_disk_info; } yadisk_disk_info;
yadisk_code yadisk_get_disk(yadisk_api_client* client, yadisk_disk_info* info); yadisk_code yadisk_get_disk(yadisk_api_client* client, yadisk_disk_info* info);

View File

@ -34,14 +34,42 @@ int main()
.token = token .token = token
}; };
yadisk_disk_info yadisk_disk_info; yadisk_disk_info info;
yadisk_get_disk(client, &yadisk_disk_info); yadisk_get_disk(client, &info);
printf("Total disk size: %lu\n", yadisk_disk_info.total_space); printf("Total disk size: %lu\n", info.total_space);
printf("Trash size: %lu\n", yadisk_disk_info.trash_size); printf("Trash size: %lu\n", info.trash_size);
printf("Used space: %lu\n", yadisk_disk_info.used_space); printf("Used space: %lu\n", info.used_space);
printf("Registration time: %s\n", yadisk_disk_info.reg_time); printf("Registration time: %s\n", info.reg_time);
printf("Is paid: %s\n", yadisk_disk_info.is_paid ? "Yes" : "No"); 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"); printf("=================\n");