Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
@Grab('com.github.groovy-wslite:groovy-wslite:1.1.0')
import wslite.rest.*
import wslite.http.auth.*
import groovy.json.*
def j = new JsonSlurper()
def base = 'http://apibunny.com'
def client = new RESTClient(base)
def visited = []
def explore
explore = { String url ->
def result = j.parseText(new String(client.get(path: url).data))
def links = result._links.findAll { k, v -> !(k in ['abandon', 'self', 'maze']) }
if (result.name) println "Visiting room: $result.name"
if (result.egg) println " -> an egg! $result.egg"
links.each { k, v ->
if (!(v.href in visited)) {
visited << v.href
println "Next -> $k: $v.href"
explore(v.href)
}
}
}
explore('/mazes/6d2a8c5c-99d0-4325-afb6-414372d3098d')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment