mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
Remove getJSON2 function
This commit is contained in:
parent
faa088b7e5
commit
efbd0f31e6
3 changed files with 14 additions and 21 deletions
|
@ -63,7 +63,9 @@ void NetworkRequest::makeAuthorizedV5(const QString &clientID, const QString &oa
|
||||||
{
|
{
|
||||||
this->setRawHeader("Client-ID", clientID);
|
this->setRawHeader("Client-ID", clientID);
|
||||||
this->setRawHeader("Accept", "application/vnd.twitchtv.v5+json");
|
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)
|
void NetworkRequest::setUseQuickLoadCache(bool value)
|
||||||
|
|
|
@ -142,7 +142,7 @@ public:
|
||||||
void setRawHeader(const char *headerName, const QByteArray &value);
|
void setRawHeader(const char *headerName, const QByteArray &value);
|
||||||
void setRawHeader(const char *headerName, const QString &value);
|
void setRawHeader(const char *headerName, const QString &value);
|
||||||
void setTimeout(int ms);
|
void setTimeout(int ms);
|
||||||
void makeAuthorizedV5(const QString &clientID, const QString &oauthToken);
|
void makeAuthorizedV5(const QString &clientID, const QString &oauthToken = QString());
|
||||||
|
|
||||||
template <typename FinishedCallback>
|
template <typename FinishedCallback>
|
||||||
void get(FinishedCallback onFinished)
|
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();
|
void execute();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -39,15 +39,19 @@ static void twitchApiGet(QString url, const QObject *caller,
|
||||||
static void twitchApiGet2(QString url, const QObject *caller, bool useQuickLoadCache,
|
static void twitchApiGet2(QString url, const QObject *caller, bool useQuickLoadCache,
|
||||||
std::function<void(const rapidjson::Document &)> successCallback)
|
std::function<void(const rapidjson::Document &)> successCallback)
|
||||||
{
|
{
|
||||||
NetworkRequest req(url);
|
NetworkRequest request(url);
|
||||||
req.setCaller(caller);
|
request.setRequestType(NetworkRequest::GetRequest);
|
||||||
req.setRawHeader("Client-ID", getDefaultClientID());
|
request.setCaller(caller);
|
||||||
req.setRawHeader("Accept", "application/vnd.twitchtv.v5+json");
|
request.makeAuthorizedV5(getDefaultClientID());
|
||||||
req.setUseQuickLoadCache(useQuickLoadCache);
|
request.setUseQuickLoadCache(useQuickLoadCache);
|
||||||
|
|
||||||
req.getJSON2([=](const rapidjson::Document &document) {
|
request.onSuccess([successCallback](const rapidjson::Document &document) {
|
||||||
successCallback(document); //
|
successCallback(document); //
|
||||||
|
|
||||||
|
return true;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
request.execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void twitchApiGetUserID(QString username, const QObject *caller,
|
static void twitchApiGetUserID(QString username, const QObject *caller,
|
||||||
|
|
Loading…
Reference in a new issue