Пример #1
0
        public static void SendToRoom(string message, string roomname, string token)
        {
            try
            {
                HipchatClient          client = new HipchatClient(token);
                HipchatGetRoomResponse room   = client.GetRoom(roomname);

                if (room != null)
                {
                    if (message.Contains("KILL"))
                    {
                        client.SendNotification(room.Id, message, RoomColors.Green, true, HipchatMessageFormat.Text);
                    }
                    else if (message.Contains("LOSS"))
                    {
                        client.SendNotification(room.Id, message, RoomColors.Red, true, HipchatMessageFormat.Text);
                    }
                    else
                    {
                        client.SendNotification(room.Id, message, RoomColors.Random, true, HipchatMessageFormat.Text);
                    }
                }
            }
            catch (Exception ex)
            {
            }
        }
Пример #2
0
 public void Init(string authToken)
 {
     _credential = new IntegrationCredential {
         AuthToken = authToken
     };
     _client = new HipchatClient(authToken);
 }
Пример #3
0
        public void CanGetAllUsers()
        {
            var client = new HipchatClient();

            var users = client.GetAllUsers();

            Assert.NotNull(users);
        }
Пример #4
0
        public void CanGetEmoticonByKnownShortcut()
        {
            var client             = new HipchatClient();
            var emoticonByShortcut = client.GetEmoticon("allthethings");

            Assert.True(emoticonByShortcut.Height > 0);
            Assert.True(emoticonByShortcut.Width > 0);
        }
Пример #5
0
        public void CanGetAllEmoticons()
        {
            var client = new HipchatClient();

            var emoticons = client.GetAllEmoticons();

            Assert.Equal(100, emoticons.Items.Count);
        }
Пример #6
0
        public void CanGetUserInfo()
        {
            var userId = 42494;
            var client = new HipchatClient();

            var userInfo = client.GetUserInfo(userId);

            Assert.NotNull(userInfo);
        }
Пример #7
0
        public GetAllWebhooksTests()
        {
            HipchatApiConfig.AuthToken = TestsConfig.AuthToken;
            _client = new HipchatClient();

            var room = _client.CreateRoom("Test Webhooks Room");

            _existingRoomId = room.Id;
        }
Пример #8
0
        public void CanCreateRoom()
        {
            IHipchatClient client = new HipchatClient();

            var result = client.CreateRoom(RoomName);

            Assert.NotNull(result);
            Assert.NotNull(result.Links);
            Assert.NotNull(result.Links.Self);
        }
Пример #9
0
        public GetRoomTests()
        {
            const string roomName = "Test GetRooms";

            HipchatApiConfig.AuthToken = TestsConfig.AuthToken;
            _client = new HipchatClient();
            var room = TestHelpers.GetARoomId(_client, roomName);

            _existingRoomId   = room;
            _existingRoomName = "Test GetRooms";
        }
Пример #10
0
        public void CanDeleteRoom()
        {
            const string testRoomName = "Delete Me";
            var          client       = new HipchatClient();

            client.CreateRoom(testRoomName);

            var result = client.DeleteRoom(testRoomName);

            Assert.True(result);
        }
Пример #11
0
        public void CanGetEmoticonByShortcut()
        {
            var client             = new HipchatClient();
            var emoticons          = client.GetAllEmoticons();
            var firstEmoticon      = emoticons.Items[0];
            var emoticonByShortcut = client.GetEmoticon(firstEmoticon.Shortcut);

            Assert.Equal(firstEmoticon.Shortcut, emoticonByShortcut.Shortcut);
            Assert.True(emoticonByShortcut.Height > 0);
            Assert.True(emoticonByShortcut.Width > 0);
        }
Пример #12
0
        public void CanGetEmoticonById()
        {
            var client        = new HipchatClient();
            var emoticons     = client.GetAllEmoticons();
            var firstEmoticon = emoticons.Items[0];
            var emoticonById  = client.GetEmoticon(firstEmoticon.Id);

            Assert.Equal(firstEmoticon.Id, emoticonById.Id);
            Assert.True(emoticonById.Height > 0);
            Assert.True(emoticonById.Width > 0);
        }
