//renvoie le nombre de favoris de l'utilsateur
        public async Task <int> GetFavoritesCount()
        {
            int count      = 0;
            var client_fav = new ImgurClient(client_id, imgur_token);
            var endpoint   = new AccountEndpoint(client_fav);
            var favourites = await endpoint.GetAccountFavoritesAsync();

            for (int i = 0; i < favourites.Count(); i++)
            {
                if (favourites.ElementAt(i).GetType().ToString() == "Imgur.API.Models.Impl.GalleryImage")
                {
                    count++;
                }
                else if (favourites.ElementAt(i).GetType().ToString() == "Imgur.API.Models.Impl.GalleryAlbum")
                {
                    GalleryAlbum galleryAlbum = (GalleryAlbum)(favourites.ElementAt(i));
                    foreach (var image in galleryAlbum.Images)
                    {
                        count++;
                    }
                }
            }

            return(count);
        }
        //renvoie les images des favoris de l'utilsateur

        /**
         * Return favorite pictures of the user
         */
        public async Task <ImageContainer> createImageContainerFromFavorites()
        {
            ImageContainer imageContainer = new ImageContainer();
            var            client_fav     = new ImgurClient(client_id, imgur_token);
            var            endpoint       = new AccountEndpoint(client_fav);
            var            favourites     = await endpoint.GetAccountFavoritesAsync();

            for (int i = 0; i < favourites.Count(); i++)
            {
                if (favourites.ElementAt(i).GetType().ToString() == "Imgur.API.Models.Impl.GalleryImage")
                {
                    GalleryImage galleryImage = (GalleryImage)(favourites.ElementAt(i));
                    Windows.UI.Xaml.Controls.Image imgImgur = new Windows.UI.Xaml.Controls.Image();
                    imgImgur.Source = new BitmapImage(new Uri(galleryImage.Link, UriKind.Absolute));
                    imgImgur.Name   = galleryImage.Id;
                    imageContainer.AddImageSource(imgImgur);
                }
                else if (favourites.ElementAt(i).GetType().ToString() == "Imgur.API.Models.Impl.GalleryAlbum")
                {
                    GalleryAlbum galleryAlbum = (GalleryAlbum)(favourites.ElementAt(i));
                    Windows.UI.Xaml.Controls.Image imgImgur = new Windows.UI.Xaml.Controls.Image();
                    foreach (var image in galleryAlbum.Images)
                    {
                        imgImgur.Source = new BitmapImage(new Uri(image.Link, UriKind.Absolute));
                        imgImgur.Name   = image.Id;
                        imageContainer.AddImageSource(imgImgur);
                    }
                }
            }

            return(imageContainer);
        }
Пример #3
0
        public async Task GetAccountFavoritesAsync_Any()
        {
            var client   = new ImgurClient(ClientId, ClientSecret, OAuth2Token);
            var endpoint = new AccountEndpoint(client);

            var submissions = await endpoint.GetAccountFavoritesAsync();

            Assert.IsTrue(submissions.Any());
        }
        public async Task GetAccountFavoritesAsync_Any_IsTrue()
        {
            var client   = new MashapeClient(ClientId, ClientSecret, MashapeKey, await GetOAuth2Token());
            var endpoint = new AccountEndpoint(client);

            var favourites = await endpoint.GetAccountFavoritesAsync();

            Assert.IsTrue(favourites.Any());
        }
Пример #5
0
        public static async Task <IEnumerable <IGalleryItem> > GetFav(UserInfo user)
        {
            var client = new ImgurClient("3f8dfa6f3541120", "dcb972ae2f6952efb8e9a156fe0c65b8136b3010");

            client.SetOAuth2Token(user.tokenObject);
            var endpoint = new AccountEndpoint(client);
            var favs     = await endpoint.GetAccountFavoritesAsync();

            return(favs);
        }
Пример #6
0
        public async Task WithOAuth2TokenNull_ThrowsArgumentNullException_GetAccountFavoritesAsync()
        {
            var client   = new ImgurClient("123", "1234");
            var endpoint = new AccountEndpoint(client);

            var exception =
                await
                Record.ExceptionAsync(
                    async() => await endpoint.GetAccountFavoritesAsync().ConfigureAwait(false))
                .ConfigureAwait(false);

            Assert.NotNull(exception);
            Assert.IsType <ArgumentNullException>(exception);
        }
