public async Task <KFBusinessModel> GetBusinessByCriteria(string term, string location) { KFBusinessModel response = new KFBusinessModel(); try { SearchRequest searchCriteria = new SearchRequest(); searchCriteria.Term = term; searchCriteria.Location = location; BusinessSearchResponse yelpResponse = await _client.SearchBusinessesAllAsync(searchCriteria); if (yelpResponse?.Error != null) { _logger?.Log($"Response error returned {yelpResponse?.Error?.Code} - {yelpResponse?.Error?.Description}"); } else { //response. //todo: map yelpResponse to response } } catch (System.Exception e) { _logger?.Log(e.ToString()); } return(response); }
//public void Dispose() //{ // this.Client.Dispose(); // this.Client = null; //} //GET /// <summary> /// Gets data from the specified URL. /// </summary> /// <typeparam name="T">Type for the strongly typed class representing data returned from the URL.</typeparam> /// <param name="url">URL to retrieve data from.</param>should be deserialized.</param> /// <param name="retryCount">Number of retry attempts if a call fails. Default is zero.</param> /// <param name="serializerType">Specifies how the data should be deserialized.</param> /// <returns>Instance of the type specified representing the data returned from the URL.</returns> /// <summary> protected async Task <T> GetAsync <T>(string url, CancellationToken ct) { if (string.IsNullOrEmpty(url)) { throw new ArgumentNullException(nameof(url)); } var response = await this.Client.GetAsync(BuildUri(url), ct); _logger?.Log(response); var data = await response.Content.ReadAsStringAsync(); var settings = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore, MissingMemberHandling = MissingMemberHandling.Ignore }; var jsonModel = JsonConvert.DeserializeObject <T>(data, settings); return(jsonModel); }
public async Task <string> GetAreaName(double latitude, double longitude) { try { ReverseGeocodingRequest request = new ReverseGeocodingRequest(Credentials.API_KEY_GOOGLE, latitude, longitude, "administrative_area_level_2"); ReverseGeocodingResponse response = await _client.ReverseGeocoding(request); if (response.status == "OK" && response.results.Count > 0) { return(response.results.First().formatted_address); } } catch (System.Exception e) { _logger?.Log(e.ToString()); } return(string.Empty); }