twitter

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2024 License: MPL-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

func New

func New(cfg Config, rdb *redis.Client) *Client

func (*Client) ExchangeTokensWithCode

func (c *Client) ExchangeTokensWithCode(ctx context.Context, code, state string) (*oauth2.Token, error)

func (*Client) GetAuthURL

func (c *Client) GetAuthURL(ctx context.Context, state string) string

func (*Client) GetListMembers added in v0.0.5

func (c *Client) GetListMembers(ctx context.Context, token *oauth2.Token, listID string, maxResults int, paginationToken string) (*ListMemberResponse, error)

GetListMembers retrieves members of a Twitter List

func (*Client) GetTweetByID added in v0.0.5

func (c *Client) GetTweetByID(ctx context.Context, token *oauth2.Token, tweetID string) (*TweetResponse, error)

func (*Client) GetTweetsByIDs added in v0.0.5

func (c *Client) GetTweetsByIDs(ctx context.Context, token *oauth2.Token, tweetIDs []string) (*TweetsResponse, error)

func (*Client) GetTweetsFromList added in v0.0.5

func (c *Client) GetTweetsFromList(ctx context.Context, token *oauth2.Token, listID string, maxResults int, paginationToken string) (*TweetsResponse, error)

GetTweetsFromList retrieves recent tweets from a given Twitter List

func (*Client) GetUserInfo

func (c *Client) GetUserInfo(ctx context.Context, token *oauth2.Token) (*UserResponse, error)

func (*Client) PostTweet

func (c *Client) PostTweet(ctx context.Context, token *oauth2.Token, tweet string) (string, error)

func (*Client) RefreshAccessToken

func (c *Client) RefreshAccessToken(ctx context.Context, token *oauth2.Token) (*oauth2.Token, error)

func (*Client) ValidateToken added in v0.0.5

func (c *Client) ValidateToken(ctx context.Context, token *oauth2.Token) error

type Config

type Config struct {
	BearerToken  string
	ClientID     string
	ClientSecret string
	CallbackURL  string
}

type ListMemberResponse added in v0.0.5

type ListMemberResponse struct {
	Data []User `json:"data"`
	Meta struct {
		ResultCount   int64  `json:"result_count"`
		PreviousToken string `json:"previous_token"`
		NextToken     string `json:"next_token"`
	} `json:"meta"`
}

type OAuthResponse

type OAuthResponse struct {
	AccessToken  string `json:"access_token"`
	RefreshToken string `json:"refresh_token"`
	TokenType    string `json:"token_type"`
	Expiry       string `json:"expiry"`
}

type TweetEntities added in v0.0.5

type TweetEntities struct {
	Urls []struct {
		URL         string `json:"url"`
		ExpandedURL string `json:"expanded_url"`
		DisplayURL  string `json:"display_url"`
	} `json:"urls"`
	Hashtags []struct {
		Tag   string `json:"tag"`
		Start int    `json:"start"`
		End   int    `json:"end"`
	} `json:"hashtags"`
	Mentions []struct {
		Username string `json:"username"`
		Start    int    `json:"start"`
		End      int    `json:"end"`
		ID       string `json:"id"`
	} `json:"mentions"`
	Annotations []struct {
		Start          int     `json:"start"`
		End            int     `json:"end"`
		Probability    float64 `json:"probability"`
		Type           string  `json:"type"`
		NormalizedText string  `json:"normalized_text"`
	} `json:"annotations"`
	CashTags []struct {
		Start int    `json:"start"`
		End   int    `json:"end"`
		Tag   string `json:"tag"`
	} `json:"cashtags"`
}

type TweetObject added in v0.0.5

type TweetObject struct {
	ID              string `json:"id"`
	Text            string `json:"text"`
	Lang            string `json:"lang"`
	InReplyToUserID string `json:"in_reply_to_user_id"`
	AuthorID        string `json:"author_id"`
	// Entities
	Entities TweetEntities `json:"entities"`
	// PublicMetrics
	PublicMetrics TweetPublicMetrics `json:"public_metrics"`
	// ReferencedTweets
	ReferencedTweets TweetReferencedTweets `json:"referenced_tweets"`
	// time
	CreatedAt *time.Time `json:"created_at"`
}

func (*TweetObject) GetFirstURL added in v0.0.5

func (t *TweetObject) GetFirstURL() string

func (*TweetObject) HasReferencedTweets added in v0.0.5

func (t *TweetObject) HasReferencedTweets() bool

func (*TweetObject) HasURL added in v0.0.5

func (t *TweetObject) HasURL() bool

type TweetPublicMetrics added in v0.0.5

type TweetPublicMetrics struct {
	RetweetCount    int64 `json:"retweet_count"`
	ReplyCount      int64 `json:"reply_count"`
	LikeCount       int64 `json:"like_count"`
	QuoteCount      int64 `json:"quote_count"`
	BookmarkCount   int64 `json:"bookmark_count"`
	ImpressionCount int64 `json:"impression_count"`
}

type TweetReferencedTweets added in v0.0.5

type TweetReferencedTweets []struct {
	Type string `json:"type"`
	ID   string `json:"id"`
}

type TweetResponse added in v0.0.5

type TweetResponse struct {
	Data     TweetObject `json:"data"`
	Includes struct {
		Users  []User        `json:"users"`
		Tweets []TweetObject `json:"tweets"`
	} `json:"includes"`
}

func (*TweetResponse) GetReferencedTweetByID added in v0.0.5

func (t *TweetResponse) GetReferencedTweetByID(id string) *TweetObject

func (*TweetResponse) GetUserByID added in v0.0.5

func (t *TweetResponse) GetUserByID(id string) *User

type TweetsResponse added in v0.0.5

type TweetsResponse struct {
	Data     []TweetObject `json:"data"`
	Includes struct {
		Users  []User        `json:"users"`
		Tweets []TweetObject `json:"tweets"`
	} `json:"includes"`
	Meta struct {
		ResultCount   int64  `json:"result_count"`
		PreviousToken string `json:"previous_token"`
		NextToken     string `json:"next_token"`
	} `json:"meta"`
}

func (*TweetsResponse) GetReferencedTweetByID added in v0.0.5

func (t *TweetsResponse) GetReferencedTweetByID(id string) *TweetObject

func (*TweetsResponse) GetUserByID added in v0.0.5

func (t *TweetsResponse) GetUserByID(id string) *User

func (*TweetsResponse) PrettyPrint added in v0.0.5

func (tr *TweetsResponse) PrettyPrint()

type User added in v0.0.5

type User struct {
	ID              string            `json:"id"`
	Name            string            `json:"name"`
	Username        string            `json:"username"`
	ProfileImageURL string            `json:"profile_image_url"`
	PublicMetrics   UserPublicMetrics `json:"public_metrics"`
}

type UserPublicMetrics added in v0.0.5

type UserPublicMetrics struct {
	FollowersCount uint64 `json:"followers_count"`
	FollowingCount uint64 `json:"following_count"`
	TweetCount     uint64 `json:"tweet_count"`
	ListedCount    uint64 `json:"listed_count"`
}

type UserResponse

type UserResponse struct {
	ID              string `json:"id"`
	Username        string `json:"username"`
	Name            string `json:"name"`
	ProfileImageURL string `json:"profile_image_url"`
}

Jump to

Keyboard shortcuts

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