Example #1
0
        /// <summary>
        /// Sends command to start a commercial of variable length.
        /// </summary>
        /// <param name="length">Enum representing the length of advertisement should be.</param>
        /// <param name="client">Client reference used to identify extension.</param>
        public static void StartCommercial(this TwitchClient client, Enums.CommercialLength length)
        {
            switch (length)
            {
            case Enums.CommercialLength.Seconds30:
                client.SendMessage(".commercial 30");
                break;

            case Enums.CommercialLength.Seconds60:
                client.SendMessage(".commercial 60");
                break;

            case Enums.CommercialLength.Seconds90:
                client.SendMessage(".commercial 90");
                break;

            case Enums.CommercialLength.Seconds120:
                client.SendMessage(".commercial 120");
                break;

            case Enums.CommercialLength.Seconds150:
                client.SendMessage(".commercial 150");
                break;

            case Enums.CommercialLength.Seconds180:
                client.SendMessage(".commercial 180");
                break;
            }
        }
Example #2
0
        /// <summary>
        /// Sends command to start a commercial of variable length.
        /// </summary>
        /// <param name="length">Enum representing the length of advertisement should be.</param>
        /// <param name="client">Client reference used to identify extension.</param>
        public static void StartCommercial(this TwitchClient client, Enums.CommercialLength length)
        {
            switch (length)
            {
            case Enums.CommercialLength.Seconds30:
                client.SendMessage(".commercial 30");
                break;

            case Enums.CommercialLength.Seconds60:
                client.SendMessage(".commercial 60");
                break;

            case Enums.CommercialLength.Seconds90:
                client.SendMessage(".commercial 90");
                break;

            case Enums.CommercialLength.Seconds120:
                client.SendMessage(".commercial 120");
                break;

            case Enums.CommercialLength.Seconds150:
                client.SendMessage(".commercial 150");
                break;

            case Enums.CommercialLength.Seconds180:
                client.SendMessage(".commercial 180");
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(length), length, null);
            }
        }
Example #3
0
            public async static Task RunCommercialAsync(string channel, Enums.CommercialLength length, string accessToken = null)
            {
                Shared.DynamicScopeValidation(Enums.AuthScopes.Channel_Commercial, accessToken);
                int lengthInt = 30;

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

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

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

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

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

                case Enums.CommercialLength.Seconds180:
                    lengthInt = 180;
                    break;
                }

                var model = new Models.API.v3.Channels.RunCommercialRequest()
                {
                    Length = lengthInt
                };

                await Requests.PostModelAsync($"https://api.twitch.tv/kraken/channels/{channel}/commercial", model, accessToken, Requests.API.v3);
            }
Example #4
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));
        }
Example #5
0
 public async Task <Models.API.v5.Channels.ChannelCommercial> StartChannelCommercialAsync(string channelId, Enums.CommercialLength duration, string authToken = null)
 {
     Api.Settings.DynamicScopeValidation(Enums.AuthScopes.Channel_Commercial, authToken);
     if (string.IsNullOrWhiteSpace(channelId))
     {
         throw new Exceptions.API.BadParameterException("The channel id is not valid. It is not allowed to be null, empty or filled with whitespaces.");
     }
     return(await Api.PostGenericAsync <Models.API.v5.Channels.ChannelCommercial>($"https://api.twitch.tv/kraken/channels/{channelId}/commercial", "{\"duration\": " + (int)duration + "}", null, authToken, ApiVersion.v5).ConfigureAwait(false));
 }