Exemple #1
0
        public async Task <IterationApiResponse> Get(string projectId, string teamId, string iterationId)
        {
            var url =
                $"DefaultCollection/{projectId}/{teamId}/_apis/work/TeamSettings/Iterations/{iterationId}?api-version=3.0";

            return(await _apiClient.Get <IterationApiResponse>(url, CacheDuration.Medium));
        }
        /// <summary>
        /// Get the desired translation
        ///     Configure via appsetting
        /// </summary>
        /// <param name="text">Text to be translated</param>
        /// <returns>Translated text</returns>
        public async Task <Translation> GetTranslationAsync(string text)
        {
            try
            {
                _logger.LogDebug("Calling {methodName}, Getting translation for {text}", nameof(GetTranslationAsync), text);

                TranslationQueryParams queryParams = new TranslationQueryParams
                {
                    Query = text
                };

                Translation response = await _client.Get(_appSettings.TranslationApi.Type, queryParams);

                _logger.LogInformation("Translation Successful, Returning data");

                return(response);
            }
            catch (ValidationApiException validationApiException)
            {
                _logger.LogError(validationApiException, "HttpRequestException occurred while calling translation api - {code} {Details}", (int)validationApiException.StatusCode, validationApiException.Message);
                return(GetErrorResponse((int)validationApiException.StatusCode, validationApiException?.Message));
            }
            catch (ApiException exception)
            {
                _logger.LogError(exception, "Exception occurred while calling translation api - {code} {Details}", (int)exception.StatusCode, exception.Message);
                return(GetErrorResponse((int)exception.StatusCode, "Api Error"));
            }
        }
Exemple #3
0
        /// <summary>
        /// Get pokemon species details - only place which some kind of description
        ///   {pokeApi}/pokemon-species/{pokemonName}/
        /// Extract Flavor text by language - configured via AppSetting
        /// </summary>
        /// <param name="pokemonName">Pokemon name or yours, if you are one.</param>
        /// <returns>Pokemon Details with error, if any</returns>
        public async Task <PokemonDetails> GetPokemonDetailsAsync(string pokemonName)
        {
            try
            {
                _logger.LogDebug("Calling {methodName}, Getting details for {pokemon}", nameof(GetPokemonDetailsAsync), pokemonName);

                PokemonSpecies species = await _client.Get($"{_appSettings.PokeApi.Key}/{pokemonName.ToLower()}", new PokemonQueryParams());

                if (!(species is null) && species.FlavorTextEntries?.Count > 0)
                {
                    _logger.LogInformation("{methodName} called successfully, returned species data", nameof(GetPokemonDetailsAsync));

                    PokemonSpeciesFlavorTexts flavorTexts = species.FlavorTextEntries.Where(x => x.Language.Name == _appSettings.PokeApi.DefaultLanguage).FirstOrDefault();

                    if (flavorTexts is null || string.IsNullOrEmpty(flavorTexts?.FlavorText))
                    {
                        _logger.LogError("Error in {methodName} - Empty Flavor text for language {lang}", nameof(GetPokemonDetailsAsync), _appSettings.PokeApi.DefaultLanguage);
                        return(GetErrorResponse(StatusCodes.Status500InternalServerError, "API Response Error"));
                    }

                    return(new PokemonDetails
                    {
                        Name = species.Name,
                        Description = flavorTexts.FlavorText.Trim().Replace('\n', ' ')
                    });
                }
                else
                {
                    _logger.LogError("Error in {methodName} - Null/Empty response from PokeAPI", nameof(GetPokemonDetailsAsync));
                    return(GetErrorResponse(StatusCodes.Status500InternalServerError, "API Response Error"));
                }
            }
Exemple #4
0
 public void ShouldThrowExceptionForInvalidUrl()
 {
     Assert.Throws <AggregateException>(() => _sut.Get("https://invalid-url"));
 }
Exemple #5
0
        public IList <Country> GetCountries()
        {
            var apiResponse = _restClient.Get(_url);

            return(MapJsonContentToCountries(apiResponse));
        }
        public async Task <TeamApiResponse> Get(string projectId, string teamId)
        {
            var url = $"/DefaultCollection/_apis/projects/{projectId}/teams/{teamId}?api-version=3.0";

            return(await _apiClient.Get <TeamApiResponse>(url, CacheDuration.Medium));
        }
        public async Task <GitBranchListApiResponse> GetBranchList(string repositoryId)
        {
            var url = $"DefaultCollection/_apis/git/repositories/{repositoryId}/refs/heads";

            return(await _apiClient.Get <GitBranchListApiResponse>(url, CacheDuration.Long));
        }
Exemple #8
0
        public async Task <QueryListApiResponse> GetList(string projectId)
        {
            var url = $"/DefaultCollection/{projectId}/_apis/wit/queries/?api-version=3.0&$expand=wiql&$depth=2";

            return(await _apiClient.Get <QueryListApiResponse>(url, CacheDuration.Short));
        }
        public async Task <ProjectApiResponse> Get(string projectId)
        {
            var url = $"DefaultCollection/_apis/projects/{projectId}?api-version=3.0";

            return(await _apiClient.Get <ProjectApiResponse>(url, CacheDuration.Long));
        }
        public async Task <WorkBoardListApiResponse> GetBoardList(string projectId, string teamId)
        {
            var url = $"DefaultCollection/{projectId}/{teamId}/_apis/work/boards?api-version=3.0";

            return(await _apiClient.Get <WorkBoardListApiResponse>(url, CacheDuration.Long));
        }