-
Notifications
You must be signed in to change notification settings - Fork 73
/
mailbox.go
49 lines (37 loc) · 998 Bytes
/
mailbox.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
package native
import (
"strconv"
"github.com/CyCoreSystems/ari"
)
type nativeMailbox struct {
conn *Conn
}
func (m *nativeMailbox) Get(name string) *ari.MailboxHandle {
return ari.NewMailboxHandle(name, m)
}
func (m *nativeMailbox) List() (mx []*ari.MailboxHandle, err error) {
mailboxes := []struct {
Name string `json:"name"`
}{}
err = Get(m.conn, "/mailboxes", &mailboxes)
for _, i := range mailboxes {
mx = append(mx, m.Get(i.Name))
}
return
}
func (m *nativeMailbox) Data(name string) (md ari.MailboxData, err error) {
err = Get(m.conn, "/mailboxes/"+name, &md)
return
}
func (m *nativeMailbox) Update(name string, oldMessages int, newMessages int) (err error) {
req := map[string]string{
"oldMessages": strconv.Itoa(oldMessages),
"newMessages": strconv.Itoa(newMessages),
}
err = Put(m.conn, "/mailboxes/"+name, nil, &req)
return err
}
func (m *nativeMailbox) Delete(name string) (err error) {
err = Delete(m.conn, "/mailboxes/"+name, nil, "")
return
}