Exemplo n.º 1
0
        public async Task <List <string> > GetTrendingsURlsOfTheDay()
        {
            var giphy     = new Giphy(_apiKey);
            var gifResult = await giphy.TrendingGifs(new TrendingParameter());

            return(gifResult.Data.Select(data => data.Url).ToList());
        }
Exemplo n.º 2
0
 public FunModule(HttpClient http, Random random, Configuration configuration, Giphy giphy)
 {
     _httpClient    = http;
     _random        = random;
     _configuration = configuration;
     _giphy         = giphy;
 }
Exemplo n.º 3
0
        public async Task <GiphySearchResult> SearchGif(string searchterm, int offset = 0)
        {
            var giphy           = new Giphy(ApiKey);
            var searchParameter = DefaultSearchParameter(searchterm);

            return(await giphy.GifSearch(searchParameter));
        }
Exemplo n.º 4
0
        public async Task Gif([Remainder]string query)
        {
            // Get the giphy token from the config file.
            string giphyToken = this.config["tokens:giphy"];

            if (string.IsNullOrWhiteSpace(giphyToken))
            {
                await ReplyAsync("No Giphy app token provided. Please enter token into the `config.json` file found in the applications root directory.");
            }
            else
            {
                Giphy giphy = new Giphy(giphyToken);

                SearchParameter searchParameter = new SearchParameter()
                {
                    Query = query
                };

                // Returns gif results.
                var gifResult = await giphy.GifSearch(searchParameter);

                if (gifResult.Data.Length > 0)
                {
                    var imageUrl = new EmbedBuilder()
                    .WithImageUrl(gifResult.Data[rand.Next() % gifResult.Data.Length].Images.Original.Url).Build();

                    await ReplyAsync("", embed: imageUrl);
                }
                else
                {
                    await ReplyAsync("[Error]: Tag provided returned no results!");
                }
            }
        }
Exemplo n.º 5
0
        public MessagesController(TelemetryClient telemetryClient)
        {
            var apiKey = System.Configuration.ConfigurationManager.AppSettings["Giphy.ApiKey"];

            this.giphyManager    = new Giphy(apiKey);
            this.telemetryClient = telemetryClient;
        }
Exemplo n.º 6
0
        async void GetGif(string url)
        {
            var giphy     = new Giphy("dc6zaTOxFJmzC");
            var gifresult = await giphy.RandomGif(new RandomParameter()
            {
                Tag = searchingText
            });

            try
            {
                using (var client = new HttpClient())
                {
                    if (url == null) // refresh gif
                    {
                        this.url = "https://media.giphy.com/media/" + gifresult.Data.Id.ToString() + "/giphy.gif";
                        //Toast.MakeText(this, "1", ToastLength.Short).Show();
                    }
                    else // load from json
                    {
                        this.url = url;
                        //Toast.MakeText(this, "2", ToastLength.Short).Show();
                    }

                    var bytes = await client.GetByteArrayAsync(this.url);

                    gifImage.SetBytes(bytes);
                    gifImage.StartAnimation();
                }
            }
            catch (Exception e)
            {
                Toast.MakeText(this, "Bad connection", ToastLength.Short).Show();
            }
        }
Exemplo n.º 7
0
 public GiphyService(string key)
 {
     if (!string.IsNullOrWhiteSpace(key))
     {
         this.giphy = new Giphy(key);
     }
 }
Exemplo n.º 8
0
        public void UploadGIFToGiphy()
        {
            if (isExportingGif)
            {
                NativeUI.Alert("Exporting In Progress", "Please wait until the GIF exporting is completed.");
                return;
            }
            else if (string.IsNullOrEmpty(exportedGifPath))
            {
                NativeUI.Alert("No Exported GIF", "Please export a GIF file first.");
                return;
            }

            isUploadingGif = true;

            var content = new GiphyUploadParams();

            content.localImagePath = exportedGifPath;
            content.tags           = "demo, easy mobile, sglib games, unity3d";

            if (!string.IsNullOrEmpty(giphyUsername) && !string.IsNullOrEmpty(giphyApiKey))
            {
                Giphy.Upload(giphyUsername, giphyApiKey, content, OnGiphyUploadProgress, OnGiphyUploadCompleted, OnGiphyUploadFailed);
            }
            else
#if UNITY_EDITOR
            { Debug.LogError("Upload failed: please provide valid Giphy username and API key in the GifDemo game object."); }
#else
            { NativeUI.Alert("Upload Failed", "Please provide valid Giphy username and API key in the GifDemo game object."); }
#endif
        }
Exemplo n.º 9
0
        internal async Task <Giphy> SearchGifs(string searchText)
        {
            Giphy giphy = new Giphy();

            try
            {
                if (!String.IsNullOrEmpty(searchText))
                {
                    string searchUrl = String.Format(Settings.SearchUrl, Settings.ApiKey, searchText, Settings.LimitCount, Settings.Offset, Settings.Rating);

                    HttpResponseMessage responseMessage = await httpClient.GetAsync(searchUrl);

                    string jsonString = responseMessage.Content.ReadAsStringAsync().Result;
                    giphy = JsonConvert.DeserializeObject <Giphy>(jsonString);

                    Settings.Offset += Settings.LimitCount;
                }
            }
            catch (Exception exception)
            {
                Debug.WriteLine(exception.Message);
            }

            return(giphy);
        }
