-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.go
72 lines (61 loc) · 1.45 KB
/
action.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
package segmentproxy
import (
"encoding/json"
"github.com/segmentio/analytics-go"
)
// Action represents common operations for all actions
type Action interface {
// Unmarshal parses a paylaod into the Action instance
Unmarshal(data []byte) error
// Send calls the appropriate analytics.Client method for the Action
Send(client *analytics.Client) error
// GetEmail returns the email found in the payload, if any
GetEmail() string
// SetUserID allows to override the user ID associated with the action
SetUserID(id string)
}
type Email struct {
Email string `json:"email"`
}
type Identify struct {
analytics.Identify
Email
}
type Group struct {
analytics.Group
Email
}
type Track struct {
analytics.Track
Email
}
func (e Email) GetEmail() string {
return e.Email
}
func (i *Identify) Unmarshal(data []byte) error {
return json.Unmarshal(data, i)
}
func (i *Identify) Send(client *analytics.Client) error {
return client.Identify(&i.Identify)
}
func (i *Identify) SetUserID(id string) {
i.UserId = id
}
func (i *Group) Unmarshal(data []byte) error {
return json.Unmarshal(data, i)
}
func (i *Group) Send(client *analytics.Client) error {
return client.Group(&i.Group)
}
func (i *Group) SetUserID(id string) {
i.UserId = id
}
func (i *Track) Unmarshal(data []byte) error {
return json.Unmarshal(data, i)
}
func (i *Track) Send(client *analytics.Client) error {
return client.Track(&i.Track)
}
func (i *Track) SetUserID(id string) {
i.UserId = id
}