예제 #1
0
        /// <summary>Constructor for Subscription</summary>
        public Subscription(string apiResponse)
        {
            JObject json = JObject.Parse(apiResponse);

            CreatedAt        = Convert.ToDateTime(json.SelectToken("created_at").ToString());
            TimeSinceCreated = DateTime.UtcNow - CreatedAt;
            User             = new Models.API.User.User(json.SelectToken("user").ToString());
        }
예제 #2
0
파일: Block.cs 프로젝트: Jeinhaus/TwitchLib
 /// <summary>
 /// Block object constructor.
 /// </summary>
 /// <param name="json"></param>
 public Block(JToken json)
 {
     UpdatedAt       = Common.Helpers.DateTimeStringToObject(json.SelectToken("updated_at")?.ToString());
     TimeSinceUpdate = DateTime.UtcNow - UpdatedAt;
     if (json.SelectToken("user") != null)
     {
         User = new User.User(json.SelectToken("user").ToString());
     }
 }
예제 #3
0
 /// <summary>Follower object constructor.</summary>
 public Follower(JToken followerData)
 {
     CreatedAt        = Common.Helpers.DateTimeStringToObject(followerData.SelectToken("created_at").ToString());
     TimeSinceCreated = DateTime.UtcNow - CreatedAt;
     if (followerData.SelectToken("notifications").ToString() == "true")
     {
         Notifications = true;
     }
     User = new User.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 Models.API.User.User(json.SelectToken("user").ToString());
     }
     if (json.SelectToken("created_at") != null)
     {
         CreatedAt = Common.Helpers.DateTimeStringToObject(json.SelectToken("created_at").ToString());
     }
 }
예제 #5
0
 /// <summary>Comment object constructor.</summary>
 public Comment(JToken json)
 {
     if (json.SelectToken("id") != null)
     {
         Id = int.Parse(json.SelectToken("id").ToString());
     }
     CreatedAt        = Common.Helpers.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.User(json.SelectToken("user").ToString());
     }
 }
예제 #6
0
 /// <summary>Constructor for Subscription (using JToken as param)</summary>
 /// <param name="json"></param>
 public Subscription(JToken json)
 {
     CreatedAt        = Convert.ToDateTime(json.SelectToken("created_at").ToString());
     TimeSinceCreated = DateTime.UtcNow - CreatedAt;
     User             = new Models.API.User.User(json.SelectToken("user").ToString());
 }
예제 #7
0
        /// <summary>Post object constructor</summary>
        public Post(JToken json)
        {
            Id               = json.SelectToken("id")?.ToString();
            CreatedAt        = Common.Helpers.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 Models.API.User.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"));
                }
            }
        }