Documentation ¶
Overview ¶
This code is based on https://github.com/kurrik/twittergo licensed as follows (Apache 2.0) Copyright 2019 Arne Roomann-Kurrik
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Index ¶
- Constants
- type ApiResponse
- func (r ApiResponse) GetBodyReader() (io.ReadCloser, error)
- 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() ([]byte, error)
- type Client
- func (c *Client) FetchAppToken() (err error)
- func (c *Client) GET(endpoint string, headers map[string]string) (*ApiResponse, error)
- func (c *Client) HttpRequest(req *http.Request) (resp *ApiResponse, err error)
- func (c *Client) POSTForm(endpoint string, fw func(*multipart.Writer) error) (*ApiResponse, error)
- func (c *Client) SetUser(user *oauth1a.UserConfig)
- func (c *Client) Sign(req *http.Request) error
- type ClientParams
- type Error
- type Errors
- type Like
- type MediaImage
- type MediaResponse
- type MediaUpload
- type RateLimitError
- type ResponseError
- type StatusUpdate
- type Tweet
- type User
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 )
const ( MaxTweetLength = 280 UrlTweetLength = 23 // number of characters a URL debit from MaxTweetLength )
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) GetBodyReader ¶
func (r ApiResponse) GetBodyReader() (io.ReadCloser, error)
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() ([]byte, error)
type Client ¶
type Client struct { Host string OAuth *oauth1a.Service User *oauth1a.UserConfig HttpClient *http.Client AppToken string }
func NewClient ¶
func NewClient(p *ClientParams) *Client
func NewClientWithConfig ¶
func NewClientWithConfig(config *oauth1a.ClientConfig, user *oauth1a.UserConfig) *Client
func (*Client) FetchAppToken ¶
func (*Client) HttpRequest ¶
func (c *Client) HttpRequest(req *http.Request) (resp *ApiResponse, err error)
Sends a HTTP request through this instance's HTTP client.
func (*Client) SetUser ¶
func (c *Client) SetUser(user *oauth1a.UserConfig)
Changes the user authorization credentials for this client.
type ClientParams ¶
type Like ¶
type Like struct { CreatedAtStr string `json:"created_at"` Id uint64 `json:"id"` User User `json:"user"` QuotedStatusId uint64 `json:"quoted_status_id"` QuotedStatus *Tweet `json:"quoted_status"` IsTruncated bool `json:"truncated"` }
Like is "favorite", recorded when you tap a heart in Twitter
type MediaImage ¶
type MediaResponse ¶
type MediaResponse struct { Id uint64 `json:"media_id"` Size int `json:"size"` ExpiresAfter time.Duration `json:"expires_after_secs"` Image *MediaImage }
type MediaUpload ¶
type MediaUpload struct { Name string BodyReader io.Reader // either set BodyReader or BodyData BodyData []byte // either set BodyReader or BodyData }
func (*MediaUpload) Send ¶
func (r *MediaUpload) Send(c *Client) (mr *MediaResponse, err error)
type RateLimitError ¶
type RateLimitError struct { Limit uint32 // the rate limit ceiling for that given endpoint Remaining uint32 // the number of requests left for {Limit} window Reset time.Time // the remaining window before the rate limit resets }
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 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 StatusUpdate ¶
StatusUpdate is used to create a new Tweet
type Tweet ¶
type Tweet struct { CreatedAtStr string `json:"created_at"` Id uint64 `json:"id"` Text string `json:"text"` User User `json:"user"` RetweetCount uint64 `json:"retweet_count"` FavoriteCount uint64 `json:"favorite_count"` IsFavorited bool `json:"favorited"` IsRetweeted bool `json:"retweeted"` InReplyToStatusId uint64 `json:"in_reply_to_status_id"` InReplyToUserId uint64 `json:"in_reply_to_user_id"` InReplyToScreenName string `json:"in_reply_to_screen_name"` }
Tweet represents an exisiting tweet
type User ¶
type User struct { Id uint64 `json:"id"` Name string `json:"name"` ScreenName string `json:"screen_name"` Location string `json:"location"` Description string `json:"description"` Url string `json:"url"` CreatedAtStr string `json:"created_at"` FollowersCount uint64 `json:"followers_count"` FollowingCount uint64 `json:"friends_count"` FavoritesCount uint64 `json:"favourites_count"` }