Exemplo n.º 1
0
        public static async Task <IAlbum> CreateAlbumAsync(string name, string description = null)
        {
            var endpoint = new AlbumEndpoint(Client);
            var album    = await endpoint.CreateAlbumAsync(name, description);

            return(album);
        }
Exemplo n.º 2
0
        public APIResult TestImgur()
        {
            var client = new ImgurClient("2f3ed3db83e866d", "62a894b5e1dd5ed77cc5b4f10eea25e3ebc3e816"
                                         , new OAuth2Token("654c446bd2f20543284db4a2d986ea234d81b98b"
                                                           , "e3100d2d2fc8b14e9131dc1aad5b9a24ca8ee22c"
                                                           , "bearer"
                                                           , "132433023"
                                                           , "frankimg"
                                                           , 315360000));
            var    endpoint      = new ImageEndpoint(client);
            var    endpointAlbum = new AlbumEndpoint(client);
            IImage image;
            bool   success = false;

            //取得圖片檔案FileStream
            using (var fs = new FileStream(@"D:\Documents\build_school\project\finalProject1\SurvivalGameVer2\SurvivalGame\Assets\images\Product1.png", FileMode.Open))
            {
                image   = endpoint.UploadImageStreamAsync(fs).GetAwaiter().GetResult();
                success = endpointAlbum.AddAlbumImagesAsync("ZeSZMYK", new List <string>()
                {
                    image.Id
                }).GetAwaiter().GetResult();
            }

            return(new APIResult()
            {
                IsSuccess = true,
                //顯示圖檔位置
                Data = $"Image uploaded.Image Url:  + {image.Link} ,ImgId:{image.Id} ,success: {success}"
            });
        }
Exemplo n.º 3
0
        public static async Task <IAlbum> GetAlbumAsync(string id)
        {
            var endpoint = new AlbumEndpoint(Client);
            var album    = await endpoint.GetAlbumAsync(id);

            return(album);
        }
        public async Task GetAlbumImageAsync_AreEqual()
        {
            var fakeHttpMessageHandler = new FakeHttpMessageHandler();
            var fakeResponse           = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(AlbumEndpointResponses.Imgur.GetAlbumImageResponse)
            };

            fakeHttpMessageHandler.AddFakeResponse(new Uri("https://api.imgur.com/3/album/5F5Cy/image/79MH23L"),
                                                   fakeResponse);

            var client   = new ImgurClient("123", "1234");
            var endpoint = new AlbumEndpoint(client, new HttpClient(fakeHttpMessageHandler));
            var image    = await endpoint.GetAlbumImageAsync("5F5Cy", "79MH23L");

            Assert.IsNotNull(image);

            Assert.AreEqual("79MH23L", image.Id);
            Assert.AreEqual(null, image.Title);
            Assert.AreEqual(null, image.Description);
            Assert.AreEqual(image.DateTime, new DateTimeOffset(new DateTime(2015, 11, 3, 23, 03, 03, DateTimeKind.Utc)));
            Assert.AreEqual("image/png", image.Type);
            Assert.AreEqual(false, image.Animated);
            Assert.AreEqual(609, image.Width);
            Assert.AreEqual(738, image.Height);
            Assert.AreEqual(451530, image.Size);
            Assert.AreEqual(2849, image.Views);
            Assert.AreEqual(1286408970, image.Bandwidth);
            Assert.AreEqual(null, image.Vote);
            Assert.AreEqual(false, image.Favorite);
            Assert.AreEqual(null, image.Nsfw);
            Assert.AreEqual(null, image.Section);
            Assert.AreEqual("http://i.imgur.com/79MH23L.png", image.Link);
        }
        public async Task CreateAlbumAsync_IsNotNull()
        {
            var client   = new MashapeClient(ClientId, ClientSecret, MashapeKey, OAuth2Token);
            var endpoint = new AlbumEndpoint(client);

            var album = await endpoint.CreateAlbumAsync(
                "TheTitle", "TheDescription",
                AlbumPrivacy.Hidden, AlbumLayout.Grid,
                "uH3kfZP", new List <string> {
                "uH3kfZP", "VzbrLbO"
            });

            Assert.IsNotNull(album);
            Assert.IsNotNull(album.Id);
            Assert.IsNotNull(album.DeleteHash);

            await GetAlbumAsync_WithAlbum_AreEqual(album);
            await GetAlbumImageAsync_WithAlbum_AreEqual(album);
            await GetAlbumImagesAsync_WithAlbum_AreEqual(album);
            await UpdateAlbumAsync_WithAlbum_AreEqual(album);
            await AddAlbumImagesAsync_WithAlbum_AreEqual(album);
            await RemoveAlbumImagesAsync_WithAlbum_AreEqual(album);
            await SetAlbumImagesAsync_WithAlbum_AreEqual(album);
            await FavoriteAlbumAsync_WithImage_IsTrue(album);
            await FavoriteAlbumAsync_WithImage_IsFalse(album);
            await DeleteAlbumAsync_WithImage_IsTrue(album);
        }
Exemplo n.º 6
0
        public async Task TestAddImagesToAlbum()
        {
            var imgurClient = await AuthenticationHelpers.CreateOAuth2AuthenticatedImgurClient();

            var albumEndpoint = new AlbumEndpoint(imgurClient);
            var imageEndpoint = new ImageEndpoint(imgurClient);

            var filePath     = VariousFunctions.GetTestsAssetDirectory() + @"\upload-image-example.jpg";
            var imageBinary  = File.ReadAllBytes(filePath);
            var createdAlbum = await albumEndpoint.CreateAlbumAsync();

            await
            albumEndpoint.AddImageToAlbumAsync(createdAlbum.Data.Id,
                                               (await imageEndpoint.UploadImageFromBinaryAsync(imageBinary)).Data.Id);

            var updatedAlbum = await albumEndpoint.GetAlbumDetailsAsync(createdAlbum.Data.Id);

            // Assert the Reponse
            Assert.IsNotNull(updatedAlbum.Data);
            Assert.AreEqual(updatedAlbum.Success, true);
            Assert.AreEqual(updatedAlbum.Status, HttpStatusCode.OK);

            // Assert the data
            Assert.AreEqual(createdAlbum.Data.ImagesCount + 1, updatedAlbum.Data.ImagesCount);
        }
Exemplo n.º 7
0
        public void ImgurSetup()
        {
            string imgID  = Karuta.REGISTY.GetString("imgur_id");
            string imgSec = Karuta.REGISTY.GetString("imgur_secret");

            if (string.IsNullOrWhiteSpace(imgID) || string.IsNullOrWhiteSpace(imgSec))
            {
                Karuta.Write("Please enter Imgur API information:");
                imgID  = Karuta.GetInput("Imgur API ID");
                imgSec = Karuta.GetInput("Imgur API Sec");
            }
            Karuta.LOGGER.Log("Connecting to imgur...", _appName);
            try
            {
                _imgurClient  = new ImgurClient(imgID, imgSec);
                albumEndpoint = new AlbumEndpoint(_imgurClient);
            }
            catch (Exception e)
            {
                Karuta.Write("Failed to connect");
                Karuta.Write(e.Message);
                _imgurClient = null;
            }

            Karuta.REGISTY.SetValue("imgur_id", imgID);
            Karuta.REGISTY.SetValue("imgur_secret", imgSec);
        }
Exemplo n.º 8
0
        public async Task TestCreateAlbum()
        {
            var imgurClient = await AuthenticationHelpers.CreateOAuth2AuthenticatedImgurClient();

            var albumEndpoint = new AlbumEndpoint(imgurClient);
            var imageEndpoint = new ImageEndpoint(imgurClient);

            var filePath    = VariousFunctions.GetTestsAssetDirectory() + @"\upload-image-example.jpg";
            var imageBinary = File.ReadAllBytes(filePath);

            var title       = String.Format("dicks-{0}", new Random().Next(100, 1337));
            var description = String.Format("black dicks, yo-{0}", new Random().Next(100, 1337));

            var uploadedImages = new List <Image>();

            for (var i = 0; i < 2; i++)
            {
                uploadedImages.Add((await imageEndpoint.UploadImageFromBinaryAsync(imageBinary)).Data);
            }
            var createdAlbum = await albumEndpoint.CreateAlbumAsync(uploadedImages.ToArray(), uploadedImages[0], title, description);

            // Assert the Reponse
            Assert.IsNotNull(createdAlbum.Data);
            Assert.AreEqual(createdAlbum.Success, true);
            Assert.AreEqual(createdAlbum.Status, HttpStatusCode.OK);

            // Assert the data
            Assert.AreEqual(createdAlbum.Data.Title, title);
            Assert.AreEqual(createdAlbum.Data.Description, description);
        }
Exemplo n.º 9
0
        public void ImgurSetup()
        {
            string imgID  = REGISTY.GetString("imgur_id");
            string imgSec = REGISTY.GetString("imgur_secret");

            if (string.IsNullOrWhiteSpace(imgID) || string.IsNullOrWhiteSpace(imgSec))
            {
                Write("Please enter Imgur API information:");
                imgID  = GetInput("Imgur API ID");
                imgSec = GetInput("Imgur API Sec");
            }
            Write("Connecting to imgur... ", false);
            try
            {
                _imgurClient  = new ImgurClient(imgID, imgSec);
                albumEndpoint = new AlbumEndpoint(_imgurClient);
            }
            catch (Exception e)
            {
                Write("Failed!");
                Write(e.Message);
                _imgurClient = null;
            }
            Write("Done!");
            REGISTY.SetValue("imgur_id", imgID);
            REGISTY.SetValue("imgur_secret", imgSec);
        }
 public async Task FavoriteAlbumAsync_WithIdNull_ThrowsArgumentNullException()
 {
     var fakeOAuth2Handler = new FakeOAuth2TokenHandler();
     var client            = new ImgurClient("123", "1234", fakeOAuth2Handler.GetOAuth2TokenCodeResponse());
     var endpoint          = new AlbumEndpoint(client);
     await endpoint.FavoriteAlbumAsync(null);
 }
Exemplo n.º 11
0
        //Gets imgur album to random featured image
        private async Task GetAlbum()
        {
            canRandomImage = true;
            try
            {
                string albumURL = currentEventInfo[5];
                string albumID  = albumURL.Substring(albumURL.IndexOf("/a/") + 3);
                var    client   = new ImgurClient(_dataServices.imgurAPI);
                var    endpoint = new AlbumEndpoint(client);

                featureAlbum = await endpoint.GetAlbumAsync(albumID);

                string foundImages = null;

                foreach (var i in featureAlbum.Images)
                {
                    foundImages += $"{i.Link}\n";
                }

                await _dataServices.ChannelLog("Getting Imgur Info from IMGUR API", $"Album URL: {albumURL}" +
                                               $"\nAlbum ID: {albumID}" +
                                               $"\nClient Credits Remaining: {client.RateLimit.ClientRemaining} of {client.RateLimit.ClientLimit}" +
                                               $"\nImages Found: {foundImages}");
            }
            catch
            {
                await _dataServices.ChannelLog($"Unable to get Imgur Album for Random Image for {currentEventInfo[2]}", "Falling back to the image in the cal event.");

                canRandomImage = false;
            }
        }
        public async Task GetAlbumAsync_AreEqual()
        {
            var fakeHttpMessageHandler = new FakeHttpMessageHandler();
            var fakeResponse           = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(AlbumEndpointResponses.Imgur.GetAlbumResponse)
            };

            fakeHttpMessageHandler.AddFakeResponse(new Uri("https://api.imgur.com/3/album/5F5Cy"), fakeResponse);

            var client   = new ImgurClient("123", "1234");
            var endpoint = new AlbumEndpoint(client, new HttpClient(fakeHttpMessageHandler));
            var album    = await endpoint.GetAlbumAsync("5F5Cy");

            Assert.IsNotNull(album);
            Assert.AreEqual("5F5Cy", album.Id);
            Assert.AreEqual(null, album.Title);
            Assert.AreEqual(null, album.Description);
            Assert.AreEqual(album.DateTime, new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddSeconds(1446591779));
            Assert.AreEqual("79MH23L", album.Cover);
            Assert.AreEqual(609, album.CoverWidth);
            Assert.AreEqual(738, album.CoverHeight);
            Assert.AreEqual("sarah", album.AccountUrl);
            Assert.AreEqual(9571, album.AccountId);
            Assert.AreEqual(AlbumPrivacy.Public, album.Privacy);
            Assert.AreEqual(AlbumLayout.Blog, album.Layout);
            Assert.AreEqual(4, album.Views);
            Assert.AreEqual("http://imgur.com/a/5F5Cy", album.Link);
            Assert.AreEqual(false, album.Favorite);
            Assert.AreEqual(null, album.Nsfw);
            Assert.AreEqual(null, album.Section);
            Assert.AreEqual(3, album.ImagesCount);
            Assert.AreEqual(3, album.Images.Count());
        }
