コード例 #1
0
        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.");
            }
        }
コード例 #2
0
ファイル: JEnumerable.cs プロジェクト: manjubscse/Worldpay
 /// <summary>
 /// Gets the <see cref="IEnumerable{JToken}"/> with the specified key.
 /// </summary>
 /// <value></value>
 public IEnumerable <JToken> this[object key]
 {
     get { return(Extensions.Values <T, JToken>(_enumerable, key)); }
 }
コード例 #3
0
 public virtual T Value <T>(object key)
 {
     return(Extensions.Convert <JToken, T>(this[key]));
 }
コード例 #4
0
        /// <summary>
        /// Gets the <see cref="JToken"/> with the specified key converted to the specified type.
        /// </summary>
        /// <typeparam name="T">The type to convert the token to.</typeparam>
        /// <param name="key">The token key.</param>
        /// <returns>The converted token value.</returns>
        public virtual T Value <T>(object key)
        {
            JToken token = this[key];

            return(Extensions.Convert <JToken, T>(token));
        }