tweeter

package
v0.0.0-...-a41f41c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 24, 2021 License: ISC Imports: 17 Imported by: 0

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

View Source
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"
)
View Source
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
)
View Source
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

type ApiResponse http.Response

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 (c *Client) FetchAppToken() (err error)

func (*Client) GET

func (c *Client) GET(endpoint string, headers map[string]string) (*ApiResponse, error)

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) POSTForm

func (c *Client) POSTForm(endpoint string, fw func(*multipart.Writer) error) (*ApiResponse, error)

func (*Client) SetUser

func (c *Client) SetUser(user *oauth1a.UserConfig)

Changes the user authorization credentials for this client.

func (*Client) Sign

func (c *Client) Sign(req *http.Request) error

Signs the request with app-only auth, fetching a bearer token if needed.

type ClientParams

type ClientParams struct {
	ConsumerKey       string
	ConsumerSecret    string
	AccessToken       string
	AccessTokenSecret string
}

type Error

type Error map[string]interface{}

func (Error) Code

func (e Error) Code() int64

func (Error) Error

func (e Error) Error() string

func (Error) Message

func (e Error) Message() string

type Errors

type Errors map[string]interface{}

func (Errors) Error

func (e Errors) Error() string

func (Errors) Errors

func (e Errors) Errors() []Error

func (Errors) String

func (e Errors) String() string

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 MediaImage struct {
	ImageType string `json:"image_type"` // e.g. "image/jpeg"
	Width     int    `json:"w"`
	Height    int    `json:"h"`
}

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

type ResponseError struct {
	Body string
	Code int
}

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

type StatusUpdate struct {
	Status   string
	MediaIds []uint64
}

StatusUpdate is used to create a new Tweet

func (*StatusUpdate) Send

func (r *StatusUpdate) Send(c *Client) (*Tweet, error)

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

func (*Tweet) CreatedAt

func (t *Tweet) CreatedAt() time.Time

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"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL