mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
Make Helix an interface (#3756)
This commit is contained in:
parent
e67d13dd2d
commit
6bb96f128b
2 changed files with 159 additions and 29 deletions
|
@ -7,7 +7,7 @@
|
||||||
|
|
||||||
namespace chatterino {
|
namespace chatterino {
|
||||||
|
|
||||||
static Helix *instance = nullptr;
|
static IHelix *instance = nullptr;
|
||||||
|
|
||||||
void Helix::fetchUsers(QStringList userIds, QStringList userLogins,
|
void Helix::fetchUsers(QStringList userIds, QStringList userLogins,
|
||||||
ResultCallback<std::vector<HelixUser>> successCallback,
|
ResultCallback<std::vector<HelixUser>> successCallback,
|
||||||
|
@ -808,10 +808,17 @@ void Helix::initialize()
|
||||||
{
|
{
|
||||||
assert(instance == nullptr);
|
assert(instance == nullptr);
|
||||||
|
|
||||||
instance = new Helix();
|
initializeHelix(new Helix());
|
||||||
}
|
}
|
||||||
|
|
||||||
Helix *getHelix()
|
void initializeHelix(IHelix *_instance)
|
||||||
|
{
|
||||||
|
assert(_instance != nullptr);
|
||||||
|
|
||||||
|
instance = _instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
IHelix *getHelix()
|
||||||
{
|
{
|
||||||
assert(instance != nullptr);
|
assert(instance != nullptr);
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,6 @@
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
#include <QUrlQuery>
|
#include <QUrlQuery>
|
||||||
#include <boost/noncopyable.hpp>
|
|
||||||
#include <boost/optional.hpp>
|
#include <boost/optional.hpp>
|
||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
@ -323,117 +322,237 @@ enum class HelixAutoModMessageError {
|
||||||
MessageNotFound,
|
MessageNotFound,
|
||||||
};
|
};
|
||||||
|
|
||||||
class Helix final : boost::noncopyable
|
class IHelix
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
// https://dev.twitch.tv/docs/api/reference#get-users
|
||||||
|
virtual void fetchUsers(
|
||||||
|
QStringList userIds, QStringList userLogins,
|
||||||
|
ResultCallback<std::vector<HelixUser>> successCallback,
|
||||||
|
HelixFailureCallback failureCallback) = 0;
|
||||||
|
virtual void getUserByName(QString userName,
|
||||||
|
ResultCallback<HelixUser> successCallback,
|
||||||
|
HelixFailureCallback failureCallback) = 0;
|
||||||
|
virtual void getUserById(QString userId,
|
||||||
|
ResultCallback<HelixUser> successCallback,
|
||||||
|
HelixFailureCallback failureCallback) = 0;
|
||||||
|
|
||||||
|
// https://dev.twitch.tv/docs/api/reference#get-users-follows
|
||||||
|
virtual void fetchUsersFollows(
|
||||||
|
QString fromId, QString toId,
|
||||||
|
ResultCallback<HelixUsersFollowsResponse> successCallback,
|
||||||
|
HelixFailureCallback failureCallback) = 0;
|
||||||
|
|
||||||
|
virtual void getUserFollowers(
|
||||||
|
QString userId,
|
||||||
|
ResultCallback<HelixUsersFollowsResponse> successCallback,
|
||||||
|
HelixFailureCallback failureCallback) = 0;
|
||||||
|
|
||||||
|
// https://dev.twitch.tv/docs/api/reference#get-streams
|
||||||
|
virtual void fetchStreams(
|
||||||
|
QStringList userIds, QStringList userLogins,
|
||||||
|
ResultCallback<std::vector<HelixStream>> successCallback,
|
||||||
|
HelixFailureCallback failureCallback) = 0;
|
||||||
|
|
||||||
|
virtual void getStreamById(
|
||||||
|
QString userId, ResultCallback<bool, HelixStream> successCallback,
|
||||||
|
HelixFailureCallback failureCallback) = 0;
|
||||||
|
|
||||||
|
virtual void getStreamByName(
|
||||||
|
QString userName, ResultCallback<bool, HelixStream> successCallback,
|
||||||
|
HelixFailureCallback failureCallback) = 0;
|
||||||
|
|
||||||
|
// https://dev.twitch.tv/docs/api/reference#get-games
|
||||||
|
virtual void fetchGames(
|
||||||
|
QStringList gameIds, QStringList gameNames,
|
||||||
|
ResultCallback<std::vector<HelixGame>> successCallback,
|
||||||
|
HelixFailureCallback failureCallback) = 0;
|
||||||
|
|
||||||
|
// https://dev.twitch.tv/docs/api/reference#search-categories
|
||||||
|
virtual void searchGames(
|
||||||
|
QString gameName,
|
||||||
|
ResultCallback<std::vector<HelixGame>> successCallback,
|
||||||
|
HelixFailureCallback failureCallback) = 0;
|
||||||
|
|
||||||
|
virtual void getGameById(QString gameId,
|
||||||
|
ResultCallback<HelixGame> successCallback,
|
||||||
|
HelixFailureCallback failureCallback) = 0;
|
||||||
|
|
||||||
|
// https://dev.twitch.tv/docs/api/reference#create-clip
|
||||||
|
virtual void createClip(QString channelId,
|
||||||
|
ResultCallback<HelixClip> successCallback,
|
||||||
|
std::function<void(HelixClipError)> failureCallback,
|
||||||
|
std::function<void()> finallyCallback) = 0;
|
||||||
|
|
||||||
|
// https://dev.twitch.tv/docs/api/reference#get-channel-information
|
||||||
|
virtual void getChannel(QString broadcasterId,
|
||||||
|
ResultCallback<HelixChannel> successCallback,
|
||||||
|
HelixFailureCallback failureCallback) = 0;
|
||||||
|
|
||||||
|
// https://dev.twitch.tv/docs/api/reference/#create-stream-marker
|
||||||
|
virtual void createStreamMarker(
|
||||||
|
QString broadcasterId, QString description,
|
||||||
|
ResultCallback<HelixStreamMarker> successCallback,
|
||||||
|
std::function<void(HelixStreamMarkerError)> failureCallback) = 0;
|
||||||
|
|
||||||
|
// https://dev.twitch.tv/docs/api/reference#get-user-block-list
|
||||||
|
virtual void loadBlocks(
|
||||||
|
QString userId, ResultCallback<std::vector<HelixBlock>> successCallback,
|
||||||
|
HelixFailureCallback failureCallback) = 0;
|
||||||
|
|
||||||
|
// https://dev.twitch.tv/docs/api/reference#block-user
|
||||||
|
virtual void blockUser(QString targetUserId,
|
||||||
|
std::function<void()> successCallback,
|
||||||
|
HelixFailureCallback failureCallback) = 0;
|
||||||
|
|
||||||
|
// https://dev.twitch.tv/docs/api/reference#unblock-user
|
||||||
|
virtual void unblockUser(QString targetUserId,
|
||||||
|
std::function<void()> successCallback,
|
||||||
|
HelixFailureCallback failureCallback) = 0;
|
||||||
|
|
||||||
|
// https://dev.twitch.tv/docs/api/reference#modify-channel-information
|
||||||
|
virtual void updateChannel(
|
||||||
|
QString broadcasterId, QString gameId, QString language, QString title,
|
||||||
|
std::function<void(NetworkResult)> successCallback,
|
||||||
|
HelixFailureCallback failureCallback) = 0;
|
||||||
|
|
||||||
|
// https://dev.twitch.tv/docs/api/reference#manage-held-automod-messages
|
||||||
|
virtual void manageAutoModMessages(
|
||||||
|
QString userID, QString msgID, QString action,
|
||||||
|
std::function<void()> successCallback,
|
||||||
|
std::function<void(HelixAutoModMessageError)> failureCallback) = 0;
|
||||||
|
|
||||||
|
// https://dev.twitch.tv/docs/api/reference/#get-cheermotes
|
||||||
|
virtual void getCheermotes(
|
||||||
|
QString broadcasterId,
|
||||||
|
ResultCallback<std::vector<HelixCheermoteSet>> successCallback,
|
||||||
|
HelixFailureCallback failureCallback) = 0;
|
||||||
|
|
||||||
|
// https://dev.twitch.tv/docs/api/reference#get-emote-sets
|
||||||
|
virtual void getEmoteSetData(
|
||||||
|
QString emoteSetId, ResultCallback<HelixEmoteSetData> successCallback,
|
||||||
|
HelixFailureCallback failureCallback) = 0;
|
||||||
|
|
||||||
|
// https://dev.twitch.tv/docs/api/reference#get-channel-emotes
|
||||||
|
virtual void getChannelEmotes(
|
||||||
|
QString broadcasterId,
|
||||||
|
ResultCallback<std::vector<HelixChannelEmote>> successCallback,
|
||||||
|
HelixFailureCallback failureCallback) = 0;
|
||||||
|
|
||||||
|
virtual void update(QString clientId, QString oauthToken) = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
class Helix final : public IHelix
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
// https://dev.twitch.tv/docs/api/reference#get-users
|
// https://dev.twitch.tv/docs/api/reference#get-users
|
||||||
void fetchUsers(QStringList userIds, QStringList userLogins,
|
void fetchUsers(QStringList userIds, QStringList userLogins,
|
||||||
ResultCallback<std::vector<HelixUser>> successCallback,
|
ResultCallback<std::vector<HelixUser>> successCallback,
|
||||||
HelixFailureCallback failureCallback);
|
HelixFailureCallback failureCallback) final;
|
||||||
void getUserByName(QString userName,
|
void getUserByName(QString userName,
|
||||||
ResultCallback<HelixUser> successCallback,
|
ResultCallback<HelixUser> successCallback,
|
||||||
HelixFailureCallback failureCallback);
|
HelixFailureCallback failureCallback) final;
|
||||||
void getUserById(QString userId, ResultCallback<HelixUser> successCallback,
|
void getUserById(QString userId, ResultCallback<HelixUser> successCallback,
|
||||||
HelixFailureCallback failureCallback);
|
HelixFailureCallback failureCallback) final;
|
||||||
|
|
||||||
// https://dev.twitch.tv/docs/api/reference#get-users-follows
|
// https://dev.twitch.tv/docs/api/reference#get-users-follows
|
||||||
void fetchUsersFollows(
|
void fetchUsersFollows(
|
||||||
QString fromId, QString toId,
|
QString fromId, QString toId,
|
||||||
ResultCallback<HelixUsersFollowsResponse> successCallback,
|
ResultCallback<HelixUsersFollowsResponse> successCallback,
|
||||||
HelixFailureCallback failureCallback);
|
HelixFailureCallback failureCallback) final;
|
||||||
|
|
||||||
void getUserFollowers(
|
void getUserFollowers(
|
||||||
QString userId,
|
QString userId,
|
||||||
ResultCallback<HelixUsersFollowsResponse> successCallback,
|
ResultCallback<HelixUsersFollowsResponse> successCallback,
|
||||||
HelixFailureCallback failureCallback);
|
HelixFailureCallback failureCallback) final;
|
||||||
|
|
||||||
// https://dev.twitch.tv/docs/api/reference#get-streams
|
// https://dev.twitch.tv/docs/api/reference#get-streams
|
||||||
void fetchStreams(QStringList userIds, QStringList userLogins,
|
void fetchStreams(QStringList userIds, QStringList userLogins,
|
||||||
ResultCallback<std::vector<HelixStream>> successCallback,
|
ResultCallback<std::vector<HelixStream>> successCallback,
|
||||||
HelixFailureCallback failureCallback);
|
HelixFailureCallback failureCallback) final;
|
||||||
|
|
||||||
void getStreamById(QString userId,
|
void getStreamById(QString userId,
|
||||||
ResultCallback<bool, HelixStream> successCallback,
|
ResultCallback<bool, HelixStream> successCallback,
|
||||||
HelixFailureCallback failureCallback);
|
HelixFailureCallback failureCallback) final;
|
||||||
|
|
||||||
void getStreamByName(QString userName,
|
void getStreamByName(QString userName,
|
||||||
ResultCallback<bool, HelixStream> successCallback,
|
ResultCallback<bool, HelixStream> successCallback,
|
||||||
HelixFailureCallback failureCallback);
|
HelixFailureCallback failureCallback) final;
|
||||||
|
|
||||||
// https://dev.twitch.tv/docs/api/reference#get-games
|
// https://dev.twitch.tv/docs/api/reference#get-games
|
||||||
void fetchGames(QStringList gameIds, QStringList gameNames,
|
void fetchGames(QStringList gameIds, QStringList gameNames,
|
||||||
ResultCallback<std::vector<HelixGame>> successCallback,
|
ResultCallback<std::vector<HelixGame>> successCallback,
|
||||||
HelixFailureCallback failureCallback);
|
HelixFailureCallback failureCallback) final;
|
||||||
|
|
||||||
// https://dev.twitch.tv/docs/api/reference#search-categories
|
// https://dev.twitch.tv/docs/api/reference#search-categories
|
||||||
void searchGames(QString gameName,
|
void searchGames(QString gameName,
|
||||||
ResultCallback<std::vector<HelixGame>> successCallback,
|
ResultCallback<std::vector<HelixGame>> successCallback,
|
||||||
HelixFailureCallback failureCallback);
|
HelixFailureCallback failureCallback) final;
|
||||||
|
|
||||||
void getGameById(QString gameId, ResultCallback<HelixGame> successCallback,
|
void getGameById(QString gameId, ResultCallback<HelixGame> successCallback,
|
||||||
HelixFailureCallback failureCallback);
|
HelixFailureCallback failureCallback) final;
|
||||||
|
|
||||||
// https://dev.twitch.tv/docs/api/reference#create-clip
|
// https://dev.twitch.tv/docs/api/reference#create-clip
|
||||||
void createClip(QString channelId,
|
void createClip(QString channelId,
|
||||||
ResultCallback<HelixClip> successCallback,
|
ResultCallback<HelixClip> successCallback,
|
||||||
std::function<void(HelixClipError)> failureCallback,
|
std::function<void(HelixClipError)> failureCallback,
|
||||||
std::function<void()> finallyCallback);
|
std::function<void()> finallyCallback) final;
|
||||||
|
|
||||||
// https://dev.twitch.tv/docs/api/reference#get-channel-information
|
// https://dev.twitch.tv/docs/api/reference#get-channel-information
|
||||||
void getChannel(QString broadcasterId,
|
void getChannel(QString broadcasterId,
|
||||||
ResultCallback<HelixChannel> successCallback,
|
ResultCallback<HelixChannel> successCallback,
|
||||||
HelixFailureCallback failureCallback);
|
HelixFailureCallback failureCallback) final;
|
||||||
|
|
||||||
// https://dev.twitch.tv/docs/api/reference/#create-stream-marker
|
// https://dev.twitch.tv/docs/api/reference/#create-stream-marker
|
||||||
void createStreamMarker(
|
void createStreamMarker(
|
||||||
QString broadcasterId, QString description,
|
QString broadcasterId, QString description,
|
||||||
ResultCallback<HelixStreamMarker> successCallback,
|
ResultCallback<HelixStreamMarker> successCallback,
|
||||||
std::function<void(HelixStreamMarkerError)> failureCallback);
|
std::function<void(HelixStreamMarkerError)> failureCallback) final;
|
||||||
|
|
||||||
// https://dev.twitch.tv/docs/api/reference#get-user-block-list
|
// https://dev.twitch.tv/docs/api/reference#get-user-block-list
|
||||||
void loadBlocks(QString userId,
|
void loadBlocks(QString userId,
|
||||||
ResultCallback<std::vector<HelixBlock>> successCallback,
|
ResultCallback<std::vector<HelixBlock>> successCallback,
|
||||||
HelixFailureCallback failureCallback);
|
HelixFailureCallback failureCallback) final;
|
||||||
|
|
||||||
// https://dev.twitch.tv/docs/api/reference#block-user
|
// https://dev.twitch.tv/docs/api/reference#block-user
|
||||||
void blockUser(QString targetUserId, std::function<void()> successCallback,
|
void blockUser(QString targetUserId, std::function<void()> successCallback,
|
||||||
HelixFailureCallback failureCallback);
|
HelixFailureCallback failureCallback) final;
|
||||||
|
|
||||||
// https://dev.twitch.tv/docs/api/reference#unblock-user
|
// https://dev.twitch.tv/docs/api/reference#unblock-user
|
||||||
void unblockUser(QString targetUserId,
|
void unblockUser(QString targetUserId,
|
||||||
std::function<void()> successCallback,
|
std::function<void()> successCallback,
|
||||||
HelixFailureCallback failureCallback);
|
HelixFailureCallback failureCallback) final;
|
||||||
|
|
||||||
// https://dev.twitch.tv/docs/api/reference#modify-channel-information
|
// https://dev.twitch.tv/docs/api/reference#modify-channel-information
|
||||||
void updateChannel(QString broadcasterId, QString gameId, QString language,
|
void updateChannel(QString broadcasterId, QString gameId, QString language,
|
||||||
QString title,
|
QString title,
|
||||||
std::function<void(NetworkResult)> successCallback,
|
std::function<void(NetworkResult)> successCallback,
|
||||||
HelixFailureCallback failureCallback);
|
HelixFailureCallback failureCallback) final;
|
||||||
|
|
||||||
// https://dev.twitch.tv/docs/api/reference#manage-held-automod-messages
|
// https://dev.twitch.tv/docs/api/reference#manage-held-automod-messages
|
||||||
void manageAutoModMessages(
|
void manageAutoModMessages(
|
||||||
QString userID, QString msgID, QString action,
|
QString userID, QString msgID, QString action,
|
||||||
std::function<void()> successCallback,
|
std::function<void()> successCallback,
|
||||||
std::function<void(HelixAutoModMessageError)> failureCallback);
|
std::function<void(HelixAutoModMessageError)> failureCallback) final;
|
||||||
|
|
||||||
// https://dev.twitch.tv/docs/api/reference/#get-cheermotes
|
// https://dev.twitch.tv/docs/api/reference/#get-cheermotes
|
||||||
void getCheermotes(
|
void getCheermotes(
|
||||||
QString broadcasterId,
|
QString broadcasterId,
|
||||||
ResultCallback<std::vector<HelixCheermoteSet>> successCallback,
|
ResultCallback<std::vector<HelixCheermoteSet>> successCallback,
|
||||||
HelixFailureCallback failureCallback);
|
HelixFailureCallback failureCallback) final;
|
||||||
|
|
||||||
// https://dev.twitch.tv/docs/api/reference#get-emote-sets
|
// https://dev.twitch.tv/docs/api/reference#get-emote-sets
|
||||||
void getEmoteSetData(QString emoteSetId,
|
void getEmoteSetData(QString emoteSetId,
|
||||||
ResultCallback<HelixEmoteSetData> successCallback,
|
ResultCallback<HelixEmoteSetData> successCallback,
|
||||||
HelixFailureCallback failureCallback);
|
HelixFailureCallback failureCallback) final;
|
||||||
|
|
||||||
// https://dev.twitch.tv/docs/api/reference#get-channel-emotes
|
// https://dev.twitch.tv/docs/api/reference#get-channel-emotes
|
||||||
void getChannelEmotes(
|
void getChannelEmotes(
|
||||||
QString broadcasterId,
|
QString broadcasterId,
|
||||||
ResultCallback<std::vector<HelixChannelEmote>> successCallback,
|
ResultCallback<std::vector<HelixChannelEmote>> successCallback,
|
||||||
HelixFailureCallback failureCallback);
|
HelixFailureCallback failureCallback) final;
|
||||||
|
|
||||||
void update(QString clientId, QString oauthToken);
|
void update(QString clientId, QString oauthToken) final;
|
||||||
|
|
||||||
static void initialize();
|
static void initialize();
|
||||||
|
|
||||||
|
@ -444,6 +563,10 @@ private:
|
||||||
QString oauthToken;
|
QString oauthToken;
|
||||||
};
|
};
|
||||||
|
|
||||||
Helix *getHelix();
|
// initializeHelix sets the helix instance to _instance
|
||||||
|
// from a normal application, this should never be called, and will instead be handled by calling Helix::initialize()
|
||||||
|
void initializeHelix(IHelix *_instance);
|
||||||
|
|
||||||
|
IHelix *getHelix();
|
||||||
|
|
||||||
} // namespace chatterino
|
} // namespace chatterino
|
||||||
|
|
Loading…
Reference in a new issue