Example #1
20
 public RedditUser(Reddit reddit, JToken json, IWebAgent webAgent)
     : base(json)
 {
     Reddit = reddit;
     WebAgent = webAgent;
     JsonConvert.PopulateObject(json["data"].ToString(), this, reddit.JsonSerializerSettings);
 }
Example #2
5
 public Post(Reddit reddit, JToken post, IWebAgent webAgent)
     : base(reddit, webAgent, post)
 {
     Reddit = reddit;
     WebAgent = webAgent;
     JsonConvert.PopulateObject(post["data"].ToString(), this, reddit.JsonSerializerSettings);
 }
 public VotableThing(Reddit reddit, IWebAgent webAgent, JToken json)
     : base(reddit, json)
 {
     Reddit = reddit;
     WebAgent = webAgent;
     JsonConvert.PopulateObject(json["data"].ToString(), this, Reddit.JsonSerializerSettings);
 }
Example #4
4
        public Comment(Reddit reddit, JToken json, IWebAgent webAgent, Thing sender)
            : base(reddit, webAgent, json)
        {
            var data = json["data"];
            JsonConvert.PopulateObject(data.ToString(), this, reddit.JsonSerializerSettings);
            Reddit = reddit;
            WebAgent = webAgent;

            // Parse sub comments
            // TODO: Consider deserializing this properly
            var subComments = new List<Comment>();
            if (data["replies"] != null && data["replies"].Any())
            {
                foreach (var comment in data["replies"]["data"]["children"])
                    subComments.Add(new Comment(reddit, comment, webAgent, sender));
            }
            Comments = subComments.ToArray();

            this.Parent = sender;

            // Handle Reddit's API being horrible
            if (data["context"] != null)
            {
                var context = data["context"].Value<string>();
                LinkId = context.Split('/')[4];
            }
        }
 public async new Task<AuthenticatedUser> InitAsync(Reddit reddit, JToken json, IWebAgent webAgent)
 {
     CommonInit(reddit, json, webAgent);
     await Task.Factory.StartNew(() => JsonConvert.PopulateObject(json["name"] == null ? json["data"].ToString() : json.ToString(), this,
         reddit.JsonSerializerSettings));
     return this;
 }
 public new AuthenticatedUser Init(Reddit reddit, JToken json, IWebAgent webAgent)
 {
     CommonInit(reddit, json, webAgent);
     JsonConvert.PopulateObject(json["name"] == null ? json["data"].ToString() : json.ToString(), this,
         reddit.JsonSerializerSettings);
     return this;
 }
Example #7
0
 /// <summary>
 /// Allows use of reddit's OAuth interface, using an app set up at https://ssl.reddit.com/prefs/apps/.
 /// </summary>
 /// <param name="clientId">Granted by reddit as part of app.</param>
 /// <param name="clientSecret">Granted by reddit as part of app.</param>
 /// <param name="redirectUri">Selected as part of app. Reddit will send users back here.</param>
 /// <param name="agent">Implementation of IWebAgent to use to make requests.</param>
 public AuthProvider(string clientId, string clientSecret, string redirectUri, IWebAgent agent)
 {
     _clientId = clientId;
      _clientSecret = clientSecret;
      _redirectUri = redirectUri;
      _webAgent = agent;
 }
Example #8
0
 public async Task<RedditUser> InitAsync(Reddit reddit, JToken json, IWebAgent webAgent)
 {
     CommonInit(reddit, json, webAgent);
     await JsonConvert.PopulateObjectAsync(json["name"] == null ? json["data"].ToString() : json.ToString(), this,
         reddit.JsonSerializerSettings);
     return this;
 }
Example #9
0
 public Comment Init(Reddit reddit, JToken json, IWebAgent webAgent, Thing sender)
 {
     var data = CommonInit(reddit, json, webAgent, sender);
     ParseComments(reddit, json, webAgent, sender);
     JsonConvert.PopulateObject(data.ToString(), this, reddit.JsonSerializerSettings);
     return this;
 }
Example #10
0
 public async Task<Comment> InitAsync(Reddit reddit, JToken json, IWebAgent webAgent, Thing sender)
 {
     var data = CommonInit(reddit, json, webAgent, sender);
     await ParseCommentsAsync(reddit, json, webAgent, sender);
     await Task.Factory.StartNew(() => JsonConvert.PopulateObject(data.ToString(), this, reddit.JsonSerializerSettings));
     return this;
 }
 /// <summary>
 /// Allows use of reddit's OAuth interface, using an app set up at https://ssl.reddit.com/prefs/apps/.
 /// </summary>
 /// <param name="clientId">Granted by reddit as part of app.</param>
 /// <param name="clientSecret">Granted by reddit as part of app.</param>
 /// <param name="redirectUri">Selected as part of app. Reddit will send users back here.</param>
 public AuthProvider(string clientId, string clientSecret, string redirectUri)
 {
     _clientId = clientId;
     _clientSecret = clientSecret;
     _redirectUri = redirectUri;
     _webAgent = new WebAgent();
 }
Example #12
0
 public Reddit()
 {
     JsonSerializerSettings = new JsonSerializerSettings();
     JsonSerializerSettings.CheckAdditionalContent = false;
     JsonSerializerSettings.DefaultValueHandling = DefaultValueHandling.Ignore;
     _webAgent = new WebAgent();
 }
 protected internal WikiPageSettings(Reddit reddit, JToken json, IWebAgent webAgent)
 {
     var editors = json["editors"].ToArray();
     Editors = editors.Select(x =>
     {
         return new RedditUser(reddit, x, webAgent);
     });
     JsonConvert.PopulateObject(json.ToString(), this, reddit.JsonSerializerSettings);
 }
Example #14
0
 public SubredditImage(Reddit reddit, SubredditStyle subredditStyle,
     string cssLink, string name, IWebAgent webAgent)
 {
     Reddit = reddit;
     WebAgent = webAgent;
     SubredditStyle = subredditStyle;
     Name = name;
     CssLink = cssLink;
 }
Example #15
0
 public SubredditImage(Reddit reddit, SubredditStyle subreddit,
     string cssLink, string name, string url, IWebAgent webAgent)
     : this(reddit, subreddit, cssLink, name, webAgent)
 {
     Url = new Uri(url);
     // Handle legacy image urls
     // http://thumbs.reddit.com/FULLNAME_NUMBER.png
     int discarded;
     if (int.TryParse(url, out discarded))
         Url = new Uri(string.Format("http://thumbs.reddit.com/{0}_{1}.png", subreddit.Subreddit.FullName, url), UriKind.Absolute);
 }
Example #16
0
 public SubredditStyle(Reddit reddit, Subreddit subreddit, JToken json, IWebAgent webAgent) : this(reddit, subreddit, webAgent)
 {
     Images = new List<SubredditImage>();
     var data = json["data"];
     CSS = HttpUtility.HtmlDecode(data["stylesheet"].Value<string>());
     foreach (var image in data["images"])
     {
         Images.Add(new SubredditImage(
             Reddit, this, image["link"].Value<string>(),
             image["name"].Value<string>(), image["url"].Value<string>(), WebAgent));
     }
 }
Example #17
0
 private async Task ParseCommentsAsync(Reddit reddit, JToken data, IWebAgent webAgent, Thing sender)
 {
     // Parse sub comments
     // TODO: Consider deserializing this properly
     var subComments = new List<Comment>();
     if (data["replies"] != null && data["replies"].Any())
     {
         foreach (var comment in data["replies"]["data"]["children"])
             subComments.Add(await new Comment().InitAsync(reddit, comment, webAgent, sender));
     }
     Comments = subComments.ToArray();            
 }
Example #18
0
 private async Task ParseCommentsAsync(Reddit reddit, JToken data, IWebAgent webAgent, Thing sender)
 {
     // Parse sub comments
     var replies = data["data"]["replies"];
     var subComments = new List<Comment>();
     if (replies != null && replies.Count() > 0)
     {
         foreach (var comment in replies["data"]["children"])
             subComments.Add(await new Comment().InitAsync(reddit, comment, webAgent, sender));
     }
     Comments = subComments.ToArray();            
 }
 protected internal Subreddit(Reddit reddit, JToken json, IWebAgent webAgent)
     : base(json)
 {
     Reddit = reddit;
     WebAgent = webAgent;
     JsonConvert.PopulateObject(json["data"].ToString(), this, reddit.JsonSerializerSettings);
     Name = Url;
     if (Name.StartsWith("/r/"))
         Name = Name.Substring(3);
     if (Name.StartsWith("r/"))
         Name = Name.Substring(2);
     Name = Name.TrimEnd('/');
 }
Example #20
0
 public RedditAuth(IWebAgent agent)
 {
     _uname = ConfigurationManager.AppSettings["BotUsername"];
     _pass = ConfigurationManager.AppSettings["BotPassword"];
     _clientId = ConfigurationManager.AppSettings["ClientID"];
     _clientSecret = ConfigurationManager.AppSettings["ClientSecret"];
     _redirectUri = ConfigurationManager.AppSettings["RedirectURI"];
     if ( string.IsNullOrEmpty( _uname ) ) throw new Exception( "Missing 'BotUsername' in config" );
     if ( string.IsNullOrEmpty( _pass ) ) throw new Exception( "Missing 'BotPassword' in config" );
     if ( string.IsNullOrEmpty( _clientId ) ) throw new Exception( "Missing 'ClientID' in config" );
     if ( string.IsNullOrEmpty( _clientSecret ) ) throw new Exception( "Missing 'ClientSecret' in config" );
     if ( string.IsNullOrEmpty( _redirectUri ) ) throw new Exception( "Missing 'RedirectURI' in config" );
     _webAgent = agent;
     _timerState = new TimerState();
 }
Example #21
0
        private JToken CommonInit(Reddit reddit, JToken json, IWebAgent webAgent, Thing sender)
        {
            base.Init(reddit, webAgent, json);
            var data = json["data"];
            Reddit = reddit;
            WebAgent = webAgent;
            this.Parent = sender;

            // Handle Reddit's API being horrible
            if (data["context"] != null)
            {
                var context = data["context"].Value<string>();
                LinkId = context.Split('/')[4];
            }
         
            return data;
        }
 public static Thing Parse(Reddit reddit, JToken json, IWebAgent webAgent)
 {
     var kind = json["kind"].ValueOrDefault<string>();
     switch (kind)
     {
         case "t1":
             return new Comment(reddit, json, webAgent, null);
         case "t2":
             return new RedditUser(reddit, json, webAgent);
         case "t3":
             return new Post(reddit, json, webAgent);
         case "t4":
             return new PrivateMessage(reddit, json, webAgent);
         case "t5":
             return new Subreddit(reddit, json, webAgent);
         default:
             return null;
     }
 }
 public PrivateMessage(Reddit reddit, JToken json, IWebAgent webAgent)
     : base(json)
 {
     Reddit = reddit;
     WebAgent = webAgent;
     JsonConvert.PopulateObject(json["data"].ToString(), this, reddit.JsonSerializerSettings);
     var data = json["data"];
     if (data["replies"] != null && data["replies"].Any())
     {
         if (data["replies"]["data"] != null)
         {
             if (data["replies"]["data"]["children"] != null)
             {
                 var replies = new List<PrivateMessage>();
                 foreach (var reply in data["replies"]["data"]["children"])
                     replies.Add(new PrivateMessage(reddit, reply, webAgent));
                 Replies = replies.ToArray();
             }
         }
     }
 }
 public SubredditSettings(Reddit reddit, Subreddit subreddit, IWebAgent webAgent)
 {
     Subreddit = subreddit;
     Reddit = reddit;
     WebAgent = webAgent;
     // Default settings, for use when reduced information is given
     AllowAsDefault = true;
     Domain = null;
     Sidebar = string.Empty;
     Language = "en";
     Title = Subreddit.DisplayName;
     WikiEditKarma = 100;
     WikiEditAge = 10;
     UseDomainCss = false;
     UseDomainSidebar = false;
     HeaderHoverText = string.Empty;
     NSFW = false;
     PublicDescription = string.Empty;
     WikiEditMode = WikiEditMode.None;
     SubredditType = SubredditType.Public;
     ShowThumbnails = true;
     ContentOptions = ContentOptions.All;
 }
Example #25
0
 public SubredditSettings(Reddit reddit, Subreddit subreddit, IWebAgent webAgent)
 {
     Subreddit = subreddit;
     Reddit    = reddit;
     WebAgent  = webAgent;
     // Default settings, for use when reduced information is given
     AllowAsDefault    = true;
     Domain            = null;
     Sidebar           = string.Empty;
     Language          = "en";
     Title             = Subreddit.DisplayName;
     WikiEditKarma     = 100;
     WikiEditAge       = 10;
     UseDomainCss      = false;
     UseDomainSidebar  = false;
     HeaderHoverText   = string.Empty;
     NSFW              = false;
     PublicDescription = string.Empty;
     WikiEditMode      = WikiEditMode.None;
     SubredditType     = SubredditType.Public;
     ShowThumbnails    = true;
     ContentOptions    = ContentOptions.All;
     SpamFilter        = new SpamFilterSettings();
 }
 private void CommonInit(Reddit reddit, JToken json, IWebAgent webAgent)
 {
     base.Init(json);
     Author = new RedditUser().Init(reddit, json["author"], webAgent);
 }
