2018-07-07 13:08:57 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <rapidjson/document.h>
|
|
|
|
#include <QJsonObject>
|
|
|
|
|
|
|
|
namespace chatterino {
|
|
|
|
|
|
|
|
class NetworkResult
|
|
|
|
{
|
|
|
|
public:
|
2019-09-19 19:03:50 +02:00
|
|
|
NetworkResult(const QByteArray &data, int status);
|
2018-07-07 13:08:57 +02:00
|
|
|
|
2019-09-03 23:32:22 +02:00
|
|
|
/// Parses the result as json and returns the root as an object.
|
|
|
|
/// Returns empty object if parsing failed.
|
2018-07-07 13:08:57 +02:00
|
|
|
QJsonObject parseJson() const;
|
2019-09-03 23:32:22 +02:00
|
|
|
/// Parses the result as json and returns the root as an array.
|
|
|
|
/// Returns empty object if parsing failed.
|
|
|
|
QJsonArray parseJsonArray() const;
|
|
|
|
/// Parses the result as json and returns the document.
|
2018-07-07 13:08:57 +02:00
|
|
|
rapidjson::Document parseRapidJson() const;
|
2018-08-02 14:23:27 +02:00
|
|
|
const QByteArray &getData() const;
|
2019-09-19 19:03:50 +02:00
|
|
|
int status() const;
|
|
|
|
|
|
|
|
static constexpr int timedoutStatus = -2;
|
2018-08-02 14:23:27 +02:00
|
|
|
|
|
|
|
private:
|
2019-09-19 19:03:50 +02:00
|
|
|
int status_;
|
2018-08-02 14:23:27 +02:00
|
|
|
QByteArray data_;
|
2018-07-07 13:08:57 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace chatterino
|