40 行
1.5 KiB
C
40 行
1.5 KiB
C
|
#include <weechat/weechat-plugin.h>
|
|||
|
#include <curl/curl.h>
|
|||
|
#include <cjson/cJSON.h>
|
|||
|
|
|||
|
#include "commands.h"
|
|||
|
#include "api.h"
|
|||
|
#include "meinfo.h"
|
|||
|
|
|||
|
void getMeInfo (struct t_gui_buffer *buffer, const char *token) {
|
|||
|
ApiRequest request = {
|
|||
|
.url = "https://api.chatwork.com/v2/me",
|
|||
|
.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 account_id = cJSON_GetObjectItem(root, "account_id")->valueint;
|
|||
|
const char *name = cJSON_GetObjectItem(root, "name")->valuestring;
|
|||
|
const char *chatwork_id = cJSON_GetObjectItem(root, "chatwork_id")->valuestring;
|
|||
|
int organization_id = cJSON_GetObjectItem(root, "organization_id")->valueint;
|
|||
|
const char *organization_name = cJSON_GetObjectItem(root, "organization_name")->valuestring;
|
|||
|
const char *department = cJSON_GetObjectItem(root, "department")->valuestring;
|
|||
|
weechat_printf(buffer, "アカウントID:%d\n", account_id);
|
|||
|
weechat_printf(buffer, "名前:%s\n", name);
|
|||
|
weechat_printf(buffer, "チャットワークID:%s\n", chatwork_id);
|
|||
|
weechat_printf(buffer, "組織ID:%d\n", organization_id);
|
|||
|
weechat_printf(buffer, "組織名:%s\n", organization_name);
|
|||
|
weechat_printf(buffer, "部局:%s\n", department);
|
|||
|
} else {
|
|||
|
weechat_printf(buffer, "JSONパーシングエラー。\n");
|
|||
|
}
|
|||
|
|
|||
|
cJSON_Delete(root);
|
|||
|
}
|
|||
|
}
|