diff options
| author | ilotterytea <iltsu@alright.party> | 2025-04-17 21:05:17 +0500 |
|---|---|---|
| committer | ilotterytea <iltsu@alright.party> | 2025-04-17 21:05:17 +0500 |
| commit | b1a2e8a26cd08545ef93192b465b68c81bbc582b (patch) | |
| tree | 72650dedd7beabd298ea9a4fdc7c459d4df976ce /bot/src/api/twitch/helix_client.cpp | |
| parent | 83f9787b6e6327e4000cc2df1a98ea5a50a1e284 (diff) | |
feat: get channel information method
Diffstat (limited to 'bot/src/api/twitch/helix_client.cpp')
| -rw-r--r-- | bot/src/api/twitch/helix_client.cpp | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/bot/src/api/twitch/helix_client.cpp b/bot/src/api/twitch/helix_client.cpp index b80895a..e3713d7 100644 --- a/bot/src/api/twitch/helix_client.cpp +++ b/bot/src/api/twitch/helix_client.cpp @@ -135,4 +135,36 @@ namespace bot::api::twitch { return streams; } + + std::vector<schemas::Stream> HelixClient::get_channel_information( + const std::vector<int> &ids) const { + std::vector<std::string> s; + + for (const int &id : ids) { + s.push_back("broadcaster_id=" + std::to_string(id)); + } + + cpr::Response response = + cpr::Get(cpr::Url{this->base_url + "/channels?" + + utils::string::join_vector(s, '&')}, + cpr::Bearer{this->token}, + cpr::Header{{"Client-Id", this->client_id.c_str()}}); + + if (response.status_code != 200) { + return {}; + } + + std::vector<schemas::Stream> streams; + + nlohmann::json j = nlohmann::json::parse(response.text); + + for (const auto &d : j["data"]) { + schemas::Stream u{std::stoi(d["broadcaster_id"].get<std::string>()), + d["broadcaster_login"], d["game_name"], d["title"]}; + + streams.push_back(u); + } + + return streams; + } } |
