-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathresponses.go
322 lines (279 loc) · 10.1 KB
/
responses.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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
package twitter
import (
"time"
)
// Response Struct
type Response struct {
Results Data
Error error
}
// Meta Struct
type Meta struct {
ResultCount int `json:"result_count,omitempty"`
NextToken string `json:"next_token,omitempty"`
PreviousToken string `json:"previous_token,omitempty"`
}
// Data Struct
type Data struct {
Data *interface{} `json:"data,omitempty"`
Includes *Includes `json:"includes,omitempty"`
Meta *Meta `json:"meta,omitempty"`
}
// Twitter Specific Data
// Coordinates response object.
type Coordinates struct {
Type string `json:"type,omitempty"`
Coordinates []float64 `json:"coordinates,omitempty"`
}
// Geo response object.
type Geo struct {
Coordinates Coordinates `json:"coordinates,omitempty"`
PlaceID string `json:"place_id,omitempty"`
}
// ReferencedTweet response object.
type ReferencedTweet struct {
Type string `json:"type,omitempty"`
ID string `json:"id,omitempty"`
}
// Attachment response object.
type Attachment struct {
MediaKeys []string `json:"media_keys,omitempty"`
PollIDs []string `json:"poll_ids,omitempty"`
}
// Annotation response object.
type Annotation struct {
ID string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"`
}
// ContextAnnotation response object.
type ContextAnnotation struct {
Domain *Annotation `json:"domain,omitempty"`
Entity *Annotation `json:"entity,omitempty"`
}
// Entity response object.
type Entity struct {
Start int `json:"start,omitempty"`
End int `json:"end,omitempty"`
}
// EntityAnnotation response object.
type EntityAnnotation struct {
*Entity
Probability float64 `json:"probability,omitempty"`
Type string `json:"type,omitempty"`
NormalizedText string `json:"normalized_text,omitempty"`
}
// EntityURL response object.
type EntityURL struct {
*Entity
URL string `json:"url,omitempty"`
ExpandedURL string `json:"expanded_url,omitempty"`
DisplayURL string `json:"display_url,omitempty"`
UnwoundURL string `json:"unwound_url,omitempty"`
}
// EntityTag response object.
type EntityTag struct {
*Entity
Tag string `json:"tag,omitempty"`
}
// EntityMention response object.
type EntityMention struct {
*Entity
UserName string `json:"username,omitempty"`
}
// Entities response object.
type Entities struct {
Annotations []*EntityAnnotation `json:"annotations,omitempty"`
URLs []*EntityURL `json:"urls,omitempty"`
HashTags []*EntityTag `json:"hashtags,omitempty"`
Mentions []*EntityMention `json:"mentions,omitempty"`
CashTags []*EntityTag `json:"cashtags,omitempty"`
}
// Withheld response object.
type Withheld struct {
Copyright bool `json:"copyright,omitempty"`
CountryCodes []string `json:"country_codes,omitempty"`
Scope string `json:"scope,omitempty"`
}
// TweetMetrics response object.
type TweetMetrics struct {
Retweets int `json:"retweet_count,omitempty"`
Replies int `json:"reply_count,omitempty"`
Likes int `json:"like_count,omitempty"`
Quotes int `json:"quote_count,omitempty"`
Impressions int `json:"impression_count,omitempty"`
URLLinkClicks int `json:"url_link_clicks,omitempty"`
UserProfileClicks int `json:"user_profile_clicks,omitempty"`
}
// UserMetrics response object.
type UserMetrics struct {
Followers int `json:"followers_count,omitempty"`
Following int `json:"following_count,omitempty"`
Tweets int `json:"tweet_count,omitempty"`
Listed int `json:"listed_count,omitempty"`
}
type MediaMetrics struct {
Playback0Count int `json:"playback_0_count,omitempty"`
Playback100Count int `json:"playback_100_count,omitempty"`
Playback25Count int `json:"playback_25_count,omitempty"`
Playback50Count int `json:"playback_50_count,omitempty"`
Playback75Count int `json:"playback_75_count,omitempty"`
ViewCount int `json:"view_count,omitempty"`
}
// Includes response object.
type Includes struct {
Tweets []*Tweet `json:"tweets,omitempty"`
Users []*User `json:"users,omitempty"`
Media []*Media `json:"media,omitempty"`
}
// Error response object.
type Error struct {
Message string `json:"message,omitempty"`
Sent string `json:"sent.omitempty"`
}
type StreamData struct {
Data *Tweet `json:"data"`
Includes *Includes `json:"includes"`
MatchingRules []*RulesData `json:"matching_rules"`
Error *Error `json:"error"`
}
// Tweet response object as returned from /2/tweets endpoint. For detailed information
// refer to https://developer.twitter.com/en/docs/twitter-api/tweets/lookup/api-reference/get-tweets.
type Tweet struct {
ID string `json:"id"`
Text string `json:"text,omitempty"`
CreatedAt string `json:"created_at,omitempty"`
AuthorID string `json:"author_id,omitempty"`
ConversationID string `json:"conversation_id,omitempty"`
InReplyToUserID string `json:"in_reply_to_user_id,omitempty"`
ReferencedTweets []*ReferencedTweet `json:"referenced_tweets,omitempty"`
Attachments *Attachment `json:"attachments,omitempty"`
Geo *Geo `json:"geo,omitempty"`
ContextAnnotations []*ContextAnnotation `json:"context_annotations,omitempty"`
Entities *Entities `json:"entities,omitempty"`
Withheld *Withheld `json:"withheld,omitempty"`
PublicMetrics *TweetMetrics `json:"public_metrics,omitempty"`
NonPublicMetrics *TweetMetrics `json:"non_public_metrics,omitempty"`
OrganicMetrics *TweetMetrics `json:"organic_metrics,omitempty"`
PromotedMetrics *TweetMetrics `json:"promoted_metrics,omitempty"`
PossibySensitive bool `json:"possibly_sensitive,omitempty"`
Lang string `json:"lang,omitempty"`
ReplySettings string `json:"reply_settings,omitempty"`
Source string `json:"source,omitempty"`
Includes *Includes `json:"includes,omitempty"`
EditHistoryIDs []string `json:"edit_history_ids"`
Errors *Error `json:"errors,omitempty"`
}
type EditControls struct {
EditsRemaining int `json:"edits_remaining,omitempty"`
IsEditEligible bool `json:"is_edit_eligible,omitempty"`
EditableUntil string `json:"editable_until,omitempty"`
}
// CreatedAtTime is a convenience wrapper that returns the Created_at time, parsed as a time.Time struct
func (t Tweet) CreatedAtTime() (time.Time, error) {
return time.Parse(time.RFC3339Nano, t.CreatedAt)
}
// User response object as returned from /2/users endpoint. For detailed information
// refer to https://developer.twitter.com/en/docs/twitter-api/users/lookup/api-reference/get-users.
type User struct {
ID string `json:"id"`
Name string `json:"name,omitempty"`
UserName string `json:"username,omitempty"`
CreatedAt string `json:"created_at,omitempty"`
Protected bool `json:"protected,omitempty"`
Withheld *Withheld `json:"withheld,omitempty"`
Location string `json:"location,omitempty"`
URL string `json:"url,omitempty"`
Description string `json:"description,omitempty"`
Verified bool `json:"verified,omitempty"`
Entities *Entities `json:"entities,omitempty"`
ProfileImageURL string `json:"profile_image_url,omitempty"`
PublicMetrics *UserMetrics `json:"public_metrics,omitempty"`
PinnedTweetID string `json:"pinned_tweet_id,omitempty"`
Includes *Includes `json:"includes,omitempty"`
Errors *Error `json:"errors,omitempty"`
}
// CreatedAtTime is a convenience wrapper that returns the Created_at time, parsed as a time.Time struct
func (u User) CreatedAtTime() (time.Time, error) {
return time.Parse(time.RFC3339Nano, u.CreatedAt)
}
type RulesData struct {
Value string `json:"value,omitempty"`
Tag string `json:"tag,omitempty"`
ID string `json:"id,omitempty"`
}
type RulesSummary struct {
Created int `json:"created,omitempty"`
NotCreated int `json:"not_created,omitempty"`
Deleted int `json:"deleted,omitempty"`
NotDeleted int `json:"not_deleted,omitempty"`
}
type RulesMeta struct {
Sent time.Time `json:"sent,omitempty"`
ResultCount int `json:"result_count,omitempty"`
Summary *RulesSummary `json:"summary,omitempty"`
}
type RulesError struct {
Value string `json:"value,omitempty"`
Id string `json:"id,omitempty"`
Title string `json:"title,omitempty"`
Type string `json:"type,omitempty"`
}
type RulesDelete struct {
Ids []string `json:"ids,omitempty"`
}
type Rules struct {
Data []*RulesData `json:"data"`
Add []*RulesData `json:"add"`
Delete *RulesDelete `json:"delete"`
Meta *RulesMeta `json:"meta"`
Errors []map[string]interface{} `json:"errors"`
}
type Media struct {
MediaKey string
Type string
URL string
DurationMS int
Height int
Width int
NonPublicMetrics *MediaMetrics
OrganicMetrics *MediaMetrics
PromotedMetrics *MediaMetrics
PublicMetrics *MediaMetrics
PreviewImageURL string
AltText string
Variants []*MediaVariant
}
type MediaVariant struct {
BitRate int
ContentType string
URL string
}
/*
func (rules *Rules) Make(m map[string]interface{}) error {
for k, v := range m {
err := Field(rules, k, v)
if err != nil {
return err
}
}
return nil
}
func Field(obj interface{}, name string, value interface{}) error {
structValue := reflect.ValueOf(obj).Elem()
structFieldValue := structValue.FieldByName(name)
if !structFieldValue.IsValid() {
return fmt.Errorf("No such field: %s in obj", name)
}
if !structFieldValue.CanSet() {
return fmt.Errorf("Cannot set %s field value", name)
}
structFieldType := structFieldValue.Type()
val := reflect.ValueOf(value)
if structFieldType != val.Type() {
return errors.New("Provided value type didn't match obj field type")
}
structFieldValue.Set(val)
return nil
}
*/