Documentation
¶
Overview ¶
Package client provides a configurable Twitter API HTTP client used by higher level service wrappers.
Index ¶
- func CheckResponse(resp *http.Response) error
- func SafeClose(closer io.ReadCloser)
- type APIError
- type Client
- func (c *Client) Delete(ctx context.Context, path string, query map[string]string) (*http.Response, error)
- func (c *Client) Do(req *http.Request) (*http.Response, error)
- func (c *Client) Get(ctx context.Context, path string, query map[string]string) (*http.Response, error)
- func (c *Client) NewRequest(ctx context.Context, method, path string, query map[string]string, ...) (*http.Request, error)
- func (c *Client) Post(ctx context.Context, path string, body interface{}, query map[string]string) (*http.Response, error)
- type Config
- type Error
- type RateLimitSnapshot
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CheckResponse ¶
CheckResponse inspects the response status code and returns an APIError when the call did not succeed.
func SafeClose ¶
func SafeClose(closer io.ReadCloser)
SafeClose closes a response body while ignoring errors.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client wraps HTTP concerns for talking to the Twitter v2 API.
func New ¶
New constructs a Client using the supplied configuration taking sensible defaults from environment variables when values are omitted.
func (*Client) Delete ¶
func (c *Client) Delete(ctx context.Context, path string, query map[string]string) (*http.Response, error)
Delete issues a DELETE request against the supplied path.
func (*Client) Get ¶
func (c *Client) Get(ctx context.Context, path string, query map[string]string) (*http.Response, error)
Get issues a GET request against the supplied path.
type Config ¶
type Config struct {
BaseURL string
BearerToken string
UserAgent string
HTTPClient *http.Client
Timeout time.Duration
}
Config describes how to construct a Client.
type RateLimitSnapshot ¶
RateLimitSnapshot captures the rate limit headers for a response.
func ParseRateLimits ¶
func ParseRateLimits(resp *http.Response) RateLimitSnapshot
ParseRateLimits extracts rate limiting information from the response headers.