forked from sivchari/gotwtr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
space_option.go
139 lines (127 loc) · 3.58 KB
/
space_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
package gotwtr
import (
"net/http"
"strings"
)
type SearchSpacesOption struct {
Expansions []Expansion
SpaceFields []SpaceField
State []StateOption
TopicFields []TopicField
UserFields []UserField
}
func (s *SearchSpacesOption) addQuery(req *http.Request, searchTerm string) {
q := req.URL.Query()
q.Add("query", searchTerm)
if len(s.Expansions) > 0 {
q.Add("expansions", strings.Join(expansionsToString(s.Expansions), ","))
}
if len(s.SpaceFields) > 0 {
q.Add("space.fields", strings.Join(spaceFieldsToString(s.SpaceFields), ","))
}
if len(s.State) > 0 {
q.Add("state", strings.Join(stateOptionToString(s.State), ","))
}
if len(s.TopicFields) > 0 {
q.Add("topic.fields", strings.Join(topicFieldsToString(s.TopicFields), ","))
}
if len(s.UserFields) > 0 {
q.Add("user.fields", strings.Join(userFieldsToString(s.UserFields), ","))
}
if len(q) > 0 {
req.URL.RawQuery = q.Encode()
}
}
type StateOption string
const (
SpaceFieldAll StateOption = "all"
SpaceFieldLive StateOption = "live"
SpaceFieldScheduled StateOption = "scheduled"
)
func stateOptionToString(sopt []StateOption) []string {
slice := make([]string, len(sopt))
for i, s := range sopt {
slice[i] = string(s)
}
return slice
}
type SpaceOption struct {
Expansions []Expansion
SpaceFields []SpaceField
TopicFields []TopicField
UserFields []UserField
}
func (s *SpaceOption) addQuery(req *http.Request) {
q := req.URL.Query()
if len(s.Expansions) > 0 {
q.Add("expansions", strings.Join(expansionsToString(s.Expansions), ","))
}
if len(s.SpaceFields) > 0 {
q.Add("space.fields", strings.Join(spaceFieldsToString(s.SpaceFields), ","))
}
if len(s.TopicFields) > 0 {
q.Add("topic.fields", strings.Join(topicFieldsToString(s.TopicFields), ","))
}
if len(s.UserFields) > 0 {
q.Add("user.fields", strings.Join(userFieldsToString(s.UserFields), ","))
}
if len(q) > 0 {
req.URL.RawQuery = q.Encode()
}
}
type DiscoverSpacesOption struct {
Expansions []Expansion
SpaceFields []SpaceField
TopicFields []TopicField
UserFields []UserField
}
func (d *DiscoverSpacesOption) addQuery(req *http.Request) {
q := req.URL.Query()
if len(d.Expansions) > 0 {
q.Add("expansions", strings.Join(expansionsToString(d.Expansions), ","))
}
if len(d.SpaceFields) > 0 {
q.Add("space.fields", strings.Join(spaceFieldsToString(d.SpaceFields), ","))
}
if len(d.TopicFields) > 0 {
q.Add("topic.fields", strings.Join(topicFieldsToString(d.TopicFields), ","))
}
if len(d.UserFields) > 0 {
q.Add("user.fields", strings.Join(userFieldsToString(d.UserFields), ","))
}
if len(q) > 0 {
req.URL.RawQuery = q.Encode()
}
}
type UsersPurchasedSpaceTicketOption struct {
Expansions []Expansion
MediaFields []MediaField
PlaceFields []PlaceField
PollFields []PollField
TweetFields []TweetField
UserFields []UserField
}
func (u *UsersPurchasedSpaceTicketOption) addQuery(req *http.Request) {
q := req.URL.Query()
if len(u.Expansions) > 0 {
q.Add("expansions", strings.Join(expansionsToString(u.Expansions), ","))
}
if len(u.MediaFields) > 0 {
q.Add("media.fields", strings.Join(mediaFieldsToString(u.MediaFields), ","))
}
if len(u.PlaceFields) > 0 {
q.Add("place.fields", strings.Join(placeFieldsToString(u.PlaceFields), ","))
}
if len(u.PollFields) > 0 {
q.Add("poll.fields", strings.Join(pollFieldsToString(u.PollFields), ","))
}
if len(u.TweetFields) > 0 {
q.Add("tweet.fields", strings.Join(tweetFieldsToString(u.TweetFields), ","))
}
if len(u.UserFields) > 0 {
q.Add("user.fields", strings.Join(userFieldsToString(u.UserFields), ","))
}
if len(q) > 0 {
req.URL.RawQuery = q.Encode()
}
}