Twitch API: v5 to Helix migration (#1560)
There's a document in src/providers/twitch/api which describes how we interact with the Twitch API. Keeping this up to date might be a healthy way for us to ensure we keep using the right APIs for the right job.
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
#include "providers/twitch/TwitchChannel.hpp"
|
||||
#include "providers/twitch/TwitchCommon.hpp"
|
||||
#include "providers/twitch/TwitchIrcServer.hpp"
|
||||
#include "providers/twitch/api/Helix.hpp"
|
||||
#include "singletons/Paths.hpp"
|
||||
#include "util/StreamLink.hpp"
|
||||
#include "widgets/helper/CommonTexts.hpp"
|
||||
@@ -85,14 +86,17 @@ void Toasts::sendChannelNotification(const QString &channelName, Platform p)
|
||||
}
|
||||
else
|
||||
{
|
||||
this->fetchChannelAvatar(
|
||||
getHelix()->getUserByName(
|
||||
channelName,
|
||||
[channelName, sendChannelNotification](QString avatarLink) {
|
||||
[channelName, sendChannelNotification](const auto &user) {
|
||||
DownloadManager *manager = new DownloadManager();
|
||||
manager->setFile(avatarLink, channelName);
|
||||
manager->setFile(user.profileImageUrl, channelName);
|
||||
manager->connect(manager,
|
||||
&DownloadManager::downloadComplete,
|
||||
sendChannelNotification);
|
||||
},
|
||||
[] {
|
||||
// on failure
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -206,53 +210,4 @@ void Toasts::sendWindowsNotification(const QString &channelName, Platform p)
|
||||
|
||||
#endif
|
||||
|
||||
void Toasts::fetchChannelAvatar(const QString channelName,
|
||||
std::function<void(QString)> successCallback)
|
||||
{
|
||||
QString requestUrl("https://api.twitch.tv/kraken/users?login=" +
|
||||
channelName);
|
||||
|
||||
NetworkRequest(requestUrl)
|
||||
|
||||
.authorizeTwitchV5(getDefaultClientID())
|
||||
.timeout(30000)
|
||||
.onSuccess([successCallback](auto result) mutable -> Outcome {
|
||||
auto root = result.parseJson();
|
||||
if (!root.value("users").isArray())
|
||||
{
|
||||
// log("API Error while getting user id, users is not an array");
|
||||
successCallback("");
|
||||
return Failure;
|
||||
}
|
||||
auto users = root.value("users").toArray();
|
||||
if (users.size() != 1)
|
||||
{
|
||||
// log("API Error while getting user id, users array size is not
|
||||
// 1");
|
||||
successCallback("");
|
||||
return Failure;
|
||||
}
|
||||
if (!users[0].isObject())
|
||||
{
|
||||
// log("API Error while getting user id, first user is not an
|
||||
// object");
|
||||
successCallback("");
|
||||
return Failure;
|
||||
}
|
||||
auto firstUser = users[0].toObject();
|
||||
auto avatar = firstUser.value("logo");
|
||||
if (!avatar.isString())
|
||||
{
|
||||
// log("API Error: while getting user avatar, first user object "
|
||||
// "`avatar` key "
|
||||
// "is not a "
|
||||
// "string");
|
||||
successCallback("");
|
||||
return Failure;
|
||||
}
|
||||
successCallback(avatar.toString());
|
||||
return Success;
|
||||
})
|
||||
.execute();
|
||||
}
|
||||
} // namespace chatterino
|
||||
|
||||
Reference in New Issue
Block a user