-
Notifications
You must be signed in to change notification settings - Fork 6
Open
Description
Some of the Graph APIs require HTTP DELETE request but the current plugin only support GET and POST. I try modifed the existing FacebookGraphService.makeRequest(urlAsString, params) as follow and seems it's working fine:
private def makeRequest(urlAsString, params) {
def resp
def encodedParams = ""
URL url
Writer writer
URLConnection connection
// Encoding the params...
if (params) {
params.each{k,v ->
if(k != 'method' && k != 'id') {
encodedParams += k.encodeAsURL() + '=' + v.encodeAsURL() + '&'
}
}
encodedParams = encodedParams[0..-2]
}
try {
// Making the request
switch(params.method) {
case "GET":
if(encodedParams) urlAsString += '?' + encodedParams
url = new URL(urlAsString)
resp = url.text
break;
case "POST":
case "DELETE":
url = new URL(urlAsString)
connection = url.openConnection()
connection.setRequestMethod(params.method)
connection.doOutput = true
writer = new OutputStreamWriter(connection.outputStream)
writer.write(encodedParams)
writer.flush()
writer.close()
connection.connect()
if (connection.responseCode == 200 || connection.responseCode == 201)
resp = connection.content.text
break;
}
} catch(Exception e) {
// resp will be null, nothing to do...
log.error(e)
}
return resp
}
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels