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

44 lines
1.7 KiB
Plaintext
Raw Permalink Normal View History

2019-01-06 18:36:53 +02:00
use ["std", "http", "json", "functional", "date"]
2016-01-12 23:14:56 +02:00
header = "* Prints current GitHub timeline *"
2019-01-06 18:36:53 +02:00
println "*" * header.length
2016-01-12 23:14:56 +02:00
println header
2019-01-06 18:36:53 +02:00
println "*" * header.length
2016-01-12 23:14:56 +02:00
// 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) {
2019-01-13 21:52:26 +02:00
println event.created_at.formatTzDate()
println "User: https://github.com/" + event.actor.login
println github_event_type(event)
println "-" * 50
2016-01-12 23:14:56 +02:00
}
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
2016-02-14 21:24:06 +02:00
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
2016-01-12 23:14:56 +02:00
}
}
2019-01-06 18:36:53 +02:00
def formatTzDate(str) = formatDate(parseTzDate(str), newFormat("yyyy-MM-dd HH:mm:ss"))
def parseTzDate(str) = parseDate(str, newFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"))