Esempio n. 1
0
        public static void Logout(redditLogin login)
        {
            redditRequest request;
            string        json = string.Empty;

            try
            {
                if (login.Data.Storage == null)
                {
                    throw new Exception("Login Data Null");
                }
                else if (String.IsNullOrEmpty(login.Data.Storage.modhash) || String.IsNullOrEmpty(login.Data.Storage.cookie))
                {
                    throw new Exception("Login Data NULL");
                }
                request = new redditRequest()
                {
                    Url     = "http://www.reddit.com/logout?uh=" + login.Data.Storage.modhash,
                    Method  = "POST",
                    User    = login.UserHandle,
                    Cookie  = login.Data.Storage.cookie,
                    Content = "uh=" + login.Data.Storage.modhash + "&top=off"
                };
                if (request.Execute(out json) != HttpStatusCode.OK)
                {
                    throw new Exception(json);
                }
            }
            catch (Exception exp)
            {
                throw exp;
            }
        }
Esempio n. 2
0
        public static redditLogin Login(string username, string password)
        {
            redditLogin login = null;

            try
            {
                redditRequest request = new redditRequest
                {
                    Url     = "http://www.reddit.com/api/login/" + username,
                    Method  = "POST",
                    Content = string.Format("api_type=json&user={0}&passwd={1}", username, password)
                };
                string json = string.Empty;
                if (request.Execute(out json) == HttpStatusCode.OK)
                {
                    login            = JsonConvert.DeserializeObject <redditLogin>(json);
                    login.UserHandle = username;
                }
            }
            catch (Exception exp)
            {
                throw exp;
            }
            return(login);
        }
Esempio n. 3
0
        public static redditMessage Inbox(redditLogin session)
        {
            redditMessage msg = null;

            try
            {
                var request = new redditRequest
                {
                    Method = "GET",
                    Cookie = session.Data.Storage.cookie,
                    User   = session.UserHandle,
                    Url    = "http://www.reddit.com/message/inbox/.json"
                };
                var json = string.Empty;
                if (request.Execute(out json) != System.Net.HttpStatusCode.OK)
                {
                    throw new Exception(json);
                }
                msg = JsonConvert.DeserializeObject <redditMessage>(json);
            }
            catch
            {
                throw new Exception("Unable To Reach Inbox");
            }
            return(msg);
        }
Esempio n. 4
0
        public static redditAbout GetMe(redditLogin session)
        {
            redditAbout rAbbout = null;
            var         request = new redditRequest
            {
                Method = "GET",
                Cookie = session.Data.Storage.cookie,
                User   = session.UserHandle,
                Url    = "http://www.reddit.com/api/me.json"
            };
            var json = string.Empty;

            if (request.Execute(out json) != System.Net.HttpStatusCode.OK)
            {
                throw new Exception(json);
            }
            rAbbout = JsonConvert.DeserializeObject <redditAbout>(json);
            return(rAbbout);
        }
Esempio n. 5
0
        public static string SendVote(string Full_ID, Vote vote, redditLogin session)
        {
            string buffer = string.Empty;

            try
            {
                var request = new redditRequest
                {
                    Method = "GET",
                    Cookie = session.Data.Storage.cookie,
                    User   = session.UserHandle,
                    Url    = "http://www.reddit.com/api/me.json"
                };
                var xml = string.Empty;
                if (request.Execute(out xml) != System.Net.HttpStatusCode.OK)
                {
                    throw new Exception(xml);
                }
            }
            catch (Exception exp)
            {
            }
            return(buffer);
        }