Skip to content

Instantly share code, notes, and snippets.

@glaforge
Last active August 29, 2015 14:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save glaforge/204db0c39d65e94bf335 to your computer and use it in GitHub Desktop.
Save glaforge/204db0c39d65e94bf335 to your computer and use it in GitHub Desktop.
@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