mirror-chatterino2/src/providers/IvrApi.hpp
Paweł 776ce8bdbc
Added subage and followage to usercard (#2023)
* Added subage and followage information to usercard

We are using Leppunen's API here to determine user's subage to the current channel and since that API call also returns followage information I decided to utilize that and save ourselves an extra Helix API call.
I also added new files specifying new class and methods for Ivr API, which can be very easily expanded with new methods in the future if we ever have to do that.
When I was coding I also saw couple unnecessary nitpicks which I fixed :)

* Added changelog entry

* remove empty lambda

* Update UserInfoPopup.cpp

* xd

Co-authored-by: fourtf <tf.four@gmail.com>
2020-10-04 18:32:52 +02:00

49 lines
1.3 KiB
C++

#pragma once
#include "common/NetworkRequest.hpp"
#include "messages/Link.hpp"
#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(QJsonObject root)
: isSubHidden(root.value("hidden").toBool())
, isSubbed(root.value("subscribed").toBool())
, subTier(root.value("meta").toObject().value("tier").toString())
, totalSubMonths(
root.value("cumulative").toObject().value("months").toInt())
, followingSince(root.value("followedAt").toString())
{
}
};
class IvrApi final : boost::noncopyable
{
public:
// https://api.ivr.fi/docs#tag/Twitch/paths/~1twitch~1subage~1{username}~1{channel}/get
void getSubage(QString userName, QString channelName,
ResultCallback<IvrSubage> resultCallback,
IvrFailureCallback failureCallback);
static void initialize();
private:
NetworkRequest makeRequest(QString url, QUrlQuery urlQuery);
};
IvrApi *getIvr();
} // namespace chatterino