63 lines
1.6 KiB
C++
63 lines
1.6 KiB
C++
// SPDX-FileCopyrightText: 2020 Contributors to Chatterino <https://chatterino.com>
|
|
//
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
#pragma once
|
|
|
|
#include "common/network/NetworkRequest.hpp"
|
|
|
|
#include <QJsonArray>
|
|
#include <QJsonObject>
|
|
|
|
#include <functional>
|
|
|
|
namespace chatterino {
|
|
|
|
using IvrFailureCallback = std::function<void()>;
|
|
template <typename... T>
|
|
using ResultCallback = std::function<void(T...)>;
|
|
|
|
struct IvrSubage {
|
|
const bool isSubHidden;
|
|
const bool isSubbed;
|
|
const QString subTier;
|
|
const int totalSubMonths;
|
|
const QString followingSince;
|
|
|
|
IvrSubage(const QJsonObject &root)
|
|
: isSubHidden(root.value("statusHidden").toBool())
|
|
, isSubbed(!root.value("meta").isNull())
|
|
, subTier(root.value("meta").toObject().value("tier").toString())
|
|
, totalSubMonths(
|
|
root.value("cumulative").toObject().value("months").toInt())
|
|
, followingSince(root.value("followedAt").toString())
|
|
{
|
|
}
|
|
};
|
|
|
|
class IvrApi final
|
|
{
|
|
public:
|
|
// https://api.ivr.fi/v2/docs/static/index.html#/Twitch/get_twitch_subage__user___channel_
|
|
void getSubage(QString userName, QString channelName,
|
|
ResultCallback<IvrSubage> resultCallback,
|
|
IvrFailureCallback failureCallback);
|
|
|
|
static void initialize();
|
|
|
|
IvrApi() = default;
|
|
|
|
IvrApi(const IvrApi &) = delete;
|
|
IvrApi &operator=(const IvrApi &) = delete;
|
|
|
|
IvrApi(IvrApi &&) = delete;
|
|
IvrApi &operator=(IvrApi &&) = delete;
|
|
|
|
private:
|
|
NetworkRequest makeRequest(QString url, QUrlQuery urlQuery);
|
|
};
|
|
|
|
IvrApi *getIvr();
|
|
|
|
} // namespace chatterino
|