Skip to content

Instantly share code, notes, and snippets.

@blizzarddreams
Created December 22, 2015 04:58
Show Gist options
  • Select an option

  • Save blizzarddreams/6edeca7ccbe82ed29f17 to your computer and use it in GitHub Desktop.

Select an option

Save blizzarddreams/6edeca7ccbe82ed29f17 to your computer and use it in GitHub Desktop.
package ircscalabot
import javax.script.ScriptException
import java.io.{PrintWriter, ByteArrayOutputStream, PrintStream}
import org.json4s._
import org.json4s.native.JsonMethods._
import org.json4s.native.Serialization.write
import scala.tools.nsc.Settings
import scala.tools.nsc.interpreter.IMain
import scalaj.http.Http
/**
* Created by Anthony on 12/19/2015.
*/
case class Gist(description: String, public: Boolean, files: Map[String, Any])
object CommandList {
val settings = new Settings()
settings.usejavacp.value = true
val out = new ByteArrayOutputStream()
val repl = new IMain(settings, new PrintWriter(out))
Console.setOut(new PrintStream(out))
def main(args: Array[String]): Unit = {
println(writeToGist("List(1, 2, 3).map(i => i*2)"))
println("done")
}
def writeToGist(input: String): String = {
implicit val formats = DefaultFormats
val url = "https://api.github.com/gists"
val gist = Gist("output", true, Map("output.md" -> Map("content" -> input)))
val jsonData = Extraction.decompose(gist)
val jsonString = write(jsonData)
val response = Http(url).postData(jsonString).asString
val gistJson = parse(response.body).extract[Map[String, Any]]
println(gistJson)
gistJson("html_url").toString()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment