-
Notifications
You must be signed in to change notification settings - Fork 246
/
lists.go
111 lines (90 loc) · 3.99 KB
/
lists.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
108
109
110
111
package anaconda
import (
"net/url"
"strconv"
"strings"
)
// CreateList implements /lists/create.json
func (a TwitterApi) CreateList(name, description string, v url.Values) (list List, err error) {
v = cleanValues(v)
v.Set("name", name)
v.Set("description", description)
response_ch := make(chan response)
a.queryQueue <- query{a.baseUrl + "/lists/create.json", v, &list, _POST, response_ch}
return list, (<-response_ch).err
}
// AddUserToList implements /lists/members/create.json
func (a TwitterApi) AddUserToList(screenName string, listID int64, v url.Values) (users []User, err error) {
v = cleanValues(v)
v.Set("list_id", strconv.FormatInt(listID, 10))
v.Set("screen_name", screenName)
var addUserToListResponse AddUserToListResponse
response_ch := make(chan response)
a.queryQueue <- query{a.baseUrl + "/lists/members/create.json", v, &addUserToListResponse, _POST, response_ch}
return addUserToListResponse.Users, (<-response_ch).err
}
// AddMultipleUsersToList implements /lists/members/create_all.json
func (a TwitterApi) AddMultipleUsersToList(screenNames []string, listID int64, v url.Values) (list List, err error) {
v = cleanValues(v)
v.Set("list_id", strconv.FormatInt(listID, 10))
v.Set("screen_name", strings.Join(screenNames, ","))
response_ch := make(chan response)
a.queryQueue <- query{a.baseUrl + "/lists/members/create_all.json", v, &list, _POST, response_ch}
r := <-response_ch
return list, r.err
}
// RemoveUserFromList implements /lists/members/destroy.json
func (a TwitterApi) RemoveUserFromList(screenName string, listID int64, v url.Values) (list List, err error) {
v = cleanValues(v)
v.Set("list_id", strconv.FormatInt(listID, 10))
v.Set("screen_name", screenName)
response_ch := make(chan response)
a.queryQueue <- query{a.baseUrl + "/lists/members/destroy.json", v, &list, _POST, response_ch}
r := <-response_ch
return list, r.err
}
// RemoveMultipleUsersFromList implements /lists/members/destroy_all.json
func (a TwitterApi) RemoveMultipleUsersFromList(screenNames []string, listID int64, v url.Values) (list List, err error) {
v = cleanValues(v)
v.Set("list_id", strconv.FormatInt(listID, 10))
v.Set("screen_name", strings.Join(screenNames, ","))
response_ch := make(chan response)
a.queryQueue <- query{a.baseUrl + "/lists/members/destroy_all.json", v, &list, _POST, response_ch}
r := <-response_ch
return list, r.err
}
// GetListsOwnedBy implements /lists/ownerships.json
// screen_name, count, and cursor are all optional values
func (a TwitterApi) GetListsOwnedBy(userID int64, v url.Values) (lists []List, err error) {
v = cleanValues(v)
v.Set("user_id", strconv.FormatInt(userID, 10))
var listResponse ListResponse
response_ch := make(chan response)
a.queryQueue <- query{a.baseUrl + "/lists/ownerships.json", v, &listResponse, _GET, response_ch}
return listResponse.Lists, (<-response_ch).err
}
func (a TwitterApi) GetListTweets(listID int64, includeRTs bool, v url.Values) (tweets []Tweet, err error) {
v = cleanValues(v)
v.Set("list_id", strconv.FormatInt(listID, 10))
v.Set("include_rts", strconv.FormatBool(includeRTs))
response_ch := make(chan response)
a.queryQueue <- query{a.baseUrl + "/lists/statuses.json", v, &tweets, _GET, response_ch}
return tweets, (<-response_ch).err
}
// GetList implements /lists/show.json
func (a TwitterApi) GetList(listID int64, v url.Values) (list List, err error) {
v = cleanValues(v)
v.Set("list_id", strconv.FormatInt(listID, 10))
response_ch := make(chan response)
a.queryQueue <- query{a.baseUrl + "/lists/show.json", v, &list, _GET, response_ch}
return list, (<-response_ch).err
}
func (a TwitterApi) GetListTweetsBySlug(slug string, ownerScreenName string, includeRTs bool, v url.Values) (tweets []Tweet, err error) {
v = cleanValues(v)
v.Set("slug", slug)
v.Set("owner_screen_name", ownerScreenName)
v.Set("include_rts", strconv.FormatBool(includeRTs))
response_ch := make(chan response)
a.queryQueue <- query{a.baseUrl + "/lists/statuses.json", v, &tweets, _GET, response_ch}
return tweets, (<-response_ch).err
}