Skip to content

Instantly share code, notes, and snippets.

@ranrubin
Last active June 25, 2019 14:41
Show Gist options
  • Save ranrubin/adcba3ac4b4b5a0f1b9912a9d95b9d76 to your computer and use it in GitHub Desktop.
Save ranrubin/adcba3ac4b4b5a0f1b9912a9d95b9d76 to your computer and use it in GitHub Desktop.
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