private void ValidateRequest(PageFetcherRequest request) { if (request.SearchKeywords.Contains("/")) { throw new ArgumentException("SearchKeywords can not contain the character '/'"); } }
/// <summary> /// A simple function that takes a string and does a ToUpper /// </summary> /// <param name="request">Information for the page request to be fetched</param> public async Task <PageFetcherResponse> PageFetcherHandler(PageFetcherRequest request) { //validate inputs, throw argument exception and terminate function if failed ValidateRequest(request); int?sequence = await ResolveSequence(request.SearchEngineType, request.SearchKeywords); //if none found than we fetch the first sequence if (sequence == null) { return new PageFetcherResponse { Success = true, Message = $"Max sequence/paging has been achieved for the search of {request.SearchKeywords}" } } ; string resolvedTargetRoute = ResolveRoute(request.SearchEngineType, request.SearchKeywords, sequence.Value); //fetch the html content of the target url string html = await FetchHtml(resolvedTargetRoute); //store it on storage string fileName = PathGenerator.GenerateStoragePath(request.SearchEngineType, request.SearchKeywords, DateTime.Now, sequence.Value); StorageClientUploadResponse uploadResponse = await StoreHtmlToStorage(fileName, html); return(new PageFetcherResponse { Success = true, FilePath = fileName }); }
public async Task <IActionResult> Fetch([FromQuery] PageFetcherRequest request) { PageFetcherResponse response = await _pageFetcher.PageFetcherHandler(request); if (response.Success) { return(Ok()); } else { return(BadRequest()); } }