예제 #1
0
        public NewUser CreateUser(string email, string name, string title, string is_group_admin = "0")
        {
            var connection = _factory.Create(ActionKey.CreateUser);

            var actionParms = new Dictionary<string, string>
                                  {
                                      {"email", email},
                                      {"name", name},
                                      {"title", title},
                                      {"is_group_admin", is_group_admin}
                                  };

            try
            {
                var response = ExecuteCall(connection, actionParms);
                var deserializer = new JsonModelDeserializer<JsonUserModel>();
                var model = deserializer.Deserialize(response.ResponseString);

                model.DeserializeModel();
                return model.User;
            }

            catch (WebException ex)
            {
                LastError = GetError(connection);
                return new NewUser() {UserId = null};
            }
        }
예제 #2
0
        public HipChatDeleteResponse DeleteUser(string userId)
        {
            var _connection = _factory.Create(ActionKey.DeleteUser);
            var actionParms = new Dictionary<string, string>
                                  {
                                      {"user_id", userId}
                                  };

            try
            {
                var response = ExecuteCall(_connection, actionParms);
                var deserializer = new JsonModelDeserializer<HipChatDeleteResponse>();
                var model = deserializer.Deserialize(response.ResponseString);
                return model;
            }

            catch(WebException ex)
            {
                var model = new HipChatDeleteResponse() {WasDeleted = false};
                return model;
            }
        }
예제 #3
0
        private IList<RoomMessage> GetRoomHistory(string roomid, string rangeSpecification)
        {
            var actionParms = new Dictionary<string, string>() { { "room_id", roomid }, { "date", rangeSpecification } };
            var connection = _factory.Create(ActionKey.GetRoomHistory, actionParms);
            var response = ExecuteCall(connection, actionParms);

            var deserializer = new JsonModelDeserializer<JsonRoomHistoryModel>();
            var model = deserializer.Deserialize(response.ResponseString);
            model.DeserializeModel();

            foreach (var message in model.Model)
            {
                message.MessageType = RoomMessageTypeIdentifier.GetMessageType(message);
            }
            return model.Model;
        }
예제 #4
0
        private ErrorModel GetError(HipChatConnection _connection)
        {
            ResultCode resultCode;

            Enum.TryParse(_connection.ResponseCode, out resultCode);
            LastError = null;

            if (_connection.ErrorStream != null)
            {
                var responseString = new StreamReader(_connection.ErrorStream).ReadToEnd();
                var deserializer = new JsonModelDeserializer<JsonErrorModel>();

                var model = deserializer.Deserialize(responseString);
                model.DeserializeModel();

                LastError = model.ErrorModel;
            }

            return LastError;
        }
예제 #5
0
        public HipChatStatus MessageRoom(string roomId, string from, string message, MessageFormat format = MessageFormat.Html)
        {
            var connection = _factory.Create(ActionKey.MessageRoom);

            var actionParms = new Dictionary<string, string>
                                  {
                                      {"room_id", roomId},
                                      {"from", from},
                                      {"message", message},
                                      {"message_format", format.ToString()}
                                  };

            var response = ExecuteCall(connection, actionParms);

            var deserializer = new JsonModelDeserializer<HipChatStatus>();

            var model = deserializer.Deserialize(response.ResponseString);

            return model;
        }
예제 #6
0
        public IList<User> GetUserList()
        {
            var connection = _factory.Create(ActionKey.ListUsers);

            var response = ExecuteCall(connection, null);

            var deserializer = new JsonModelDeserializer <JsonUsersModel>();

            var model = deserializer.Deserialize(response.ResponseString);
            model.DeserializeModel();

            return model.Model;
        }
예제 #7
0
        public User GetUser(String userId)
        {
            var actionParms = new Dictionary<string, string>
                                  {
                                      {"user_id", userId}
                                  };

            var _connection = _factory.Create(ActionKey.ShowUser, actionParms);

            try
            {
                var response = ExecuteCall(_connection, actionParms);

                var deserializer = new JsonModelDeserializer<JsonUserModel>();

                var model = deserializer.Deserialize(response.ResponseString);
                model.DeserializeModel();

                return model.User;
            }

            catch (WebException ex)
            {
                //var model = new HipChatDeleteResponse() { WasDeleted = false };
                return null;
            }
        }
예제 #8
0
        public RoomDetail GetRoomInfo(string roomId)
        {
            var actionParms = new Dictionary<string, string>() { { "room_id", roomId } };

            var connection = _factory.Create(ActionKey.ShowRoom,actionParms);

            var response = ExecuteCall(connection, actionParms);

            var deserializer = new JsonModelDeserializer<JsonRoomDetailModel>();
            var model = deserializer.Deserialize(response.ResponseString);
            model.DeserializeModel();

            return model.RoomInfo;
        }