Skip to content

Instantly share code, notes, and snippets.

@osima
Created August 21, 2011 11:16
Show Gist options
  • Select an option

  • Save osima/1160480 to your computer and use it in GitHub Desktop.

Select an option

Save osima/1160480 to your computer and use it in GitHub Desktop.
Get a Gist's Content 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 gistUrl = 'https://gist.github.com/raw/949445'
def hc = new HttpClient()
def method = new GetMethod( gistUrl )
hc.executeMethod( method )
def reader = new InputStreamReader( method.getResponseBodyAsStream(), encoding )
def code = reader.text
reader.close()
method.releaseConnection()
println code
println 'https://raw.github.com/gist/949445'.toURL().getText('UTF-8')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment