internal async Task <YelpSearchResult> GetResults(YelpAPIContext context, YelpSearch search) { var authToken = context.YelpAuthToken.OrderByDescending(a => a.expire_date).SingleOrDefault(); var client = new HttpClient(); //creat the query search string var queryString = Uri.EscapeUriString(String.Format($"?term={search.Term}&location={search.Location}", search.Term, search.Location)); // created the complete url for which the Http Post will be used client.BaseAddress = new System.UriBuilder(baseUrl + searchUri + queryString).Uri; // clean up headers for API call operations client.DefaultRequestHeaders.Accept.Clear(); // name = [value] Post data in the Http header - Adding to the the Authorization to header client.DefaultRequestHeaders.Add("Authorization", authToken.token_type + " " + Uri.EscapeDataString(authToken.access_token)); //Posting the content created to the URL var response = await client.GetAsync(client.BaseAddress); // The Response returns from yelp var responseString = await response.Content.ReadAsStringAsync(); // Take the response string and convert to the json var searchResult = JsonConvert.DeserializeObject <YelpSearchResult>(responseString); return(searchResult); }
public YelpAuthTokensController(YelpAPIContext context) { _context = context; }
public SearchController(IOptions <Models.ConfigurationKeys> appKeys, YelpAPIContext context) { AppKeys = appKeys.Value; _context = context; }