Created
October 19, 2013 08:45
-
-
Save sarmbruster/7053223 to your computer and use it in GitHub Desktop.
This file contains hidden or 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(group='org.codehaus.groovy.modules.http-builder', module='http-builder', version='0.6' ) | |
@Grab(group='net.sf.json-lib', module='json-lib', version='2.2.3', classifier='jdk15') | |
import groovyx.net.http.* | |
import static groovyx.net.http.ContentType.* | |
import static groovyx.net.http.Method.* | |
def static transaction(statement, params,success, error) | |
{ | |
def http = new HTTPBuilder( 'http://localhost:7474' ) | |
//http.setProxy('localhost', 8888, 'http') // uncomment if proxy should be used | |
http.request( POST, JSON ) { | |
uri.path = '/db/data/transaction' | |
headers.'X-Stream' = 'true' | |
requestContentType = JSON | |
//body = [ statements : statement , params : params ?: [:] ] | |
body = [ statements : [ | |
[statement: statement , parameters : params ?: [:] ] | |
] ] | |
// uri.query = [ param : 'value' ] | |
response.success = { resp, json -> | |
if (success) success(json) | |
else { | |
println "Status ${resp.statusLine} Columns ${json.columns}\nData: ${json.data}" | |
} | |
} | |
response.failure = { resp, message -> | |
def result=[status:resp.statusLine.statusCode,statusText:resp.statusLine.reasonPhrase] | |
result.headers = resp.headers.collect { h -> [ (h.name) : h.value ] } | |
result.message = message | |
if (error) { | |
error(result) | |
} else { | |
println "Status: ${result.status} : ${result.statusText} " | |
println 'Headers: ${result.headers}' | |
println 'Message: ${result.message}' | |
} | |
} | |
} | |
} | |
transaction("start n=node(*) return n",[id:56981],{ println "Success: ${it}" },{ println "Error: ${it}" }) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment