#include #include #include #include #include "commands.h" #include "api.h" #include "roomsinfo.h" void getRoomsInfo (struct t_gui_buffer *buffer, const char *token) { ApiRequest request = { .url = "https://api.chatwork.com/v2/rooms", .token = token, }; ApiResponse response = makeApiRequest(&request); if (response.result != CURLE_OK) { weechat_printf(buffer, "GETリクエストエラー:%s\n", curl_easy_strerror(response.result)); } else { cJSON *root = response.data; if (root != NULL) { int size = cJSON_GetArraySize(root); for (int i = 0; i < size; i++) { cJSON *room = cJSON_GetArrayItem(root, i); int room_id = cJSON_GetObjectItem(room, "room_id")->valueint; const char *name = cJSON_GetObjectItem(room, "name")->valuestring; const char *type = cJSON_GetObjectItem(room, "type")->valuestring; if (strcmp(type, "my") == 0) { weechat_printf(buffer, "%d - %s\n", room_id, name); } else if (strcmp(type, "direct") == 0) { weechat_printf(buffer, "%d - DM %s\n", room_id, name); } else if (strcmp(type, "group") == 0) { weechat_printf(buffer, "%d - グループ %s\n", room_id, name); } } } else { weechat_printf(buffer, "JSONパーシングエラー。\n"); } cJSON_Delete(root); } }