forked from hwiorn/ari
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mailbox.go
71 lines (56 loc) · 1.89 KB
/
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package ari
// Mailbox is the communication path to an Asterisk server for
// operating on mailbox resources
type Mailbox interface {
// Get gets a handle to the mailbox for further operations
Get(key *Key) *MailboxHandle
// List lists the mailboxes in asterisk
List(filter *Key) ([]*Key, error)
// Data gets the current state of the mailbox
Data(key *Key) (*MailboxData, error)
// Update updates the state of the mailbox, or creates if does not exist
Update(key *Key, oldMessages int, newMessages int) error
// Delete deletes the mailbox
Delete(key *Key) error
}
// MailboxData respresents the state of an Asterisk (voice) mailbox
type MailboxData struct {
// Key is the cluster-unique identifier for this mailbox
Key *Key `json:"key"`
Name string `json:"name"`
NewMessages int `json:"new_messages"` // Number of new (unread) messages
OldMessages int `json:"old_messages"` // Number of old (read) messages
}
// A MailboxHandle is a handle to a mailbox instance attached to an
// ari transport
type MailboxHandle struct {
key *Key
m Mailbox
}
// NewMailboxHandle creates a new mailbox handle given the name and mailbox transport
func NewMailboxHandle(key *Key, m Mailbox) *MailboxHandle {
return &MailboxHandle{
key: key,
m: m,
}
}
// ID returns the identifier for the mailbox handle
func (mh *MailboxHandle) ID() string {
return mh.key.ID
}
// Key returns the key for the mailbox handle
func (mh *MailboxHandle) Key() *Key {
return mh.key
}
// Data gets the current state of the mailbox
func (mh *MailboxHandle) Data() (*MailboxData, error) {
return mh.m.Data(mh.key)
}
// Update updates the state of the mailbox, or creates if does not exist
func (mh *MailboxHandle) Update(oldMessages int, newMessages int) error {
return mh.m.Update(mh.key, oldMessages, newMessages)
}
// Delete deletes the mailbox
func (mh *MailboxHandle) Delete() error {
return mh.m.Delete(mh.key)
}