-
Notifications
You must be signed in to change notification settings - Fork 0
/
GithubStatus.cpp
54 lines (43 loc) · 1.15 KB
/
GithubStatus.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
//
// Created by Ondra on 8.4.2020.
//
#include "GithubStatus.h"
#include "win.h"
#include "json.hpp"
#include <Winhttp.h>
using json = nlohmann::json;
GithubStatus::GithubStatus() : request(url) {
}
GithubStatus::~GithubStatus() {
}
void GithubStatus::update(std::function<void(const Status &)> callback) {
auto reqCallback = [this, callback](const std::string &response, const std::map<string, string> &headers, long statusCode) -> void {
auto result = json::parse(response);
// https://www.githubstatus.com/api/#status
/*
{
"page":{
"id":"kctbh9vrtdwd",
"name":"GitHub",
"url":"https://www.githubstatus.com",
"time_zone":"Etc/UTC",
"updated_at":"2020-04-08T08:09:34.236Z"
},
"status":{
"indicator":"none",
"description":"All Systems Operational"
}
}
*/
if (statusCode >= 200 && statusCode < 300) {
status.icon = result["status"]["indicator"].get<std::string>();
status.message = result["status"]["description"].get<std::string>();
status.timestamp = result["page"]["updated_at"].get<std::string>();
callback(status);
}
};
try {
request.update(endpoint, reqCallback);
} catch (...) {
}
}