forked from g8rswimmer/go-twitter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
user_params.go
125 lines (118 loc) · 3.28 KB
/
user_params.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
package twitter
import (
"net/http"
"strconv"
"strings"
"time"
)
// UserFieldOptions are the tweet options for the response
type UserFieldOptions struct {
Expansions []Expansion
TweetFields []TweetField
UserFields []UserField
}
func (u UserFieldOptions) addQuery(req *http.Request) {
q := req.URL.Query()
if len(u.Expansions) > 0 {
q.Add("expansions", strings.Join(expansionStringArray(u.Expansions), ","))
}
if len(u.TweetFields) > 0 {
q.Add("tweet.fields", strings.Join(tweetFieldStringArray(u.TweetFields), ","))
}
if len(u.UserFields) > 0 {
q.Add("user.fields", strings.Join(userFieldStringArray(u.UserFields), ","))
}
if len(q) > 0 {
req.URL.RawQuery = q.Encode()
}
}
// UserFollowOptions are the options that can be passed for the following APIs
type UserFollowOptions struct {
Expansions []Expansion
TweetFields []TweetField
UserFields []UserField
MaxResults int
PaginationToken string
}
func (u UserFollowOptions) addQuery(req *http.Request) {
q := req.URL.Query()
if len(u.Expansions) > 0 {
q.Add("expansions", strings.Join(expansionStringArray(u.Expansions), ","))
}
if len(u.TweetFields) > 0 {
q.Add("tweet.fields", strings.Join(tweetFieldStringArray(u.TweetFields), ","))
}
if len(u.UserFields) > 0 {
q.Add("user.fields", strings.Join(userFieldStringArray(u.UserFields), ","))
}
if u.MaxResults > 0 {
q.Add("max_results", strconv.Itoa(u.MaxResults))
}
if len(u.PaginationToken) > 0 {
q.Add("pagination_token", u.PaginationToken)
}
if len(q) > 0 {
req.URL.RawQuery = q.Encode()
}
}
// UserTimelineOpts are options in the user tweet timeline
type UserTimelineOpts struct {
Excludes []Exclude
Expansions []Expansion
MediaFields []MediaField
PlaceFields []PlaceField
PollFields []PollField
TweetFields []TweetField
UserFields []UserField
SinceID string
UntilID string
PaginationToken string
MaxResults int
StartTime time.Time
EndTime time.Time
}
func (u UserTimelineOpts) addQuery(req *http.Request) {
q := req.URL.Query()
if len(u.Excludes) > 0 {
q.Add("exclude", strings.Join(excludetringArray(u.Excludes), ","))
}
if len(u.TweetFields) > 0 {
q.Add("tweet.fields", strings.Join(tweetFieldStringArray(u.TweetFields), ","))
}
if len(u.UserFields) > 0 {
q.Add("user.fields", strings.Join(userFieldStringArray(u.UserFields), ","))
}
if len(u.MediaFields) > 0 {
q.Add("media.fields", strings.Join(mediaFieldStringArray(u.MediaFields), ","))
}
if len(u.PlaceFields) > 0 {
q.Add("place.fields", strings.Join(placeFieldStringArray(u.PlaceFields), ","))
}
if len(u.PollFields) > 0 {
q.Add("poll.fields", strings.Join(pollFieldStringArray(u.PollFields), ","))
}
if len(u.Expansions) > 0 {
q.Add("expansions", strings.Join(expansionStringArray(u.Expansions), ","))
}
if len(u.SinceID) > 0 {
q.Add("since_id", u.SinceID)
}
if len(u.UntilID) > 0 {
q.Add("until_id", u.UntilID)
}
if u.MaxResults > 0 {
q.Add("max_results", strconv.Itoa(u.MaxResults))
}
if len(u.PaginationToken) > 0 {
q.Add("pagination_token", u.PaginationToken)
}
if !u.EndTime.IsZero() {
q.Add("end_time", u.EndTime.Format(time.RFC3339))
}
if !u.StartTime.IsZero() {
q.Add("start_time", u.StartTime.Format(time.RFC3339))
}
if len(q) > 0 {
req.URL.RawQuery = q.Encode()
}
}