Simple Github API client using Groovy RESTClient
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
/** | |
* 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 | |
} | |
} | |
} |
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
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