Пример #7
0
        public async Task Any_GetAccountFavoritesAsync()
        {
            const string mockUrl      = "https://api.imgur.com/3/account/me/favorites/2/oldest";
            var          mockResponse = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(MockAccountEndpointResponses.GetAccountFavorites)
            };

            var client    = new ImgurClient("123", "1234", MockOAuth2Token);
            var endpoint  = new AccountEndpoint(client, new HttpClient(new MockHttpMessageHandler(mockUrl, mockResponse)));
            var favorites = await endpoint.GetAccountFavoritesAsync(page : 2, sort : AccountGallerySortOrder.Oldest).ConfigureAwait(false);

            Assert.True(favorites.Any());
        }
        public async Task GetAccountFavoritesAsync_Any()
        {
            var fakeHttpMessageHandler = new FakeHttpMessageHandler();
            var fakeResponse           = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(AccountEndpointResponses.GetAccountFavoritesResponse)
            };

            fakeHttpMessageHandler.AddFakeResponse(new Uri("https://api.imgur.com/3/account/me/favorites"), fakeResponse);

            var fakeOAuth2Handler = new FakeOAuth2TokenHandler();
            var client            = new ImgurClient("123", "1234", fakeOAuth2Handler.GetOAuth2TokenCodeResponse());
            var endpoint          = new AccountEndpoint(client, new HttpClient(fakeHttpMessageHandler));
            var favorites         = await endpoint.GetAccountFavoritesAsync();

            Assert.IsTrue(favorites.Any());
        }
Пример #9
0
        private async Task GetFavoriteImagesAsync(string query)
        {
            var endpoint = new AccountEndpoint(currentUser);
            IEnumerable <IGalleryItem> images = await endpoint.GetAccountFavoritesAsync();

            if (this.images != null)
            {
                this.images.Clear();
            }
            this.images = FilterClass <IGalleryItem> .convertList(query, images.ToList());

            _adapter = new LvImgBinder(this, Resource.Layout.listview_model, this.images, currentUser);
            RunOnUiThread(() =>
            {
                _lv.Adapter    = _adapter;
                _lv.ItemClick += lv_ItemClick;
            });
        }
Пример #10
0
        public async Task getFavorites()
        {
            try
            {
                var client     = new ImgurClient(MainPage._clientId, MainPage.userToken);
                var endpoint   = new AccountEndpoint(client);
                var favourites = await endpoint.GetAccountFavoritesAsync();

                foreach (IGalleryItem img in favourites)
                {
                    var galleryAlbum = img as IGalleryAlbum;
                    if (galleryAlbum != null)
                    {
                        foreach (IImage albumImage in galleryAlbum.Images)
                        {
                            Debug.WriteLine("Album Image: " + albumImage.Link + "   " + albumImage.Id);
                            Uri imageUri = new Uri(albumImage.Link);
                            var newImage = new ClientImage(new BitmapImage(imageUri), albumImage.Id, true);
                            _favouriteList.Add(newImage);
                        }
                    }
                    else
                    {
                        var galleryImage = img as IGalleryImage;
                        Debug.WriteLine("Image: " + galleryImage.Link);
                        Uri imageUri = new Uri(galleryImage.Link);
                        var newImage = new ClientImage(new BitmapImage(imageUri), galleryImage.Id, false);
                        _favouriteList.Add(newImage);
                    }
                }
            }
            catch (ImgurException imgurEx)
            {
                Debug.Write("An error occurred getting an image from Imgur.");
                Debug.Write(imgurEx.Message);
            }
            catch (System.ArgumentNullException e)
            {
                Debug.WriteLine("An error occurred getting an image from Imgur." + e.Message);
            }
        }
 public async Task GetAccountFavoritesAsync_WithOAuth2TokenNull_ThrowsArgumentNullException()
 {
     var client   = new ImgurClient("123", "1234");
     var endpoint = new AccountEndpoint(client);
     await endpoint.GetAccountFavoritesAsync();
 }