github.com/CyCoreSystems/ari@v4.8.4+incompatible/mailbox.go (about)

     1  package ari
     2  
     3  // Mailbox is the communication path to an Asterisk server for
     4  // operating on mailbox resources
     5  type Mailbox interface {
     6  
     7  	// Get gets a handle to the mailbox for further operations
     8  	Get(key *Key) *MailboxHandle
     9  
    10  	// List lists the mailboxes in asterisk
    11  	List(filter *Key) ([]*Key, error)
    12  
    13  	// Data gets the current state of the mailbox
    14  	Data(key *Key) (*MailboxData, error)
    15  
    16  	// Update updates the state of the mailbox, or creates if does not exist
    17  	Update(key *Key, oldMessages int, newMessages int) error
    18  
    19  	// Delete deletes the mailbox
    20  	Delete(key *Key) error
    21  }
    22  
    23  // MailboxData respresents the state of an Asterisk (voice) mailbox
    24  type MailboxData struct {
    25  	// Key is the cluster-unique identifier for this mailbox
    26  	Key *Key `json:"key"`
    27  
    28  	Name        string `json:"name"`
    29  	NewMessages int    `json:"new_messages"` // Number of new (unread) messages
    30  	OldMessages int    `json:"old_messages"` // Number of old (read) messages
    31  }
    32  
    33  // A MailboxHandle is a handle to a mailbox instance attached to an
    34  // ari transport
    35  type MailboxHandle struct {
    36  	key *Key
    37  	m   Mailbox
    38  }
    39  
    40  // NewMailboxHandle creates a new mailbox handle given the name and mailbox transport
    41  func NewMailboxHandle(key *Key, m Mailbox) *MailboxHandle {
    42  	return &MailboxHandle{
    43  		key: key,
    44  		m:   m,
    45  	}
    46  }
    47  
    48  // ID returns the identifier for the mailbox handle
    49  func (mh *MailboxHandle) ID() string {
    50  	return mh.key.ID
    51  }
    52  
    53  // Key returns the key for the mailbox handle
    54  func (mh *MailboxHandle) Key() *Key {
    55  	return mh.key
    56  }
    57  
    58  // Data gets the current state of the mailbox
    59  func (mh *MailboxHandle) Data() (*MailboxData, error) {
    60  	return mh.m.Data(mh.key)
    61  }
    62  
    63  // Update updates the state of the mailbox, or creates if does not exist
    64  func (mh *MailboxHandle) Update(oldMessages int, newMessages int) error {
    65  	return mh.m.Update(mh.key, oldMessages, newMessages)
    66  }
    67  
    68  // Delete deletes the mailbox
    69  func (mh *MailboxHandle) Delete() error {
    70  	return mh.m.Delete(mh.key)
    71  }