Documentation
¶
Index ¶
- Constants
- type Client
- func (c *Client) Block(user string, targetUser string) (bool, error)
- func (c *Client) DoRequest(req *http.Request, v interface{}) error
- func (c *Client) LikingUsers(id string, params *url.Values) *LikingUsersInterator
- func (c *Client) Me(params *url.Values) (*User, error)
- func (c *Client) NewRequest(method, path string, payload interface{}) (*http.Request, error)
- func (c *Client) Tweet(tweetID string, params *url.Values) (*Tweet, error)
- func (c *Client) User(id string, params *url.Values) (*User, error)
- type ClientOption
- type HTTPClient
- type HTTPError
- type LikingUsersInterator
- type Logger
- type Tweet
- type User
Constants ¶
const DefaultBaseURL = "https://api.twitter.com/2"
DefaultBaseURL used for API requests. Use WithBaseURL() to change.
const DefaultTweetFields = "id,author_id,created_at,text"
DefaultTweetFields is the default list of tweet fields requested.
const DefaultUserFields = "id,name,username,created_at,description,location,pinned_tweet_id,profile_image_url,protected,url,verified,withheld"
DefaultUserFields is the default list of user fields requested.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a Twitter API client.
func NewClient ¶
func NewClient(httpClient HTTPClient, options ...ClientOption) *Client
NewClient returns a new Client struct.
func (*Client) Block ¶
Block causes the user to block the target user. API: https://developer.twitter.com/en/docs/twitter-api/users/blocks/api-reference/post-users-user_id-blocking Rate limit: 50 requests per 15-minute window per each authenticated user.
func (*Client) DoRequest ¶
DoRequest makes a request to the API and unmarshales the response into v.
func (*Client) LikingUsers ¶
func (c *Client) LikingUsers(id string, params *url.Values) *LikingUsersInterator
LikingUsers returns an iterator to get information about a Tweet’s liking users. API: https://developer.twitter.com/en/docs/twitter-api/tweets/likes/api-reference/get-tweets-id-liking_users Rate limit: 75 requests per 15-minute window per each authenticated user.
func (*Client) Me ¶
Me returns information about an authorized user. API: https://developer.twitter.com/en/docs/twitter-api/users/lookup/api-reference/get-users-me Rate limit: 75 requests per 15-minute window per each authenticated user.
func (*Client) NewRequest ¶
NewRequest returns a http.Request for the given path. If a payload is provided it will get JSON encoded.
func (*Client) Tweet ¶
Tweet returns information about a single Tweet. API: https://developer.twitter.com/en/docs/twitter-api/tweets/lookup/api-reference/get-tweets-id Rate limit: 900 requests per 15-minute window per each authenticated user.
func (*Client) User ¶
User returns information about a single user. API: https://developer.twitter.com/en/docs/twitter-api/users/lookup/api-reference/get-users-id Rate limit: 900 requests per 15-minute window per each authenticated user.
type ClientOption ¶
type ClientOption func(*Client)
ClientOption sets some additional options on a client.
func EnableRateLimitRetry ¶
func EnableRateLimitRetry() ClientOption
EnableRateLimitRetry enables wait and retry on 429 responses. Default is false.
func WithBaseURL ¶
func WithBaseURL(url string) ClientOption
WithBaseURL sets the base URL for request.
func WithLogger ¶
func WithLogger(logger Logger) ClientOption
WithLogger sets the logger used in the client. By default no log output is emitted.
type HTTPClient ¶
HTTPClient models the http client interface.
type HTTPError ¶
type HTTPError struct { Response *http.Response StatusCode int Status string RateLimitReset time.Time // time when the rate-limiting will reset and it's safe to retry requests }
HTTPError contains information about a failed http request.
type LikingUsersInterator ¶
type LikingUsersInterator struct {
// contains filtered or unexported fields
}
LikingUsersInterator is used to iterate over liking users results.
func (*LikingUsersInterator) NextPage ¶
func (i *LikingUsersInterator) NextPage() bool
NextPage advances the iterator and returns true if there are more results.
func (*LikingUsersInterator) User ¶
func (i *LikingUsersInterator) User() ([]*User, error)
Users returns the liking users result for the current pagination token.
type Logger ¶
type Logger interface {
Printf(format string, v ...interface{})
}
Logger is a simple logger interface.
type Tweet ¶
type Tweet struct { ID string `json:"id"` AuthorID string `json:"author_id"` CreatedAt time.Time `json:"created_at"` Text string `json:"text"` }
Tweet data returned from the API.
type User ¶
type User struct { ID string `json:"id"` Name string `json:"name"` UserName string `json:"username"` CreatedAt time.Time `json:"created_at"` Description string `json:"description"` Location string `json:"location"` PinnedTweetID string `json:"pinned_tweet_id"` ProfileImageUrl string `json:"profile_image_url"` Protected bool `json:"protected"` URL string `json:"url"` Verified bool `json:"verified"` Withheld bool `json:"withheld"` }
User data returned from the API.