Exemplo n.º 10
0
        public void UploadGIFToGiphy()
        {
            if (isExportingGif)
            {
                NativeUI.Alert("Exporting In Progress", "Please wait until the GIF exporting is completed.");
                return;
            }
            else if (string.IsNullOrEmpty(exportedGifPath))
            {
                NativeUI.Alert("No Exported GIF", "Please export a GIF file first.");
                return;
            }

            isUploadingGif = true;

            var content = new GiphyUploadParams();

            content.localImagePath = exportedGifPath;
            content.tags           = "demo, easy mobile, sglib games, unity3d";

            if (!string.IsNullOrEmpty(giphyUsername) && !string.IsNullOrEmpty(giphyApiKey))
            {
                Giphy.Upload(giphyUsername, giphyApiKey, content, OnGiphyUploadProgress, OnGiphyUploadCompleted, OnGiphyUploadFailed);
            }
            else
            {
                Giphy.Upload(content, OnGiphyUploadProgress, OnGiphyUploadCompleted, OnGiphyUploadFailed);
            }
        }
Exemplo n.º 11
0
        public async Task GifIdsIsEmpty_ThrowsFormatException()
        {
            var giphy = new Giphy("test");

            List <string> data = new List <string>();

            _ = await Assert.ThrowsAsync <FormatException>(() => giphy.GifsById(data));
        }
Exemplo n.º 12
0
        public async Task Search_ParameterIsNull_ThrowsNullReferenceException()
        {
            var giphy = new Giphy("test");

            RandomParameter search = null;

            _ = await Assert.ThrowsAsync <NullReferenceException>(() => giphy.Random(search));
        }
Exemplo n.º 13
0
        public async Task ParameterIsNull_ThrowsNullReferenceException()
        {
            var giphy = new Giphy("test");

            StickerTranslateParameter search = null;

            _ = await Assert.ThrowsAsync <NullReferenceException>(() => giphy.StickerTranslate(search));
        }
Exemplo n.º 14
0
        public async Task NotSuccessStatusCode_ThrowsHttpRequestException()
        {
            var mockHttpHandler = HttpHandler.GetMockFailedHttpHandlerObject();
            var giphy           = new Giphy(mockHttpHandler);
            var id = "xT4uQulxzV39haRFjG";

            _ = await Assert.ThrowsAsync <HttpRequestException>(() => giphy.GifById(id));
        }
Exemplo n.º 15
0
        public async Task GifIdIsEmpty_ThrowsFormatException()
        {
            var giphy = new Giphy("test");

            string id = "";

            _ = await Assert.ThrowsAsync <FormatException>(() => giphy.GifById(id));
        }
Exemplo n.º 16
0
        public async Task Trending_ParameterIsNull_ThrowsNullReferenceException()
        {
            var giphy = new Giphy("test");

            TrendingParameter search = null;

            _ = await Assert.ThrowsAsync <NullReferenceException>(() => giphy.Trending(search));
        }
Exemplo n.º 17
0
        public async Task Search_NotSuccessStatusCode_ThrowsHttpRequestException()
        {
            var mockHttpHandler = HttpHandler.GetMockFailedHttpHandlerObject();
            var giphy           = new Giphy(mockHttpHandler);
            var search          = new RandomParameter();

            _ = await Assert.ThrowsAsync <HttpRequestException>(() => giphy.Random(search));
        }
Exemplo n.º 18
0
        public async Task GifIdsIsNull_ThrowsFormatException()
        {
            var giphy = new Giphy("test");

            List <string> data = null;

            _ = await Assert.ThrowsAsync <NullReferenceException>(() => giphy.GifsById(data));
        }
Exemplo n.º 19
0
 public BasicTest()
 {
     api_token = Environment.GetEnvironmentVariable("GIPHY_TOKEN");
     if (string.IsNullOrEmpty(api_token))
     {
         throw new Exception("You must set the API Token in your Environment Variables!");
     }
     giphy = new Giphy(api_token);
 }
Exemplo n.º 20
0
        public async Task ItemInListContainsNullValue_ThrowsFormatException()
        {
            var giphy = new Giphy("test");

            List <string> data = new List <string> {
                "test1", null, "test3"
            };

            _ = await Assert.ThrowsAsync <NullReferenceException>(() => giphy.GifsById(data));
        }
Exemplo n.º 21
0
        public async Task NotSuccessStatusCode_ThrowsHttpRequestException()
        {
            var           mockHttpHandler = HttpHandler.GetMockFailedHttpHandlerObject();
            var           giphy           = new Giphy(mockHttpHandler);
            List <string> data            = new List <string> {
                "test1", "test2"
            };

            _ = await Assert.ThrowsAsync <HttpRequestException>(() => giphy.GifsById(data));
        }
        public async Task <string> GetRandomSticker(string searchParameter)
        {
            var giphy = new Giphy(Configuration["RemotePuzzle:GiphyApiKey"]);

            var randomGif = await giphy.RandomSticker(new GiphyDotNet.Model.Parameters.RandomParameter {
                Tag = searchParameter
            });

            return(randomGif.Data.ImageMp4Url);
        }
