Exemple #1
0
        /// <summary>
        /// Gets the global configuration data.
        /// </summary>
        /// <param name="clientID">The client ID of the extension</param>
        /// <param name="clientSecret">The client secret of the extension</param>
        /// <param name="ownerID">The owner user ID of the extension</param>
        /// <returns>The global configuration data for the extension</returns>
        public static async Task <ConfigurationModel> GetGlobalConfiguration(string clientID, string clientSecret, string ownerID)
        {
            Validator.ValidateString(clientID, "clientID");
            Validator.ValidateString(clientSecret, "clientSecret");
            Validator.ValidateString(ownerID, "ownerID");

            using (AdvancedHttpClient client = TwitchExtensionService.GetHttpClient(clientID, clientSecret, ownerID, null))
            {
                HttpResponseMessage response = await client.GetAsync($"https://api.twitch.tv/extensions/{clientID}/configurations/segments/global");

                if (response.IsSuccessStatusCode)
                {
                    JObject jobj = await response.ProcessJObjectResponse();

                    if (jobj != null && jobj.Count > 0)
                    {
                        ConfigurationResultModel result = jobj.Values().First().ToObject <ConfigurationResultModel>();
                        if (result != null)
                        {
                            return(new ConfigurationModel(result));
                        }
                    }
                    return(null);
                }
                else
                {
                    return(null);
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Gets the configuration data for the specified channel.
        /// </summary>
        /// <param name="clientID">The client ID of the extension</param>
        /// <param name="clientSecret">The client secret of the extension</param>
        /// <param name="ownerID">The owner user ID of the extension</param>
        /// <param name="channelID">The channel ID to broadcast to</param>
        /// <returns>The channel-specific configuration data for the extension</returns>
        public static async Task <IEnumerable <ChannelConfigurationModel> > GetChannelConfiguration(string clientID, string clientSecret, string ownerID, string channelID)
        {
            Validator.ValidateString(clientID, "clientID");
            Validator.ValidateString(clientSecret, "clientSecret");
            Validator.ValidateString(ownerID, "ownerID");
            Validator.ValidateString(channelID, "channelID");

            using (AdvancedHttpClient client = TwitchExtensionService.GetHttpClient(clientID, clientSecret, ownerID, channelID))
            {
                HttpResponseMessage response = await client.GetAsync($"https://api.twitch.tv/extensions/{clientID}/configurations/segments/broadcaster?channel_id={channelID}");

                if (response.IsSuccessStatusCode)
                {
                    List <ChannelConfigurationModel> results = new List <ChannelConfigurationModel>();
                    JObject jobj = await response.ProcessJObjectResponse();

                    if (jobj != null)
                    {
                        foreach (var kvp in jobj)
                        {
                            ConfigurationResultModel result = kvp.Value.ToObject <ConfigurationResultModel>();
                            if (result != null)
                            {
                                results.Add(new ChannelConfigurationModel(result));
                            }
                        }
                    }
                    return(results);
                }
                else
                {
                    return(new List <ChannelConfigurationModel>());
                }
            }
        }