use "std" use "http" use "json" use "functional" header = "* Prints current GitHub timeline *" println "*" * length(header) println header println "*" * length(header) // Executes in main thread //http("https://api.github.com/events", def(r) { // foreach(jsondecode(r), ::show_github_events) //}) // Executes in new thread thread(::http, "https://api.github.com/events", def(r) { foreach(jsondecode(r), ::show_github_events) }) def show_github_events(event) { println event.created_at println "User: https://github.com/" + event.actor.login println github_event_type(event) println "-" * 50 } def github_event_type(event) { repo = "https://github.com/" + event.repo.name payload = event.payload return match event.type { case "CommitCommentEvent": "commented commit in " + repo + "\n" + payload.comment.body case "CreateEvent": "created " + payload.ref_type + " on " + repo case "DeleteEvent": "deleted " + payload.ref_type + " on " + repo case "ForkEvent": "forked repository " + repo case "IssueCommentEvent": "commented issue " + payload.issue.title + " on " + repo + "\n" + payload.comment.body case "IssuesEvent": payload.action + " issue '" + payload.issue.title + "' on " + repo case "PullRequestEvent": payload.action + " pull request #" + payload.number + " '" + payload.pull_request.title + "' on " + repo case "PushEvent": "pushed " + length(payload.commits) + " commits to " + repo case "WatchEvent": "start watching repository " + repo case type : type + " on " + repo } }