-
-
Notifications
You must be signed in to change notification settings - Fork 21
/
parameter.go
81 lines (63 loc) · 1.69 KB
/
parameter.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
package types
import (
"io"
"strconv"
"github.com/michimani/gotwi/fields"
"github.com/michimani/gotwi/internal/util"
)
type SampleStreamBackfillMinutes int
func (v SampleStreamBackfillMinutes) Valid() bool {
return int(v) > 0 && int(v) <= 5
}
func (v SampleStreamBackfillMinutes) String() string {
return strconv.Itoa(int(v))
}
type SampleStreamInput struct {
accessToken string
// Query parameters
BackfillMinutes SampleStreamBackfillMinutes
Expansions fields.ExpansionList
MediaFields fields.MediaFieldList
PlaceFields fields.PlaceFieldList
PollFields fields.PollFieldList
TweetFields fields.TweetFieldList
UserFields fields.UserFieldList
}
var getQueryParameters = map[string]struct{}{
"backfill_minutes": {},
"expansions": {},
"media.fields": {},
"place.fields": {},
"poll.fields": {},
"tweet.fields": {},
"user.fields": {},
}
func (p *SampleStreamInput) SetAccessToken(token string) {
p.accessToken = token
}
func (p *SampleStreamInput) AccessToken() string {
return p.accessToken
}
func (p *SampleStreamInput) ResolveEndpoint(endpointBase string) string {
if p == nil {
return ""
}
endpoint := endpointBase
pm := p.ParameterMap()
if len(pm) > 0 {
qs := util.QueryString(pm, getQueryParameters)
endpoint += "?" + qs
}
return endpoint
}
func (p *SampleStreamInput) Body() (io.Reader, error) {
return nil, nil
}
func (p *SampleStreamInput) ParameterMap() map[string]string {
m := map[string]string{}
m = fields.SetFieldsParams(m, p.Expansions, p.MediaFields, p.PlaceFields, p.PollFields, p.TweetFields, p.UserFields)
if p.BackfillMinutes.Valid() {
m["backfill_minutes"] = p.BackfillMinutes.String()
}
return m
}