forked from riobard/go-mailgun
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomplaint.go
41 lines (35 loc) · 785 Bytes
/
complaint.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
package mailgun
import (
"encoding/json"
"net/url"
"strconv"
"time"
)
type Complaint struct {
Count int `json:"count"`
CreatedAt string `json:"created_at"`
Address string `json:"address"`
}
func (c *Complaint) Time() time.Time {
t, _ := time.Parse(time.RFC1123, c.CreatedAt)
return t
}
func (c *Client) Complaints(domain string, limit, skip int) (total int, res []Complaint, err error) {
v := url.Values{}
v.Set("limit", strconv.Itoa(limit))
v.Set("skip", strconv.Itoa(skip))
body, err := c.api("GET", "/"+domain+"/complaints", v)
if err != nil {
return
}
var j struct {
Total int `json:"total_count"`
Items []Complaint `json:"items"`
}
err = json.Unmarshal(body, &j)
if err != nil {
return
}
total, res = j.Total, j.Items
return
}