forked from mailgun/mailgun-go
/
campaigns.go
79 lines (70 loc) · 2.71 KB
/
campaigns.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
package mailgun
// Campaigns have been deprecated since development work on this SDK commenced.
// Please refer to http://documentation.mailgun.com/api_reference .
type Campaign struct {
Id string `json:"id"`
Name string `json:"name"`
CreatedAt string `json:"created_at"`
DeliveredCount int `json:"delivered_count"`
ClickedCount int `json:"clicked_count"`
OpenedCount int `json:"opened_count"`
SubmittedCount int `json:"submitted_count"`
UnsubscribedCount int `json:"unsubscribed_count"`
BouncedCount int `json:"bounced_count"`
ComplainedCount int `json:"complained_count"`
DroppedCount int `json:"dropped_count"`
}
type campaignsEnvelope struct {
TotalCount int `json:"total_count"`
Items []Campaign `json:"items"`
}
// Campaigns have been deprecated since development work on this SDK commenced.
// Please refer to http://documentation.mailgun.com/api_reference .
func (m *MailgunImpl) GetCampaigns() (int, []Campaign, error) {
r := newHTTPRequest(generateApiUrl(m, campaignsEndpoint))
r.setClient(m.Client())
r.setBasicAuth(basicAuthUser, m.ApiKey())
var envelope campaignsEnvelope
err := getResponseFromJSON(r, &envelope)
if err != nil {
return -1, nil, err
}
return envelope.TotalCount, envelope.Items, nil
}
// Campaigns have been deprecated since development work on this SDK commenced.
// Please refer to http://documentation.mailgun.com/api_reference .
func (m *MailgunImpl) CreateCampaign(name, id string) error {
r := newHTTPRequest(generateApiUrl(m, campaignsEndpoint))
r.setClient(m.Client())
r.setBasicAuth(basicAuthUser, m.ApiKey())
payload := newUrlEncodedPayload()
payload.addValue("name", name)
if id != "" {
payload.addValue("id", id)
}
_, err := makePostRequest(r, payload)
return err
}
// Campaigns have been deprecated since development work on this SDK commenced.
// Please refer to http://documentation.mailgun.com/api_reference .
func (m *MailgunImpl) UpdateCampaign(oldId, name, newId string) error {
r := newHTTPRequest(generateApiUrl(m, campaignsEndpoint) + "/" + oldId)
r.setClient(m.Client())
r.setBasicAuth(basicAuthUser, m.ApiKey())
payload := newUrlEncodedPayload()
payload.addValue("name", name)
if newId != "" {
payload.addValue("id", newId)
}
_, err := makePostRequest(r, payload)
return err
}
// Campaigns have been deprecated since development work on this SDK commenced.
// Please refer to http://documentation.mailgun.com/api_reference .
func (m *MailgunImpl) DeleteCampaign(id string) error {
r := newHTTPRequest(generateApiUrl(m, campaignsEndpoint) + "/" + id)
r.setClient(m.Client())
r.setBasicAuth(basicAuthUser, m.ApiKey())
_, err := makeDeleteRequest(r)
return err
}