Ejemplo n.º 1
0
        public async Task TestImgur()
        {
            string      error       = null;
            Image       urlImage    = null;
            Image       streamImage = null;
            CreateAlbum album       = null;

            try
            {
                urlImage = await imgur.UploadImageAnonymous("https://github.com/fluidicon.png", "name", "title", "description");

                using (Stream ms = ResourceRetriever.GetStream("images/vs-icon.png"))
                {
                    streamImage = await imgur.UploadImageAnonymous(ms, "name", "title", "description");
                }

                bool updated = await imgur.UpdateImageAnonymous(streamImage.Deletehash, "updated title", "a new description");

                //Album
                album = await imgur.CreateAlbumAnonymous(new string[] { streamImage.Deletehash }, "album title", "album description", AlbumPrivacy.Public, AlbumLayout.Horizontal, streamImage.Id);

                bool result = await imgur.UpdateAlbumAnonymous(album.DeleteHash, new string[] { streamImage.Deletehash, urlImage.Deletehash }, "updated album title", "update album description", AlbumPrivacy.Hidden, AlbumLayout.Blog, streamImage.Id);

                bool addImagesResult = await imgur.AddImagesToAlbumAnonymous(album.DeleteHash, new string[] { streamImage.Deletehash, urlImage.Deletehash });

                bool removeImagesResult = await imgur.RemoveImagesFromAlbumAnonymous(album.DeleteHash, new string[] { urlImage.Id });
            }
            catch (Exception e)
            {
                error = e.Message;
            }
            finally
            {
                if (urlImage != null)
                {
                    await imgur.DeleteImageAnonymous(urlImage.Deletehash);
                }

                if (streamImage != null)
                {
                    await imgur.DeleteImageAnonymous(streamImage.Deletehash);
                }

                if (album != null)
                {
                    await imgur.DeleteAlbumAnonymous(album.DeleteHash);
                }
            }

            Assert.IsNull(error, error);
        }
Ejemplo n.º 2
0
        private static async void UploadImage()
        {
            try
            {
                //Image
                ImgurImage urlImage = await imgur.UploadImageAnonymous("https://assets-cdn.github.com/images/modules/logos_page/GitHub-Mark.png", "name", "title", "description");

                byte[]       buff = File.ReadAllBytes("vs-icon.png");
                MemoryStream ms   = new MemoryStream(buff);

                ImgurImage streamImage = await imgur.UploadImageAnonymous(ms, "name", "title", "description");

                bool updated = await imgur.UpdateImageAnonymous(streamImage.Deletehash, "updated title", "a new description");

                ImgurImage getImage = await imgur.GetImage(streamImage.Id);

                //Album
                ImgurCreateAlbum createdAlbum = await imgur.CreateAlbumAnonymous(new string[] { streamImage.Id }, "album title", "album description", ImgurAlbumPrivacy.Public, ImgurAlbumLayout.Horizontal, streamImage.Id);

                bool result = await imgur.UpdateAlbumAnonymous(createdAlbum.DeleteHash, new string[] { streamImage.Id, urlImage.Id }, "updated album title", "update album description", ImgurAlbumPrivacy.Hidden, ImgurAlbumLayout.Blog, urlImage.Id);

                bool addImagesResult = await imgur.AddImagesToAlbumAnonymous(createdAlbum.DeleteHash, new string[] { streamImage.Id, urlImage.Id });

                bool removeImagesResult = await imgur.RemoveImagesFromAlbumAnonymous(createdAlbum.DeleteHash, new string[] { urlImage.Id });

                ImgurAlbum album = await imgur.GetAlbum(createdAlbum.Id);



                //Delete
                bool deleteAlbum = await imgur.DeleteAlbumAnonymous(createdAlbum.DeleteHash);

                bool deletedUrlImage = await imgur.DeleteImageAnonymous(urlImage.Deletehash);

                bool deletedStreamImage = await imgur.DeleteImageAnonymous(streamImage.Deletehash);
            }
            catch (Exception e)
            {
                System.Console.Write(e.Message);
            }
        }
Ejemplo n.º 3
0
        public async Task TestDeleteImage()
        {
            var mockHttp = new MockHttpMessageHandler();

            mockHttp.When(HttpMethod.Post, baseUrl + "image/some-delete-hash")
            .Respond(HttpStatusCode.OK, MediaTypeNames.Application.Json,
                     ResourceRetriever.GetJsonString("responses/delete-image-ok.json"));

            imgur = new Imgur(apiKey, mockHttp);

            bool success = await imgur.DeleteImageAnonymous("some-delete-hash");

            Assert.IsTrue(success);
        }