github.com/CyCoreSystems/ari@v4.8.4+incompatible/client/native/sound.go (about) 1 package native 2 3 import ( 4 "errors" 5 "net/url" 6 7 "github.com/CyCoreSystems/ari" 8 ) 9 10 // Sound provides the ARI Sound accessors for the native client 11 type Sound struct { 12 client *Client 13 } 14 15 // Data returns the details of a given ARI Sound 16 // Equivalent to GET /sounds/{name} 17 func (s *Sound) Data(key *ari.Key) (*ari.SoundData, error) { 18 if key == nil || key.ID == "" { 19 return nil, errors.New("sound key not supplied") 20 } 21 22 var data = new(ari.SoundData) 23 if err := s.client.get("/sounds/"+key.ID, data); err != nil { 24 return nil, dataGetError(err, "sound", "%v", key.ID) 25 } 26 27 data.Key = s.client.stamp(key) 28 return data, nil 29 } 30 31 // List returns available sounds limited by the provided filters. 32 // valid filters are "lang", "format", and nil (no filter) 33 // An empty filter returns all available sounds 34 func (s *Sound) List(filters map[string]string, keyFilter *ari.Key) (sh []*ari.Key, err error) { 35 36 var sounds = []struct { 37 Name string `json:"name"` 38 }{} 39 40 uri := "/sounds" 41 if len(filters) > 0 { 42 v := url.Values{} 43 for key, val := range filters { 44 v.Set(key, val) 45 } 46 uri += "?" + v.Encode() 47 } 48 49 if keyFilter == nil { 50 keyFilter = s.client.stamp(ari.NewKey(ari.SoundKey, "")) 51 } 52 53 err = s.client.get(uri, &sounds) 54 if err != nil { 55 return nil, err 56 } 57 58 // Store whatever we received, even if incomplete or error 59 for _, i := range sounds { 60 k := s.client.stamp(ari.NewKey(ari.SoundKey, i.Name)) 61 if keyFilter.Match(k) { 62 sh = append(sh, k) 63 } 64 } 65 66 return sh, err 67 }