forked from g8rswimmer/go-twitter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
space_lookup.go
185 lines (167 loc) · 5.17 KB
/
space_lookup.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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
package twitter
import (
"net/http"
"strings"
)
// SpacesLookupOpts are the options for the space lookup
type SpacesLookupOpts struct {
Expansions []Expansion
SpaceFields []SpaceField
TopicFields []TopicField
UserFields []UserField
}
func (s SpacesLookupOpts) addQuery(req *http.Request) {
q := req.URL.Query()
if len(s.Expansions) > 0 {
q.Add("expansions", strings.Join(expansionStringArray(s.Expansions), ","))
}
if len(s.SpaceFields) > 0 {
q.Add("space.fields", strings.Join(spaceFieldStringArray(s.SpaceFields), ","))
}
if len(s.TopicFields) > 0 {
q.Add("topic.fields", strings.Join(topicFieldStringArray(s.TopicFields), ","))
}
if len(s.UserFields) > 0 {
q.Add("user.fields", strings.Join(userFieldStringArray(s.UserFields), ","))
}
if len(q) > 0 {
req.URL.RawQuery = q.Encode()
}
}
// SpacesLookupResponse is the response for the space lookup
type SpacesLookupResponse struct {
Raw *SpacesRaw
RateLimit *RateLimit
}
type spaceRaw struct {
Space *SpaceObj `json:"data"`
Includes *SpacesRawIncludes `json:"includes,omitempty"`
Errors []*ErrorObj `json:"errors,omitempty"`
}
// SpacesRaw the raw space objects
type SpacesRaw struct {
Spaces []*SpaceObj `json:"data"`
Includes *SpacesRawIncludes `json:"includes,omitempty"`
Errors []*ErrorObj `json:"errors,omitempty"`
}
// SpacesRawIncludes are the includes for a space
type SpacesRawIncludes struct {
Users []*UserObj `json:"users,omitempty"`
Topics []*TopicObj `json:"topics,omitempty"`
}
// SpacesByCreatorLookupOpts are the options for the space by creator
type SpacesByCreatorLookupOpts struct {
Expansions []Expansion
SpaceFields []SpaceField
TopicFields []TopicField
UserFields []UserField
}
func (s SpacesByCreatorLookupOpts) addQuery(req *http.Request) {
q := req.URL.Query()
if len(s.Expansions) > 0 {
q.Add("expansions", strings.Join(expansionStringArray(s.Expansions), ","))
}
if len(s.SpaceFields) > 0 {
q.Add("space.fields", strings.Join(spaceFieldStringArray(s.SpaceFields), ","))
}
if len(s.TopicFields) > 0 {
q.Add("topic.fields", strings.Join(topicFieldStringArray(s.TopicFields), ","))
}
if len(s.UserFields) > 0 {
q.Add("user.fields", strings.Join(userFieldStringArray(s.UserFields), ","))
}
if len(q) > 0 {
req.URL.RawQuery = q.Encode()
}
}
// SpacesByCreatorLookupResponse is the response to the space by creator
type SpacesByCreatorLookupResponse struct {
Raw *SpacesRaw
Meta *SpacesByCreatorMeta `json:"meta"`
RateLimit *RateLimit
}
// SpacesByCreatorMeta the meta for the space by creator
type SpacesByCreatorMeta struct {
ResultCount int `json:"result_count"`
}
// SpaceBuyersLookupOpts are the options for the space buyer lookup
type SpaceBuyersLookupOpts struct {
Expansions []Expansion
TweetFields []TweetField
UserFields []UserField
MediaFields []MediaField
PlaceFields []PlaceField
PollFields []PollField
}
func (s SpaceBuyersLookupOpts) addQuery(req *http.Request) {
q := req.URL.Query()
if len(s.Expansions) > 0 {
q.Add("expansions", strings.Join(expansionStringArray(s.Expansions), ","))
}
if len(s.TweetFields) > 0 {
q.Add("tweet.fields", strings.Join(tweetFieldStringArray(s.TweetFields), ","))
}
if len(s.UserFields) > 0 {
q.Add("user.fields", strings.Join(userFieldStringArray(s.UserFields), ","))
}
if len(s.MediaFields) > 0 {
q.Add("media.fields", strings.Join(mediaFieldStringArray(s.MediaFields), ","))
}
if len(s.PlaceFields) > 0 {
q.Add("place.fields", strings.Join(placeFieldStringArray(s.PlaceFields), ","))
}
if len(s.PollFields) > 0 {
q.Add("poll.fields", strings.Join(pollFieldStringArray(s.PollFields), ","))
}
if len(q) > 0 {
req.URL.RawQuery = q.Encode()
}
}
// SpaceBuyersLookupResponse is the space buyers lookup response
type SpaceBuyersLookupResponse struct {
Raw *UserRaw
RateLimit *RateLimit
}
// SpaceTweetsLookupOpts are the options for the space tweets lookup
type SpaceTweetsLookupOpts struct {
Expansions []Expansion
MediaFields []MediaField
PlaceFields []PlaceField
PollFields []PollField
TweetFields []TweetField
UserFields []UserField
}
func (s SpaceTweetsLookupOpts) addQuery(req *http.Request) {
q := req.URL.Query()
if len(s.Expansions) > 0 {
q.Add("expansions", strings.Join(expansionStringArray(s.Expansions), ","))
}
if len(s.MediaFields) > 0 {
q.Add("media.fields", strings.Join(mediaFieldStringArray(s.MediaFields), ","))
}
if len(s.PlaceFields) > 0 {
q.Add("place.fields", strings.Join(placeFieldStringArray(s.PlaceFields), ","))
}
if len(s.PollFields) > 0 {
q.Add("poll.fields", strings.Join(pollFieldStringArray(s.PollFields), ","))
}
if len(s.TweetFields) > 0 {
q.Add("tweet.fields", strings.Join(tweetFieldStringArray(s.TweetFields), ","))
}
if len(s.UserFields) > 0 {
q.Add("user.fields", strings.Join(userFieldStringArray(s.UserFields), ","))
}
if len(q) > 0 {
req.URL.RawQuery = q.Encode()
}
}
// SpaceTweetsLookupResponse is the response for the space tweets lookup
type SpaceTweetsLookupResponse struct {
Raw *TweetRaw
Meta *SpaceTweetsLookupMeta `json:"meta"`
RateLimit *RateLimit
}
// SpaceTweetsLookupMeta is the space tweets lookup meta
type SpaceTweetsLookupMeta struct {
ResultCount int `json:"result_count"`
}