private static async void getImg() { UnsplasharpClient client = new UnsplasharpClient( "93123f0db401f8367e061a60e9b0976b9bc9c3cafe5133f344bba4010c97a4de", "ec8401ec0727226a41f9fea4ef184c10f7efef4b009ee910dbf3ca386a"); await client.SearchPhotos("new"); }
private async Task SearchImagesTask() { var client = new UnsplasharpClient(_apiToken); List <Photo> photosFound = null; if (!string.IsNullOrEmpty(_collectionId)) { photosFound = await client.GetCollectionPhotos(_collectionId, 1, _maxResultCount); } else { photosFound = await client.SearchPhotos(_searchQuery, 1, _maxResultCount); } _photos = photosFound; Log.Debug($"got {photosFound.Count} images from Unsplash"); _urls.Clear(); foreach (var p in photosFound) { _urls.Add(p.Urls.Regular); } ResultList.Value = _urls; _photoIndex = -1; ResultList.DirtyFlag.Invalidate(); }
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 async Task RateLimitTest() { var client = new UnsplasharpClient(Credentials.ApplicationId); var photosFound = await client.GetRandomPhoto(); Assert.IsTrue(client.RateLimitRemaining < client.MaxRateLimit); }
private void EnsureRateLimit(UnsplasharpClient client) { if (client.RateLimitRemaining == 0) { throw new Exception("Rate limit!"); } }
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 UnSplashDataService(IOptions <ApiSettings> options) { var accessKey = options.Value.AccessKey ?? ApplicationId; var secretKey = options.Value.Secret ?? Secret; _client = new UnsplasharpClient(accessKey, secretKey); }
public async Task NotifyPropertyChangedTest() { var id = "TPv9dh822VA"; var client = new UnsplasharpClient(Credentials.ApplicationId); var photo = await client.GetPhoto(id); photo.Downloads = 20000; }
public UnsplashService(IConfigurationRoot configurationRoot, IMapper mapper) { var accessKey = configurationRoot.GetSection("unsplash:AccessKey").Value ?? ApplicationId; var secretKey = configurationRoot.GetSection("unsplash:SecretKey").Value ?? Secret; _client = new UnsplasharpClient(accessKey, secretKey); _mapper = mapper ?? throw new ArgumentNullException(nameof(mapper)); }
public async Task GetMonthlyStatsTest() { var client = new UnsplasharpClient(Credentials.ApplicationId); var monthlyStats = await client.GetMonthlyStats(); Assert.IsNotNull(monthlyStats); Assert.IsTrue(monthlyStats.Views > 0); }
public async Task GetTotalStatsTest() { var client = new UnsplasharpClient(Credentials.ApplicationId); var totalStats = await client.GetTotalStats(); Assert.IsNotNull(totalStats); Assert.IsTrue(totalStats.Photos > 0); }
public async Task ListUserCollectionsTest() { var username = "******"; var client = new UnsplasharpClient(Credentials.ApplicationId); var userCollections = await client.ListUserCollections(username); Assert.IsNotNull(userCollections); }
public async Task GetUserStatsTest() { var username = "******"; var client = new UnsplasharpClient(Credentials.ApplicationId); var userStats = await client.GetUserStats(username); Assert.IsNotNull(userStats); }
public async Task GetCollectionTest() { var client = new UnsplasharpClient(Credentials.ApplicationId); var listCollection = await client.ListCollections(); var collection = await client.GetCollection(listCollection[0].Id); Assert.IsNotNull(collection); }
public async Task GetPhotoStatsTest() { var client = new UnsplasharpClient(Credentials.ApplicationId); var listPhotos = await client.ListPhotos(); var statsPhoto = await client.GetPhotoStats(listPhotos[0].Id); Assert.IsNotNull(statsPhoto); }
public async Task ListUserLikedPhotosTest() { var username = "******"; var client = new UnsplasharpClient(Credentials.ApplicationId); var userLikedPhotos = await client.ListUserLikedPhotos(username); Assert.IsNotNull(userLikedPhotos); Assert.IsTrue(userLikedPhotos.Count > 0); }
public async Task GetPhotoDownloadLinkTest() { var client = new UnsplasharpClient(Credentials.ApplicationId); var listPhotos = await client.ListPhotos(); var downloadLink = await client.GetPhotoDownloadLink(listPhotos[0].Id); Assert.IsNotNull(downloadLink); }
public async Task GetUserTest() { var username = "******"; var client = new UnsplasharpClient(Credentials.ApplicationId); var user = await client.GetUser(username); var userCustomProfileImage = client.GetUser("seteales", width: 100, height: 100); Assert.IsNotNull(user); }
public async Task ListCuratedPhotosTest() { var client = new UnsplasharpClient(Credentials.ApplicationId); var listCuratedPhotos = await client.ListCuratedPhotos(); var listCuratedPhotosPaged = await client.ListCuratedPhotos(2); Assert.IsTrue(listCuratedPhotos.Count > 0); Assert.IsTrue(listCuratedPhotosPaged.Count > 0); }
public async Task ListPhotosTest() { var client = new UnsplasharpClient(Credentials.ApplicationId); var listPhotos = await client.ListPhotos(); var listPhotosPaged = await client.ListPhotos(page : 2, perPage : 15, orderBy : OrderBy.Popular); Assert.IsTrue(listPhotos.Count > 0); Assert.IsTrue(listPhotosPaged.Count > 0); }
public async Task ListRelatedCollectionsTest() { var client = new UnsplasharpClient(Credentials.ApplicationId); var listCollection = await client.ListCollections(); var collectionsRelated = await client.ListRelatedCollections(listCollection[0].Id); Assert.IsNotNull(collectionsRelated); Assert.IsTrue(collectionsRelated.Count > 0); }
public async Task ListUserPhotosTest() { var username = "******"; var client = new UnsplasharpClient(Credentials.ApplicationId); var userPhotos = await client.ListUserPhotos(username, perPage : 40); var userPhotosCustomParam = await client.ListUserPhotos(username, page : 2, perPage : 2, stats : true); Assert.IsNotNull(userPhotos); Assert.IsTrue(userPhotos.Count > 0); }
public async Task GetCollectionPhotosTest() { var client = new UnsplasharpClient(Credentials.ApplicationId); var listCollection = await client.ListCollections(); var collection = await client.GetCollection(listCollection[0].Id); var listPhotos = await client.GetCollectionPhotos(collection.Id); Assert.IsNotNull(listPhotos); Assert.IsTrue(listPhotos.Count > 0); }
public async Task ListCuratedCollectionsTest() { var client = new UnsplasharpClient(Credentials.ApplicationId); var listCuratedCollection = await client.ListCuratedCollections(); var listCuratedCollectionPaged = await client.ListCuratedCollections(2); Assert.IsNotNull(listCuratedCollection); Assert.IsNotNull(listCuratedCollectionPaged); Assert.IsTrue(listCuratedCollection.Count > 0); Assert.IsTrue(listCuratedCollectionPaged.Count > 0); }
public async Task SearchPhotosTest() { var query = "mountains"; var client = new UnsplasharpClient(Credentials.ApplicationId); var photosFound = await client.SearchPhotos(query); var photosFoundPaged = await client.SearchPhotos(query, 2); Assert.IsTrue(photosFound.Count > 0); Assert.IsTrue(photosFoundPaged.Count > 0); Assert.IsNotNull(client.LastPhotosSearchQuery); Assert.IsTrue(client.LastPhotosSearchTotalPages > 0); Assert.IsTrue(client.LastPhotosSearchTotalResults > 0); }
public async Task GetPhotos() { PhotosList.Clear(); var client = new UnsplasharpClient(App.ServiceId); var photosList = await client.GetCollectionPhotos(collectionId); foreach (var photo in photosList) { var newPhoto = new Photo { Url = photo.Urls.Regular, Likes = photo.Likes }; PhotosList.Add(newPhoto); } }
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")); } }
public async Task LoadCollection() { FeaturedList.Clear(); var client = new UnsplasharpClient(App.ServiceId); var listFeaturedCollection = await client.ListFeaturedCollections(); foreach (var collection in listFeaturedCollection) { var newCollection = new CollectionModel { CollectionId = collection.Id, Title = collection.Title, Url = collection.CoverPhoto.Urls.Small, Description = collection.Description, Likes = collection.CoverPhoto.Likes }; FeaturedList.Add(newCollection); } }
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."); }
public async Task GetPhotoTest() { //var id = "TPv9dh822VA"; var id = "qcs09SwNPHY"; var client = new UnsplasharpClient(Credentials.ApplicationId); var photo = await client.GetPhoto(id); // Custom size var photoWidth = await client.GetPhoto(id, width : 400); var photoWidthHeight = await client.GetPhoto(id, width : 500, height : 500); // Custom size + cropped var photoCropped = await client.GetPhoto(id, 600, 600, 10, 10, 100, 100); Assert.IsNotNull(photo); Assert.IsNotNull(photoWidth); Assert.IsNotNull(photoWidthHeight); Assert.IsNotNull(photoCropped); Assert.IsNotNull(photoWidth.Urls.Custom); Assert.IsNotNull(photoWidthHeight.Urls.Custom); Assert.IsNotNull(photoCropped.Urls.Custom); }