github.com/CyCoreSystems/ari@v4.8.4+incompatible/storedRecording.go (about) 1 package ari 2 3 // StoredRecording represents a communication path interacting with an Asterisk 4 // server for stored recording resources 5 type StoredRecording interface { 6 7 // List lists the recordings 8 List(filter *Key) ([]*Key, error) 9 10 // Get gets the Recording by type 11 Get(key *Key) *StoredRecordingHandle 12 13 // data gets the data for the stored recording 14 Data(key *Key) (*StoredRecordingData, error) 15 16 // Copy copies the recording to the destination name 17 // 18 // NOTE: because ARI offers no forced-copy, Copy should always return the 19 // StoredRecordingHandle of the destination, even if the Copy fails. Doing so 20 // allows the user to Delete the existing StoredRecording before retrying. 21 Copy(key *Key, dest string) (*StoredRecordingHandle, error) 22 23 // Delete deletes the recording 24 Delete(key *Key) error 25 } 26 27 // StoredRecordingData is the data for a stored recording 28 type StoredRecordingData struct { 29 // Key is the cluster-unique identifier for this stored recording 30 Key *Key `json:"key"` 31 32 Format string `json:"format"` 33 Name string `json:"name"` 34 } 35 36 // ID returns the identifier for the stored recording. 37 func (d StoredRecordingData) ID() string { 38 return d.Name //TODO: does the identifier include the Format and Name? 39 } 40 41 // A StoredRecordingHandle is a reference to a stored recording that can be operated on 42 type StoredRecordingHandle struct { 43 key *Key 44 s StoredRecording 45 exec func(a *StoredRecordingHandle) error 46 executed bool 47 } 48 49 // NewStoredRecordingHandle creates a new stored recording handle 50 func NewStoredRecordingHandle(key *Key, s StoredRecording, exec func(a *StoredRecordingHandle) error) *StoredRecordingHandle { 51 return &StoredRecordingHandle{ 52 key: key, 53 s: s, 54 exec: exec, 55 } 56 } 57 58 // ID returns the identifier for the stored recording 59 func (s *StoredRecordingHandle) ID() string { 60 return s.key.ID 61 } 62 63 // Key returns the Key for the stored recording 64 func (s *StoredRecordingHandle) Key() *Key { 65 return s.key 66 } 67 68 // Exec executes any staged operations 69 func (s *StoredRecordingHandle) Exec() (err error) { 70 if !s.executed { 71 s.executed = true 72 if s.exec != nil { 73 err = s.exec(s) 74 s.exec = nil 75 } 76 } 77 return 78 } 79 80 // Data gets the data for the stored recording 81 func (s *StoredRecordingHandle) Data() (*StoredRecordingData, error) { 82 return s.s.Data(s.key) 83 } 84 85 // Copy copies the stored recording. 86 // 87 // NOTE: because ARI offers no forced-copy, this should always return the 88 // StoredRecordingHandle of the destination, even if the Copy fails. Doing so 89 // allows the user to Delete the existing StoredRecording before retrying. 90 func (s *StoredRecordingHandle) Copy(dest string) (*StoredRecordingHandle, error) { 91 return s.s.Copy(s.key, dest) 92 } 93 94 // Delete deletes the recording 95 func (s *StoredRecordingHandle) Delete() error { 96 return s.s.Delete(s.key) 97 }