Ejemplo n.º 1
0
        /// <summary>
        /// Says the message in the specified room.
        /// </summary>
        /// <param name="room">The room.</param>
        /// <param name="message">The message.</param>
        /// <param name="args">The args.</param>
        public void SayHtml(Room room, string message, params object[] args)
        {
            //Say(room, string.Format(message, args), true);

            var credentials = CredentialService.GetCredentials();

            var url  = "https://api.hipchat.com/v1/rooms/message?format=xml&auth_token=" + credentials.ApiToken;
            var body = new Dictionary <string, string>();

            body.Add("room_id", room.Id.ToString());
            body.Add("from", current.Name);
            body.Add("message", string.Format(message, args));

            var client   = new HttpClient();
            var postTask = client.PostAsync(url, new FormUrlEncodedContent(body));

            postTask.ContinueWith(x =>
            {
                if (x.Result.IsSuccessStatusCode)
                {
                    Out.WriteLine("Html Message Sent");
                }
                else
                {
                    Out.WriteLine("Html Message Failed");
                }
            });
        }
Ejemplo n.º 2
0
        public void TestGetCredentials()
        {
            var config = new Config();

            config.SetValue("Credentials", "Name", "Bob");
            config.SetValue("Credentials", "JabberID", "123");
            config.SetValue("Credentials", "Password", "Password");
            config.SetValue("Credentials", "ApiToken", "123456");

            Mock <IConfigService>()
            .Setup(call => call.GetConfig())
            .Returns(config);

            var result = service.GetCredentials();

            Assert.AreEqual("123456", result.ApiToken);
            Assert.AreEqual("123", result.JabberId);
            Assert.AreEqual("Bob", result.Name);
            Assert.AreEqual("Password", result.Password);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Gets all the rooms.
        /// </summary>
        /// <returns></returns>
        public IList <Room> List()
        {
            var rooms = new List <Room>();

            var credentials = CredentialService.GetCredentials();

            var url = "https://api.hipchat.com/v1/rooms/list?format=xml&auth_token=" + credentials.ApiToken;

            var response = HttpService.Get(url);

            if (response.Success)
            {
                var xml = response.ToXml();

                foreach (var node in xml.GetMatches("//room"))
                {
                    var room = new Room();

                    room.Id          = node.GetInnerXml("//room_id").AsInt32();
                    room.Name        = node.GetInnerXml("//name");
                    room.Topic       = node.GetInnerXml("//topic");
                    room.LastActive  = node.GetInnerXml("//last_actice").ToDouble().FromUnixTimestamp();
                    room.Created     = node.GetInnerXml("//created").ToDouble().FromUnixTimestamp();;
                    room.OwnerUserId = node.GetInnerXml("//owner_user_id").AsInt32();
                    room.IsArchived  = node.GetInnerXml("//is_archived") == "1";
                    room.IsPrivate   = node.GetInnerXml("//is_private") == "1";
                    room.JabberId    = node.GetInnerXml("//xmpp_jid");

                    // Strip domain part
                    room.JabberId = room.JabberId.SubstringBeforeChar("@");

                    rooms.Add(room);
                }
            }

            _roomCache = rooms;
            return(rooms);
        }