But the big pain right now is that you have togo to so many different websites todo a simple transaction and I really want to have this all combined in one single tool.
So the api exspects from you to be queried over post arguments and the first thing which came to my mind was to use the fantastic HttpBuilder in groovy.
so let's define a simple method to simplify life a bit for us
private executeQuery(Map parameter, String path) {
def http = new HTTPBuilder("https://mtgox.com/")
def result = ""
http.post(body: parameter, path: path, requestContentType: URLENC) { resp, json ->
if (resp.statusLine.statusCode == 200) {
result = json
}
else {
result = false
}
}
return result
and a second method to actually call this
def getCurrentBalance() {
if (MtGoxAccessHandler.isConfigured()) {
def values = executeQuery([
name: MtGoxAccessHandler.getUserName(),
pass: MtGoxAccessHandler.getPassword()],
"/code/getFunds.php")
return [usd: values.usds, coins: values.btcs]
}
else {
return false
}
}
The class MtGoxAccessHandler is just a little helper, which stores the username and password and allows me to simplify the code a bit and easy testing.
This post is also related to the google code project DeepBitView
No comments:
Post a Comment