Documentation ¶
Index ¶
- type TwitterClient
- func (t *TwitterClient) GetTimeline(username string) ([]anaconda.Tweet, error)
- func (t *TwitterClient) ListTweets(searchTerm string, tweetType string) ([]anaconda.Tweet, error)
- func (t *TwitterClient) PostTweet(message string) error
- func (t *TwitterClient) SendDM(recipientUsername string, message string) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type TwitterClient ¶
type TwitterClient struct {
// contains filtered or unexported fields
}
the package defines a struct TwitterClient that holds the anaconda Twitter API client and it also defines two methods PostTweet and GetTimeline that can be used to interact with Twitter.
NewTwitterClient function creates and returns a new TwitterClient, it sets the consumer key and secret and the access token and secret of your account and creates a new twitter api client using the anaconda.NewTwitterApi(os.Getenv("TWITTER_ACCESS_TOKEN"), os.Getenv("TWITTER_ACCESS_TOKEN_SECRET")) function.
PostTweet function sends a tweet using the message passed as a parameter and GetTimeline function gets the recent tweets from a user's timeline using the username passed as a parameter.
TwitterClient is a struct that holds the anaconda Twitter API client
func NewTwitterClient ¶
func NewTwitterClient() (*TwitterClient, error)
NewTwitterClient creates and returns a new TwitterClient
func (*TwitterClient) GetTimeline ¶
func (t *TwitterClient) GetTimeline(username string) ([]anaconda.Tweet, error)
GetTimeline gets the recent tweets from a user's timeline
func (*TwitterClient) ListTweets ¶
ListTweets returns a list of tweets that match a certain hashtag or from a certain user
This function takes a searchTerm and a tweetType as parameters, it creates a url values and set the count of tweets to 100, it then gets tweets according to the tweetType passed as a parameter, whether it is a hashtag or a user tweets by calling the t.api.GetSearch(searchTerm, v) and t.api.GetUserTimeline(searchTerm, v) respectively. It returns error if it fails otherwise it will return the tweets.
func (*TwitterClient) PostTweet ¶
func (t *TwitterClient) PostTweet(message string) error
PostTweet sends a tweet
func (*TwitterClient) SendDM ¶
func (t *TwitterClient) SendDM(recipientUsername string, message string) error
SendDM sends a direct message to a user
This function takes a recipientUsername and a message as parameters, it creates a url values and set the recipientUsername and then sends the message as a direct message to the user using the t.api.PostDMToScreenName(message, v) function. It returns error if it fails otherwise it will return nil.