public async Task GetRandomPhotoTest() { var client = new UnsplasharpClient(Credentials.ApplicationId); var randomPhoto = await client.GetRandomPhoto(); var randomPhotoFromCollection = await client.GetRandomPhoto("499830"); var randomPhotoFromCollections = await client.GetRandomPhoto(new string[] { "499830", "194162" }); var randomPhotoFromUser = await client.GetRandomPhoto(1, username : "******"); var randomPhotosFromQuery = await client.GetRandomPhoto(count : 3, query : "woman"); var randomPhotoFeatured = await client.GetRandomPhoto(featured : true); var randomPortraitPhoto = await client.GetRandomPhoto(Orientation.Portrait); var randomPortraitPhotoFeatured = await client.GetRandomPhoto(Orientation.Portrait, featured : true); Assert.IsNotNull(randomPhoto); Assert.IsNotNull(randomPhotoFromCollection); Assert.IsNotNull(randomPhotoFromCollections); Assert.IsTrue(randomPhotoFromUser.Count > 0); Assert.IsTrue(randomPhotosFromQuery.Count > 0); Assert.IsTrue(randomPhotoFeatured.Count > 0); Assert.IsTrue(randomPortraitPhoto.Count > 0); Assert.IsTrue(randomPortraitPhotoFeatured.Count > 0); }
public static async System.Threading.Tasks.Task <Photo> GeneratePhotoAsync(params string[] searchTerms) { string terms = string.Empty; if (searchTerms != null) { foreach (var term in searchTerms) { terms += term; terms += ","; } terms = terms.Substring(0, terms.Length - 1); } var client = new UnsplasharpClient(App.ServiceId); var photos = await client.GetRandomPhoto(UnsplasharpClient.Orientation.Landscape, false, query : terms); if (photos.Count > 0) { var first = photos.FirstOrDefault(); if (first != null) { var photo = new Photo { Url = first.Urls.Regular, Title = first.Description, Likes = first.Likes }; return(photo); } } return(null); }
public async Task RateLimitTest() { var client = new UnsplasharpClient(Credentials.ApplicationId); var photosFound = await client.GetRandomPhoto(); Assert.IsTrue(client.RateLimitRemaining < client.MaxRateLimit); }
private async void SetWallpaper() { Random rand = new Random(); if (lstKeywords[0] == "NO") { MetroFramework.MetroMessageBox.Show(this, "Couldn't fetch Wallpaper please input at least one Keyword and press [Save Keywords]!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); lstKeywords.Clear(); } else { try { var indexRand = rand.Next(0, lstKeywords.Count - 1); var photo = await client.GetRandomPhoto(count : 1, query : lstKeywords[indexRand]); pictureBox1.ImageLocation = photo[0].Links.Download; DownloadWallpaper.Download(filePathPics, photo[0].Links.Download); Wallpaper.SetWallpaper(filePathPics + "ImageToday.jpg"); }catch (Exception ex) { MessageBox.Show(ex.ToString()); //MetroFramework.MetroMessageBox.Show(this, "Please input at least one Keyword and press [Save Keywords]!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private async void GetRandomPhotos() { EnableControls(false); _mainPageCounter = 1; _photos.Clear(); _photos = await _client.GetRandomPhoto(4); DisplayPhotos(); }
public virtual async Task <IActionResult> BackgroundImage(string query) { try { if (Engine.Settings.Integrations.UnsplashAccessKey.IsSet()) { var client = new UnsplasharpClient(Engine.Settings.Integrations.UnsplashAccessKey); var photosFound = await client.GetRandomPhoto(UnsplasharpClient.Orientation.Squarish, query : query); return(Json(photosFound)); } else { return(Content(Engine.Settings.Basic.LoginAreaSettings.BackgroundImages.Split(Environment.NewLine).PickRandom())); } } catch { return(Content("https://source.unsplash.com/random")); } }
static void Main(string[] args) { string apikey = ""; if (args.Length == 0) { Console.WriteLine("Please set Unsplash API Key in first arg."); return; } else { apikey = args[0]; } var client = new UnsplasharpClient(apikey); Unsplasharp.Models.Photo randomPhoto = null; string imagePath = ""; Task task = Task.Factory.StartNew(async() => { randomPhoto = await client.GetRandomPhoto(); }).Unwrap(); task.Wait(); // %TEMP%に保存 // imagePath = Path.GetTempPath() + randomPhoto.Id + ".jpg"; // jpg決め打ちでいいのかな・・・ WebClient wc = new WebClient(); wc.DownloadFile(randomPhoto.Links.Download, imagePath); Wallpaper.SetWallpaper(imagePath, WallpaperStyle.ResizeFill); // Wallpaper.UnsetWallpaper(); Console.WriteLine("Set Wallpaper."); }