Exemplo n.º 13
0
        public bool SetFavoriteAlbum(string id)
        {
            var endpoint_ = new AlbumEndpoint(Imgur);

            endpoint_.FavoriteAlbumAsync(id);
            return(true);
        }
Exemplo n.º 14
0
        async Task <IEnumerable <IImage> > AccessTheWebAsync()
        {
            var client   = new ImgurClient(token);
            var endpoint = new AlbumEndpoint(client);
            var images   = await endpoint.GetAlbumImagesAsync(albumlink);

            return(images);
        }
        public async Task GetAlbumAsync_WithAlbum_AreEqual(IAlbum actualAlbum)
        {
            var client   = new MashapeClient(ClientId, ClientSecret, MashapeKey, OAuth2Token);
            var endpoint = new AlbumEndpoint(client);

            var album = await endpoint.GetAlbumAsync(actualAlbum.Id);

            Assert.AreEqual(actualAlbum.Id, album.Id);
        }
        public async Task GetAlbumImagesAsync_WithAlbum_AreEqual(IAlbum actualAlbum)
        {
            var client   = new MashapeClient(ClientId, ClientSecret, MashapeKey);
            var endpoint = new AlbumEndpoint(client);

            var albums = await endpoint.GetAlbumImagesAsync(actualAlbum.Id);

            Assert.AreEqual(2, albums.Count());
        }
        public async Task DeleteImageAsync_WithImage_IsTrue(IAlbum actualAlbum)
        {
            var client   = new MashapeClient(ClientId, ClientSecret, MashapeKey);
            var endpoint = new AlbumEndpoint(client);

            var deleted = await endpoint.DeleteAlbumAsync(actualAlbum.DeleteHash);

            Assert.IsTrue(deleted);
        }
        public async Task GetAlbumAsync_WithAlbum_AreEqual(IAlbum actualAlbum)
        {
            var client   = new ImgurClient(ClientId, ClientSecret);
            var endpoint = new AlbumEndpoint(client);

            var album = await endpoint.GetAlbumAsync(actualAlbum.Id);

            Assert.AreEqual(actualAlbum.Id, album.Id);
        }
Exemplo n.º 19
0
 public SpotifyHttpClient(HttpClient httpClient)
 {
     _httpClient = httpClient;
     Player      = new PlayerEndpoint(httpClient);
     Albums      = new AlbumEndpoint(httpClient);
     Artists     = new ArtistEndpoint(httpClient);
     Playlist    = new PlaylistEndpoint(httpClient);
     Search      = new SearchEndpoint(httpClient);
 }
        public async Task FavoriteAlbumAsync_WithImage_IsTrue(IAlbum actualAlbum)
        {
            var client   = new MashapeClient(ClientId, ClientSecret, MashapeKey, OAuth2Token);
            var endpoint = new AlbumEndpoint(client);

            var favorited = await endpoint.FavoriteAlbumAsync(actualAlbum.Id);

            Assert.IsTrue(favorited);
        }
        public async Task UpdateAlbumAsync_WithAlbum_AreEqual(IAlbum actualAlbum)
        {
            var client   = new MashapeClient(ClientId, ClientSecret, MashapeKey, OAuth2Token);
            var endpoint = new AlbumEndpoint(client);

            var updated = await endpoint.UpdateAlbumAsync(actualAlbum.Id, "TestTitle");

            Assert.IsTrue(updated);
        }
