diff --git a/src/common/NetworkRequest.cpp b/src/common/NetworkRequest.cpp index 56a257d4a..640b477f9 100644 --- a/src/common/NetworkRequest.cpp +++ b/src/common/NetworkRequest.cpp @@ -63,7 +63,9 @@ void NetworkRequest::makeAuthorizedV5(const QString &clientID, const QString &oa { this->setRawHeader("Client-ID", clientID); this->setRawHeader("Accept", "application/vnd.twitchtv.v5+json"); - this->setRawHeader("Authorization", "OAuth " + oauthToken); + if (!oauthToken.isEmpty()) { + this->setRawHeader("Authorization", "OAuth " + oauthToken); + } } void NetworkRequest::setUseQuickLoadCache(bool value) diff --git a/src/common/NetworkRequest.hpp b/src/common/NetworkRequest.hpp index 3d990cab7..16e4f0287 100644 --- a/src/common/NetworkRequest.hpp +++ b/src/common/NetworkRequest.hpp @@ -142,7 +142,7 @@ public: void setRawHeader(const char *headerName, const QByteArray &value); void setRawHeader(const char *headerName, const QString &value); void setTimeout(int ms); - void makeAuthorizedV5(const QString &clientID, const QString &oauthToken); + void makeAuthorizedV5(const QString &clientID, const QString &oauthToken = QString()); template void get(FinishedCallback onFinished) @@ -255,19 +255,6 @@ public: }); } - template - void getJSON2(FinishedCallback onFinished) - { - this->get([onFinished{std::move(onFinished)}](const QByteArray &bytes) -> bool { - auto object = parseJSONFromData2(bytes); - onFinished(object); - - // XXX: Maybe return onFinished? For now I don't want to force onFinished to have a - // return value - return true; - }); - } - void execute(); private: diff --git a/src/common/UrlFetch.hpp b/src/common/UrlFetch.hpp index c677076d4..5ed00ada3 100644 --- a/src/common/UrlFetch.hpp +++ b/src/common/UrlFetch.hpp @@ -39,15 +39,19 @@ static void twitchApiGet(QString url, const QObject *caller, static void twitchApiGet2(QString url, const QObject *caller, bool useQuickLoadCache, std::function successCallback) { - NetworkRequest req(url); - req.setCaller(caller); - req.setRawHeader("Client-ID", getDefaultClientID()); - req.setRawHeader("Accept", "application/vnd.twitchtv.v5+json"); - req.setUseQuickLoadCache(useQuickLoadCache); + NetworkRequest request(url); + request.setRequestType(NetworkRequest::GetRequest); + request.setCaller(caller); + request.makeAuthorizedV5(getDefaultClientID()); + request.setUseQuickLoadCache(useQuickLoadCache); - req.getJSON2([=](const rapidjson::Document &document) { + request.onSuccess([successCallback](const rapidjson::Document &document) { successCallback(document); // + + return true; }); + + request.execute(); } static void twitchApiGetUserID(QString username, const QObject *caller,