-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathdirect_message_option.go
More file actions
57 lines (53 loc) · 1.38 KB
/
direct_message_option.go
File metadata and controls
57 lines (53 loc) · 1.38 KB
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
package gotwtr
import (
"net/http"
"strconv"
"strings"
)
type DirectMessageOption struct {
DMEventFields []DMEventField
EventTypes EventTypes
Expansions []Expansion
MaxResults int
MediaFields []MediaField
PaginationToken string
TweetFields []TweetField
UserFields []UserField
}
func (d *DirectMessageOption) addQuery(req *http.Request) {
q := req.URL.Query()
if len(d.DMEventFields) > 0 {
q.Add("dm_event.fields", strings.Join(dmEventFieldsToString(d.DMEventFields), ","))
}
if len(d.EventTypes) > 0 {
q.Add("event_types", string(d.EventTypes))
}
if len(d.Expansions) > 0 {
q.Add("expansions", strings.Join(expansionsToString(d.Expansions), ","))
}
if d.MaxResults > 0 {
q.Add("max_results", strconv.Itoa(d.MaxResults))
}
if len(d.MediaFields) > 0 {
q.Add("media.fields", strings.Join(mediaFieldsToString(d.MediaFields), ","))
}
if d.PaginationToken != "" {
q.Add("pagination_token", d.PaginationToken)
}
if len(d.TweetFields) > 0 {
q.Add("tweet.fields", strings.Join(tweetFieldsToString(d.TweetFields), ","))
}
if len(d.UserFields) > 0 {
q.Add("user.fields", strings.Join(userFieldsToString(d.UserFields), ","))
}
if len(q) > 0 {
req.URL.RawQuery = q.Encode()
}
}
func dmEventFieldsToString(defs []DMEventField) []string {
slice := make([]string, len(defs))
for i, def := range defs {
slice[i] = string(def)
}
return slice
}