This repository has been archived on 2022-08-17. You can view files and clone it, but cannot push or open issues or pull requests.
dex/vendor/github.com/mailgun/mailgun-go/campaigns.go

80 lines
2.7 KiB
Go
Raw Normal View History

2015-08-18 05:57:27 +05:30
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) {
2016-06-28 22:48:18 +05:30
r := newHTTPRequest(generateApiUrl(m, campaignsEndpoint))
r.setClient(m.Client())
r.setBasicAuth(basicAuthUser, m.ApiKey())
2015-08-18 05:57:27 +05:30
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 {
2016-06-28 22:48:18 +05:30
r := newHTTPRequest(generateApiUrl(m, campaignsEndpoint))
r.setClient(m.Client())
r.setBasicAuth(basicAuthUser, m.ApiKey())
2015-08-18 05:57:27 +05:30
2016-06-28 22:48:18 +05:30
payload := newUrlEncodedPayload()
payload.addValue("name", name)
2015-08-18 05:57:27 +05:30
if id != "" {
2016-06-28 22:48:18 +05:30
payload.addValue("id", id)
2015-08-18 05:57:27 +05:30
}
_, 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 {
2016-06-28 22:48:18 +05:30
r := newHTTPRequest(generateApiUrl(m, campaignsEndpoint) + "/" + oldId)
r.setClient(m.Client())
r.setBasicAuth(basicAuthUser, m.ApiKey())
2015-08-18 05:57:27 +05:30
2016-06-28 22:48:18 +05:30
payload := newUrlEncodedPayload()
payload.addValue("name", name)
2015-08-18 05:57:27 +05:30
if newId != "" {
2016-06-28 22:48:18 +05:30
payload.addValue("id", newId)
2015-08-18 05:57:27 +05:30
}
_, 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 {
2016-06-28 22:48:18 +05:30
r := newHTTPRequest(generateApiUrl(m, campaignsEndpoint) + "/" + id)
r.setClient(m.Client())
r.setBasicAuth(basicAuthUser, m.ApiKey())
2015-08-18 05:57:27 +05:30
_, err := makeDeleteRequest(r)
return err
}