forked from Scorpio69t/jpush-api-golang-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaudience.go
87 lines (70 loc) · 1.83 KB
/
audience.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
package jpush
import (
"log"
)
type AudienceType string
const (
TAG AudienceType = "tag" // 标签OR
TAG_AND AudienceType = "tag_and" // 标签AND
TAG_NOT AudienceType = "tag_not" // 标签NOT
ALIAS AudienceType = "alias" // 别名
REGISTRATION_ID AudienceType = "registration_id" // 注册ID
SEGMENT AudienceType = "segment" // 用户分群 ID
ABTEST AudienceType = "abtest" // A/B Test ID
)
func (a AudienceType) String() string {
return string(a)
}
type Audience struct {
Object interface{}
audience map[AudienceType][]string
}
func (a *Audience) Interface() interface{} {
return a.Object
}
// All set all audiences
func (a *Audience) All() {
a.Object = "all"
}
// SetID set audiences by id
func (a *Audience) SetID(ids []string) {
a.set(REGISTRATION_ID, ids)
}
// SetTag set audiences by tag
func (a *Audience) SetTag(tags []string) {
a.set(TAG, tags)
}
// SetTagAnd set audiences by tag_and
func (a *Audience) SetTagAnd(tags []string) {
a.set(TAG_AND, tags)
}
// SetTagNot set audiences by tag_not
func (a *Audience) SetTagNot(tags []string) {
a.set(TAG_NOT, tags)
}
// SetAlias set audiences by alias
func (a *Audience) SetAlias(aliases []string) {
a.set(ALIAS, aliases)
}
// SetSegment set audiences by segment
func (a *Audience) SetSegment(segments []string) {
a.set(SEGMENT, segments)
}
// SetABTest set audiences by abtest
func (a *Audience) SetABTest(abtests []string) {
a.set(ABTEST, abtests)
}
// set set audiences
func (a *Audience) set(key AudienceType, v []string) {
switch a.Object.(type) {
case string:
log.Printf("audience already set all")
return // do nothing
default:
}
if a.audience == nil {
a.audience = make(map[AudienceType][]string)
a.Object = a.audience
}
a.audience[key] = v
}