public async Task LoginAsync(ICommand command, BattleshipsData data) { using (var httpClient = new HttpClient()) { var bodyData = new FormUrlEncodedContent(new[] { new KeyValuePair<string, string>("Username", command.Parameters[0]), new KeyValuePair<string, string>("Password", command.Parameters[1]), new KeyValuePair<string, string>("grant_type", "password"), }); var response = await httpClient.PostAsync(RestEndpoints.LoginEndpoint, bodyData); string result; if (!response.IsSuccessStatusCode) { result = await response.Content.ReadAsStringAsync(); } else { var accessToken = (await response.Content.ReadAsAsync<LoginDTO>()).Access_Token; data.LogUser(accessToken); result = string.Format(Messages.LogedInMessage, command.Parameters[0]); } this.UserInterface.WriteLine(result); } }
public BattleshipsEngine(CommandExecutor commandExecutor, IUserInterface userInterface, BattleshipsData data) { this.commandExecutor = commandExecutor; this.userInterface = userInterface; this.data = data; }