Zak Taccardi
06/03/2024, 6:18 PMcurl command with ExecOperations in Gradle. What is the best way to get the response values from it? specifically the json response body and http status codeephemient
06/03/2024, 6:41 PMZak Taccardi
06/03/2024, 6:42 PMephemient
06/03/2024, 6:42 PMephemient
06/03/2024, 6:43 PMZak Taccardi
06/03/2024, 6:43 PMZak Taccardi
06/03/2024, 6:43 PMval standardOut = ByteArrayOutputStream()
exec.exec {
// by default this would run in the sample app's project dir - we want the root project dir
workingDir(rootProjectDirectory)
val spec = this
spec.commandLine(
"curl",
"-X",
"POST",
"-H",
"Authorization: APIKey $dataTheoremApiKey",
"--data",
"\"\"",
"<https://someUrl.com/v1/upload_init>"
)
standardOutput = standardOut
}
val output = standardOut.toString()
logger.lifecycle(output)
val json = output.substring(
startIndex = output.indexOf("{ ")
.also { startIndex ->
if (startIndex == -1) {
error("startIndex was not found")
}
},
endIndex = output.indexOf(" }")
.also { endIndex ->
if (endIndex == -1) {
error("endIndex was not found")
}
}
// inclusive
.let { endIndex -> endIndex + 2 },
)
but seems a bit obnoxious lolephemient
06/03/2024, 6:44 PMephemient
06/03/2024, 6:44 PMZak Taccardi
06/03/2024, 6:44 PM