TwitchREST.h 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #pragma once
  9. #include "ITwitchREST.h"
  10. namespace Twitch
  11. {
  12. class TwitchREST : public ITwitchREST
  13. {
  14. private:
  15. using GetChannelCallback = AZStd::function<void(const ChannelInfo&, const ReceiptID&, ResultCode)>;
  16. public:
  17. TwitchREST();
  18. virtual ~TwitchREST() {}
  19. void FlushEvents() override;
  20. void GetUser(ReceiptID& receipt) override;
  21. void ResetFriendsNotificationCount(const ReceiptID& receipt, const AZStd::string& friendID) override;
  22. void GetFriendNotificationCount(const ReceiptID& receipt, const AZStd::string& friendID) override;
  23. void GetFriendRecommendations(const ReceiptID& receipt, const AZStd::string& friendID) override;
  24. void GetFriends(const ReceiptID& receipt, const AZStd::string& friendID, const AZStd::string& cursor) override;
  25. void GetFriendStatus(const ReceiptID& receipt, const AZStd::string& sourceFriendID, const AZStd::string& targetFriendID) override;
  26. void AcceptFriendRequest(const ReceiptID& receipt, const AZStd::string& friendID) override;
  27. void GetFriendRequests(const ReceiptID& receipt, const AZStd::string& cursor) override;
  28. void CreateFriendRequest(const ReceiptID& receipt, const AZStd::string& friendID) override;
  29. void DeclineFriendRequest(const ReceiptID& receipt, const AZStd::string& friendID) override;
  30. void UpdatePresenceStatus(const ReceiptID& receipt, PresenceAvailability availability, PresenceActivityType activityType, const AZStd::string& gameContext) override;
  31. void GetPresenceStatusofFriends(const ReceiptID& receipt) override;
  32. void GetPresenceSettings(const ReceiptID& receipt) override;
  33. void UpdatePresenceSettings(const ReceiptID& receipt, bool isInvisible, bool shareActivity) override;
  34. void GetChannel(const ReceiptID& receipt) override;
  35. void GetChannelbyID(const ReceiptID& receipt, const AZStd::string& channelID) override;
  36. void UpdateChannel(const ReceiptID& receipt, const ChannelUpdateInfo& channelUpdateInfo) override;
  37. void GetChannelEditors(ReceiptID& receipt, const AZStd::string& channelID) override;
  38. void GetChannelFollowers(ReceiptID& receipt, const AZStd::string& channelID, const AZStd::string& cursor, AZ::u64 offset) override;
  39. void GetChannelTeams(ReceiptID& receipt, const AZStd::string& channelID) override;
  40. void GetChannelSubscribers(ReceiptID& receipt, const AZStd::string& channelID, AZ::u64 offset) override;
  41. void CheckChannelSubscriptionbyUser(ReceiptID& receipt, const AZStd::string& channelID, const AZStd::string& userID) override;
  42. void GetChannelVideos(ReceiptID& receipt, const AZStd::string& channelID, BroadCastType boradcastType, const AZStd::string& language, AZ::u64 offset) override;
  43. void StartChannelCommercial(ReceiptID& receipt, const AZStd::string& channelID, CommercialLength length) override;
  44. void ResetChannelStreamKey(ReceiptID& receipt, const AZStd::string& channelID) override;
  45. bool IsValidGameContext(const AZStd::string& gameContext) const override;
  46. void AddHTTPRequest(const AZStd::string& URI, Aws::Http::HttpMethod method, const HttpRequestor::Headers & headers, const HttpRequestor::Callback & callback) override;
  47. void AddHTTPRequest(const AZStd::string& URI, Aws::Http::HttpMethod method, const HttpRequestor::Headers & headers, const AZStd::string& body, const HttpRequestor::Callback& callback) override;
  48. private:
  49. void InternalGetChannel(const ReceiptID& receipt, const GetChannelCallback& callback);
  50. AZStd::string BuildBaseURL(const AZStd::string& family, const AZStd::string& friendID = "") const;
  51. AZStd::string BuildKrakenURL(const AZStd::string& family) const;
  52. HttpRequestor::Headers GetDefaultHeaders();
  53. HttpRequestor::Headers GetClientIDHeader();
  54. void AddOAuthtHeader(HttpRequestor::Headers& headers);
  55. void AddClientIDHeader(HttpRequestor::Headers& headers);
  56. void AddAcceptToHeader(HttpRequestor::Headers& headers);
  57. void AddToHeader(HttpRequestor::Headers& headers, const AZStd::string& name, const AZStd::string& key) const;
  58. void AddToHeader(HttpRequestor::Headers& headers, const AZStd::string& name, AZ::s64 key) const;
  59. void AddToHeader(HttpRequestor::Headers& headers, const AZStd::string& name, AZ::u64 key) const;
  60. AZ::u64 SafeGetUserInfoFromUserContainer(UserInfo& userInfo, const Aws::Utils::Json::JsonView& jsonInfo) const;
  61. AZ::u64 SafeGetUserInfo(UserInfo& userInfo, const Aws::Utils::Json::JsonView& jsonInfo) const;
  62. bool SafeGetJSONString(AZStd::string& value, const char*key, const Aws::Utils::Json::JsonView& json) const;
  63. bool SafeGetJSONu64(AZ::u64& value, const char*key, const Aws::Utils::Json::JsonView& json) const;
  64. bool SafeGetJSONs64(AZ::s64& value, const char*key, const Aws::Utils::Json::JsonView& json) const;
  65. bool SafeGetJSONbool(bool& value, const char*key, const Aws::Utils::Json::JsonView& json) const;
  66. bool SafeGetJSONdouble(double& value, const char*key, const Aws::Utils::Json::JsonView& json) const;
  67. AZ::u64 SafeGetUserNotifications(UserNotifications& iserNotifications, const Aws::Utils::Json::JsonView& json) const;
  68. bool SafeGetPresenceActivityType(PresenceActivityType& activityType, const Aws::Utils::Json::JsonView& json) const;
  69. bool SafeGetPresenceAvailability(PresenceAvailability& availability, const Aws::Utils::Json::JsonView& json) const;
  70. AZ::u64 SafeGetChannelInfo(ChannelInfo& channelInfo, const Aws::Utils::Json::JsonView& json) const;
  71. AZ::u64 SafeGetTeamInfo(TeamInfo& teamInfo, const Aws::Utils::Json::JsonView& json) const;
  72. bool SafeGetJSONBroadCastType(BroadCastType& type, const char*key, const Aws::Utils::Json::JsonView& json) const;
  73. bool SafeGetJSONVideoChannel(VideoChannelInfo& channelInfo, const Aws::Utils::Json::JsonView& json) const;
  74. bool SafeGetJSONVideoFPS(FPSInfo& fps, const Aws::Utils::Json::JsonView& json) const;
  75. bool SafeGetJSONVideoPreview(PreviewInfo& preview, const Aws::Utils::Json::JsonView& json) const;
  76. bool SafeGetJSONVideoResolutions(ResolutionsInfo& resolutions, const Aws::Utils::Json::JsonView& json) const;
  77. bool SafeGetJSONVideoThumbnailInfo(ThumbnailInfo& info, const char *key, const Aws::Utils::Json::JsonView& json) const;
  78. bool SafeGetJSONVideoThumbnails(ThumbnailsInfo& thumbnails, const Aws::Utils::Json::JsonView& json) const;
  79. bool SafeGetChannelCommunityInfo(CommunityInfo & info, const Aws::Utils::Json::JsonView& json) const;
  80. AZStd::string GetPresenceAvailabilityName(PresenceAvailability availability) const;
  81. AZStd::string GetPresenceActivityTypeName(PresenceActivityType activityType) const;
  82. PresenceAvailability GetPresenceAvailability(const AZStd::string& name) const;
  83. PresenceActivityType GetPresenceActivityType(const AZStd::string& name) const;
  84. AZStd::string GetBroadCastTypeNameFromType(BroadCastType type) const;
  85. BroadCastType GetBroadCastTypeFromName(const AZStd::string& name) const;
  86. AZ::u64 GetComercialLength(CommercialLength lenght) const;
  87. private:
  88. static const char * kProtocol; // protocol to use, typically https
  89. static const char * kBasePath; // base path for the Twitch API
  90. static const char * kVer; // version for the Twitch API
  91. static const char * kKraken; // the name for the kraken api
  92. static const char * kAuthType; // Authorization type
  93. static const char * kAcceptType; // Accept type (and version)
  94. using PresenceAvailabilityMap = AZStd::map<PresenceAvailability, AZStd::string>;
  95. using PresenceActivityTypeNameMap = AZStd::map<PresenceActivityType, AZStd::string>;
  96. private:
  97. PresenceAvailabilityMap m_availabilityMap;
  98. PresenceActivityTypeNameMap m_activityTypeMap;
  99. };
  100. }