Пример #13
0
        public UpdateRoomTests()
        {
            HipchatApiConfig.AuthToken = TestsConfig.AuthToken;
            _client = new HipchatClient();
            var room = _client.CreateRoom("TestUpdateRoom");

            _createdRoomId = room.Id;

            var getRoomResponse = _client.GetRoom(_createdRoomId);

            _owner = getRoomResponse.Owner;
        }
Пример #14
0
        private static void Main()
        {
            HipchatClient hipchatClient = new HipchatClient("1KoQTmxVnWZDcHObCfPKKKvMnR9msOlX4Wn54fJG");

            var r = hipchatClient.SendNotification(2259497, new SendRoomNotificationRequest
            {
                MessageFormat = HipchatMessageFormat.Text,
                Message       = "Hello :) (yey)",
                Color         = RoomColors.Green,
                Notify        = true
            });
        }
Пример #15
0
        public GetRoomTests()
        {
            const string roomName = "Test GetRooms";

            HipchatApiConfig.AuthToken = TestsConfig.AuthToken;
            _client = new HipchatClient();

            var room = _client.CreateRoom(roomName);

            _existingRoomId   = room.Id;
            _existingRoomName = "Test GetRooms";
        }
Пример #16
0
        //[Fact]
        public void GenerateAuthTokenWithUsernameAndPassword()
        {
            //insert your username and password here
            const string username = "";
            const string password = "";

            var client = new HipchatClient("YourToken");

            var token = client.GenerateToken(GrantType.Password, Enumerable.Empty <TokenScope>(),
                                             username, password: password);

            Assert.NotNull(token);
        }
Пример #17
0
        public static List <string> GetAllUsers(string token)
        {
            HipchatClient client             = new HipchatClient(token);
            HipchatGetAllUsersResponse users = client.GetAllUsers();
            List <string> UserNames          = new List <string>();

            foreach (HipchatUser user in users.Items)
            {
                UserNames.Add(user.Name);
            }

            return(UserNames);
        }
Пример #18
0
        public static List <string> GetAllRooms(string token)
        {
            HipchatClient client             = new HipchatClient(token);
            HipchatGetAllRoomsResponse rooms = client.GetAllRooms();
            List <string> RoomNames          = new List <string>();

            foreach (HipchatGetAllRoomsResponseItems room in rooms.Items)
            {
                RoomNames.Add(room.Name);
            }

            return(RoomNames);
        }
Пример #19
0
        public static void CreateUser(string token, string name, string email, string title, string password)
        {
            HipchatClient client = new HipchatClient(token);

            HipchatApiV2.Requests.CreateUserRequest request = new HipchatApiV2.Requests.CreateUserRequest();
            request.Name        = name;
            request.MentionName = name.Replace(" ", "");
            request.Title       = title;
            request.Email       = email;
            request.Password    = password;

            HipchatCreateUserResponse response = client.CreateUser(request);
        }
Пример #20
0
 public static int GetARoomId(HipchatClient client, string roomName)
 {
     try
     {
         var room = client.GetRoom(roomName);
         return(room.Id);
     }
     catch (HipchatRoomNotFoundException)
     {
         var room = client.CreateRoom(roomName);
         return(room.Id);
     }
 }
Пример #21
0
        public void GenerateTokenExample()
        {
            var client = new HipchatClient();

            var token = client.GenerateToken(GrantType.ClientCredentials,
                                             new List <TokenScope>
            {
                TokenScope.SendNotification,
            },
                                             "", /*Auth Id*/
                                             "" /*Auth Secret*/);

            Assert.NotNull(token);
        }
Пример #22
0
        public void CanCreateRoom()
        {
            var client = new HipchatClient();

            try
            {
                client.PrivateMessageUser("*****@*****.**", "test message");
            }
            catch
            {
                // they removed does not throw, i don't know better way how to fail an assert
                Assert.True(false);
            }
        }