Exemplo n.º 22
0
        public async Task DeleteAlbumAsync_WithImage_IsTrue(IAlbum actualAlbum)
        {
            var client   = new ImgurClient(ClientId, ClientSecret, OAuth2Token);
            var endpoint = new AlbumEndpoint(client);

            var deleted = await endpoint.DeleteAlbumAsync(actualAlbum.Id);

            Assert.IsTrue(deleted);
        }
        public async Task UpdateAlbumAsync_WithAlbum_AreEqual(IAlbum actualAlbum)
        {
            var client   = new ImgurClient(ClientId, ClientSecret);
            var endpoint = new AlbumEndpoint(client);

            var updated = await endpoint.UpdateAlbumAsync(actualAlbum.DeleteHash, "TestTitle");

            Assert.IsTrue(updated);
        }
Exemplo n.º 24
0
        internal async static Task Meme(ReceivedMessage Message)
        {
            var client   = new ImgurClient(Bot.Config["ImgurId"], Bot.Config["ImgurSecret"]);
            var endpoint = new AlbumEndpoint(client);
            var images   = await endpoint.GetAlbumImagesAsync("AEWxy");

            var imagesArray = images.ToArray();

            Message.Respond(imagesArray[Rand.Next(0, imagesArray.Length)].Link, false);
        }
        public async Task GetAlbumImageAsync_WithAlbum_AreEqual(IAlbum actualAlbum)
        {
            var client   = new MashapeClient(ClientId, ClientSecret, MashapeKey, OAuth2Token);
            var endpoint = new AlbumEndpoint(client);

            var image = await endpoint.GetAlbumImageAsync(actualAlbum.Id, "uH3kfZP");

            Assert.IsNotNull(image);
            Assert.AreEqual("uH3kfZP", image.Id);
        }
        public async Task RemoveAlbumImagesAsync_WithAlbum_AreEqual(IAlbum actualAlbum)
        {
            var client   = new MashapeClient(ClientId, ClientSecret, MashapeKey, OAuth2Token);
            var endpoint = new AlbumEndpoint(client);

            var updated = await endpoint.RemoveAlbumImagesAsync(actualAlbum.Id, new List <string> {
                "uH3kfZP", "VzbrLbO"
            });

            Assert.IsTrue(updated);
        }
Exemplo n.º 27
0
        public async Task BuiTask()
        {
            ImgurClient   client   = new ImgurClient(Globals.Settings.ImgurClientId);
            AlbumEndpoint endpoint = new AlbumEndpoint(client);
            IAlbum        album    = await endpoint.GetAlbumAsync("KJTbv");

            int randomInt = Globals.Random.Next(0, album.ImagesCount);

            string imageLink = album.Images.Select(e => e.Link).ToList()[randomInt];

            await this.ReplyAsync(imageLink);
        }
        public async Task RemoveAlbumImagesAsync_WithAlbum_AreEqual(IAlbum actualAlbum)
        {
            var client   = new ImgurClient(ClientId, ClientSecret);
            var endpoint = new AlbumEndpoint(client);

            var updated =
                await endpoint.RemoveAlbumImagesAsync(actualAlbum.DeleteHash, new List <string> {
                "uH3kfZP", "VzbrLbO"
            });

            Assert.IsTrue(updated);
        }
Exemplo n.º 29
0
        public async Task SetAlbumImagesAsync_WithAlbum_AreEqual(IAlbum actualAlbum)
        {
            var client   = new ImgurClient(ClientId, ClientSecret, OAuth2Token);
            var endpoint = new AlbumEndpoint(client);

            var updated =
                await endpoint.SetAlbumImagesAsync(actualAlbum.Id, new List <string> {
                "uH3kfZP", "OkFyVOe", "Y8BbQuU"
            });

            Assert.IsTrue(updated);
        }
Exemplo n.º 30
0
        /// <summary>
        /// Create a New Album and get Link and AlbumID/DeleteHash
        /// </summary>
        /// <returns>Album Link and Album ID (or Album DeleteHash, if not logged in)</returns>
        public async Task <Tuple <string, string> > CreateAlbum()
        {
            AlbumEndpoint endpoint = new AlbumEndpoint(_client);
            IAlbum        album    = await endpoint.CreateAlbumAsync("Images uploaded with ImgurSniper",
                                                                     "https://mrousavy.github.io/ImgurSniper");

            //Logged in User = Item2 = Album ID
            Tuple <string, string> pair = _client.OAuth2Token != null ?
                                          new Tuple <string, string>(album.Id, album.Id) :
                                          new Tuple <string, string>(album.Id, album.DeleteHash);

            return(pair);
        }