Exemplo n.º 23
0
        public async Task QueryNotSpecified_ThrowsFormatException()
        {
            var giphy = new Giphy("test");

            //  The query variable was not set in the paramter model
            //  which is required to run a query on giphy's api
            var search = new StickerTranslateParameter();

            _ = await Assert.ThrowsAsync <FormatException>(() => giphy.StickerTranslate(search));
        }
Exemplo n.º 24
0
        public async Task NotSuccessStatusCode_ThrowsHttpRequestException()
        {
            var mockHttpHandler = HttpHandler.GetMockFailedHttpHandlerObject();
            var giphy           = new Giphy(mockHttpHandler);
            var search          = new StickerTranslateParameter {
                Query = "test"
            };

            _ = await Assert.ThrowsAsync <HttpRequestException>(() => giphy.StickerTranslate(search));
        }
Exemplo n.º 25
0
        static void Main(string[] args)
        {
            IConfiguration configuration = new ConfigurationBuilder()
                                           .AddJsonFile(Path.GetFullPath(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"..\..\..\appsettings.json")), true, true)
                                           .Build();
            var apikey = configuration.GetSection("giphyapikey").Value;

            bool stayInSearch = true;
            var  giphy        = new Giphy(apikey, new MemoryCache(new MemoryCacheOptions()));

            while (stayInSearch)
            {
                Console.WriteLine("Please enter a word or words you want to search for gifs for: ");
                var searchQuery = Console.ReadLine();

                if (string.IsNullOrEmpty(searchQuery))
                {
                    continue;
                }
                // Returns gif results
                var gifs = giphy.GetOrCreateSearchResults(searchQuery);
                Console.WriteLine($"Following the search results for '{searchQuery}':\n\n");
                gifs.Wait();
                foreach (var url in gifs.Result)
                {
                    Console.WriteLine(url);
                }

                ConsoleKey response;
                do
                {
                    Console.Write("\n\nAre you want to keep searching for gifs ? [y/n]");
                    response = Console.ReadKey(false).Key;
                    if (response != ConsoleKey.Enter)
                    {
                        Console.WriteLine();
                    }
                } while (response != ConsoleKey.Y && response != ConsoleKey.N);

                stayInSearch = response == ConsoleKey.Y;
            }

            Console.WriteLine("\n\nPlease enter any key to get trending gifs\n\n");
            Console.ReadKey();
            Console.WriteLine($"Following the search results for trending gifs:\n\n");
            var trendingParameter = new TrendingParameter();
            var t2 = giphy.TrendingGifs(trendingParameter);

            t2.Wait();
            foreach (Data item in t2.Result.Data)
            {
                Console.WriteLine(item.EmbedUrl);
            }
            Console.ReadKey();
        }
Exemplo n.º 26
0
        public GiphyBot(ChannelConnector connector) : base(connector)
        {
            m_giphy = new Giphy(ApiKey);

            Connector.Message += OnMessage;

            m_timer           = new Timer();
            m_timer.Interval  = TimeSpan.FromMinutes(1).TotalMilliseconds;
            m_timer.Elapsed  += TimerElapsed;
            m_timer.AutoReset = true;
        }
Exemplo n.º 27
0
        public async Task WhenCalled_ReturnsGiphySingle()
        {
            var mockHttpHandler = HttpHandler.GetMockSuccessHttpHandlerObject();
            var giphy           = new Giphy(mockHttpHandler);
            var id = "xT4uQulxzV39haRFjG";

            var actual = await giphy.GifById(id);

            Assert.NotNull(actual);
            Assert.IsType <GiphySingle>(actual);
        }
Exemplo n.º 28
0
        public async Task Search_WhenCalled_ReturnsGiphySingle()
        {
            var mockHttpHandler = HttpHandler.GetMockSuccessHttpHandlerObject();
            var giphy           = new Giphy(mockHttpHandler);
            var search          = new RandomParameter();

            var actual = await giphy.Random(search);

            Assert.NotNull(actual);
            Assert.IsType <GiphySingle>(actual);
        }
        public async Task WhenCalled_ReturnsRootObject()
        {
            var mockHttpHandler = HttpHandler.GetMockSuccessHttpHandlerObject();
            var giphy           = new Giphy(mockHttpHandler);
            var search          = new StickerTrendingParameter();

            var actual = await giphy.StickerTrending(search);

            Assert.NotNull(actual);
            Assert.IsType <RootObject>(actual);
        }
        public async Task <Giphy> GetGiphyTaskAsync(string query)
        {
            Giphy giphy = null;
            HttpResponseMessage response = await _client.GetAsync(
                $"{_giphyEndpoint}?q={query}&limit={_giphyLimit}&rating={_giphyRating}&api_key={_giphyKey}");

            if (response.IsSuccessStatusCode)
            {
                giphy = await response.Content.ReadAsJsonAsync <Giphy>();
            }
            return(giphy);
        }