Add support for rate_limit_status endpoint#124
Conversation
| } | ||
|
|
||
| // RateLimitStatusResponse response of rate limit status | ||
| type RateLimitStatusResponse struct { |
There was a problem hiding this comment.
Let's say RateLimit. There is a common tendency in PRs to have Response at the end of things, but its nicer to refer to them by objecty names to separate what they are from how they were obtained.
|
|
||
| // RateLimitStatusResponse response of rate limit status | ||
| type RateLimitStatusResponse struct { | ||
| RateLimitContext *RateLimitContext `json:"rate_limit_context,omitempty"` |
There was a problem hiding this comment.
These types aren't ever sent / marshaled to JSON so there should be no need for the omitempty on fields.
| } | ||
| } | ||
|
|
||
| // RateLimitStatusResponse response of rate limit status |
There was a problem hiding this comment.
RateLimitStatus summarizes current rate limits of resource families.
|
|
||
| // Status returns rate limits. | ||
| // https://developer.twitter.com/en/docs/developer-utilities/rate-limit-status/api-reference/get-application-rate_limit_status | ||
| func (s *RateLimitService) Status(params *RateLimitStatusParams) (RateLimitStatusResponse, *http.Response, error) { |
There was a problem hiding this comment.
Returned type should be a pointer for consistency with the rest of the library
| client := NewClient(httpClient) | ||
| tweets, _, err := client.RateLimits.Status(&RateLimitStatusParams{Resources: "statuses,users,help"}) | ||
| expected := RateLimitStatusResponse{ | ||
| RateLimitContext: &RateLimitContext{AccessToken: "786491-24zE39NUezJ8UTmOGOtLhgyLgCkPyY4dAcx6NA6sDKw"}, |
There was a problem hiding this comment.
Please make sure this isn't real.
There was a problem hiding this comment.
It's the one given on twitter example : https://developer.twitter.com/en/docs/developer-utilities/rate-limit-status/api-reference/get-application-rate_limit_status.html
|
|
||
| // RateLimitStatusParams are the parameters for RateLimitService.Status. | ||
| type RateLimitStatusParams struct { | ||
| Resources string `url:"resources,omitempty"` |
There was a problem hiding this comment.
If the endpoint takes a list of resource kinds, the API should take a slice of those resource kinds. What if a user wanted to construct that list in a higher level function and append items to it conditionally? Let's not assume its one comma separated string please
| Reset: 1403602426}}}} | ||
|
|
||
| assert.Nil(t, err) | ||
| assert.Equal(t, expected, tweets) |
| type RateLimitResource struct { | ||
| Limit int `json:"limit,omitempty"` | ||
| Remaining int `json:"remaining,omitempty"` | ||
| Reset int `json:"reset,omitempty"` |
There was a problem hiding this comment.
int64, this is an epoch time. Don't want bugs in 2038.
| Users map[string]*RateLimitResource `json:"users,omitempty"` | ||
| Statuses map[string]*RateLimitResource `json:"statuses,omitempty"` | ||
| Help map[string]*RateLimitResource `json:"help,omitempty"` | ||
| Search map[string]*RateLimitResource `json:"search,omitempty"` |
There was a problem hiding this comment.
I see these are the 4 keys from the Twitter examples. Have you tried others to try to find the full set or resources?
There was a problem hiding this comment.
Looks like there are a lot more https://developer.twitter.com/en/docs/basics/rate-limits
| Resources string `url:"resources,omitempty"` | ||
| } | ||
|
|
||
| // Status returns rate limits. |
There was a problem hiding this comment.
Let's improve this so its more helpful. Status summarizes the current rate limits of specified resource families.
|
Looks pretty good, should be fairly quick fixes. |
bd5f167 to
3af734a
Compare
3af734a to
3d48534
Compare
Support endpoints for rate limits : https://developer.twitter.com/en/docs/developer-utilities/rate-limit-status/api-reference/get-application-rate_limit_status