コード例 #1
0
        public void AlbumCRUD()
        {
            string albumTitle       = "K1tt3ns!";
            string descriptor       = "An album created to talk about cats";
            string albumTitleUpdate = "dogsarecool";
            string albumDescUpdate  = "album desc update";


            // grab some images (from another album) to use in our test album
            List <ImgurImage> listOfImages = new List <ImgurImage>(ImgurApiSource.Instance.AlbumImagesAsync(testAlbum).Result);

            // create the album
            ImgurAlbum album = ImgurApiSource.Instance.AlbumCreationAsync(listOfImages, listOfImages[0], albumTitle, descriptor, Privacy.ignore, Layout.ignore).Result;

            Assert.AreEqual(album.Title, albumTitle);
            Assert.AreEqual(album.Description, descriptor);
            Assert.AreEqual(album.ImagesInAlbum, listOfImages.Count);

            // update information
            List <string> stringList    = new List <string>();
            ImgurBasic    responseBasic = ImgurApiSource.Instance.AlbumUpdateAsync(album.deletehash, stringList, null, albumTitleUpdate, albumDescUpdate, Privacy.hidden, Layout.blog).Result;

            Assert.IsTrue(responseBasic.success);

            // destroy
            ImgurBasic deleteResponse = ImgurApiSource.Instance.AlbumDeletionAsync(album.deletehash).Result;

            Assert.IsTrue(deleteResponse.success);
        }
コード例 #2
0
        public void DeleteUploadedImageByDeleteHash()
        {
            ImgurImage test = ImgurApiSource.Instance.PostImageAnonymousAsync(ImageBytes, "Hello", "DescriptionTest").Result;

            System.Threading.SpinWait.SpinUntil(() => 0 == 1, TimeSpan.FromSeconds(4));

            Assert.IsNotNull(test.Deletehash);

            ImgurBasic result = ImgurApiSource.Instance.DeleteImageAsync(test.Deletehash).Result;

            Assert.IsTrue(result.success);
        }
コード例 #3
0
 public void RemoveImages()
 {
     // Cleanup any images we might have uploaded to Imgur during testing
     foreach (ImgurImage i in imagesToDelete)
     {
         ImgurBasic result = ImgurApiSource.Instance.DeleteImageAsync(i.Deletehash).Result;
         if (!result.success)
         {
             throw new Exception("Unable to delete uploaded test images");
         }
     }
 }
コード例 #4
0
        /// <summary>
        /// Updates the title or description of an image. You can only update an image you own and is associated with your account. For an anonymous image, {id} must be the image's deletehash.
        /// </summary>
        /// <param name="deleteHashOrImageID">The deletehash or ID of an image (ID ONLY WORKS IF LOGGED IN!)</param>
        /// <param name="Title">The title of the image.</param>
        /// <param name="Description">The description of the image.</param>
        /// <returns></returns>
        public async Task <ImgurBasic> ImageUpdateAsync(String deleteHashOrImageID, String Title = "", String Description = "")
        {
            MultipartFormDataContent content = new MultipartFormDataContent(BoundaryGuid.ToString());

            if (Title != "")
            {
                content.Add(new StringContent(Title), ImgurEndpoints.ImageEndpointParameterLookup[ImgurParameters.title]);
            }
            if (Description != "")
            {
                content.Add(new StringContent(Description), ImgurEndpoints.ImageEndpointParameterLookup[ImgurParameters.description]);
            }
            String responseString = await PostAnonymousImgurDataAsync(ImgurEndpoints.ImageUpdate(deleteHashOrImageID), content);

            ImgurBasic status = await Task.Run(() => JsonConvert.DeserializeObject <ImgurBasic>(responseString, _defaultSerializerSettings));

            return(status);
        }
コード例 #5
0
        public void UpdateImageByDeleteHash()
        {
            ImgurImage test = ImgurApiSource.Instance.ImageUploadAsync(ImageBytes, "Hello", "DescriptionTest").Result;

            // pause for 4 seconds while the server updates
            System.Threading.SpinWait.SpinUntil(() => 0 == 1, TimeSpan.FromSeconds(4));

            Assert.IsNotNull(test.Deletehash);

            ImgurBasic result = ImgurApiSource.Instance.ImageUpdateAsync(test.Deletehash, "NewTitle", "NewDescription").Result;

            // pause for 4 more seconds while the server updates
            System.Threading.SpinWait.SpinUntil(() => 0 == 1, TimeSpan.FromSeconds(4));

            ImgurImage image = ImgurApiSource.Instance.ImageDetailsAsync(test.ID).Result;

            Assert.AreEqual(image.Title, "NewTitle");
            Assert.AreEqual(image.Description, "NewDescription");
        }
コード例 #6
0
        /// <summary>
        /// Update the information of an album. For anonymous albums, {album} should be the deletehash that is returned at creation.
        /// </summary>
        /// <param name="albumID">The album ID (only if logged in) or deletehash of the album to update</param>
        /// <param name="imageIDs">The image ids that you want to be included in the album.</param>
        /// <param name="coverImageId">The id of the image you want to set as the cover.</param>
        /// <param name="title"> The title of the album </param>
        /// <param name="description">The description of the album</param>
        /// <param name="albumPrivacy">Sets the privacy level of the album. Values are : public | hidden | secret. Defaults to user's privacy settings for logged in users.</param>
        /// <param name="albumLayout">Sets the layout to display the album. Values are : blog | grid | horizontal | vertical</param>
        /// <returns></returns>
        public async Task <ImgurBasic> AlbumUpdateAsync(string albumID, List <string> imageIDs = null, string coverImageId = "", String title = "", String description = "", Privacy albumPrivacy = Privacy.ignore, Layout albumLayout = Layout.ignore)
        {
            if (albumID == null)
            {
                throw new ArgumentNullException("albumID");
            }

            MultipartFormDataContent content = new MultipartFormDataContent(BoundaryGuid.ToString());

            if (imageIDs.Count != 0 || imageIDs == null)
            {
                string serializedImageList = await Task.Run(() => JsonConvert.SerializeObject(imageIDs));

                content.Add(new StringContent(serializedImageList), ImgurEndpoints.ImageEndpointParameterLookup[ImgurParameters.ids]);
            }
            if (coverImageId != String.Empty && coverImageId != null && coverImageId != "")
            {
                content.Add(new StringContent(coverImageId), ImgurEndpoints.ImageEndpointParameterLookup[ImgurParameters.cover]);
            }
            if (title != "")
            {
                content.Add(new StringContent(title), ImgurEndpoints.ImageEndpointParameterLookup[ImgurParameters.title]);
            }
            if (description != "")
            {
                content.Add(new StringContent(title), ImgurEndpoints.ImageEndpointParameterLookup[ImgurParameters.description]);
            }
            if (albumPrivacy != Privacy.ignore)
            {
                content.Add(new StringContent(Utilities.convertToString(albumPrivacy)), ImgurEndpoints.ImageEndpointParameterLookup[ImgurParameters.privacy]);
            }
            if (albumLayout != Layout.ignore)
            {
                content.Add(new StringContent(Utilities.convertToString(albumLayout)), ImgurEndpoints.ImageEndpointParameterLookup[ImgurParameters.layout]);
            }
            String responseString = await PostAnonymousImgurDataAsync(ImgurEndpoints.AlbumUpdate(albumID), content);

            ImgurBasic status = await Task.Run(() => JsonConvert.DeserializeObject <ImgurBasic>(responseString, _defaultSerializerSettings));

            return(status);
        }