Own-Programming-Language-Tu.../examples/network/github_timeline.own

64 lines
1.8 KiB
Plaintext
Raw Normal View History

2016-01-12 23:14:56 +02:00
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
actor = event.actor
println "User: https://github.com/" + actor.login
2016-01-12 23:14:56 +02:00
println github_event_type(event)
println "-" * 50
}
def github_event_type(event) {
type = event.type
repo = "https://github.com/" + event.repo.name
payload = event.payload
2016-01-12 23:14:56 +02:00
if (type == "CommitCommentEvent") {
return "commented commit in " + repo + "\n" + payload.comment.body
2016-01-12 23:14:56 +02:00
}
if (type == "CreateEvent") {
return "created " + payload.ref_type + " on " + repo
2016-01-12 23:14:56 +02:00
}
if (type == "DeleteEvent") {
return "deleted " + payload.ref_type + " on " + repo
2016-01-12 23:14:56 +02:00
}
if (type == "ForkEvent") {
return "forked repository " + repo
}
if (type == "IssueCommentEvent") {
return "commented issue " + payload.issue.title + " on " + repo + "\n" + payload.comment.body
2016-01-12 23:14:56 +02:00
}
if (type == "IssuesEvent") {
return payload.action + " issue '" + payload.issue.title + "' on " + repo
2016-01-12 23:14:56 +02:00
}
if (type == "PullRequestEvent") {
pr = payload.pull_request
return payload.action + " pull request #" + payload.number + " '" + pr.title + "' on " + repo
2016-01-12 23:14:56 +02:00
}
if (type == "PushEvent") {
return "pushed " + length(payload.commits) + " commits to " + repo
2016-01-12 23:14:56 +02:00
}
if (type == "WatchEvent") {
return "start watching repository " + repo
}
return type + " on " + repo
}