Esempio n. 1
0
        internal async static void CreateCommunityCoverImage(string communityId, string base64CoverImage, string accessToken = null)
        {
            JObject json = new JObject();

            json["cover_image"] = base64CoverImage;
            string resp = await Requests.MakeRestRequest($"https://api.twitch.tv/kraken/communities/{communityId}/images/cover", "POST", json.ToString(), accessToken, 5);
        }
Esempio n. 2
0
        internal async static Task <string> CreateCommunityCoverImage(string communityId, Image coverImage, string accessToken = null)
        {
            JObject json = new JObject();

            json["cover_image"] = Common.Helpers.ImageToBase64(coverImage);
            return(await Requests.MakeRestRequest($"https://api.twitch.tv/kraken/communities/{communityId}/images/cover", "POST", json.ToString(), accessToken, 5));
        }
Esempio n. 3
0
        internal async static Task <string> CreateCommunityAvatarImage(string communityId, string base64AvatarImage, string accessToken = null)
        {
            JObject json = new JObject();

            json["avatar_image"] = base64AvatarImage;
            return(await Requests.MakeRestRequest($"https://api.twitch.tv/kraken/communities/{communityId}/images/avatar", "POST", json.ToString(), accessToken, 5));
        }
Esempio n. 4
0
        internal static async Task <Models.API.Channel.Channel> UpdateStreamTitleAndGame(string status, string game, string channel,
                                                                                         string accessToken = null)
        {
            var data = "{\"channel\":{\"status\":\"" + status + "\",\"game\":\"" + game + "\"}}";

            return(new Models.API.Channel.Channel(JObject.Parse(await Requests.MakeRestRequest($"https://api.twitch.tv/kraken/channels/{channel}", "PUT", data, accessToken))));
        }
Esempio n. 5
0
        internal async static void CreateCommunityAvatarImage(string communityId, Image avatarImage, string accessToken = null)
        {
            JObject json = new JObject();

            json["avatar_image"] = Common.Helpers.ImageToBase64(avatarImage);
            string resp = await Requests.MakeRestRequest($"https://api.twitch.tv/kraken/communities/{communityId}/images/avatar", "POST", json.ToString(), accessToken, 5);
        }
Esempio n. 6
0
        // TODO: Untested
        internal static async void UploadVideo(string vidId, string uploadToken, string fileName, string accessToken = null)
        {
            long maxUploadSize = 10737418240; // 10GBs
            long chunkSize     = 10485760;    // 10MBs

            // Check if file exists
            if (!File.Exists(fileName))
            {
                throw new Exceptions.API.UploadVideo.UploadVideoPart.BadPartException("File doesn't appear to exist!");
            }

            // Check if file abides by Twitch's size rule (between 5mb and 25mb)
            FileInfo info = new FileInfo(fileName);

            if (info.Length > maxUploadSize)
            {
                throw new Exceptions.API.UploadVideo.UploadVideoPart.BadPartException("File is larger than 10GBs. Twitch does not allow files this large.");
            }

            // read and upload chunks
            using (var file = File.OpenRead(fileName))
            {
                int bytes;
                var buffer = new byte[chunkSize];
                int i      = 1;
                while ((bytes = file.Read(buffer, 0, buffer.Length)) > 0)
                {
                    await Requests.MakeRestRequest($"https://uploads.twitch.tv/upload/{vidId}?index={i}&upload_token={uploadToken}", "POST", null, accessToken, 4, buffer);

                    i++;
                }
            }
        }
Esempio n. 7
0
        internal static async Task <Models.API.Clip.ClipsResponse> GetFollowedClips(string cursor = "0", int limit = 10, bool trending = false, string accessToken = null)
        {
            string cursorStr   = $"cursor={cursor}";
            string limitStr    = $"limit={limit}";
            string trendingStr = $"trending={trending.ToString().ToLower()}";
            string url         = $"https://api.twitch.tv/kraken/clips/followed?{cursorStr}&{limitStr}&{trendingStr}";

            return(new Models.API.Clip.ClipsResponse(JObject.Parse(await Requests.MakeRestRequest(url, "POST", null, accessToken, 4))));
        }
Esempio n. 8
0
        // TODO: 404ing
        internal static async Task <Models.API.Video.UploadVideo.CreateVideoResponse> CreateVideo(string channel, string title, string accessToken = "")
        {
            JObject data = new JObject();

            data.Add("channel_name", channel);
            data.Add("title", title);

            var resp = await Requests.MakeRestRequest("https://api.twitch.tv/kraken/videos", "POST", data.ToString(), accessToken, 4);

            return(new Models.API.Video.UploadVideo.CreateVideoResponse(JObject.Parse(resp)));
        }
