예제 #1
0
파일: User.cs 프로젝트: mattregul/Twixel
 /// <summary>
 /// Unfollows a channel.
 /// Requires authorization.
 /// Requires user_follows_edit.
 /// </summary>
 /// <param name="channel">The name of the channel</param>
 /// <returns>
 /// Returns true the request succeeded.
 /// Throws an exception if the channel was not being followed.
 /// Throws an exception if the channel could not be unfollowed.
 /// </returns>
 public async Task <bool> UnfollowChannel(string channel)
 {
     TwitchConstants.Scope relevantScope = TwitchConstants.Scope.UserFollowsEdit;
     if (authorized && authorizedScopes.Contains(relevantScope))
     {
         Url    url = new Url(TwitchConstants.baseUrl).AppendPathSegments("users", name, "follows", "channels", channel);
         Uri    uri = new Uri(url.ToString());
         string responseString;
         try
         {
             responseString = await Twixel.DeleteWebData(uri, accessToken, version);
         }
         catch (TwitchException ex)
         {
             if (ex.Status == 404)
             {
                 throw new TwixelException(channel + " was not being followed.", ex);
             }
             else if (ex.Status == 422)
             {
                 throw new TwixelException(channel + " could not be unfollowed. Try again.", ex);
             }
             else
             {
                 throw new TwixelException(TwitchConstants.twitchAPIErrorString, ex);
             }
         }
         if (string.IsNullOrEmpty(responseString))
         {
             return(true);
         }
         else
         {
             throw new TwixelException(TwitchConstants.unknownErrorString);
         }
     }
     else
     {
         if (!authorized)
         {
             throw new TwixelException(NotAuthedError());
         }
         else if (!authorizedScopes.Contains(relevantScope))
         {
             throw new TwixelException(MissingPermissionError(relevantScope));
         }
         else
         {
             throw new TwixelException(TwitchConstants.unknownErrorString);
         }
     }
 }
예제 #2
0
파일: User.cs 프로젝트: mattregul/Twixel
 /// <summary>
 /// Resets this user's stream key.
 /// Updates channel object.
 /// Requires authorization.
 /// Requires channel_stream.
 /// </summary>
 /// <returns>The new stream key</returns>
 public async Task <string> ResetStreamKey()
 {
     TwitchConstants.Scope relevantScope = TwitchConstants.Scope.ChannelStream;
     if (authorized && authorizedScopes.Contains(relevantScope))
     {
         Url    url = new Url(TwitchConstants.baseUrl).AppendPathSegments("channels", name, "stream_key");
         Uri    uri = new Uri(url.ToString());
         string responseString;
         try
         {
             responseString = await Twixel.DeleteWebData(uri, accessToken, version);
         }
         catch (TwitchException ex)
         {
             if (ex.Status == 422)
             {
                 throw new TwixelException("Error resetting stream key.", ex);
             }
             else
             {
                 throw new TwixelException(TwitchConstants.twitchAPIErrorString, ex);
             }
         }
         JObject responseObject = JObject.Parse(responseString);
         channel   = HelperMethods.LoadChannel(responseObject, version);
         streamKey = (string)responseObject["stream_key"];
         return(streamKey);
     }
     else
     {
         if (!authorized)
         {
             throw new TwixelException(NotAuthedError());
         }
         else if (!authorizedScopes.Contains(relevantScope))
         {
             throw new TwixelException(MissingPermissionError(relevantScope));
         }
         else
         {
             throw new TwixelException(TwitchConstants.unknownErrorString);
         }
     }
 }
예제 #3
0
파일: User.cs 프로젝트: Sinfire/Twixel
        /// <summary>
        /// Unblocks a user. Requires user authorization.
        /// </summary>
        /// <param name="username">The name of the user to block</param>
        /// <returns>The current list of blocked users</returns>
        public async Task <List <User> > UnblockUser(string username)
        {
            if (authorized && authorizedScopes.Contains(TwitchConstants.Scope.UserBlocksEdit))
            {
                Uri uri;
                uri = new Uri("https://api.twitch.tv/kraken/users/" + name + "/blocks/" + username);
                string responseString = await Twixel.DeleteWebData(uri, accessToken);

                if (responseString == "")
                {
                    blockedUsers.Remove(GetBlockedUser(username));
                    return(blockedUsers);
                }
                else if (responseString == "404")
                {
                    twixel.CreateError(username + "was never blocked");
                    return(null);
                }
                else if (responseString == "422")
                {
                    twixel.CreateError(username + " could not be unblocked. Try again.");
                    return(null);
                }
                else
                {
                    twixel.CreateError(responseString);
                    return(null);
                }
            }
            else
            {
                if (!authorized)
                {
                    twixel.CreateError(name + " is not authorized");
                }
                else if (!authorizedScopes.Contains(TwitchConstants.Scope.UserBlocksEdit))
                {
                    twixel.CreateError(name + " has not given user_blocks_edit permissions");
                }
                return(null);
            }
        }
예제 #4
0
파일: User.cs 프로젝트: Sinfire/Twixel
        /// <summary>
        /// Unfollows a channel. Requires user authorization.
        /// </summary>
        /// <param name="channel">The name of the channel</param>
        /// <returns>If the request succeeded</returns>
        public async Task <bool> UnfollowChannel(string channel)
        {
            if (authorized && authorizedScopes.Contains(TwitchConstants.Scope.UserFollowsEdit))
            {
                Uri uri;
                uri = new Uri("https://api.twitch.tv/kraken/users/" + name + "/follows/channels/" + channel);
                string responseString = await Twixel.DeleteWebData(uri, accessToken);

                if (responseString == "")
                {
                    return(true);
                }
                else if (responseString == "404")
                {
                    twixel.CreateError(channel + "was not being followed");
                    return(false);
                }
                else if (responseString == "422")
                {
                    twixel.CreateError(channel + " could not be unfollowed. Try again.");
                    return(false);
                }
                else
                {
                    twixel.CreateError(responseString);
                    return(false);
                }
            }
            else
            {
                if (!authorized)
                {
                    twixel.CreateError(name + " is not authorized");
                }
                else if (!authorizedScopes.Contains(TwitchConstants.Scope.UserFollowsEdit))
                {
                    twixel.CreateError(name + " has not given user_follows_edit permissions");
                }
                return(false);
            }
        }
예제 #5
0
파일: User.cs 프로젝트: Sinfire/Twixel
        /// <summary>
        /// Resets this user's stream key. Requires user authorization.
        /// </summary>
        /// <returns>The new stream key</returns>
        public async Task <string> ResetStreamKey()
        {
            if (authorized && authorizedScopes.Contains(TwitchConstants.Scope.ChannelStream))
            {
                Uri uri;
                uri = new Uri("https://api.twitch.tv/kraken/channels/" + name + "/stream_key");
                string responseString = await Twixel.DeleteWebData(uri, accessToken);

                if (responseString != "422")
                {
                    streamKey = (string)JObject.Parse(responseString)["stream_key"];
                    return(streamKey);
                }
                else if (responseString == "422")
                {
                    twixel.CreateError("Error reseting stream key");
                    return(null);
                }
                else
                {
                    twixel.CreateError(responseString);
                    return(null);
                }
            }
            else
            {
                if (!authorized)
                {
                    twixel.CreateError(name + " is not authorized");
                }
                else if (!authorizedScopes.Contains(TwitchConstants.Scope.ChannelStream))
                {
                    twixel.CreateError(name + " has not given channel_stream permissions");
                }
                return(null);
            }
        }