Пример #1
0
        internal static Message FromJson(JToken token)
        {
            Message msg = new Message();

            msg.ID = token["id"].ToString();
            msg.Name = token["name"].ToString();
            msg.WasComment = bool.Parse(token["was_comment"].ToString());

            if (token["first_message"].ToString().Length > 0)
            {
                msg.FirstMessage = bool.Parse(token["first_message"].ToString());
            }

            msg.New = bool.Parse(token["new"].ToString());
            msg.BodyHtml = token["body_html"].ToString();
            msg.Body = token["body"].ToString();
            msg.Destination = token["dest"].ToString();
            msg.Author = token["author"].ToString();
            msg.Subject = token["subject"].ToString();
            msg.SubReddit = token["subreddit"].ToString();
            msg.Context = token["context"].ToString();
            msg.ParentID = token["parent_id"].ToString();

            msg.Created = new DateTime(1970, 1, 1, 0, 0, 0, 0);
            double created = Double.Parse(token["created"].ToString());
            msg.Created = msg.Created.AddSeconds(created);

            return msg;
        }
Пример #2
0
        public static void Send(Session session, Message message, string iden, string captcha)
        {
            var request = new Request
            {
                Url = "http://www.reddit.com/api/compose",
                Method = "POST",
                Cookie = session.Cookie,
                Content = "uh=" + session.ModHash +
                          "&to=" + message.Destination +
                          "&subject=" + message.Subject +
                          "&thing_id=" +
                          "&text=" + message.Body +
                          "&iden=" + iden +
                          "&captcha=" + captcha +
                          "&id=#compose-message" +
                          "&renderstyle=html"
            };

            var json = string.Empty;
            if (request.Execute(out json) != System.Net.HttpStatusCode.OK)
            {

            }

            /*
            {
                "jquery": [
                    [0, 1, "call", ["#compose-message"]],
                    [1, 2, "attr", "find"],
                    [2, 3, "call", [".status"]],
                    [3, 4, "attr", "hide"],
                    [4, 5, "call", []],
                    [5, 6, "attr", "html"],
                    [6, 7, "call", [""]],
                    [7, 8, "attr", "end"],
                    [8, 9, "call", []],
                    [1, 10, "attr", "find"],
                    [10, 11, "call", [".status"]],
                    [11, 12, "attr", "show"],
                    [12, 13, "call", []],
                    [13, 14, "attr", "html"],
                    [14, 15, "call", ["your message has been delivered"]],
                    [15, 16, "attr", "end"],
                    [16, 17, "call", []],
                    [1, 18, "attr", "find"],
                    [18, 19, "call", ["*[name=captcha]"]],
                    [19, 20, "attr", "attr"],
                    [20, 21, "call", ["value", ""]],
                    [21, 22, "attr", "end"],
                    [22, 23, "call", []],
                    [1, 24, "attr", "find"],
                    [24, 25, "call", ["*[name=to]"]],
                    [25, 26, "attr", "attr"],
                    [26, 27, "call", ["value", ""]],
                    [27, 28, "attr", "end"],
                    [28, 29, "call", []],
                    [1, 30, "attr", "find"],
                    [30, 31, "call", ["*[name=text]"]],
                    [31, 32, "attr", "attr"],
                    [32, 33, "call", ["value", ""]],
                    [33, 34, "attr", "end"],
                    [34, 35, "call", []],
                    [1, 36, "attr", "find"],
                    [36, 37, "call", ["*[name=subject]"]],
                    [37, 38, "attr", "attr"],
                    [38, 39, "call", ["value", ""]],
                    [39, 40, "attr", "end"],
                    [40, 41, "call", []]
                ]
            }
             */
        }