Last active
June 25, 2019 14:41
-
-
Save ranrubin/adcba3ac4b4b5a0f1b9912a9d95b9d76 to your computer and use it in GitHub Desktop.
This file contains 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
package org.boo | |
httpEnv | |
def construct(String base_url){ | |
httpEnv = [ | |
base_url: base_url, | |
curl_options: '-sS', | |
debug: false, | |
authentication_header: '', | |
ignore_flag: "null" | |
] | |
} | |
def getHttpEnv(){ | |
return httpEnv | |
} | |
def put(String path, String data){ | |
return exec_request(" -H \'Content-Type: application/json\'", "${httpEnv.curl_options}", 'PUT', "${httpEnv.base_url}/${path}", data) | |
} | |
def get(String path){ | |
return exec_request('', "${httpEnv.curl_options}", 'GET', "${httpEnv.base_url}/${path}",'') | |
} | |
def exec_request(String headers, String curl_opt, String operation, String full_url, String data){ | |
def command = "curl ${curl_opt} -X${operation} ${full_url} ${headers}" | |
if (data != "null" && data != '') { | |
command = "${command} -d \'${data}\'" | |
if (httpEnv.debug){ | |
echo "$data" | |
} | |
} | |
return sh (script: "${command}", returnStdout: true) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment