i m not able to consume Google rest API in groovy.
I m newbie with groovy :S and i m using HTTPBuilder to ask the service. My code is:
public static void testJSONPost() {
def builder = new HTTPBuilder("https://www.googleapis.com/qpxExpress/v1/trips/search?key={$MY_WEB_KEY}")
def result = builder.request(POST, JSON) { req ->
uri.query = ["request": ["passengers": ["adultCount": 1],"slice": [["origin": "BOS","destination": "LAX","date": "2015-05-13"],["origin": "LAX","destination": "BOS","date": "2015-05-23"]]]]
response.success = {resp, json ->
println "JSON POST Success: ${resp.statusLine}"
return json.name
}
response.failure = {resp ->
println "JSON POST Failed: ${resp.statusLine}"
}
}
}
testJSONPost()
I tried with curl example and it worked:
curl -d @reques.json --header "Content-Type: application/json" https://www.googleapis.com/qpxExpress/v1/trips/search?key=MY_WEB_KEY
The content of "reques.json" is:
{
"request": {
"passengers": {
"adultCount": 1
},
"slice": [
{
"origin": "BOS",
"destination": "LAX",
"date": "2015-05-13"
},
{
"origin": "LAX",
"destination": "BOS",
"date": "2015-06-06"
}
]
}
}
The key that i m using is a web key.
Well i ll keep on searching and trying.