Example #27
0
 /// <inheritdoc />
 public AuthenticatedUser(IWebAgent agent, JToken json) : base(agent, json)
 {
 }
Example #28
0
 public async Task<ModAction> InitAsync(Reddit reddit, JToken post, IWebAgent webAgent)
 {
     CommonInit(reddit, post, webAgent);
     await Task.Factory.StartNew(() => JsonConvert.PopulateObject(post["data"].ToString(), this, reddit.JsonSerializerSettings));
     return this;
 }
Example #29
0
#pragma warning restore 1591
        /// <inheritdoc />
        public LiveUpdateEvent(IWebAgent agent, JToken json) : base(agent, json)
        {
            FullName = Name;
            Name     = Name.Replace("LiveUpdateEvent_", "");
        }
Example #30
0
 /// <summary>
 /// Allows use of reddit's OAuth interface, using an app set up at https://ssl.reddit.com/prefs/apps/.
 /// </summary>
 /// <param name="clientId">Granted by reddit as part of app.</param>
 /// <param name="clientSecret">Granted by reddit as part of app.</param>
 /// <param name="redirectUri">Selected as part of app. Reddit will send users back here.</param>
 /// <param name="agent">Implementation of IWebAgent to use to make requests.</param>
 public AuthProvider(string clientId, string clientSecret, string redirectUri, IWebAgent agent)
 {
     _clientId     = clientId;
     _clientSecret = clientSecret;
     _redirectUri  = redirectUri;
     _webAgent     = agent;
 }
Example #31
0
 public Post Init(Reddit reddit, JToken post, IWebAgent webAgent)
 {
     CommonInit(reddit, post, webAgent);
     JsonConvert.PopulateObject(post["data"].ToString(), this, reddit.JsonSerializerSettings);
     return(this);
 }
Example #32
0
 /// <summary>
 /// Initialize.
 /// </summary>
 /// <param name="reddit"></param>
 /// <param name="json"></param>
 /// <param name="webAgent"></param>
 /// <returns></returns>
 public Contributor Init(Reddit reddit, JToken json, IWebAgent webAgent) 
 {
     CommonInit(json);
     JsonConvert.PopulateObject(json.ToString(), this, reddit.JsonSerializerSettings);
     return this;
 }
Example #33
0
 private void CommonInit(Reddit reddit, JToken json, IWebAgent webAgent)
 {
     base.Init(json);
     Reddit   = reddit;
     WebAgent = webAgent;
 }
Example #34
0
 /// <inheritdoc />
 public BannedUser(IWebAgent agent, JToken json) : base(agent, json)
 {
 }
Example #35
0
 /// <inheritdoc />
 public RedditUser(IWebAgent agent, JToken json) : base(agent, json)
 {
 }
Example #36
0
 /// <inheritdoc />
 public Post(IWebAgent agent, JToken json) : base(agent, json)
 {
 }
Example #37
0
 /// <inheritdoc />
 public VotableThing(IWebAgent agent, JToken json) : base(agent, json)
 {
 }
Example #38
0
 /// <summary>
 /// Initialize.
 /// </summary>
 /// <param name="reddit"></param>
 /// <param name="json"></param>
 /// <param name="webAgent"></param>
 /// <returns></returns>
 public async Task<Contributor> InitAsync(Reddit reddit, JToken json, IWebAgent webAgent)
 {
     CommonInit(json);
     await Task.Factory.StartNew(() => JsonConvert.PopulateObject(json.ToString(), this, reddit.JsonSerializerSettings));
     return this;
 }
        protected static async internal Task <T> GetThingAsync <T>(IWebAgent agent, string url) where T : Things.Thing
        {
            var json = await agent.Get(url).ConfigureAwait(false);

            return(Things.Thing.Parse <T>(agent, json));
        }
Example #40
0
 private void CommonInit(Reddit reddit, JToken more, IWebAgent webAgent)
 {
     base.Init(more);
     Reddit   = reddit;
     WebAgent = webAgent;
 }
