/// <summary> /// Distinguishes (or undistinguishes) an item /// </summary> /// <param name="distinguishType">Type you want to distinguish <see cref="DistinguishType"/></param> /// <param name="sticky">Stickies the Thing if applicable</param> public async Task DistinguishAsync(DistinguishType distinguishType, bool sticky = false) { string how; switch (distinguishType) { case DistinguishType.Admin: how = "admin"; break; case DistinguishType.Moderator: how = "yes"; break; case DistinguishType.None: how = "no"; break; default: how = "special"; break; } var json = await WebAgent.Post(DistinguishUrl, new { how, id = FullName, //oAuth requires the full ID sticky = sticky }).ConfigureAwait(false); if (json["jquery"].Count(i => i[0].Value <int>() == 11 && i[1].Value <int>() == 12) == 0) { throw new Exception("You are not permitted to distinguish this comment."); } }
public void Distinguish(DistinguishType distinguishType) { if (Reddit.User == null) { throw new Exception("No user logged in."); } var request = Reddit.CreatePost(DistinguishUrl); CommentState commentState = new CommentState(); commentState.AsyncRequest = request; commentState.ParameterValue = distinguishType; request.BeginGetRequestStream(new AsyncCallback(DistinguishRequest), commentState); }
public void Distinguish(DistinguishType distinguishType) { if (Reddit.User == null) { throw new AuthenticationException("No user logged in."); } var request = WebAgent.CreatePost(DistinguishUrl); var stream = request.GetRequestStream(); string how; switch (distinguishType) { case DistinguishType.Admin: how = "admin"; break; case DistinguishType.Moderator: how = "yes"; break; case DistinguishType.None: how = "no"; break; default: how = "special"; break; } WebAgent.WritePostBody(stream, new { how, id = Id, uh = Reddit.User.Modhash }); stream.Close(); var response = request.GetResponse(); var data = WebAgent.GetResponseString(response.GetResponseStream()); var json = JObject.Parse(data); if ( json["jquery"].Count( i => Extensions.Value <int>(i[0]) == 11 && Extensions.Value <int>(i[1]) == 12) == 0) { throw new AuthenticationException("You are not permitted to distinguish this comment."); } }
private void DistinguishRequest(IAsyncResult ar) { CommentState commentState = (CommentState)ar.AsyncState; DistinguishType distinguishType = (DistinguishType)commentState.ParameterValue; HttpWebRequest request = commentState.AsyncRequest; Stream stream = request.EndGetRequestStream(ar); string how; switch (distinguishType) { case DistinguishType.Admin: how = "admin"; break; case DistinguishType.Moderator: how = "yes"; break; case DistinguishType.None: how = "no"; break; default: how = "special"; break; } Reddit.WritePostBody(stream, new { how, id = Id, uh = Reddit.User.Modhash }); request.BeginGetResponse(new AsyncCallback(DistinguishResponse), commentState); }
public void Distinguish(DistinguishType distinguishType) { if (Reddit.User == null) throw new AuthenticationException("No user logged in."); var request = Reddit.CreatePost(DistinguishUrl); var stream = request.GetRequestStream(); string how; switch (distinguishType) { case DistinguishType.Admin: how = "admin"; break; case DistinguishType.Moderator: how = "yes"; break; case DistinguishType.None: how = "no"; break; default: how = "special"; break; } Reddit.WritePostBody(stream, new { how = how, id = Id, uh = Reddit.User.Modhash }); stream.Close(); var response = request.GetResponse(); var data = Reddit.GetResponseString(response.GetResponseStream()); var json = JObject.Parse(data); if (json["jquery"].Count(i => i[0].Value<int>() == 11 && i[1].Value<int>() == 12) == 0) throw new AuthenticationException("You are not permitted to distinguish this comment."); }