Chatterino
IvrApi.hpp
Go to the documentation of this file.
1 #pragma once
2 
4 #include "messages/Link.hpp"
6 
7 #include <boost/noncopyable.hpp>
8 
9 #include <functional>
10 
11 namespace chatterino {
12 
13 using IvrFailureCallback = std::function<void()>;
14 template <typename... T>
15 using ResultCallback = std::function<void(T...)>;
16 
17 struct IvrSubage {
18  const bool isSubHidden;
19  const bool isSubbed;
20  const QString subTier;
21  const int totalSubMonths;
22  const QString followingSince;
23 
24  IvrSubage(const QJsonObject &root)
25  : isSubHidden(root.value("statusHidden").toBool())
26  , isSubbed(!root.value("meta").isNull())
27  , subTier(root.value("meta").toObject().value("tier").toString())
28  , totalSubMonths(
29  root.value("cumulative").toObject().value("months").toInt())
30  , followingSince(root.value("followedAt").toString())
31  {
32  }
33 };
34 
35 struct IvrEmoteSet {
36  const QString setId;
37  const QString displayName;
38  const QString login;
39  const QString channelId;
40  const QString tier;
41  const QJsonArray emotes;
42 
43  IvrEmoteSet(const QJsonObject &root)
44  : setId(root.value("setID").toString())
45  , displayName(root.value("channelName").toString())
46  , login(root.value("channelLogin").toString())
47  , channelId(root.value("channelID").toString())
48  , tier(root.value("tier").toString())
49  , emotes(root.value("emoteList").toArray())
50 
51  {
52  }
53 };
54 
55 struct IvrEmote {
56  const QString code;
57  const QString id;
58  const QString setId;
59  const QString url;
60  const QString emoteType;
61  const QString imageType;
62 
63  explicit IvrEmote(const QJsonObject &root)
64  : code(root.value("code").toString())
65  , id(root.value("id").toString())
66  , setId(root.value("setID").toString())
67  , url(QString(TWITCH_EMOTE_TEMPLATE)
68  .replace("{id}", this->id)
69  .replace("{scale}", "3.0"))
70  , emoteType(root.value("type").toString())
71  , imageType(root.value("assetType").toString())
72  {
73  }
74 };
75 
76 class IvrApi final : boost::noncopyable
77 {
78 public:
79  // https://api.ivr.fi/v2/docs/static/index.html#/Twitch/get_twitch_subage__user___channel_
80  void getSubage(QString userName, QString channelName,
81  ResultCallback<IvrSubage> resultCallback,
82  IvrFailureCallback failureCallback);
83 
84  // https://api.ivr.fi/v2/docs/static/index.html#/Twitch/get_twitch_emotes_sets
85  void getBulkEmoteSets(QString emoteSetList,
86  ResultCallback<QJsonArray> successCallback,
87  IvrFailureCallback failureCallback);
88 
89  static void initialize();
90 
91 private:
92  NetworkRequest makeRequest(QString url, QUrlQuery urlQuery);
93 };
94 
95 IvrApi *getIvr();
96 
97 } // namespace chatterino
std::function< void()> IvrFailureCallback
Definition: IvrApi.hpp:13
const bool isSubHidden
Definition: IvrApi.hpp:18
const QString displayName
Definition: IvrApi.hpp:37
Definition: NetworkRequest.hpp:13
IvrEmoteSet(const QJsonObject &root)
Definition: IvrApi.hpp:43
IvrEmote(const QJsonObject &root)
Definition: IvrApi.hpp:63
const QString id
Definition: IvrApi.hpp:57
const QString setId
Definition: IvrApi.hpp:36
const QString setId
Definition: IvrApi.hpp:58
const QString login
Definition: IvrApi.hpp:38
const QString url
Definition: IvrApi.hpp:59
Definition: Application.cpp:48
IvrApi * getIvr()
Definition: IvrApi.cpp:79
std::function< void(T...)> ResultCallback
Definition: IvrApi.hpp:15
Definition: IvrApi.hpp:17
#define TWITCH_EMOTE_TEMPLATE
Definition: TwitchEmotes.hpp:15
const QString imageType
Definition: IvrApi.hpp:61
const QString tier
Definition: IvrApi.hpp:40
const int totalSubMonths
Definition: IvrApi.hpp:21
const QString subTier
Definition: IvrApi.hpp:20
const QJsonArray emotes
Definition: IvrApi.hpp:41
Definition: IvrApi.hpp:55
const QString followingSince
Definition: IvrApi.hpp:22
const QString channelId
Definition: IvrApi.hpp:39
Definition: IvrApi.hpp:76
const QString emoteType
Definition: IvrApi.hpp:60
const QString code
Definition: IvrApi.hpp:56
const bool isSubbed
Definition: IvrApi.hpp:19
Definition: IvrApi.hpp:35
IvrSubage(const QJsonObject &root)
Definition: IvrApi.hpp:24