public async Task <FullContactResponse> Enrichment(string country, string query)
        {
            _httpClient.BaseAddress = new Uri(enrichApiUrl);
            _httpClient.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", _bingEntitySearchConfiguration.ApiKey);

            string market = MarketByCountry(country.Trim().ToLower());

            if (string.IsNullOrEmpty(market))
            {
                return(FullContactResponse.CountryNotSupported());
            }

            string marketQuery = $"?mkt={market}";

            string queryUri = entityApiUrl + marketQuery + "&q=" + System.Net.WebUtility.UrlEncode(query);

            var response = await _httpClient.GetAsync(queryUri);

            if (response.IsSuccessStatusCode)
            {
                var rawResponse = await response.Content.ReadAsStringAsync();

                RawEnrichment rawEnrichment = JsonConvert.DeserializeObject <RawEnrichment>(rawResponse);
                return(FullContactResponse.CreateNew(rawEnrichment));
            }
            else if (response.StatusCode == System.Net.HttpStatusCode.NotFound)
            {
                return(FullContactResponse.NotFound());
            }
            else
            {
                return(FullContactResponse.Error(response.ToString()));
            }
        }
Exemple #2
0
 public static FullContactResponse CreateNew(RawEnrichment rawEnrichment)
 {
     return(new FullContactResponse(rawEnrichment, FullContactResponseStatus.DataFound));
 }
Exemple #3
0
 protected FullContactResponse(RawEnrichment rawEnrichment, FullContactResponseStatus status)
 {
     Enrichment = rawEnrichment;
     Status     = status;
 }