示例#1
0
        public void CanUpdateUser()
        {
            var request = new UpdateUserRequest() {Email = UserEmail, Name = UserName, MentionName = "NumberOne",
                                                   Title = "President"};
            var result = _client.UpdateUser(UserEmail, request);

            Assert.True(result);

            var userInfo = _client.GetUserInfo(UserEmail);
            Assert.Equal(request.Title, userInfo.Title);
        }
示例#2
0
        public bool UpdateUser(string idOrEmail, UpdateUserRequest request)
        {
            using (JsonSerializerConfigScope())
            {
                var result = false;
                if (string.IsNullOrEmpty(idOrEmail))
                {
                    throw new ArgumentOutOfRangeException("idOrEmail", "Valid id, email address, or mention name (beginning with an '@') of the user required.");
                }
                if (string.IsNullOrEmpty(request.Name) || request.Name.Length > 50)
                {
                    throw new ArgumentOutOfRangeException("name", "Valid length range: 1 - 50.");
                }
                if (string.IsNullOrEmpty(request.Email))
                {
                    throw new ArgumentOutOfRangeException("email", "Valid email of the user required.");
                }

                try
                {
                    HipchatEndpoints.UpdateUserEndpointFormat
                    .Fmt(idOrEmail)
                    .AddHipchatAuthentication(_authToken)
                    .PutJsonToUrl(data:request, responseFilter: resp =>
                    {
                        if (resp.StatusCode == HttpStatusCode.NoContent)
                            result = true;
                    });
                }
                catch (Exception exception)
                {
                    Console.WriteLine(exception.Message);
                    if (exception is WebException)
                        throw ExceptionHelpers.WebExceptionHelper(exception as WebException, "admin_group");

                    throw ExceptionHelpers.GeneralExceptionHelper(exception, "UpdateUser");
                }

                return result;
            }
        }