Esempio n. 9
0
        internal async static void TimeoutCommunityUser(string communityId, string userId, int durationInHours, string reason = null, string accessToken = null)
        {
            JObject json = new JObject();

            json["duration"] = durationInHours;
            if (reason != null)
            {
                json["reason"] = reason;
            }
            string resp = await Requests.MakeRestRequest($"https://api.twitch.tv/kraken/communities/{communityId}/timeouts/{userId}", "PUT", json.ToString(), accessToken, 5);
        }
Esempio n. 10
0
        internal async static Task <string> CreateCommunity(string name, string summary, string description, string rules, string accessToken = null)
        {
            if (name.Length < 3 || name.Length > 25)
            {
                throw new BadParameterException("Name parameter must be between 3 and 25 characters of length.");
            }
            if (name.Contains(" "))
            {
                throw new BadParameterException("Name parameter cannot contain space characters.");
            }
            if (summary.Length > 160)
            {
                throw new BadParameterException("Summary parameter must be 160 or less characters of length.");
            }
            if (description.Length > 1572864)
            {
                throw new BadParameterException("Description must be 1,572,864 characters or less of length.");
            }
            if (rules.Length > 1572864)
            {
                throw new BadParameterException("Rules must be 1,572,864 characters or less of length.");
            }

            JObject jsonObj = new JObject();

            jsonObj["name"]        = name;
            jsonObj["summary"]     = summary;
            jsonObj["description"] = description;
            jsonObj["rules"]       = rules;

            string response = (await Requests.MakeRestRequest("https://api.twitch.tv/kraken/communities", "POST", jsonObj.ToString(), accessToken, 5));

            var    json = JObject.Parse(response);
            JToken id;

            if (json.TryGetValue("_id", out id))
            {
                return(id.ToString());
            }
            else
            {
                return(null);
            }
        }
Esempio n. 11
0
        internal async static void UpdateCommunity(string communityId, string summary = null, string description = null, string rules = null, string email = null, string accessToken = null)
        {
            if (summary != null && summary.Length > 160)
            {
                throw new BadParameterException("Summary parameter must be 160 or less characters of length.");
            }
            if (description != null && description.Length > 1572864)
            {
                throw new BadParameterException("Description must be 1,572,864 characters or less of length.");
            }
            if (rules != null && rules.Length > 1572864)
            {
                throw new BadParameterException("Rules must be 1,572,864 characters or less of length.");
            }

            JObject json = new JObject();

            if (summary != null)
            {
                json["summary"] = summary;
            }
            if (description != null)
            {
                json["description"] = description;
            }
            if (rules != null)
            {
                json["rules"] = rules;
            }
            if (email != null)
            {
                json["email"] = email;
            }

            string response = (await Requests.MakeRestRequest($"https://api.twitch.tv/kraken/communities/{communityId}", "PUT", json.ToString(), accessToken, 5));
        }
Esempio n. 12
0
        internal static async Task <string> RunCommercial(Enums.CommercialLength length, string channel,
                                                          string accessToken = null)
        {
            // Default to 30 seconds?
            int seconds = 30;

            switch (length)
            {
            case Enums.CommercialLength.Seconds30:
                seconds = 30;
                break;

            case Enums.CommercialLength.Seconds60:
                seconds = 60;
                break;

            case Enums.CommercialLength.Seconds90:
                seconds = 90;
                break;

            case Enums.CommercialLength.Seconds120:
                seconds = 120;
                break;

            case Enums.CommercialLength.Seconds150:
                seconds = 150;
                break;

            case Enums.CommercialLength.Seconds180:
                seconds = 180;
                break;
            }
            return(await
                   Requests.MakeRestRequest($"https://api.twitch.tv/kraken/channels/{channel}/commercial", "POST",
                                            $"length={seconds}", accessToken));
        }
Esempio n. 13
0
 internal async static void BanCommunityUser(string communityId, string userId, string accessToken = null)
 {
     string resp = await Requests.MakeRestRequest($"https://api.twitch.tv/kraken/communities/{communityId}/bans/{userId}", "PUT", null, accessToken, 5);
 }
Esempio n. 14
0
 internal static async Task <string> ResetStreamKey(string channel, string accessToken = null)
 {
     return(await
            Requests.MakeRestRequest($"https://api.twitch.tv/kraken/channels/{channel}/streamkey", "DELETE", "", accessToken));
 }
Esempio n. 15
0
 internal async static void RemoveCommunityAvatarImage(string communityId, string accessToken = null)
 {
     string resp = await Requests.MakeRestRequest($"https://api.twitch.tv/kraken/communities/{communityId}/images/avatar", "DELETE", null, accessToken, 5);
 }
