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}; } }
public void DeserializeModel() { ResultCode resultCode; ResultCode.TryParse(Data["code"], out resultCode); ErrorModel = new ErrorModel() { ErrorResult = resultCode, Message = Data["message"], ErrorType = Data["type"] }; }
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; }
public HipChatException(ErrorModel errorModel, Exception innerException) : base(String.Format("HipChat Error -- Type:[{0}] Message:[{1}]", errorModel.ErrorType, errorModel.Message, innerException)) { Error = errorModel; }