Пример #1
0
        /// <summary>
        /// Updates a channel's status. Requires user authorization.
        /// </summary>
        /// <param name="status">The new status</param>
        /// <param name="game">The new game</param>
        /// <returns></returns>
        public async Task <Channel> UpdateChannel(string status, string game)
        {
            if (authorized && authorizedScopes.Contains(TwitchConstants.Scope.ChannelEditor))
            {
                Uri uri;
                uri = new Uri("https://api.twitch.tv/kraken/channels/" + name);
                JObject content = new JObject();
                content["channel"]           = new JObject();
                content["channel"]["status"] = status;
                content["channel"]["game"]   = game;
                string responseString = await Twixel.PutWebData(uri, accessToken, content.ToString());

                if (Twixel.GoodStatusCode(responseString))
                {
                    return(twixel.LoadChannel(JObject.Parse(responseString)));
                }
                else
                {
                    twixel.CreateError(responseString);
                    return(null);
                }
            }
            else
            {
                if (!authorized)
                {
                    twixel.CreateError(name + " is not authorized");
                }
                else if (!authorizedScopes.Contains(TwitchConstants.Scope.ChannelEditor))
                {
                    twixel.CreateError(name + " has not given channel_editor permissions");
                }
                return(null);
            }
        }
Пример #2
0
        /// <summary>
        /// Gets a list of channels this user is following
        /// </summary>
        /// <param name="limit">How many channels to get at one time. Default is 25. Maximum is 100</param>
        /// <returns>A list of channels</returns>
        public async Task <List <Channel> > RetrieveFollowing(int limit)
        {
            Uri uri;

            if (limit <= 100)
            {
                uri = new Uri("https://api.twitch.tv/kraken/users/" + name + "/follows/channels?limit=" + limit.ToString());
            }
            else
            {
                twixel.CreateError("You cannot get more than 100 channels at a time");
                return(null);
            }
            string responseString = await Twixel.GetWebData(uri);

            if (Twixel.GoodStatusCode(responseString))
            {
                nextFollowing = new WebUrl((string)JObject.Parse(responseString)["_links"]["next"]);
                List <Channel> followedChannels = new List <Channel>();
                foreach (JObject o in (JArray)JObject.Parse(responseString)["follows"])
                {
                    followedChannels.Add(twixel.LoadChannel((JObject)o["channel"]));
                }
                return(followedChannels);
            }
            else
            {
                twixel.CreateError(responseString);
                return(null);
            }
        }
Пример #3
0
        /// <summary>
        /// Gets the channel object for this user. Requires user authorization.
        /// </summary>
        /// <returns>A channel object</returns>
        public async Task <Channel> RetrieveChannel()
        {
            if (authorized && authorizedScopes.Contains(TwitchConstants.Scope.ChannelRead))
            {
                Uri uri;
                uri = new Uri("https://api.twitch.tv/kraken/channel");
                string responseString = await Twixel.GetWebData(uri, accessToken);

                if (Twixel.GoodStatusCode(responseString))
                {
                    streamKey = (string)JObject.Parse(responseString)["stream_key"];
                    channel   = twixel.LoadChannel(JObject.Parse(responseString));
                    return(channel);
                }
                else
                {
                    twixel.CreateError(responseString);
                    return(null);
                }
            }
            else
            {
                if (!authorized)
                {
                    twixel.CreateError(name + " is not authorized");
                }
                else if (!authorizedScopes.Contains(TwitchConstants.Scope.ChannelRead))
                {
                    twixel.CreateError(name + " has not given channel_read permissions");
                }
                return(null);
            }
        }
Пример #4
0
        /// <summary>
        /// Gets the list of users that can edit this user's channel. Requires user authorization.
        /// </summary>
        /// <returns>A list of users</returns>
        public async Task <List <User> > RetrieveChannelEditors()
        {
            if (authorized && authorizedScopes.Contains(TwitchConstants.Scope.ChannelRead))
            {
                Uri uri;
                uri = new Uri("https://api.twitch.tv/kraken/channels/" + name + "/editors");
                string responseString = await Twixel.GetWebData(uri, accessToken);

                if (Twixel.GoodStatusCode(responseString))
                {
                    foreach (JObject o in (JArray)JObject.Parse(responseString)["users"])
                    {
                        if (!ContainsEditor((string)o["name"]))
                        {
                            channelEditors.Add(twixel.LoadUser(o));
                        }
                    }
                    return(channelEditors);
                }
                else
                {
                    twixel.CreateError(responseString);
                    return(null);
                }
            }
            else
            {
                if (!authorized)
                {
                    twixel.CreateError(name + " is not authorized");
                }
                else if (!authorizedScopes.Contains(TwitchConstants.Scope.ChannelRead))
                {
                    twixel.CreateError(name + " has not given channel_read permissions");
                }
                return(null);
            }
        }
Пример #5
0
        /// <summary>
        /// Gets a list of channels this user is following
        /// </summary>
        /// <param name="getNext">If this method was called before then this will get the next page of channels</param>
        /// <returns>A list of channels</returns>
        public async Task <List <Channel> > RetrieveFollowing(bool getNext)
        {
            Uri uri;

            if (!getNext)
            {
                uri = new Uri("https://api.twitch.tv/kraken/users/" + name + "/follows/channels");
            }
            else
            {
                if (nextFollowing != null)
                {
                    uri = nextFollowing.url;
                }
                else
                {
                    uri = new Uri("https://api.twitch.tv/kraken/users/" + name + "/follows/channels");
                }
            }
            string responseString = await Twixel.GetWebData(uri);

            if (Twixel.GoodStatusCode(responseString))
            {
                nextFollowing = new WebUrl((string)JObject.Parse(responseString)["_links"]["next"]);
                List <Channel> followedChannels = new List <Channel>();
                foreach (JObject o in (JArray)JObject.Parse(responseString)["follows"])
                {
                    followedChannels.Add(twixel.LoadChannel((JObject)o["channel"]));
                }
                return(followedChannels);
            }
            else
            {
                twixel.CreateError(responseString);
                return(null);
            }
        }