// GET: SearchResults public async Task <ActionResult> Index(string searchValue) { if (searchValue != null) { RepoResults repoResults = new RepoResults(); // Start the search function repoResults = await search.Start("repositories?q=" + searchValue); return(View(repoResults.items)); } return(RedirectToAction("Index", "Home")); }
public async Task <RepoResults> Start(string searchValue) { client.BaseAddress = new Uri(baseAddress); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue("Matrix_Test", "1.0")); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/vnd.github.mercy-preview+json")); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); HttpResponseMessage response = await client.GetAsync(searchValue); if (response.IsSuccessStatusCode) { repoResults = await response.Content.ReadAsAsync <RepoResults>(); return(repoResults); } return(null); }
public RepoSerarch() { client = new HttpClient(); baseAddress = "https://api.github.com/search/"; repoResults = new RepoResults(); }