/// <summary> /// Block object constructor. /// </summary> /// <param name="json"></param> public Block(JToken json) { UpdatedAt = Common.DateTimeStringToObject(json.SelectToken("updated_at")?.ToString()); TimeSinceUpdate = DateTime.UtcNow - UpdatedAt; if (json.SelectToken("user") != null) User = new User(json.SelectToken("user").ToString()); }
/// <summary>Follower object constructor.</summary> public Follower(JToken followerData) { CreatedAt = Common.DateTimeStringToObject(followerData.SelectToken("created_at").ToString()); TimeSinceCreated = DateTime.UtcNow - CreatedAt; if (followerData.SelectToken("notifications").ToString() == "true") Notifications = true; User = new User(followerData.SelectToken("user").ToString()); }
/// <summary>Constructor for ChannelHasUserSubscribedResponse object.</summary> /// <param name="json"></param> public ChannelHasUserSubscribedResponse(JToken json) { Id = json.SelectToken("_id")?.ToString(); if (json.SelectToken("user") != null) User = new User(json.SelectToken("user").ToString()); if (json.SelectToken("created_at") != null) CreatedAt = Common.DateTimeStringToObject(json.SelectToken("created_at").ToString()); }
/// <summary>Post object constructor</summary> public Post(JToken json) { Id = json.SelectToken("id")?.ToString(); CreatedAt = Common.DateTimeStringToObject(json.SelectToken("created_at")?.ToString()); TimeSinceCreated = DateTime.UtcNow - CreatedAt; if (json.SelectToken("deleted") != null) Deleted = json.SelectToken("deleted").ToString().ToLower() == "true"; Body = json.SelectToken("body")?.ToString(); Emotes = new List<Emote>(); if (json.SelectToken("emotes") != null) foreach (JToken emote in json.SelectToken("emotes")) Emotes.Add(new Emote(emote)); Reactions = new List<Reaction>(); if (json.SelectToken("reactions") != null) foreach (JToken reaction in json.SelectToken("reactions")) Reactions.Add(new Reaction(reaction)); if (json.SelectToken("user") != null) User = new User(json.SelectToken("user").ToString()); Comments = new List<Comment>(); var comments = json.SelectToken("comments"); if (comments.SelectToken("_total") != null) CommentsTotal = int.Parse(comments.SelectToken("_total").ToString()); CommentsCursor = comments.SelectToken("_cursor")?.ToString(); if (comments.SelectToken("comments") != null) foreach (JToken comment in comments.SelectToken("comments")) Comments.Add(new Comment(comment)); Permissions = new List<KeyValuePair<string, bool>>(); if (json.SelectToken("permissions") != null) { JToken permissions = json.SelectToken("permissions"); if (permissions.SelectToken("can_reply") != null) Permissions.Add(new KeyValuePair<string, bool>("can_reply", permissions.SelectToken("can_reply").ToString() == "true")); if (permissions.SelectToken("can_moderate") != null) Permissions.Add(new KeyValuePair<string, bool>("can_moderate", permissions.SelectToken("can_moderate").ToString() == "true")); if (permissions.SelectToken("can_delete") != null) Permissions.Add(new KeyValuePair<string, bool>("can_delete", permissions.SelectToken("can_delete").ToString() == "true")); } }
/// <summary>Comment object constructor.</summary> public Comment(JToken json) { if (json.SelectToken("id") != null) Id = int.Parse(json.SelectToken("id").ToString()); CreatedAt = Common.DateTimeStringToObject(json.SelectToken("created_at")?.ToString()); TimeSinceCreated = DateTime.UtcNow - CreatedAt; if (json.SelectToken("deleted") != null) Deleted = json.SelectToken("deleted").ToString().ToLower() == "true"; Body = json.SelectToken("body")?.ToString(); Permissions = new List<KeyValuePair<string, bool>>(); if (json.SelectToken("permissions") != null) { JToken permissions = json.SelectToken("permissions"); if (permissions.SelectToken("can_delete") != null) Permissions.Add(new KeyValuePair<string, bool>("can_delete", permissions.SelectToken("can_delete").ToString().ToLower() == "true")); } Emotes = new List<Emote>(); if (json.SelectToken("emotes") != null) foreach (JToken emote in json.SelectToken("emotes")) Emotes.Add(new Emote(emote)); Reactions = new List<Reaction>(); if (json.SelectToken("reactions") != null) foreach (JToken reaction in json.SelectToken("reactions")) Reactions.Add(new Reaction(reaction)); if (json.SelectToken("user") != null) User = new User(json.SelectToken("user").ToString()); }