Remove getJSON2 function

This commit is contained in:
Rasmus Karlsson 2018-07-06 20:00:03 +00:00
parent faa088b7e5
commit efbd0f31e6
3 changed files with 14 additions and 21 deletions

View file

@ -63,8 +63,10 @@ void NetworkRequest::makeAuthorizedV5(const QString &clientID, const QString &oa
{
this->setRawHeader("Client-ID", clientID);
this->setRawHeader("Accept", "application/vnd.twitchtv.v5+json");
if (!oauthToken.isEmpty()) {
this->setRawHeader("Authorization", "OAuth " + oauthToken);
}
}
void NetworkRequest::setUseQuickLoadCache(bool value)
{

View file

@ -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 <typename FinishedCallback>
void get(FinishedCallback onFinished)
@ -255,19 +255,6 @@ public:
});
}
template <typename FinishedCallback>
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:

View file

@ -39,15 +39,19 @@ static void twitchApiGet(QString url, const QObject *caller,
static void twitchApiGet2(QString url, const QObject *caller, bool useQuickLoadCache,
std::function<void(const rapidjson::Document &)> 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,