-
Notifications
You must be signed in to change notification settings - Fork 73
/
asterisk.go
100 lines (81 loc) · 2.35 KB
/
asterisk.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package native
import (
"errors"
"github.com/CyCoreSystems/ari"
)
var errOnlyUnsupported = errors.New("Only-restricted AsteriskInfo requests are not yet implemented")
type nativeAsterisk struct {
conn *Conn
logging ari.Logging
modules ari.Modules
config ari.Config
}
// Config returns the config resource
func (a *nativeAsterisk) Config() ari.Config {
return a.config
}
// Modules returns the modules resource
func (a *nativeAsterisk) Modules() ari.Modules {
return a.modules
}
// Logging returns the logging resource
func (a *nativeAsterisk) Logging() ari.Logging {
return a.logging
}
// Info returns various data about the Asterisk system
// Equivalent to GET /asterisk/info
func (a *nativeAsterisk) Info(only string) (*ari.AsteriskInfo, error) {
var m ari.AsteriskInfo
path := "/asterisk/info"
// If we are passed an 'only' parameter
// pass it on as the 'only' querystring parameter
if only != "" {
path += "?only=" + only
return &m, errOnlyUnsupported
}
// TODO: handle "only" parameter
// the problem is that responses with "only" do not
// conform to the AsteriskInfo model; they just return
// the subobjects requested
// That means we should probably break this
// method into multiple submethods
err := Get(a.conn, path, &m)
return &m, err
}
// ReloadModule tells asterisk to load the given module
func (a *nativeAsterisk) ReloadModule(name string) error {
return a.Modules().Reload(name)
}
type nativeAsteriskVariables struct {
conn *Conn
}
// Variables returns the variables interface for the Asterisk server
func (a *nativeAsterisk) Variables() ari.Variables {
return &nativeAsteriskVariables{a.conn}
}
// Get returns the value of the given global variable
// Equivalent to GET /asterisk/variable
func (a *nativeAsteriskVariables) Get(key string) (string, error) {
type variable struct {
Value string `json:"value"`
}
var m variable
path := "/asterisk/variable?variable=" + key
err := Get(a.conn, path, &m)
if err != nil {
return "", err
}
return m.Value, nil
}
// Set sets a global channel variable
// (Equivalent to POST /asterisk/variable)
func (a *nativeAsteriskVariables) Set(key string, value string) error {
path := "/asterisk/variable"
type request struct {
Variable string `json:"variable"`
Value string `json:"value,omitempty"`
}
req := request{key, value}
err := Post(a.conn, path, nil, &req)
return err
}