Skip to content

Instantly share code, notes, and snippets.

@osima
Created December 7, 2011 04:48
Show Gist options
  • Save osima/1441506 to your computer and use it in GitHub Desktop.
Save osima/1441506 to your computer and use it in GitHub Desktop.
fetch code from gist using groovy
//
// fetch code from gist using groovy
//
@Grab(group='commons-httpclient', module='commons-httpclient', version='3.1')
import org.apache.commons.httpclient.*
import org.apache.commons.httpclient.methods.*
def encoding = 'UTF-8'
def gistId='1174714'
def filename='main.xml'
def gistUrl="http://gist.github.com/raw/${gistId}/${filename}"
def hc = new HttpClient()
def method = new GetMethod( gistUrl )
hc.executeMethod( method )
def reader = new InputStreamReader( method.getResponseBodyAsStream(), encoding )
def r = reader.text
reader.close()
method.releaseConnection()
println r
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment