public async Task <ILobby> RequestInstanceAsync(string lobbyId, string username, string password) { var request = _requestFactory.Get("/api/Lobby/" + lobbyId).AddAuthentication(username, password); var response = await request.SendAsync(); return(response.IsSuccessStatusCode ? response.ReadBodyAsType <Lobby>() : null); }
public void RequestInstance_CallsGetWithCorrectPath() { //arrange var uut = new UserProxy(_fakeFactory); _fakeFactory.Get("api/User/Login").Returns(_fakeBuilder); //act var result = uut.RequestInstanceAsync(_userFake.Username, _userFake.Password).Result; //assert _fakeFactory.Received().Get("api/User/Login"); }
public async Task <IGamePlayerInfo> GetPlayerInfoAsync(string username, string password, string gameId) { var request = _requestFactory.Get(_apiPath + gameId) .AddAuthentication(username, password); var response = await request.SendAsync(); return(response.IsSuccessStatusCode ? response.ReadBodyAsType <IGamePlayerInfo>() : null); }
public async Task <IEnumerable <CountryDto> > GetCountries() { var response = await httpRequestFactory.Get($"{apiSettings.CountryApiUrl}/country"); if (response.IsSuccessStatusCode) { return(response.ContentAsType <IEnumerable <CountryDto> >()); } throw new CountriesNotFoundException(); }
public async Task <IEnumerable <TeamSportDto> > GetTeamSports() { var response = await httpRequestFactory.Get($"{apiSettings.SportApiUrl}/teamsports"); if (response.IsSuccessStatusCode) { return(response.ContentAsType <IEnumerable <TeamSportDto> >()); } return(null); }
public static async Task <byte[]> GetBytesAsync(this IHttpRequestFactory httpRequestFactory, string url, TimeoutSpecification timeout = default) { if (url == null) { throw new ArgumentNullException(nameof(url)); } var response = await httpRequestFactory.Get(url.ToUrl()).SendAsync(timeout).ConfigureAwait(false); return(await response.GetBytesAsync().ConfigureAwait(false)); }
public async Task <List <AlbumViewModel> > GetUserAlbums(int userId) { string jsonServiceApiUri = $"{AppSettingsConfiguration.AppSetting("ThirdPartyApiUris:JsonHolderAlbumsUri")}"; var response = await _httpRequestFactory.Get(jsonServiceApiUri); var responseData = response.Content.ReadAsStringAsync().Result; List <AlbumViewModel> albumViewModels = JsonConvert.DeserializeObject <List <AlbumViewModel> >(responseData); List <AlbumViewModel> filteredAlbumViewModels = albumViewModels.Where(a => a.UserId == userId).ToList(); return(filteredAlbumViewModels); }
public async Task <IUser> RequestInstanceAsync(string username, string password) { var request = _httpRequestFactory.Get("api/User/Login").AddAuthentication(username, password); var response = await request.SendAsync(); if (!response.IsSuccessStatusCode) { return(null); } return(response.ReadBodyAsType <User>()); }
public static async Task <byte[]?> TryGetBytesAsync(this IHttpRequestFactory httpRequestFactory, string url, TimeoutSpecification timeout = default) { if (url == null) { throw new ArgumentNullException(nameof(url)); } var response = await httpRequestFactory.Get(url.ToUrl()).SendAsync(timeout, IgnoreNotFoundApiErrors).ConfigureAwait(false); return(response.Status.IsNotFound ? default : await response.GetBytesAsync().ConfigureAwait(false)); }
public async Task <List <PhotoViewModel> > GetUserSpecificAlbumPhotos(int userId) { string jsonServiceApiUri = $"{AppSettingsConfiguration.AppSetting("ThirdPartyApiUris:JsonHolderPhotosUri")}"; var response = await _httpRequestFactory.Get(jsonServiceApiUri); var responseData = response.Content.ReadAsStringAsync().Result; List <PhotoViewModel> photoViewModels = JsonConvert.DeserializeObject <List <PhotoViewModel> >(responseData); List <AlbumViewModel> albumViewModels = await _albumService.GetUserAlbums(userId); var userSpecificAlbums = albumViewModels.Select(s => s.Id).ToArray(); List <PhotoViewModel> filteredPhotoViewModels = photoViewModels.Where(p => userSpecificAlbums.Contains(p.AlbumId)).ToList(); return(filteredPhotoViewModels); }
protected override IHttpRequest MakeRequestForCommonTests(IHttpRequestFactory http) => http.Get("/some-resource");
public async Task <IEnumerable <Application.Competitions.Queries.GetCompetitions.CompetitionDto> > GetCompetitions(GetCompetitionsQuery query) { var response = await httpRequestFactory.Get($"{apiSettings.CompetitionApiUrl}"); if (response.IsSuccessStatusCode) { return(response.ContentAsType <IEnumerable <Application.Competitions.Queries.GetCompetitions.CompetitionDto> >()); } return(new List <Application.Competitions.Queries.GetCompetitions.CompetitionDto>()); }
public static IHttpRequest Get(this IHttpRequestFactory requestFactory, string url) => requestFactory.Get(url.ToUrl());