From c9d2c133aace7a36bf47a0c58826bf570fc3335d Mon Sep 17 00:00:00 2001 From: Will Norris Date: Fri, 24 May 2013 11:24:04 -0700 Subject: [PATCH] fill out readme and other docs a bit more --- CONTRIBUTING.md | 4 +++ README.md | 69 +++++++++++++++++++++++++++++++++++++++++++-- examples/example.go | 6 ++-- github.go | 4 +++ 4 files changed, 78 insertions(+), 5 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 37d84d9..0d42744 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -39,6 +39,10 @@ again. 1. Go makes it very simple to ensure properly formatted code, so always run `go fmt` on your code before committing it. + 1. Any significant changes should almost always be accompanied by tests. The + project already has good test coverage, so look at some of the existing + tests if you're unsure how to go about it. + 1. Do your best to have [well-formed commit messages][] for each change. This provides consistency throughout the project, and ensures that commit messages are able to be formatted properly by various git tools. diff --git a/README.md b/README.md index 59783fd..215c45c 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,75 @@ -# go-github +# go-github # go-github is Go library for accessing the [GitHub API][]. +**Documentation:** + + +## Usage ## + +Construct a new GitHub client, then use the various services on the client to +access different parts of the GitHub API. For example, list all organizations +for user "willnorris": + +```go +client := github.NewClient(nil) +orgs, err := client.Organizations.List("willnorris", nil) +``` + +Some API methods have optional parameters than can be passed. For example, +list recently updated repositories for org "github": + +```go +client := github.NewClient(nil) +opt := &github.RepositoryListByOrgOptions{Sort: "updated"} +repos, err := client.Repositories.ListByOrg("github", opt) +``` + +The go-github library does not directly handle authentication. Instead, when +creating a new client, pass an `http.Client` than can handle authentication for +you. The easiest, and recommended, way to do this is using the [goauth2][] +library, but you can of course use any other library that provides an +`http.Client`. For example, to use the goauth2 library with an existing OAuth +access token: + +```go +t := &oauth.Transport{ + Config: &oauth.Config{}, + Token: &oauth.Token{AccessToken: "..."} +} + +client := github.NewClient(t.Client()) + +// list all repositories for the authenticated user +repos, err := client.Repositories.List(nil) +``` + +See the [goauth2 docs][] for complete instructions on using that library. + +Also note that when using an authenticated Client, all calls made by the client +will include the specified OAuth token. Therefore, authenticated clients should +almost never be shared between different users. + [GitHub API]: http://developer.github.com/v3/ +[goauth2]: https://code.google.com/p/goauth2/ +[goauth2 docs]: http://godoc.org/code.google.com/p/goauth2/oauth + + +## Roadmap ## + +This library is being initially developed for an internal application at +Google, so API methods will likely be implemented in the order that they are +needed by that application. You can track the status of implementation in +[this Google spreadsheet][]. Eventually, I would like to cover the entire +GitHub API, so contributions are of course [always welcome][]. The calling +pattern is pretty well established, so adding new methods is relatively +straightforward. + +[this Google spreadhsheet]: https://docs.google.com/spreadsheet/ccc?key=0ApoVX4GOiXr-dGNKN1pObFh6ek1DR2FKUjBNZ1FmaEE&usp=sharing +[always welcome]: CONTRIBUTING.md + -## License +## License ## This library is distributed under the BSD-style license found in the LICENSE file. diff --git a/examples/example.go b/examples/example.go index 8bb8175..14dbbe6 100644 --- a/examples/example.go +++ b/examples/example.go @@ -10,6 +10,7 @@ func main() { client := github.NewClient(nil) fmt.Println("Recently updated repositories owned by user willnorris:") + opt := &github.RepositoryListOptions{Type: "owner", Sort: "updated", Direction: "desc"} repos, err := client.Repositories.List("willnorris", opt) if err != nil { @@ -21,8 +22,7 @@ func main() { rate, err := client.RateLimit() if err != nil { fmt.Printf("Error fetching rate limit: %#v\n\n", err) - return + } else { + fmt.Printf("API Rate Limit: %#v\n\n", rate) } - - fmt.Printf("API Rate Limit: %#v\n\n", rate) } diff --git a/github.go b/github.go index 96c3f08..29f64f2 100644 --- a/github.go +++ b/github.go @@ -38,6 +38,10 @@ capable http.Client: // list all repositories for the authenticated user repos, err := client.Repositories.List(nil) +Note that when using an authenticated Client, all calls made by the client will +include the specified OAuth token. Therefore, authenticated clients should +almost never be shared between different users. + The full GitHub API is documented at http://developer.github.com/v3/. */ package github