Example #41
0
 public ModeratorUser(IWebAgent agent, JToken json) : base(agent, json)
 {
 }
Example #42
0
 private void CommonInit(Reddit reddit, JToken json, IWebAgent webAgent)
 {
     base.Init(json);
     Reddit = reddit;
     WebAgent = webAgent;
 }
Example #43
0
 public More Init(Reddit reddit, JToken more, IWebAgent webAgent)
 {
     CommonInit(reddit, more, webAgent);
     JsonConvert.PopulateObject(more["data"].ToString(), this, reddit.JsonSerializerSettings);
     return(this);
 }
Example #44
0
 /// <summary>
 /// Creates an implementation of MultiData
 /// </summary>
 /// <param name="agent">IWebAgent Object to use</param>
 /// <param name="json">Json Token containing the information for the Multi</param>
 /// <param name="subs">Whether there are subs</param>
 protected internal MultiData(IWebAgent agent, JToken json, bool subs = true)
 {
     Data = new MData(agent, json["data"], subs);
     Helpers.PopulateObject(json, this);
 }
 public SpellChecker(IWebAgent agent)
 {
     _agent = agent;
 }
Example #46
0
 /// <inheritdoc />
 protected internal WikiPageRevision(IWebAgent agent, JToken json) : base(agent, json)
 {
     Author = new RedditUser(agent, json["author"]);
 }
Example #47
0
 private void CommonInit(Reddit reddit, JToken post, IWebAgent webAgent)
 {
     base.Init(reddit, webAgent, post);
     Reddit   = reddit;
     WebAgent = webAgent;
 }
Example #48
0
        public static IEnumerable<TBUserNote> GetUserNotes(IWebAgent webAgent, string subName)
        {
            var request = webAgent.CreateGet(String.Format(ToolBoxUserNotesWiki, subName));
            var reqResponse = webAgent.ExecuteRequest(request);
            var response = JObject.Parse(reqResponse["data"]["content_md"].Value<string>());

            int version = response["ver"].Value<int>();
            string[] mods = response["constants"]["users"].Values<string>().ToArray();

            string[] warnings = response["constants"]["warnings"].Values<string>().ToArray();

            if (version < 6) throw new ToolBoxUserNotesException("Unsupported ToolBox version");

            try
            {
                var data = Convert.FromBase64String(response["blob"].Value<string>());

                string uncompressed;
                using (System.IO.MemoryStream compressedStream = new System.IO.MemoryStream(data))
                {
                    compressedStream.ReadByte();
                    compressedStream.ReadByte(); //skips first to bytes to fix zlib block size
                    using (DeflateStream blobStream = new DeflateStream(compressedStream, CompressionMode.Decompress))
                    {
                        using (var decompressedReader = new System.IO.StreamReader(blobStream))
                        {
                            uncompressed = decompressedReader.ReadToEnd();
                        }

                    }
                }

                JObject users = JObject.Parse(uncompressed);

                List<TBUserNote> toReturn = new List<TBUserNote>();
                foreach (KeyValuePair<string, JToken> user in users)
                {
                    var x = user.Value;
                    foreach (JToken note in x["ns"].Children())
                    {

                        TBUserNote uNote = new TBUserNote();
                        uNote.AppliesToUsername = user.Key;
                        uNote.SubName = subName;
                        uNote.SubmitterIndex = note["m"].Value<int>();
                        uNote.Submitter = mods[uNote.SubmitterIndex];
                        uNote.NoteTypeIndex = note["w"].Value<int>();
                        uNote.NoteType = warnings[uNote.NoteTypeIndex];
                        uNote.Message = note["n"].Value<string>();
                        uNote.Timestamp = UnixTimeStamp.UnixTimeStampToDateTime(note["t"].Value<long>());
                        uNote.Url = UnsquashLink(subName, note["l"].ValueOrDefault<string>());

                        toReturn.Add(uNote);
                    }
                }
                return toReturn;
            }
            catch (Exception e)
            {
                throw new ToolBoxUserNotesException("An error occured while processing Usernotes wiki. See inner exception for details", e);
            }
        }
Example #49
0
 public Post(Reddit reddit, JToken post, IWebAgent webAgent) : base(reddit, webAgent, post)
 {
     Reddit   = reddit;
     WebAgent = webAgent;
     JsonConvert.PopulateObject(post["data"].ToString(), this, reddit.JsonSerializerSettings);
 }
Example #50
0
        /// <summary>
        /// Get the subreddit settings page.
        /// </summary>
        /// <param name="subreddit">A subreddit.</param>
        /// <param name="reddit"></param>
        /// <param name="json"></param>
        /// <param name="webAgent"></param>
        public SubredditSettings(Subreddit subreddit, Reddit reddit, JObject json, IWebAgent webAgent) : this(reddit, subreddit, webAgent)
        {
            var data = json["data"];

            AllowAsDefault    = data["default_set"].ValueOrDefault <bool>();
            AllowImages       = data["allow_images"].ValueOrDefault <bool>();
            Domain            = data["domain"].ValueOrDefault <string>();
            Sidebar           = HttpUtility.HtmlDecode(data["description"].ValueOrDefault <string>() ?? string.Empty);
            Language          = data["language"].ValueOrDefault <string>();
            Title             = data["title"].ValueOrDefault <string>();
            WikiEditKarma     = data["wiki_edit_karma"].ValueOrDefault <int>();
            UseDomainCss      = data["domain_css"].ValueOrDefault <bool>();
            UseDomainSidebar  = data["domain_sidebar"].ValueOrDefault <bool>();
            HeaderHoverText   = data["header_hover_text"].ValueOrDefault <string>();
            NSFW              = data["over_18"].ValueOrDefault <bool>();
            PublicDescription = HttpUtility.HtmlDecode(data["public_description"].ValueOrDefault <string>() ?? string.Empty);
            SpamFilter        = new SpamFilterSettings
            {
                LinkPostStrength = GetSpamFilterStrength(data["spam_links"].ValueOrDefault <string>()),
                SelfPostStrength = GetSpamFilterStrength(data["spam_selfposts"].ValueOrDefault <string>()),
                CommentStrength  = GetSpamFilterStrength(data["spam_comments"].ValueOrDefault <string>())
            };
            if (data["wikimode"] != null)
            {
                var wikiMode = data["wikimode"].ValueOrDefault <string>();
                switch (wikiMode)
                {
                case "disabled":
                    WikiEditMode = WikiEditMode.None;
                    break;

                case "modonly":
                    WikiEditMode = WikiEditMode.Moderators;
                    break;

                case "anyone":
                    WikiEditMode = WikiEditMode.All;
                    break;
                }
            }
            if (data["subreddit_type"] != null)
            {
                var type = data["subreddit_type"].ValueOrDefault <string>();
                switch (type)
                {
                case "public":
                    SubredditType = SubredditType.Public;
                    break;

                case "private":
                    SubredditType = SubredditType.Private;
                    break;

                case "restricted":
                    SubredditType = SubredditType.Restricted;
                    break;
                }
            }
            ShowThumbnails = data["show_media"].ValueOrDefault <bool>();
            WikiEditAge    = data["wiki_edit_age"].ValueOrDefault <int>();
            if (data["content_options"] != null)
            {
                var contentOptions = data["content_options"].ValueOrDefault <string>();
                switch (contentOptions)
                {
                case "any":
                    ContentOptions = ContentOptions.All;
                    break;

                case "link":
                    ContentOptions = ContentOptions.LinkOnly;
                    break;

                case "self":
                    ContentOptions = ContentOptions.SelfOnly;
                    break;
                }
            }
        }
Example #51
0
        /// <summary>
        /// Returns a <see cref="RedditUser"/> by username
        /// </summary>
        /// <param name="agent">WebAgent to perform search</param>
        /// <param name="username">Username of user to return</param>
        /// <returns></returns>
        public static async Task <RedditUser> GetUserAsync(IWebAgent agent, string username)
        {
            var json = await agent.Get(string.Format(UserInfoUrl, username)).ConfigureAwait(false);

            return(new RedditUser(agent, json));
        }
Example #52
0
 public ModAction Init(Reddit reddit, JToken json, IWebAgent webAgent)
 {
     CommonInit(reddit, json, webAgent);
     JsonConvert.PopulateObject(json["data"].ToString(), this, reddit.JsonSerializerSettings);
     return this;
 }
Example #53
0
 public SubredditStyle(Reddit reddit, Subreddit subreddit, IWebAgent webAgent)
 {
     Reddit    = reddit;
     Subreddit = subreddit;
     WebAgent  = webAgent;
 }
 public SubredditSettings(Subreddit subreddit, Reddit reddit, JObject json, IWebAgent webAgent)
     : this(reddit, subreddit, webAgent)
 {
     var data = json["data"];
     AllowAsDefault = data["default_set"].ValueOrDefault<bool>();
     Domain = data["domain"].ValueOrDefault<string>();
     Sidebar = HttpUtility.HtmlDecode(data["description"].ValueOrDefault<string>() ?? string.Empty);
     Language = data["language"].ValueOrDefault<string>();
     Title = data["title"].ValueOrDefault<string>();
     WikiEditKarma = data["wiki_edit_karma"].ValueOrDefault<int>();
     UseDomainCss = data["domain_css"].ValueOrDefault<bool>();
     UseDomainSidebar = data["domain_sidebar"].ValueOrDefault<bool>();
     HeaderHoverText = data["header_hover_text"].ValueOrDefault<string>();
     NSFW = data["over_18"].ValueOrDefault<bool>();
     PublicDescription = HttpUtility.HtmlDecode(data["public_description"].ValueOrDefault<string>() ?? string.Empty);
     if (data["wikimode"] != null)
     {
         var wikiMode = data["wikimode"].ValueOrDefault<string>();
         switch (wikiMode)
         {
             case "disabled":
                 WikiEditMode = WikiEditMode.None;
                 break;
             case "modonly":
                 WikiEditMode = WikiEditMode.Moderators;
                 break;
             case "anyone":
                 WikiEditMode = WikiEditMode.All;
                 break;
         }
     }
     if (data["subreddit_type"] != null)
     {
         var type = data["subreddit_type"].ValueOrDefault<string>();
         switch (type)
         {
             case "public":
                 SubredditType = SubredditType.Public;
                 break;
             case "private":
                 SubredditType = SubredditType.Private;
                 break;
             case "restricted":
                 SubredditType = SubredditType.Restricted;
                 break;
         }
     }
     ShowThumbnails = data["show_media"].ValueOrDefault<bool>();
     WikiEditAge = data["wiki_edit_age"].ValueOrDefault<int>();
     if (data["content_options"] != null)
     {
         var contentOptions = data["content_options"].ValueOrDefault<string>();
         switch (contentOptions)
         {
             case "any":
                 ContentOptions = ContentOptions.All;
                 break;
             case "link":
                 ContentOptions = ContentOptions.LinkOnly;
                 break;
             case "self":
                 ContentOptions = ContentOptions.SelfOnly;
                 break;
         }
     }
 }
Example #55
0
 /// <summary>
 /// Creates a new Listing instance
 /// </summary>
 /// <param name="reddit"></param>
 /// <param name="url"></param>
 /// <param name="webAgent"></param>
 internal Listing(Reddit reddit, string url, IWebAgent webAgent)
 {
     WebAgent = webAgent;
     Reddit   = reddit;
     Url      = url;
 }
 internal WikiPageRevision Init(Reddit reddit, JToken json, IWebAgent webAgent)
 {
     CommonInit(reddit, json, webAgent);
     JsonConvert.PopulateObject(json.ToString(), this, reddit.JsonSerializerSettings);
     return(this);
 }
Example #57
0
 /// <summary>
 /// Initialize.
 /// </summary>
 /// <param name="reddit"></param>
 /// <param name="json"></param>
 /// <param name="webAgent"></param>
 /// <returns></returns>
 public async Task <BannedUser> InitAsync(Reddit reddit, JToken json, IWebAgent webAgent)
 {
     CommonInit(json);
     JsonConvert.PopulateObject(json.ToString(), this, reddit.JsonSerializerSettings);
     return(this);
 }
Example #58
0
 protected internal WikiPage(Reddit reddit, JToken json, IWebAgent webAgent)
 {
     RevisionBy = new RedditUser().Init(reddit, json["revision_by"], webAgent);
     JsonConvert.PopulateObject(json.ToString(), this, reddit.JsonSerializerSettings);
 }
Example #59
0
 public Images(IWebAgent agent, JToken json)
 {
 }
 public PrivateMessage Init(Reddit reddit, JToken json, IWebAgent webAgent)
 {
     CommonInit(reddit, json, webAgent);
     JsonConvert.PopulateObject(json["data"].ToString(), this, reddit.JsonSerializerSettings);
     return(this);
 }