Пример #23
0
        public ViewRecentRoomHistoryTests()
        {
            const string roomName = "Test ViewRecentRoomHistory";

            HipchatApiConfig.AuthToken = TestsConfig.AuthToken;
            _client = new HipchatClient();

            _existingRoomId   = TestHelpers.GetARoomId(_client, roomName);
            _existingRoomName = roomName;

            // Add notifications to history
            _client.SendNotification(_existingRoomId, "First entry to history");
            _client.ShareFileWithRoom(_existingRoomId.ToString(), @"..\..\Data\RUv8sSn.png", "Second entry to history with file");
        }
Пример #24
0
    public void Handle(MessageFailed message)
    {
        var failedMessageId  = message.FailedMessageId;
        var exceptionMessage = message.FailureDetails.Exception.Message;

        var chatMessage = string.Format("Message with id: {0} failed with reason: '{1}'. Open in ServiceInsight: {2}",
                                        failedMessageId,
                                        exceptionMessage,
                                        GetServiceInsightUri(failedMessageId));

        using (var client = new HipchatClient())
        {
            client.PostChatMessage(chatMessage);
        }
    }
Пример #25
0
        //[Fact]
        public void GenerateAuthToken()
        {
            //insert your authId and auth Secret here
            const string authId     = "";
            const string authSecret = "";

            var client = new HipchatClient();

            var token = client.GenerateToken(GrantType.ClientCredentials,
                                             new List <TokenScope> {
                TokenScope.SendNotification
            }, authId, authSecret);

            Assert.NotNull(token);
        }
        private bool SendHipchatNotification(string body)
        {
            var client = new HipchatClient(_configuration.ApiKey);

            var roomColor = (RoomColors)Enum.Parse(typeof(RoomColors), _configuration.NotificationColor, true);

            var sendMessageResult = client.SendNotification(_configuration.RoomName, body, roomColor, true, HipchatMessageFormat.Text);

            if (!sendMessageResult)
            {
                throw new ApplicationException(string.Format("Could not send notification to room {0}", _configuration.RoomName));
            }

            return(true);
        }
Пример #27
0
        public GetAllWebhooksTests()
        {
            HipchatApiConfig.AuthToken = TestsConfig.AuthToken;
            _client = new HipchatClient();


            try
            {
                var existingRoom = _client.GetRoom("Test Webhooks Room");
                _existingRoomId = existingRoom.Id;
            }
            catch (Exception)
            {
                var room = _client.CreateRoom("Test Webhooks Room");
                _existingRoomId = room.Id;
            }
        }
Пример #28
0
        public UpdateUserTests()
        {
            HipchatApiConfig.AuthToken = TestsConfig.AuthToken;
            _client = new HipchatClient();

            try
            {
                _client.GetUserInfo(UserEmail);
            }
            catch (Exception)
            {
                _client.CreateUser(new CreateUserRequest()
                {
                    Email = UserEmail, Name = UserName
                });
            }
        }
        public HipchatUser GetUser(string userName)
        {
            string authToken = ConfigurationManager.AppSettings["AuthTokens.Admin"];

            try
            {
                HipchatClient client   = new HipchatClient(authToken);
                var           response = client.GetUserInfo(userName);

                return(new HipchatUser()
                {
                    Id = response.Id, MentionName = response.MentionName, Name = response.Name
                });
            }
            catch
            {
                return(null);
            }
        }
Пример #30
0
        public static void SendPM(string message, string username, string token)
        {
            try
            {
                HipchatClient client             = new HipchatClient(token);
                HipchatGetAllUsersResponse users = client.GetAllUsers();

                foreach (HipchatUser user in users.Items)
                {
                    if (user.Name == username)
                    {
                        client.PrivateMessageUser(user.Id.ToString(), message, true, HipchatMessageFormat.Text);
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
            }
        }