This repository has been archived by the owner on Apr 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtwitter.go
75 lines (60 loc) · 1.77 KB
/
twitter.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
74
75
package main
import (
"net/url"
"strconv"
"github.com/ChimeraCoder/anaconda"
)
//go:generate moq -out twitterapi_moq_test.go . TwitterAPI
type TwitterAPI interface {
GetSelf(v url.Values) (u anaconda.User, err error)
GetUserTimeline(v url.Values) (timeline []anaconda.Tweet, err error)
GetFavorites(v url.Values) (favorites []anaconda.Tweet, err error)
DeleteTweet(id int64, trimUser bool) (tweet anaconda.Tweet, err error)
Unfavorite(id int64) (rt anaconda.Tweet, err error)
UnRetweet(id int64, trimUser bool) (rt anaconda.Tweet, err error)
}
type Twitter struct {
api TwitterAPI
}
func (t *Twitter) Self() (int64, error) {
user, err := t.api.GetSelf(nil)
if err != nil {
return 0, err
}
return user.Id, nil
}
func (t *Twitter) GetUserTimeline(limitTweetID int64) ([]anaconda.Tweet, error) {
v := url.Values{}
v.Set("include_rts", "1")
v.Set("count", "200")
v.Set("trim_user", "true")
// if 0, will return latest 200 tweets.
// otherwise, reteurn 200 before specified tweetID.
if limitTweetID != 0 {
v.Set("max_id", strconv.Itoa(int(limitTweetID)))
}
return t.api.GetUserTimeline(v)
}
func (t *Twitter) GetUserFavorites(limitTweetID int64) ([]anaconda.Tweet, error) {
v := url.Values{}
v.Set("count", "200")
v.Set("include_entities", "false")
// if 0, will return latest 200 tweets.
// otherwise, return 200 before specified tweetID.
if limitTweetID != 0 {
v.Set("max_id", strconv.Itoa(int(limitTweetID)))
}
return t.api.GetFavorites(v)
}
func (t *Twitter) Delete(tweetID int64) error {
_, err := t.api.DeleteTweet(tweetID, true)
return err
}
func (t *Twitter) UnFavorite(tweetID int64) error {
_, err := t.api.Unfavorite(tweetID)
return err
}
func (t *Twitter) UnRetweet(tweetID int64) error {
_, err := t.api.UnRetweet(tweetID, true)
return err
}