weechat-chatwork/roomsinfo.c

45 行
1.4 KiB
C
Raw パーマリンク Blame 履歴

このファイルには曖昧(ambiguous)なUnicode文字が含まれています

このファイルには、他の文字と見間違える可能性があるUnicode文字が含まれています。 それが意図的なものと考えられる場合は、この警告を無視して構いません。 それらの文字を表示するにはエスケープボタンを使用します。

#include <string.h>
#include <weechat/weechat-plugin.h>
#include <curl/curl.h>
#include <cjson/cJSON.h>
#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);
}
}