renamed twitch api get functions

This commit is contained in:
fourtf 2018-06-26 17:12:50 +02:00
parent 54eb07e116
commit c74bc00106
6 changed files with 24 additions and 23 deletions

View file

@ -23,7 +23,7 @@
namespace chatterino {
static void get(QString url, const QObject *caller,
static void twitchApiGet(QString url, const QObject *caller,
std::function<void(const QJsonObject &)> successCallback)
{
NetworkRequest req(url);
@ -36,7 +36,7 @@ static void get(QString url, const QObject *caller,
});
}
static void get2(QString url, const QObject *caller, bool useQuickLoadCache,
static void twitchApiGet2(QString url, const QObject *caller, bool useQuickLoadCache,
std::function<void(const rapidjson::Document &)> successCallback)
{
NetworkRequest req(url);
@ -50,7 +50,7 @@ static void get2(QString url, const QObject *caller, bool useQuickLoadCache,
});
}
static void getAuthorized(QString url, const QString &clientID, const QString &oauthToken,
static void twitchApiGetAuthorized(QString url, const QString &clientID, const QString &oauthToken,
const QObject *caller,
std::function<void(const QJsonObject &)> successCallback)
{
@ -65,10 +65,11 @@ static void getAuthorized(QString url, const QString &clientID, const QString &o
});
}
static void getUserID(QString username, const QObject *caller,
static void twitchApiGetUserID(QString username, const QObject *caller,
std::function<void(QString)> successCallback)
{
get("https://api.twitch.tv/kraken/users?login=" + username, caller,
twitchApiGet(
"https://api.twitch.tv/kraken/users?login=" + username, caller,
[=](const QJsonObject &root) {
if (!root.value("users").isArray()) {
Log("API Error while getting user id, users is not an array");
@ -94,7 +95,7 @@ static void getUserID(QString username, const QObject *caller,
successCallback(id.toString());
});
}
static void put(QUrl url, std::function<void(QJsonObject)> successCallback)
static void twitchApiPut(QUrl url, std::function<void(QJsonObject)> successCallback)
{
QNetworkRequest request(url);
@ -124,7 +125,7 @@ static void put(QUrl url, std::function<void(QJsonObject)> successCallback)
});
}
static void sendDelete(QUrl url, std::function<void()> successCallback)
static void twitchApiDelete(QUrl url, std::function<void()> successCallback)
{
QNetworkRequest request(url);

View file

@ -119,7 +119,7 @@ void TwitchAccount::loadIgnores()
void TwitchAccount::ignore(const QString &targetName,
std::function<void(IgnoreResult, const QString &)> onFinished)
{
getUserID(targetName, QThread::currentThread(), [=](QString targetUserID) {
twitchApiGetUserID(targetName, QThread::currentThread(), [=](QString targetUserID) {
this->ignoreByID(targetUserID, targetName, onFinished); //
});
}
@ -179,7 +179,7 @@ void TwitchAccount::ignoreByID(const QString &targetUserID, const QString &targe
void TwitchAccount::unignore(const QString &targetName,
std::function<void(UnignoreResult, const QString &message)> onFinished)
{
getUserID(targetName, QThread::currentThread(), [=](QString targetUserID) {
twitchApiGetUserID(targetName, QThread::currentThread(), [=](QString targetUserID) {
this->unignoreByID(targetUserID, targetName, onFinished); //
});
}

View file

@ -83,7 +83,7 @@ TwitchChannel::TwitchChannel(const QString &channelName, Communi::IrcConnection
}
}
get("https://tmi.twitch.tv/group/user/" + this->name + "/chatters",
twitchApiGet("https://tmi.twitch.tv/group/user/" + this->name + "/chatters",
QThread::currentThread(), refreshChatters);
};
@ -332,7 +332,7 @@ void TwitchChannel::refreshLiveStatus()
std::weak_ptr<Channel> weak = this->shared_from_this();
get2(url, QThread::currentThread(), false, [weak](const rapidjson::Document &d) {
twitchApiGet2(url, QThread::currentThread(), false, [weak](const rapidjson::Document &d) {
ChannelPtr shared = weak.lock();
if (!shared) {
@ -432,7 +432,7 @@ void TwitchChannel::fetchRecentMessages()
std::weak_ptr<Channel> weak = this->shared_from_this();
get(genericURL.arg(roomID), QThread::currentThread(), [weak](QJsonObject obj) {
twitchApiGet(genericURL.arg(roomID), QThread::currentThread(), [weak](QJsonObject obj) {
ChannelPtr shared = weak.lock();
if (!shared) {

View file

@ -172,7 +172,7 @@ AdvancedLoginWidget::AdvancedLoginWidget()
this->ui.buttonLowerRow.layout.addWidget(&this->ui.buttonLowerRow.fillInUserIDButton);
connect(&this->ui.buttonLowerRow.fillInUserIDButton, &QPushButton::clicked, [=]() {
getUserID(this->ui.usernameInput.text(), this, [=](const QString &userID) {
twitchApiGetUserID(this->ui.usernameInput.text(), this, [=](const QString &userID) {
this->ui.userIDInput.setText(userID); //
});
});

View file

@ -171,10 +171,10 @@ void UserInfoPopup::installEvents()
this->ui_.follow->setEnabled(false);
if (this->ui_.follow->isChecked()) {
put(requestUrl,
twitchApiPut(requestUrl,
[this](QJsonObject) { this->ui_.follow->setEnabled(true); });
} else {
sendDelete(requestUrl, [this] { this->ui_.follow->setEnabled(true); });
twitchApiDelete(requestUrl, [this] { this->ui_.follow->setEnabled(true); });
}
});
@ -234,13 +234,13 @@ void UserInfoPopup::updateUserData()
std::weak_ptr<bool> hack = this->hack_;
// get user info
getUserID(this->userName_, this, [this, hack](QString id) {
twitchApiGetUserID(this->userName_, this, [this, hack](QString id) {
auto currentUser = getApp()->accounts->twitch.getCurrent();
this->userId_ = id;
// get channel info
get(
twitchApiGet(
"https://api.twitch.tv/kraken/channels/" + id, this, [this](const QJsonObject &obj) {
this->ui_.followerCountLabel->setText(
TEXT_FOLLOWERS + QString::number(obj.value("followers").toInt()));

View file

@ -449,7 +449,7 @@ void Split::doOpenViewerList()
}
auto loadingLabel = new QLabel("Loading...");
get("https://tmi.twitch.tv/group/user/" + this->getChannel()->name + "/chatters",
twitchApiGet("https://tmi.twitch.tv/group/user/" + this->getChannel()->name + "/chatters",
this, [=](QJsonObject obj) {
QJsonObject chattersObj = obj.value("chatters").toObject();