Пример #1
0
        public User(string host, int userId, IAuthenticationProvider auth = null)
        {
            host.ThrowIfNullOrEmpty(nameof(host));

            host = host.GetChatHost();

            var url = string.Format(userProfilePath, host, userId);
            GetWithStatusResult result = null;

            if (auth == null)
            {
                result = HttpRequest.GetWithStatusAsync(url).Result;
            }
            else
            {
                result = HttpRequest.GetWithStatusAsync(url, auth[host]).Result;
            }

            if (result.Status != System.Net.HttpStatusCode.OK)
            {
                throw new Exception($"Unable to find user {userId} on {host}.");
            }

            var dom = new HtmlParser().ParseDocument(result.Body);

            Host             = host;
            Id               = userId;
            Username         = GetUsername(dom, out var isMod);
            IsModerator      = isMod;
            AccountCreatedOn = GetAccountCreated(dom);
            About            = GetBio(dom);
            Reputation       = GetReputation(dom);
            MessageStats     = GetMessageStats(dom);
            AllTimeMessages  = GetAllTimeMessages(dom);
            AllTimeRooms     = GetAllTimeRooms(dom);
            Owns             = GetOwnedRooms(dom);
            CurrentlyIn      = GetCurrentlyInRooms(dom);
        }
Пример #2
0
        public Room(string host, int roomId, IAuthenticationProvider auth = null)
        {
            host.ThrowIfNullOrEmpty(nameof(host));

            host = host.GetChatHost();

            var url = string.Format(roomProfilePath, host, roomId);
            GetWithStatusResult result = null;

            if (auth == null)
            {
                result = HttpRequest.GetWithStatusAsync(url).Result;
            }
            else
            {
                result = HttpRequest.GetWithStatusAsync(url, auth[host]).Result;
            }

            if (result.Status != System.Net.HttpStatusCode.OK)
            {
                throw new Exception($"Unable to find room {roomId} on {host}.");
            }

            var dom = new HtmlParser().ParseDocument(result.Body);

            Host         = host;
            Id           = roomId;
            Name         = GetName(dom);
            States       = GetStates(dom);
            Description  = GetDescription(dom);
            Tags         = GetTags(dom);
            FirstMessage = GetFirstMessage(dom);
            MessageStats = GetMessageStats(dom);
            Owners       = GetOwners(dom);
            CurrentUsers = GetCurrentUsers(dom);
        }