-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.go
109 lines (92 loc) · 2.29 KB
/
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
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
package goplurk
import (
"strconv"
"strings"
"time"
)
type Options interface {
Get() map[string]string
}
type baseOptions struct {
options map[string]string
}
func (o *baseOptions) Get() map[string]string {
if o.options == nil {
o.options = map[string]string{}
}
return o.options
}
func (o *baseOptions) set(key, value string) {
o.Get()[key] = value
}
type PlurkAddOptions struct {
baseOptions
}
func NewPlurkAddOptions() *PlurkAddOptions {
return &PlurkAddOptions{}
}
func (o *PlurkAddOptions) LimitedTo(ids ...int64) *PlurkAddOptions {
limitedToStrs := []string{}
for _, limited := range ids {
limitedToStrs = append(limitedToStrs, strconv.FormatInt(limited, 10))
}
o.set("limited_to", "["+strings.Join(limitedToStrs, ",")+"]")
return o
}
func (o *PlurkAddOptions) NoComments() *PlurkAddOptions {
o.set("no_comments", "1")
return o
}
func (o *PlurkAddOptions) FriendsOnlyComments() *PlurkAddOptions {
o.set("no_comments", "2")
return o
}
func (o *PlurkAddOptions) Lang(lang string) *PlurkAddOptions {
o.set("lang", lang)
return o
}
type GetPlurksOptions struct {
baseOptions
}
func NewGetPlurksOptions() *GetPlurksOptions {
return &GetPlurksOptions{}
}
func (o *GetPlurksOptions) Offset(offset time.Time) *GetPlurksOptions {
o.set("offset", offset.UTC().Format(time.RFC3339))
return o
}
// Limit the number of plurks returned
func (o *GetPlurksOptions) Limit(limit int64) *GetPlurksOptions {
o.set("limit", strconv.FormatInt(limit, 10))
return o
}
// Limit the my plurks returned
func (o *GetPlurksOptions) FilterMy() *GetPlurksOptions {
o.set("filter", "my")
return o
}
// Limit the favorite plurks returned
func (o *GetPlurksOptions) FilterFavorite() *GetPlurksOptions {
o.set("filter", "favorite")
return o
}
// Limit the replurked plurks returned
func (o *GetPlurksOptions) FilterReplurked() *GetPlurksOptions {
o.set("filter", "replurked")
return o
}
// Limit the private plurks returned
func (o *GetPlurksOptions) FilterPrivate() *GetPlurksOptions {
o.set("filter", "private")
return o
}
// Limit the responded plurks returned
func (o *GetPlurksOptions) FilterResponded() *GetPlurksOptions {
o.set("filter", "responded")
return o
}
// Limit the mentioned plurks returned
func (o *GetPlurksOptions) FilterMentioned() *GetPlurksOptions {
o.set("filter", "mentioned")
return o
}