forked from sivchari/gotwtr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
user_option.go
149 lines (137 loc) · 3.58 KB
/
user_option.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
package gotwtr
import (
"net/http"
"strconv"
"strings"
)
type RetrieveUserOption struct {
Expansions []Expansion
TweetFields []TweetField
UserFields []UserField
}
func (r *RetrieveUserOption) addQuery(req *http.Request) {
q := req.URL.Query()
if len(r.Expansions) > 0 {
q.Add("expansions", strings.Join(expansionsToString(r.Expansions), ","))
}
if len(r.TweetFields) > 0 {
q.Add("tweet.fields", strings.Join(tweetFieldsToString(r.TweetFields), ","))
}
if len(r.UserFields) > 0 {
q.Add("user.fields", strings.Join(userFieldsToString(r.UserFields), ","))
}
if len(q) > 0 {
req.URL.RawQuery = q.Encode()
}
}
type FollowOption struct {
Expansions []Expansion
MaxResults int
PaginationToken string
TweetFields []TweetField
UserFields []UserField
}
func (f *FollowOption) addQuery(req *http.Request) {
q := req.URL.Query()
if len(f.Expansions) > 0 {
q.Add("expansions", strings.Join(expansionsToString(f.Expansions), ","))
}
if f.MaxResults > 0 {
q.Add("max_results", strconv.Itoa(f.MaxResults))
}
if len(f.PaginationToken) > 0 {
q.Add("pagination_token", f.PaginationToken)
}
if len(f.TweetFields) > 0 {
q.Add("tweet.fields", strings.Join(tweetFieldsToString(f.TweetFields), ","))
}
if len(f.UserFields) > 0 {
q.Add("user.fields", strings.Join(userFieldsToString(f.UserFields), ","))
}
if len(q) > 0 {
req.URL.RawQuery = q.Encode()
}
}
type BlockOption struct {
Expansions []Expansion
MaxResults int
PaginationToken string
TweetFields []TweetField
UserFields []UserField
}
func (b *BlockOption) addQuery(req *http.Request) {
q := req.URL.Query()
if len(b.Expansions) > 0 {
q.Add("expansions", strings.Join(expansionsToString(b.Expansions), ","))
}
if b.MaxResults > 0 {
q.Add("max_results", strconv.Itoa(b.MaxResults))
}
if len(b.PaginationToken) > 0 {
q.Add("pagination_token", b.PaginationToken)
}
if len(b.TweetFields) > 0 {
q.Add("tweet.fields", strings.Join(tweetFieldsToString(b.TweetFields), ","))
}
if len(b.UserFields) > 0 {
q.Add("user.fields", strings.Join(userFieldsToString(b.UserFields), ","))
}
if len(q) > 0 {
req.URL.RawQuery = q.Encode()
}
}
type MuteOption struct {
Expansions []Expansion
MaxResults int
PaginationToken string
TweetFields []TweetField
UserFields []UserField
}
func (m *MuteOption) addQuery(req *http.Request) {
q := req.URL.Query()
if len(m.Expansions) > 0 {
q.Add("expansions", strings.Join(expansionsToString(m.Expansions), ","))
}
if m.MaxResults > 0 {
q.Add("max_results", strconv.Itoa(m.MaxResults))
}
if len(m.PaginationToken) > 0 {
q.Add("pagination_token", m.PaginationToken)
}
if len(m.TweetFields) > 0 {
q.Add("tweet.fields", strings.Join(tweetFieldsToString(m.TweetFields), ","))
}
if len(m.UserFields) > 0 {
q.Add("user.fields", strings.Join(userFieldsToString(m.UserFields), ","))
}
if len(q) > 0 {
req.URL.RawQuery = q.Encode()
}
}
func userFieldsToString(ufs []UserField) []string {
slice := make([]string, len(ufs))
for i, uf := range ufs {
slice[i] = string(uf)
}
return slice
}
type MeOption struct {
Expansions []Expansion
TweetFields []TweetField
UserFields []UserField
}
func (m *MeOption) addQuery(req *http.Request) {
q := req.URL.Query()
if len(m.Expansions) > 0 {
q.Add("expansions", strings.Join(expansionsToString(m.Expansions), ","))
}
if len(m.TweetFields) > 0 {
q.Add("tweet.fields", strings.Join(tweetFieldsToString(m.TweetFields), ","))
}
if len(m.UserFields) > 0 {
q.Add("user.fields", strings.Join(userFieldsToString(m.UserFields), ","))
}
if len(q) > 0 {
req.URL.RawQuery = q.Encode()
}
}