diff --git a/CMakeLists.txt b/CMakeLists.txt index 9ec292f..14d92c5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,8 +5,11 @@ set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/modules) find_package(Neon REQUIRED) find_package(JsonC REQUIRED) -add_library(yadisk src/yandex_disk_api.c - tests/ctest.c) +add_library(yadisk src/yandex_disk_api.c) +add_executable(test-app tests/app.c) target_include_directories(yadisk PRIVATE ${NEON_INCLUDE_DIR} ${JSON_C_INCLUDE_DIR}) -target_link_libraries(yadisk ${NEON_LIBRARIES} ${JSON_C_LIBRARIES}) \ No newline at end of file +target_link_libraries(yadisk ${NEON_LIBRARIES} ${JSON_C_LIBRARIES}) + +target_include_directories(test-app PRIVATE "${CMAKE_SOURCE_DIR}/src" ${NEON_INCLUDE_DIR} ${JSON_C_INCLUDE_DIR}) +target_link_libraries(test-app yadisk) \ No newline at end of file diff --git a/src/yandex_disk_api.c b/src/yandex_disk_api.c index b94d92e..5e982ac 100644 --- a/src/yandex_disk_api.c +++ b/src/yandex_disk_api.c @@ -17,21 +17,23 @@ static int api_http_request( void yadisk_get_disk(yadisk_api_client *client, yadisk_disk_info* info) { char* output = NULL; - int result = api_http_request(client, "GET", "/v1/disk", &output); + int error = api_http_request(client, "GET", "/v1/disk", &output); json_object* root = json_tokener_parse(output); - free(output); - if (!result) { + if (error) { json_object_put(root); return; } json_object* total_space = NULL; - json_object_object_get_ex(root, "total_space", &total_space); - info->total_space = json_object_get_int64(total_space); + if (!json_object_object_get_ex(root, "total_space", &total_space)) { + printf("Key total_space doesn't exists!"); + } + info->total_space = json_object_get_uint64(total_space); json_object_put(total_space); json_object_put(root); + free(output); } void yadisk_delete_disk_resources(yadisk_api_client *client) { diff --git a/src/yandex_disk_api.h b/src/yandex_disk_api.h index 12bf5c8..add9624 100644 --- a/src/yandex_disk_api.h +++ b/src/yandex_disk_api.h @@ -17,7 +17,7 @@ typedef struct yadisk_api_client typedef struct yadisk_disk_info { - long total_space; + unsigned long total_space; } yadisk_disk_info; void yadisk_get_disk(yadisk_api_client* client, yadisk_disk_info* info); diff --git a/tests/app.c b/tests/app.c new file mode 100644 index 0000000..034695b --- /dev/null +++ b/tests/app.c @@ -0,0 +1,25 @@ +// +// Created by maxim on 27.11.23. +// + +#include +#include + +int main() { + char token[1024]; + + printf("Enter OAuth token: "); + fgets(token, sizeof(token), stdin); + + yadisk_api_client* client = &(yadisk_api_client){ + .token = token + }; + + yadisk_disk_info yadisk_disk_info; + + yadisk_get_disk(client, &yadisk_disk_info); + + printf("Total disk size: %lu", yadisk_disk_info.total_space); + + return 0; +} \ No newline at end of file