public async Task <bool> SaveLocationPhoto(string location) { var client = new Unsplash.Client(_config["Keys:Unsplash"]); var request = new SearchPhotosRequest(location, null, 1, Sort.RELEVANT, null, null, Orientation.LANDSCAPE); var result = await client.SearchPhotosAsync(request); if (result.results.Count == 0) { return(false); } var photo = result.results[0].urls.small; if (photo == null) { return(false); } using (var webClient = new WebClient()) { var localPath = Path.Combine(_config["FileStorage:LocationPath"], location.ToLower() + ".jpg"); webClient.DownloadFile(photo, localPath); } return(true); }
public void SearchPhotosRequest_ArgumentsQueryWithoutAWhitespace_ProducesAnExpectedURI() { var query = "ab"; uint page = 1; uint perPage = 5; var sort = Sort.LATEST; var collections = new[] { "1", "2" }; var color = ColorFilter.GREEN; var orientation = Orientation.SQUARISH; var request = new SearchPhotosRequest(query, page, perPage, sort, collections, color, orientation); Assert.Matches($"&query={query}" + $"&page={page}" + $"&per_page={perPage}" + $"&order_by={sort.Describe()}" + $"&collections={collections.Join()}" + $"&color={color.Describe()}" + $"&orientation={orientation.Describe()}", request.Uri.AbsoluteUri); }
public async Task <Photos.SearchResults> SearchPhotosAsync(string query) { string encoded = WebUtility.UrlEncode(query); var uri = new SearchPhotosRequest(encoded).Uri; HttpResponseMessage response = await netClient.GetAsync(uri).ConfigureAwait(false); return(await ParseResponseAsync <Photos.SearchResults>(response).ConfigureAwait(false)); }
public async Task <Photos.SearchResults> SearchPhotosAsync(SearchPhotosRequest request) { if (request == null) { throw new ArgumentNullException(nameof(request)); } HttpResponseMessage response = await netClient.GetAsync(request.Uri).ConfigureAwait(false); return(await ParseResponseAsync <Photos.SearchResults>(response).ConfigureAwait(false)); }