Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
58 lines (53 sloc) 2.02 KB
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Web;
using unirest_net.http;
using System.IO;
namespace MemeBot
public enum Meme
Brian, Fry, GrumpyCat, OMG, Spiderman, Troll, Wonka
public class MemeAPI
private static string RAPID_API_KEY = "<RAPID_API_KEY>";
/// <summary>
/// This methods calls the APIMeme ( ) through RapidAPI ( )
/// and returns the generated meme as Base64String
/// </summary>
public async Task<string> GenerateMeme(Meme meme, string topText, string bottomText)
var response = await Unirest.get($"{ HttpUtility.HtmlEncode(bottomText) }&font=Impact&font_size=50&meme={ ConvertMemeToURL(meme) }&top={ HttpUtility.HtmlEncode(topText) }")
.header("X-Mashape-Key", RAPID_API_KEY )
.header("X-Mashape-Host", "")
return Convert.ToBase64String(response.Body.ToArray());
private string ConvertMemeToURL(Meme meme)
case Meme.Brian:
return "Bad-Luck-Brian";
case Meme.Fry:
return "Futurama-Fry";
case Meme.GrumpyCat:
return "Grumpy-Cat";
case Meme.OMG:
return "OMG-Cat";
case Meme.Spiderman:
return "Spiderman-Computer-Desk";
case Meme.Troll:
return "Troll-Face";
case Meme.Wonka:
return "Condescending-Wonka";
throw new NotImplementedException();