/// <summary> /// Blocks a user /// </summary> /// <param name="twitterCtx">Twitter Context</param> /// <param name="userID">ID of user to block</param> /// <param name="screenName">Screen name of user to block</param> /// <param name="includeEntities">Set to false to not include entities (default: true)</param> /// <param name="skipStatus">Don't include status</param> /// <param name="callback">Async Callback used in Silverlight queries</param> /// <returns>User that was unblocked</returns> public static User CreateBlock(this TwitterContext twitterCtx, ulong userID, string screenName, bool includeEntities, bool skipStatus, Action <TwitterAsyncResponse <User> > callback) { if (userID <= 0 && string.IsNullOrEmpty(screenName)) { throw new ArgumentException("Either userID or screenName are required parameters.", "UserIDOrScreenName"); } var blocksUrl = twitterCtx.BaseUrl + "blocks/create.json"; var reqProc = new BlocksRequestProcessor <User>(); ITwitterExecute twitExe = twitterCtx.TwitterExecutor; twitExe.AsyncCallback = callback; var resultsJson = twitExe.PostToTwitter( blocksUrl, new Dictionary <string, string> { { "user_id", userID <= 0 ? (string)null : userID.ToString() }, { "screen_name", screenName }, { "include_entities", includeEntities.ToString().ToLower() }, { "skip_status", skipStatus.ToString().ToLower() } }, response => reqProc.ProcessActionResult(response, UserAction.SingleUser)); User results = reqProc.ProcessActionResult(resultsJson, UserAction.SingleUser); return(results); }
/// <summary> /// Unblocks a user. /// </summary> /// <param name="userID">ID of user to block</param> /// <param name="screenName">Screen name of user to block</param> /// <param name="includeEntities">Set to false to not include entities (default: true)</param> /// <param name="skipStatus">Don't include status</param> /// <returns>User that was unblocked</returns> public async Task <User> DestroyBlockAsync(ulong userID, string screenName, bool includeEntities, bool skipStatus, CancellationToken cancelToken = default(CancellationToken)) { if (userID <= 0 && string.IsNullOrWhiteSpace(screenName)) { throw new ArgumentException("Either userID or screenName are required parameters.", "UserIDOrScreenName"); } var blocksUrl = BaseUrl + "blocks/destroy.json"; var reqProc = new BlocksRequestProcessor <User>(); RawResult = await TwitterExecutor.PostFormUrlEncodedToTwitterAsync <User>( HttpMethod.Post.ToString(), blocksUrl, new Dictionary <string, string> { { "user_id", userID <= 0 ? (string)null : userID.ToString() }, { "screen_name", screenName }, { "include_entities", includeEntities.ToString().ToLower() }, { "skip_status", skipStatus.ToString().ToLower() } }, cancelToken) .ConfigureAwait(false); return(reqProc.ProcessActionResult(RawResult, UserAction.SingleUser)); }