-
-
Notifications
You must be signed in to change notification settings - Fork 21
/
parameter.go
88 lines (67 loc) · 1.6 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
82
83
84
85
86
87
88
package types
import (
"io"
"net/url"
"strconv"
"strings"
"github.com/michimani/gotwi/fields"
"github.com/michimani/gotwi/internal/util"
)
type ListMaxResults int
func (m ListMaxResults) Valid() bool {
return m > 1 && m <= 100
}
func (m ListMaxResults) String() string {
return strconv.Itoa(int(m))
}
type ListInput struct {
accessToken string
// Path parameter
ID string // List ID
// Query parameters
MaxResults ListMaxResults
PaginationToken string
Expansions fields.ExpansionList
TweetFields fields.TweetFieldList
UserFields fields.UserFieldList
}
var listQueryParameters = map[string]struct{}{
"max_results": {},
"pagination_token": {},
"expansions": {},
"tweet.fields": {},
"user.fields": {},
}
func (p *ListInput) SetAccessToken(token string) {
p.accessToken = token
}
func (p *ListInput) AccessToken() string {
return p.accessToken
}
func (p *ListInput) ResolveEndpoint(endpointBase string) string {
if p.ID == "" {
return ""
}
encoded := url.QueryEscape(p.ID)
endpoint := strings.Replace(endpointBase, ":id", encoded, 1)
pm := p.ParameterMap()
if len(pm) > 0 {
qs := util.QueryString(pm, listQueryParameters)
endpoint += "?" + qs
}
return endpoint
}
func (p *ListInput) Body() (io.Reader, error) {
return nil, nil
}
func (p *ListInput) ParameterMap() map[string]string {
m := map[string]string{}
if p.MaxResults.Valid() {
m["max_results"] = p.MaxResults.String()
}
if p.PaginationToken != "" {
m["pagination_token"] = p.PaginationToken
}
m = fields.SetFieldsParams(m, p.Expansions, p.TweetFields, p.UserFields)
return m
}