forked from g8rswimmer/go-twitter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tweet_counts_options.go
84 lines (77 loc) · 1.98 KB
/
tweet_counts_options.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
package twitter
import (
"net/http"
"time"
)
// Granularity is the granularity that you want the timeseries count data to be grouped by
type Granularity string
const (
// GranularityMinute will group tweet in minutes
GranularityMinute Granularity = "minute"
// GranularityHour is the default granularity
GranularityHour Granularity = "hour"
// GranularityDay will group tweet on a daily basis
GranularityDay Granularity = "day"
)
// TweetRecentCountsOpts are the optional paramters that can be passed to the tweet recent counts callout
type TweetRecentCountsOpts struct {
StartTime time.Time
EndTime time.Time
SinceID string
UntilID string
Granularity Granularity
}
func (t TweetRecentCountsOpts) addQuery(req *http.Request) {
q := req.URL.Query()
if !t.StartTime.IsZero() {
q.Add("start_time", t.StartTime.Format(time.RFC3339))
}
if !t.EndTime.IsZero() {
q.Add("end_time", t.EndTime.Format(time.RFC3339))
}
if len(t.SinceID) > 0 {
q.Add("since_id", t.SinceID)
}
if len(t.UntilID) > 0 {
q.Add("until_id", t.UntilID)
}
if len(t.Granularity) > 0 {
q.Add("granularity", string(t.Granularity))
}
if len(q) > 0 {
req.URL.RawQuery = q.Encode()
}
}
// TweetAllCountsOpts are the optional paramters that can be passed to the tweet all counts callout
type TweetAllCountsOpts struct {
StartTime time.Time
EndTime time.Time
SinceID string
UntilID string
Granularity Granularity
NextToken string
}
func (t TweetAllCountsOpts) addQuery(req *http.Request) {
q := req.URL.Query()
if !t.StartTime.IsZero() {
q.Add("start_time", t.StartTime.Format(time.RFC3339))
}
if !t.EndTime.IsZero() {
q.Add("end_time", t.EndTime.Format(time.RFC3339))
}
if len(t.SinceID) > 0 {
q.Add("since_id", t.SinceID)
}
if len(t.UntilID) > 0 {
q.Add("until_id", t.UntilID)
}
if len(t.Granularity) > 0 {
q.Add("granularity", string(t.Granularity))
}
if len(t.NextToken) > 0 {
q.Add("next_token", t.NextToken)
}
if len(q) > 0 {
req.URL.RawQuery = q.Encode()
}
}