From d29f4d744e3b38ae4a369e8a095f76524e0ca601 Mon Sep 17 00:00:00 2001 From: Will Norris Date: Fri, 11 Apr 2014 09:55:04 -0700 Subject: [PATCH] switch rate.Reset to be a Timstamp depending on who people are using rate.Reset this may or may not be a breaking change, since Timestamp supports all of the exported methods from time.Time. --- github/github.go | 21 ++++++--------------- github/github_test.go | 2 +- 2 files changed, 7 insertions(+), 16 deletions(-) diff --git a/github/github.go b/github/github.go index fd60665..66e75e1 100644 --- a/github/github.go +++ b/github/github.go @@ -270,7 +270,7 @@ func (r *Response) populateRate() { } if reset := r.Header.Get(headerRateReset); reset != "" { if v, _ := strconv.ParseInt(reset, 10, 64); v != 0 { - r.Rate.Reset = time.Unix(v, 0) + r.Rate.Reset = Timestamp{time.Unix(v, 0)} } } } @@ -390,11 +390,7 @@ func parseBoolResponse(err error) (bool, error) { // API response wrapper to a rate limit request. type rateResponse struct { - Rate struct { - Limit int `json:"limit"` - Remaining int `json:"remaining"` - Reset int64 `json:"reset"` - } `json:"rate"` + *Rate `json:"rate"` } // Rate represents the rate limit for the current client. Unauthenticated @@ -402,13 +398,13 @@ type rateResponse struct { // 5,000 per hour. type Rate struct { // The number of requests per hour the client is currently limited to. - Limit int + Limit int `json:"limit"` // The number of remaining requests the client can make this hour. - Remaining int + Remaining int `json:"remaining"` // The time at which the current rate limit will reset. - Reset time.Time + Reset Timestamp `json:"reset"` } // RateLimit returns the rate limit for the current client. @@ -424,12 +420,7 @@ func (c *Client) RateLimit() (*Rate, *Response, error) { return nil, nil, err } - rate := &Rate{ - Limit: response.Rate.Limit, - Remaining: response.Rate.Remaining, - Reset: time.Unix(response.Rate.Reset, 0), - } - return rate, resp, err + return response.Rate, resp, err } /* diff --git a/github/github_test.go b/github/github_test.go index 2ae4fb8..397565e 100644 --- a/github/github_test.go +++ b/github/github_test.go @@ -521,7 +521,7 @@ func TestRateLimit(t *testing.T) { want := &Rate{ Limit: 2, Remaining: 1, - Reset: time.Date(2013, 7, 1, 17, 47, 53, 0, time.UTC).Local(), + Reset: Timestamp{time.Date(2013, 7, 1, 17, 47, 53, 0, time.UTC).Local()}, } if !reflect.DeepEqual(rate, want) { t.Errorf("RateLimit returned %+v, want %+v", rate, want)