Browse Source

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.
Will Norris 12 years ago
parent
commit
d29f4d744e
2 changed files with 7 additions and 16 deletions
  1. +6
    -15
      github/github.go
  2. +1
    -1
      github/github_test.go

+ 6
- 15
github/github.go View File

@ -270,7 +270,7 @@ func (r *Response) populateRate() {
} }
if reset := r.Header.Get(headerRateReset); reset != "" { if reset := r.Header.Get(headerRateReset); reset != "" {
if v, _ := strconv.ParseInt(reset, 10, 64); v != 0 { 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. // API response wrapper to a rate limit request.
type rateResponse struct { 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 // Rate represents the rate limit for the current client. Unauthenticated
@ -402,13 +398,13 @@ type rateResponse struct {
// 5,000 per hour. // 5,000 per hour.
type Rate struct { type Rate struct {
// The number of requests per hour the client is currently limited to. // 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. // 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. // 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. // RateLimit returns the rate limit for the current client.
@ -424,12 +420,7 @@ func (c *Client) RateLimit() (*Rate, *Response, error) {
return nil, nil, err 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
} }
/* /*


+ 1
- 1
github/github_test.go View File

@ -521,7 +521,7 @@ func TestRateLimit(t *testing.T) {
want := &Rate{ want := &Rate{
Limit: 2, Limit: 2,
Remaining: 1, 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) { if !reflect.DeepEqual(rate, want) {
t.Errorf("RateLimit returned %+v, want %+v", rate, want) t.Errorf("RateLimit returned %+v, want %+v", rate, want)


Loading…
Cancel
Save