-
Notifications
You must be signed in to change notification settings - Fork 3
/
campaign.go
114 lines (96 loc) · 3.67 KB
/
campaign.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
110
111
112
113
114
package lytics
import (
"net/url"
"strings"
"time"
)
const (
campaignEndpoint = "program/campaign/:id"
campaignListEndpoint = "program/campaign" //status
variationEndpoint = "program/campaign/variation/:id"
variationListEndpoint = "program/campaign/variation"
)
type Campaign struct {
Id string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Status string `json:"status,omitempty"`
SystemStatus string `json:"system_status,omitempty"`
PublishedAt time.Time `json:"published_at,omitempty"`
CreatedAt time.Time `json:"created_at,omitempty"`
UpdatedAt time.Time `json:"updated_at,omitempty"`
StartAt time.Time `json:"start_at,omitempty"`
EndAt time.Time `json:"end_at,omitempty"`
Segments []string `json:"segments,omitempty"`
DeletedAt time.Time `json:"deleted_at,omitempty"`
Deleted bool `json:"deleted,omitempty"`
Aid int `json:"aid,omitempty"`
AccountId string `json:"account_id,omitempty"`
UserId string `json:"user_id,omitempty"`
}
type Variation struct {
Id string `json:"id,omitempty"`
Variation int `json:"variation"`
CampaignId string `json:"campaign_id,omitempty"`
Vehicle string `json:"vehicle,omitempty"`
Reach string `json:"reach,omitempty"`
Conversion string `json:"conversion,omitempty"`
Detail map[string]interface{} `json:"detail,omitempty"`
DetailOverride map[string]interface{} `json:"detail_override,omitempty"`
CreatedAt time.Time `json:"created_at,omitempty"`
UpdatedAt time.Time `json:"updated_at,omitempty"`
Deleted bool `json:"deleted,omitempty"`
DeletedAt time.Time `json:"deleted_at,omitempty"`
Preview bool `json:"preview,omitempty"`
Aid int `json:"aid,omitempty"`
AccountId string `json:"account_id,omitempty" bson:"account_id"`
UserId string `json:"user_id,omitempty" bson:"user_id"`
}
// GetCampaign returns the details for a single personalization campaign
func (l *Client) GetCampaign(id string) (Campaign, error) {
res := ApiResp{}
data := Campaign{}
// make the request
err := l.Get(parseLyticsURL(campaignEndpoint, map[string]string{"id": id}), nil, nil, &res, &data)
if err != nil {
return data, err
}
return data, nil
}
// GetCampaignList returns the details for all campaigns in an account
// optional status parameter to filter by status: published, unpublished, deleted
func (l *Client) GetCampaignList(status []string) ([]Campaign, error) {
params := url.Values{}
res := ApiResp{}
data := []Campaign{}
if len(status) > 0 {
params.Add("status", strings.Join(status, ","))
}
// make the request
err := l.Get(campaignListEndpoint, params, nil, &res, &data)
if err != nil {
return data, err
}
return data, nil
}
// GetVariation returns the details for a single campaign variation
func (l *Client) GetVariation(id string) (Variation, error) {
res := ApiResp{}
data := Variation{}
// make the request
err := l.Get(parseLyticsURL(variationEndpoint, map[string]string{"id": id}), nil, nil, &res, &data)
if err != nil {
return data, err
}
return data, nil
}
// GetVariationList returns the details for all variations of all campaigns in the account
func (l *Client) GetVariationList() ([]Variation, error) {
res := ApiResp{}
data := []Variation{}
// make the request
err := l.Get(variationListEndpoint, nil, nil, &res, &data)
if err != nil {
return data, err
}
return data, nil
}