Esempio n. 16
0
 internal async static void RemoveChannelCommunity(string channelId, string accessToken = null)
 {
     string resp = await Requests.MakeRestRequest($"https://api.twitch.tv/kraken/channels/{channelId}/community", "DELETE", null, accessToken, 5);
 }
Esempio n. 17
0
 internal async static Task <string> AddCommunityModerator(string communityId, string userId, string accessToken = null)
 {
     return(await Requests.MakeRestRequest($"https://api.twitch.tv/kraken/communities/{communityId}/moderators/{userId}", "PUT", null, accessToken, 5));
 }
Esempio n. 18
0
 internal async static Task <string> RemoveCommunityCoverImage(string communityId, string accessToken = null)
 {
     return(await Requests.MakeRestRequest($"https://api.twitch.tv/kraken/communities/{communityId}/images/cover", "DELETE", null, accessToken, 5));
 }
Esempio n. 19
0
 internal static async void UnfollowChannel(string username, string channel, string accessToken = null)
 {
     await Requests.MakeRestRequest($"https://api.twitch.tv/kraken/users/{username}/follows/channels/{channel}", "DELETE", "", accessToken);
 }
Esempio n. 20
0
 internal static async Task <Models.API.Follow.Follow> FollowChannel(string username, string channel, string accessToken = null)
 {
     return(new Models.API.Follow.Follow(await Requests.MakeRestRequest($"https://api.twitch.tv/kraken/users/{username}/follows/channels/{channel}", "PUT", "", accessToken)));
 }
Esempio n. 21
0
 internal static async void UnblockUser(string username, string blockedUsername, string accessToken = null)
 {
     await Requests.MakeRestRequest($"https://api.twitch.tv/kraken/users/{username}/blocks/{blockedUsername}", "DELETE", "", accessToken);
 }
Esempio n. 22
0
 internal static async Task <Models.API.Block.Block> BlockUser(string username, string blockedUsername, string accessToken = null)
 {
     return(new Models.API.Block.Block(JObject.Parse(await Requests.MakeRestRequest($"https://api.twitch.tv/kraken/users/{username}/blocks/{blockedUsername}", "PUT", "", accessToken))));
 }
Esempio n. 23
0
        internal static async Task <string> UpdateStreamDelay(int delay, string channel, string accessToken = null)
        {
            var data = "{\"channel\":{\"delay\":" + delay + "}}";

            return(await Requests.MakeRestRequest($"https://api.twitch.tv/kraken/channels/{channel}", "PUT", data, accessToken));
        }
Esempio n. 24
0
 internal async static void UnTimeoutCommunityUser(string communityId, string userId, string accessToken = null)
 {
     string resp = await Requests.MakeRestRequest($"https://api.twitch.tv/kraken/communities/{communityId}/timeouts/{userId}", "DELETE", null, accessToken, 5);
 }
Esempio n. 25
0
 internal async static void RemoveCommunityModerator(string communityId, string userId, string accessToken = null)
 {
     string resp = await Requests.MakeRestRequest($"https://api.twitch.tv/kraken/communities/{communityId}/moderators/{userId}", "DELETE", null, accessToken, 5);
 }
Esempio n. 26
0
 //TODO: Untested
 internal static async void CompleteVideoUpload(string videoId, string uploadToken, string accessToken = null)
 {
     await Requests.MakeRestRequest($"https://uploads.twitch.tv/upload/{videoId}/complete", "POST", $"upload_token={uploadToken}", accessToken, 4);
 }
Esempio n. 27
0
 internal async static Task <string> SetChannelCommunity(string channelId, string communityId, string accessToken = null)
 {
     return(await Requests.MakeRestRequest($"https://api.twitch.tv/kraken/channels/{channelId}/community/{communityId}", "PUT", null, accessToken, 5));
 }
Esempio n. 28
0
 internal static async Task <Models.API.Feed.PostToChannelFeedResponse> PostToChannelFeed(string content, bool share, string channel, string accessToken = null)
 {
     return(new Models.API.Feed.PostToChannelFeedResponse(JObject.Parse(await Requests.MakeRestRequest($"https://api.twitch.tv/kraken/feed/{channel}/posts", "POST", $"content={content}&share={(share ? "true" : "false")}", accessToken))));
 }
Esempio n. 29
0
 internal async static Task <string> UnBanCommunityUser(string communityId, string userId, string accessToken = null)
 {
     return(await Requests.MakeRestRequest($"https://api.twitch.tv/kraken/communities/{communityId}/bans/{userId}", "DELETE", null, accessToken, 5));
 }
Esempio n. 30
0
 internal static async void DeleteChannelFeedPost(string postId, string channel, string accessToken = null)
 {
     await Requests.MakeRestRequest($"https://api.twitch.tv/kraken/feed/{channel}/posts/{postId}", "DELETE", null, accessToken);
 }