Last active
August 29, 2015 14:18
-
-
Save glaforge/204db0c39d65e94bf335 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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