diff --git a/README.md b/README.md index a08e304..ba8320b 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,12 @@ # go-github # -go-github is Go library for accessing the [GitHub API][]. +go-github is Go client library for accessing the [GitHub API][]. **Documentation:** **Build Status:** [![Build Status](https://travis-ci.org/google/go-github.png?branch=master)](https://travis-ci.org/google/go-github) **Test Coverage:** [![Test Coverage](https://coveralls.io/repos/google/go-github/badge.png?branch=master)](https://coveralls.io/r/google/go-github?branch=master) ([gocov report](https://drone.io/github.com/google/go-github/files/coverage.html)) -go-github requires Go version 1.1. - -[issue-9]: https://github.com/google/go-github/issues/9 +go-github requires Go version 1.1 or greater. ## Usage ## @@ -26,8 +24,8 @@ orgs, _, err := client.Organizations.List("willnorris", nil) ``` Some API methods have optional parameters that can be passed. For example, -to list repositories for org "github", sorted by the time they were last -updated: +to list repositories for the "github" organization, sorted by the time they +were last updated: ```go client := github.NewClient(nil) @@ -35,12 +33,14 @@ opt := &github.RepositoryListByOrgOptions{Sort: "updated"} repos, _, err := client.Repositories.ListByOrg("github", opt) ``` +### Authentication ### + The go-github library does not directly handle authentication. Instead, when creating a new client, pass an `http.Client` that can handle authentication for you. The easiest and recommended way to do this is using the [goauth2][] library, but you can always use any other library that provides an `http.Client`. If you have an OAuth2 access token (for example, a [personal -API token][]), you can use it with the goauth2 library like the following: +API token][]), you can use it with the goauth2 using: ```go t := &oauth.Transport{ @@ -55,14 +55,13 @@ 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. +For complete usage of go-github, see the full [package docs][]. [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 [personal API token]: https://github.com/blog/1509-personal-api-tokens +[package docs]: http://godoc.org/github.com/google/go-github/github ## Roadmap ## @@ -70,13 +69,13 @@ almost never be shared between different users. 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 +[this Google spreadsheet][roadmap]. Eventually, I would like to cover the entire +GitHub API, so contributions are of course [always welcome][contributing]. The +calling pattern is pretty well established, so adding new methods is relatively straightforward. -[this Google spreadsheet]: https://docs.google.com/spreadsheet/ccc?key=0ApoVX4GOiXr-dGNKN1pObFh6ek1DR2FKUjBNZ1FmaEE&usp=sharing -[always welcome]: CONTRIBUTING.md +[roadmap]: https://docs.google.com/spreadsheet/ccc?key=0ApoVX4GOiXr-dGNKN1pObFh6ek1DR2FKUjBNZ1FmaEE&usp=sharing +[contributing]: CONTRIBUTING.md ## License ## diff --git a/github/doc.go b/github/doc.go index f07bc5a..9b324c4 100644 --- a/github/doc.go +++ b/github/doc.go @@ -6,8 +6,8 @@ /* Package github provides a client for using the GitHub API. -Access different parts of the GitHub API using the various services on a GitHub -Client: +Construct a new GitHub client, then use the various services on the client to +access different parts of the GitHub API. For example: client := github.NewClient(nil) @@ -20,8 +20,18 @@ Set optional parameters for an API method by passing an Options object. opt := &github.RepositoryListByOrgOptions{Sort: "updated"} repos, _, err := client.Repositories.ListByOrg("github", opt) -Make authenticated API calls by constructing a GitHub client using an OAuth -capable http.Client: +The services of a client divide the API into logical chunks and correspond to +the structure of the GitHub API documentation at +http://developer.github.com/v3/. + +Authentication + +The go-github library does not directly handle authentication. Instead, when +creating a new client, pass an http.Client that can handle authentication for +you. The easiest and recommended way to do this is using the goauth2 library, +but you can always use any other library that provides an http.Client. If you +have an OAuth2 access token (for example, a personal API token), you can use it +with the goauth2 using: import "code.google.com/p/goauth2/oauth" @@ -34,12 +44,43 @@ capable http.Client: client := github.NewClient(t.Client()) // list all repositories for the authenticated user - repos, _, err := client.Repositories.List(nil) + 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/. +Rate Limiting + +GitHub imposes a rate limit on all API clients. Unauthenticated clients are +limited to 60 requests per hour, while authenticated clients can make up to +5,000 requests per hour. To receive the higher rate limit when making calls +that are not issued on behalf of a user, use the +UnauthenticatedRateLimitedTransport. + +The Rate field on a client tracks the rate limit information based on the most +recent API call. This is updated on every call, but may be out of date if it's +been some time since the last API call and other clients have made subsequent +requests since then. You can always call RateLimit() directly to get the most +up-to-date rate limit data for the client. + +Learn more about GitHub rate limiting at +http://developer.github.com/v3/#rate-limiting. + +Creating and Updating Resources + +All structs for GitHub resources use pointer values for all non-repeated fields. +This allows distinguishing between unset fields and those set to a zero-value. +Helper functions have been provided to easily create these pointers for string, +bool, and int values. For example: + + // create a new private repository named "foo" + repo := &github.Repo{ + Name: github.String("foo"), + Private: github.Bool(true), + } + client.Repositories.Create("", repo) + +Users who have worked with protocol buffers should find this pattern familiar. */ package github