forked from abourget/ari
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplaybacks.go
63 lines (51 loc) · 1.08 KB
/
playbacks.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
package ari
import (
"fmt"
)
//
// Service
//
type PlaybackService struct {
client *Client
}
func (s *PlaybackService) Get(playbackId string) (*Playback, error) {
var out Playback
if _, err := s.client.Get(fmt.Sprintf("/playbacks/%s", playbackId), nil, &out); err != nil {
return nil, err
}
out.setClient(s.client)
return &out, nil
}
//
// Model
//
type Playback struct {
Id string
Language string
MediaURI string `json:"media_uri"`
State string
TargetURI string `json:"target_uri"`
// For further manipulations
client *Client
}
func (p *Playback) setClient(client *Client) {
if p != nil {
p.client = client
}
}
func (p *Playback) Stop() error {
_, err := p.client.Delete(fmt.Sprintf("/playbacks/%s", p.Id), nil)
return err
}
func (p *Playback) Control(operation string) (status int, err error) {
query := map[string]string{"operation": operation}
res, err := p.client.Post(fmt.Sprintf("/playbacks/%s/control", p.Id), query, nil)
if err != nil {
if res != nil {
return res.Status(), err
} else {
return 0, err
}
}
return res.Status(), err
}