-
Notifications
You must be signed in to change notification settings - Fork 3
/
consumer.go
73 lines (57 loc) · 1.62 KB
/
consumer.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package main
import (
"errors"
"github.com/waka/twg/twitter"
)
type Consumer struct {
config *Config
screenName string
apiClient *twitter.Client
}
func NewConsumer() *Consumer {
return &Consumer{config: LoadConfig()}
}
func (cons *Consumer) Auth() error {
if cons.config.IsAuthenticated() == false {
accessToken, err := twitter.Authenticate()
if err != nil {
return err
}
screenName := accessToken.AdditionalData["screen_name"]
cons.config.Set(accessToken.Token, accessToken.Secret, screenName)
if cons.config.Save() == false {
return errors.New("Failed to save config")
}
}
cons.apiClient = twitter.NewClient(
cons.config.AccessToken,
cons.config.AccessTokenSecret,
)
cons.screenName = cons.config.ScreenName
return nil
}
func (cons *Consumer) GetTimeline() ([]*twitter.Tweet, error) {
return cons.apiClient.GetTimeline()
}
func (cons *Consumer) GetMentions() ([]*twitter.Tweet, error) {
return cons.apiClient.GetMentions()
}
func (cons *Consumer) GetListTimeline(listName string) ([]*twitter.Tweet, error) {
screenName := cons.screenName
return cons.apiClient.GetListTimeline(screenName, listName)
}
func (cons *Consumer) Tweet(text string) error {
return cons.apiClient.DoTweet(text)
}
func (cons *Consumer) Reply(text string, tweet *twitter.Tweet) error {
return cons.apiClient.DoReply(text, tweet.Id)
}
func (cons *Consumer) Favorite(tweet *twitter.Tweet) error {
return cons.apiClient.DoFavorite(tweet.Id)
}
func (cons *Consumer) Retweet(tweet *twitter.Tweet) error {
return cons.apiClient.DoRetweet(tweet.Id)
}
func (cons *Consumer) GetScreenName() string {
return cons.screenName
}