Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Simple Github API client using Groovy RESTClient
/**
* Simple Github API client that supports basic auth.
*/
class GithubClient {
String username
String password
String owner
String repository
String fetchFileContents(String filePath) {
request("${repoUrl}contents/${filePath}").content.decodeBase64()
}
public Map request(String url) {
githubApi.get(path : url).responseData
}
private String getRepoUrl() {
"repos/${owner}/${repository}/"
}
private RESTClient getGithubApi() {
return new RESTClient("https://api.github.com/").with {
headers.'User-Agent' = 'Mozilla/5.0'
if (username && password) {
headers['Authorization'] = 'Basic '+"${username}:${password}".getBytes('iso-8859-1').encodeBase64()
}
it
}
}
}
@joshareed
Copy link

You might also consider using the new Personal API Tokens so you don't have to embed your username and password: https://github.com/blog/1509-personal-api-tokens

@joshareed
Copy link

Here's the script that I use to generate weekly summary emails of Github issues: https://gist.github.com/joshareed/5706061

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment