コード例 #1
0
ファイル: Program.cs プロジェクト: sttrox/Wallee
 private static async void getImg()
 {
     UnsplasharpClient client = new UnsplasharpClient(
         "93123f0db401f8367e061a60e9b0976b9bc9c3cafe5133f344bba4010c97a4de",
         "ec8401ec0727226a41f9fea4ef184c10f7efef4b009ee910dbf3ca386a");
     await client.SearchPhotos("new");
 }
コード例 #2
0
        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();
        }
コード例 #3
0
ファイル: PhotoTests.cs プロジェクト: rootasjey/unsplasharp
        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);
        }
コード例 #4
0
ファイル: GeneralTests.cs プロジェクト: spboyer/unsplasharp
        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!");
     }
 }
コード例 #6
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);
        }
コード例 #7
0
        public UnSplashDataService(IOptions <ApiSettings> options)
        {
            var accessKey = options.Value.AccessKey ?? ApplicationId;
            var secretKey = options.Value.Secret ?? Secret;

            _client = new UnsplasharpClient(accessKey, secretKey);
        }
コード例 #8
0
ファイル: PhotoTests.cs プロジェクト: rootasjey/unsplasharp
        public async Task NotifyPropertyChangedTest()
        {
            var id     = "TPv9dh822VA";
            var client = new UnsplasharpClient(Credentials.ApplicationId);
            var photo  = await client.GetPhoto(id);

            photo.Downloads = 20000;
        }
コード例 #9
0
        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));
        }
コード例 #10
0
ファイル: GeneralTests.cs プロジェクト: spboyer/unsplasharp
        public async Task GetMonthlyStatsTest()
        {
            var client       = new UnsplasharpClient(Credentials.ApplicationId);
            var monthlyStats = await client.GetMonthlyStats();

            Assert.IsNotNull(monthlyStats);
            Assert.IsTrue(monthlyStats.Views > 0);
        }
コード例 #11
0
ファイル: GeneralTests.cs プロジェクト: spboyer/unsplasharp
        public async Task GetTotalStatsTest()
        {
            var client     = new UnsplasharpClient(Credentials.ApplicationId);
            var totalStats = await client.GetTotalStats();

            Assert.IsNotNull(totalStats);
            Assert.IsTrue(totalStats.Photos > 0);
        }
コード例 #12
0
ファイル: UserTests.cs プロジェクト: rootasjey/unsplasharp
        public async Task ListUserCollectionsTest()
        {
            var username        = "******";
            var client          = new UnsplasharpClient(Credentials.ApplicationId);
            var userCollections = await client.ListUserCollections(username);

            Assert.IsNotNull(userCollections);
        }
コード例 #13
0
ファイル: UserTests.cs プロジェクト: rootasjey/unsplasharp
        public async Task GetUserStatsTest()
        {
            var username  = "******";
            var client    = new UnsplasharpClient(Credentials.ApplicationId);
            var userStats = await client.GetUserStats(username);

            Assert.IsNotNull(userStats);
        }
コード例 #14
0
        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);
        }
コード例 #15
0
ファイル: PhotoTests.cs プロジェクト: rootasjey/unsplasharp
        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);
        }
コード例 #16
0
ファイル: UserTests.cs プロジェクト: rootasjey/unsplasharp
        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);
        }
コード例 #17
0
ファイル: PhotoTests.cs プロジェクト: rootasjey/unsplasharp
        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);
        }
コード例 #18
0
ファイル: UserTests.cs プロジェクト: rootasjey/unsplasharp
        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);
        }
コード例 #19
0
        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);
        }
コード例 #20
0
ファイル: PhotoTests.cs プロジェクト: rootasjey/unsplasharp
        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);
        }
コード例 #21
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);
        }
コード例 #22
0
ファイル: UserTests.cs プロジェクト: rootasjey/unsplasharp
        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);
        }
コード例 #23
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);
        }
コード例 #24
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);
        }
コード例 #25
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);
        }
コード例 #26
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);
            }
        }
コード例 #27
0
ファイル: ImageController.cs プロジェクト: HoodDigital/Hood
        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"));
            }
        }
コード例 #28
0
        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);
            }
        }
コード例 #29
0
ファイル: Program.cs プロジェクト: pinkylab/WallpaperChanger
        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.");
        }
コード例 #30
0
ファイル: PhotoTests.cs プロジェクト: rootasjey/unsplasharp
        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);
        }