forked from mattbaird/gochimp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mandrill_senders.go
82 lines (73 loc) · 3.36 KB
/
mandrill_senders.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
// Copyright 2013 Matthew Baird
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package gochimp
import (
"errors"
"time"
)
// see https://mandrillapp.com/api/docs/senders.html
const senders_list_endpoint string = "/senders/list.json" //Return the senders that have tried to use this account.
const senders_domains_endpoint string = "/senders/domains.json" //Returns the sender domains that have been added to this account.
const senders_info_endpoint string = "/senders/info.json" //Return more detailed information about a single sender, including aggregates of recent stats
const senders_time_series_endpoint string = "/senders/time-series.json" //Return the recent history (hourly stats for the last 30 days) for a sender
// can error with one of the following: Invalid_Key, ValidationError, GeneralError
func (a *MandrillAPI) SenderList() ([]Sender, error) {
var response []Sender
var params map[string]interface{} = make(map[string]interface{})
err := parseMandrillJson(a, senders_list_endpoint, params, &response)
return response, err
}
// can error with one of the following: Invalid_Key, ValidationError, GeneralError
func (a *MandrillAPI) SenderDomains() ([]Domain, error) {
var response []Domain
var params map[string]interface{} = make(map[string]interface{})
err := parseMandrillJson(a, senders_domains_endpoint, params, &response)
return response, err
}
// can error with one of the following: Unknown_Sender, Invalid_Key, ValidationError, GeneralError
func (a *MandrillAPI) SenderInfo(address string) (SenderInfo, error) {
var response SenderInfo
if address == "" {
return response, errors.New("address cannot be blank")
}
var params map[string]interface{} = make(map[string]interface{})
params["address"] = address
err := parseMandrillJson(a, senders_info_endpoint, params, &response)
return response, err
}
// can error with one of the following: Unknown_Sender, Invalid_Key, ValidationError, GeneralError
func (a *MandrillAPI) SenderTimeSeries(address string) ([]TimeSeries, error) {
var response []TimeSeries
if address == "" {
return response, errors.New("address cannot be blank")
}
var params map[string]interface{} = make(map[string]interface{})
params["address"] = address
err := parseMandrillJson(a, senders_time_series_endpoint, params, &response)
return response, err
}
type SenderInfo struct {
Address string `json:"address"`
CreatedAt time.Time `json:"created_at"`
Sent int32 `json:"sent"`
HardBounces int32 `json:"hard_bounces"`
SoftBounces int32 `json:"soft_bounces"`
Rejects int32 `json:"rejects"`
Complaints int32 `json:"complaints"`
Unsubs int32 `json:"unsubs"`
Opens int32 `json:"opens"`
Clicks int32 `json:"clicks"`
Stats []Stat `json:"stats"`
}
type Domain struct {
Domain string `json:"domain"`
CreatedAt time.Time `json:"created_at"`
}