Documentation ¶
Overview ¶
Implements a Twitter client library in Go.
Index ¶
- Constants
- type APIResponse
- func (r APIResponse) HasMediaRateLimit() bool
- func (r APIResponse) HasRateLimit() bool
- func (r APIResponse) MediaRateLimit() uint32
- func (r APIResponse) MediaRateLimitRemaining() uint32
- func (r APIResponse) MediaRateLimitReset() time.Time
- func (r APIResponse) Parse(out interface{}) (err error)
- func (r APIResponse) RateLimit() uint32
- func (r APIResponse) RateLimitRemaining() uint32
- func (r APIResponse) RateLimitReset() time.Time
- func (r APIResponse) ReadBody() string
- type BearerToken
- type Client
- func (c *Client) FetchAppToken() (err error)
- func (c *Client) GetAppToken() string
- func (c *Client) SendRequest(req *http.Request) (resp *APIResponse, err error)
- func (c *Client) SetAppToken(token string)
- func (c *Client) SetUser(user *oauth1a.UserConfig)
- func (c *Client) Sign(req *http.Request) (err error)
- type CursoredLists
- type Error
- type Errors
- type List
- type Lists
- type MediaResponse
- type RateLimitError
- type RateLimitResponse
- type ResponseError
- type SearchResults
- type Timeline
- type Tweet
- type User
- type VideoUpload
Constants ¶
const ( H_LIMIT = "X-Rate-Limit-Limit" H_LIMIT_REMAIN = "X-Rate-Limit-Remaining" H_LIMIT_RESET = "X-Rate-Limit-Reset" H_MEDIA_LIMIT = "X-MediaRateLimit-Limit" H_MEDIA_LIMIT_REMAIN = "X-MediaRateLimit-Remaining" H_MEDIA_LIMIT_RESET = "X-MediaRateLimit-Reset" )
const ( STATUS_OK = 200 STATUS_CREATED = 201 STATUS_ACCEPTED = 202 STATUS_NO_CONTENT = 204 STATUS_INVALID = 400 STATUS_UNAUTHORIZED = 401 STATUS_FORBIDDEN = 403 STATUS_NOTFOUND = 404 STATUS_LIMIT = 429 STATUS_GATEWAY = 502 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type APIResponse ¶
APIResponse provides methods for retrieving information from the HTTP headers in a Twitter API response.
func (APIResponse) HasMediaRateLimit ¶
func (r APIResponse) HasMediaRateLimit() bool
func (APIResponse) HasRateLimit ¶
func (r APIResponse) HasRateLimit() bool
func (APIResponse) MediaRateLimit ¶
func (r APIResponse) MediaRateLimit() uint32
func (APIResponse) MediaRateLimitRemaining ¶
func (r APIResponse) MediaRateLimitRemaining() uint32
func (APIResponse) MediaRateLimitReset ¶
func (r APIResponse) MediaRateLimitReset() time.Time
func (APIResponse) Parse ¶
func (r APIResponse) Parse(out interface{}) (err error)
Parse unmarshals a JSON encoded HTTP response into the supplied interface, with handling for the various kinds of errors the Twitter API can return.
The returned error may be of the type Errors, RateLimitError, ResponseError, or an error returned from io.Reader.Read().
func (APIResponse) RateLimit ¶
func (r APIResponse) RateLimit() uint32
func (APIResponse) RateLimitRemaining ¶
func (r APIResponse) RateLimitRemaining() uint32
func (APIResponse) RateLimitReset ¶
func (r APIResponse) RateLimitReset() time.Time
func (APIResponse) ReadBody ¶
func (r APIResponse) ReadBody() string
ReadBody returns the body of the response as a string. Only one of ReadBody and Parse may be called on a given APIResponse.
type BearerToken ¶
type BearerToken struct {
AccessToken string
}
type Client ¶
type Client struct { Host string OAuth *oauth1a.Service User *oauth1a.UserConfig AppToken *BearerToken HttpClient *http.Client }
Implements a Twitter client.
func NewClient ¶
func NewClient(config *oauth1a.ClientConfig, user *oauth1a.UserConfig) *Client
Creates a new Twitter client with the supplied OAuth configuration. Supports the use of HTTP proxies through the $HTTP_PROXY env var. For example:
export HTTP_PROXY=http://localhost:8888
When using a proxy, disable TLS certificate verification with the following:
export TLS_INSECURE=1
func (*Client) FetchAppToken ¶
Requests a new app auth bearer token and stores it.
func (*Client) GetAppToken ¶
Returns the current app-only auth token or an empty string. Must call FetchAppToken to populate this value before getting it. You may call SetAppToken with the value returned by this call in order to restore a previously-fetched bearer token to use.
func (*Client) SendRequest ¶
func (c *Client) SendRequest(req *http.Request) (resp *APIResponse, err error)
Sends a HTTP request through this instance's HTTP client.
func (*Client) SetAppToken ¶
Sets the app-only auth token to the specified string.
func (*Client) SetUser ¶
func (c *Client) SetUser(user *oauth1a.UserConfig)
Changes the user authorization credentials for this client.
type CursoredLists ¶
type CursoredLists map[string]interface{}
func (CursoredLists) Lists ¶
func (cl CursoredLists) Lists() Lists
func (CursoredLists) NextCursorStr ¶
func (cl CursoredLists) NextCursorStr() string
func (CursoredLists) PreviousCursorStr ¶
func (cl CursoredLists) PreviousCursorStr() string
type List ¶
type List map[string]interface{}
A List!
func (List) MemberCount ¶
func (List) SubscriberCount ¶
type MediaResponse ¶
type MediaResponse map[string]interface{}
Response for media upload requests.
func (MediaResponse) ExpiresAfterSecs ¶
func (r MediaResponse) ExpiresAfterSecs() int32
func (MediaResponse) MediaId ¶
func (r MediaResponse) MediaId() int64
func (MediaResponse) Size ¶
func (r MediaResponse) Size() int64
func (MediaResponse) Video ¶
func (r MediaResponse) Video() VideoUpload
type RateLimitError ¶
RateLimitError is returned from SendRequest when a rate limit is encountered.
func (RateLimitError) Error ¶
func (e RateLimitError) Error() string
func (RateLimitError) HasRateLimit ¶
func (e RateLimitError) HasRateLimit() bool
func (RateLimitError) RateLimit ¶
func (e RateLimitError) RateLimit() uint32
func (RateLimitError) RateLimitRemaining ¶
func (e RateLimitError) RateLimitRemaining() uint32
func (RateLimitError) RateLimitReset ¶
func (e RateLimitError) RateLimitReset() time.Time
type RateLimitResponse ¶
type RateLimitResponse interface { // HasRateLimit returns false if the ratelimiting information is // optional and missing. HasRateLimit() bool // RateLimit returns the requests per time period capacity of the // limit. RateLimit() uint32 // RateLimitRemaining returns how many requests are still available // in the current time period. RateLimitRemaining() uint32 // RateLimitReset returns when the rate limit will reset. RateLimitReset() time.Time }
RateLimitResponse is implemented by both RateLimitError and APIResponse.
type ResponseError ¶
Error returned if there was an issue parsing the response body.
func NewResponseError ¶
func NewResponseError(code int, body string) ResponseError
func (ResponseError) Error ¶
func (e ResponseError) Error() string
type SearchResults ¶
type SearchResults map[string]interface{}
It's a structured list of Tweets!
func (SearchResults) SearchMetadata ¶
func (sr SearchResults) SearchMetadata() map[string]interface{}
func (SearchResults) Statuses ¶
func (sr SearchResults) Statuses() []Tweet
type Tweet ¶
type Tweet map[string]interface{}
It's a Tweet! (Adorably referred to by the API as a "status").
type VideoUpload ¶
type VideoUpload map[string]interface{}
Nested response structure for video uploads.
func (VideoUpload) Type ¶
func (v VideoUpload) Type() string