Esempio n. 1
0
 public SubredditStyle GetStylesheet()
 {
     var request = Reddit.CreateGet(string.Format(StylesheetUrl, Name));
     var response = request.GetResponse();
     var data = Reddit.GetResponseString(response.GetResponseStream());
     var json = JToken.Parse(data);
     return new SubredditStyle(Reddit, this, json);
 }
Esempio n. 2
0
        public Comment[] GetComments()
        {
            var comments = new List <Comment>();

            var request  = Reddit.CreateGet(string.Format(GetCommentsUrl, Id));
            var response = request.GetResponse();
            var data     = Reddit.GetResponseString(response.GetResponseStream());
            var json     = JArray.Parse(data);

            var postJson = json.Last()["data"]["children"];

            foreach (var comment in postJson)
            {
                comments.Add(new Comment(Reddit, comment));
            }

            return(comments.ToArray());
        }
Esempio n. 3
0
 public SubredditSettings GetSettings()
 {
     if (Reddit.User == null)
         throw new AuthenticationException("No user logged in.");
     try
     {
         var request = Reddit.CreateGet(string.Format(GetSettingsUrl, Name));
         var response = request.GetResponse();
         var data = Reddit.GetResponseString(response.GetResponseStream());
         var json = JObject.Parse(data);
         return new SubredditSettings(this, Reddit, json);
     }
     catch // TODO: More specific catch
     {
         // Do it unauthed
         var request = Reddit.CreateGet(string.Format(GetReducedSettingsUrl, Name));
         var response = request.GetResponse();
         var data = Reddit.GetResponseString(response.GetResponseStream());
         var json = JObject.Parse(data);
         return new SubredditSettings(this, Reddit, json);
     }
 }
Esempio n. 4
0
        public IEnumerable <ModeratorUser> GetModerators()
        {
            var request        = Reddit.CreateGet(string.Format(ModeratorsUrl, Name));
            var response       = request.GetResponse();
            var responseString = Reddit.GetResponseString(response.GetResponseStream());
            var json           = JObject.Parse(responseString);
            var type           = json["kind"].ToString();

            if (type != "UserList")
            {
                throw new FormatException("Reddit responded with an object that is not a user listing.");
            }
            var data   = json["data"];
            var mods   = data["children"].ToArray();
            var result = new ModeratorUser[mods.Length];

            for (var i = 0; i < mods.Length; i++)
            {
                var mod = new ModeratorUser(Reddit, mods[i]);
                result[i] = mod;
            }
            return(result);
        }