-
Notifications
You must be signed in to change notification settings - Fork 246
/
tweets.go
107 lines (96 loc) · 4 KB
/
tweets.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package anaconda
import (
"fmt"
"net/url"
"strconv"
)
func (a TwitterApi) GetTweet(id int64, v url.Values) (tweet Tweet, err error) {
v = cleanValues(v)
v.Set("id", strconv.FormatInt(id, 10))
response_ch := make(chan response)
a.queryQueue <- query{a.baseUrl + "/statuses/show.json", v, &tweet, _GET, response_ch}
return tweet, (<-response_ch).err
}
func (a TwitterApi) GetTweetsLookupByIds(ids []int64, v url.Values) (tweet []Tweet, err error) {
var pids string
for w, i := range ids {
pids += strconv.FormatInt(i, 10)
if w != len(ids)-1 {
pids += ","
}
}
v = cleanValues(v)
v.Set("id", pids)
response_ch := make(chan response)
a.queryQueue <- query{a.baseUrl + "/statuses/lookup.json", v, &tweet, _GET, response_ch}
return tweet, (<-response_ch).err
}
func (a TwitterApi) GetRetweets(id int64, v url.Values) (tweets []Tweet, err error) {
response_ch := make(chan response)
a.queryQueue <- query{a.baseUrl + fmt.Sprintf("/statuses/retweets/%d.json", id), v, &tweets, _GET, response_ch}
return tweets, (<-response_ch).err
}
//PostTweet will create a tweet with the specified status message
func (a TwitterApi) PostTweet(status string, v url.Values) (tweet Tweet, err error) {
v = cleanValues(v)
v.Set("status", status)
response_ch := make(chan response)
a.queryQueue <- query{a.baseUrl + "/statuses/update.json", v, &tweet, _POST, response_ch}
return tweet, (<-response_ch).err
}
//DeleteTweet will destroy (delete) the status (tweet) with the specified ID, assuming that the authenticated user is the author of the status (tweet).
//If trimUser is set to true, only the user's Id will be provided in the user object returned.
func (a TwitterApi) DeleteTweet(id int64, trimUser bool) (tweet Tweet, err error) {
v := url.Values{}
if trimUser {
v.Set("trim_user", "t")
}
response_ch := make(chan response)
a.queryQueue <- query{a.baseUrl + fmt.Sprintf("/statuses/destroy/%d.json", id), v, &tweet, _POST, response_ch}
return tweet, (<-response_ch).err
}
//Retweet will retweet the status (tweet) with the specified ID.
//trimUser functions as in DeleteTweet
func (a TwitterApi) Retweet(id int64, trimUser bool) (rt Tweet, err error) {
v := url.Values{}
if trimUser {
v.Set("trim_user", "t")
}
response_ch := make(chan response)
a.queryQueue <- query{a.baseUrl + fmt.Sprintf("/statuses/retweet/%d.json", id), v, &rt, _POST, response_ch}
return rt, (<-response_ch).err
}
//UnRetweet will renove retweet Untweets a retweeted status.
//Returns the original Tweet with retweet details embedded.
//
//https://developer.twitter.com/en/docs/tweets/post-and-engage/api-reference/post-statuses-unretweet-id
//trim_user: tweet returned in a timeline will include a user object
//including only the status authors numerical ID.
func (a TwitterApi) UnRetweet(id int64, trimUser bool) (rt Tweet, err error) {
v := url.Values{}
if trimUser {
v.Set("trim_user", "t")
}
response_ch := make(chan response)
a.queryQueue <- query{a.baseUrl + fmt.Sprintf("/statuses/unretweet/%d.json", id), v, &rt, _POST, response_ch}
return rt, (<-response_ch).err
}
// Favorite will favorite the status (tweet) with the specified ID.
// https://developer.twitter.com/en/docs/tweets/post-and-engage/api-reference/post-favorites-create
func (a TwitterApi) Favorite(id int64) (rt Tweet, err error) {
v := url.Values{}
v.Set("id", fmt.Sprint(id))
response_ch := make(chan response)
a.queryQueue <- query{a.baseUrl + fmt.Sprintf("/favorites/create.json"), v, &rt, _POST, response_ch}
return rt, (<-response_ch).err
}
// Un-favorites the status specified in the ID parameter as the authenticating user.
// Returns the un-favorited status in the requested format when successful.
// https://developer.twitter.com/en/docs/tweets/post-and-engage/api-reference/post-favorites-destroy
func (a TwitterApi) Unfavorite(id int64) (rt Tweet, err error) {
v := url.Values{}
v.Set("id", fmt.Sprint(id))
response_ch := make(chan response)
a.queryQueue <- query{a.baseUrl + fmt.Sprintf("/favorites/destroy.json"), v, &rt, _POST, response_ch}
return rt, (<-response_ch).err
}