/
asterisk.go
90 lines (73 loc) · 2.12 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
package native
import (
"fmt"
"github.com/rotisserie/eris"
"github.com/CyCoreSystems/ari/v6"
)
// Asterisk provides the ARI Asterisk accessors for a native client
type Asterisk struct {
client *Client
}
// Logging provides the ARI Asterisk Logging accessors for a native client
func (a *Asterisk) Logging() ari.Logging {
return &Logging{a.client}
}
// Modules provides the ARI Asterisk Modules accessors for a native client
func (a *Asterisk) Modules() ari.Modules {
return &Modules{a.client}
}
// Config provides the ARI Asterisk Config accessors for a native client
func (a *Asterisk) Config() ari.Config {
return &Config{a.client}
}
/*
conn *Conn
logging ari.Logging
modules ari.Modules
config ari.Config
}
*/
// Info returns various data about the Asterisk system
// Equivalent to GET /asterisk/info
func (a *Asterisk) Info(key *ari.Key) (*ari.AsteriskInfo, error) {
var m ari.AsteriskInfo
return &m, eris.Wrap(
a.client.get("/asterisk/info", &m),
"failed to get asterisk info",
)
}
// AsteriskVariables provides the ARI Variables accessors for server-level variables
type AsteriskVariables struct {
client *Client
}
// Variables returns the variables interface for the Asterisk server
func (a *Asterisk) Variables() ari.AsteriskVariables {
return &AsteriskVariables{a.client}
}
// Get returns the value of the given global variable
// Equivalent to GET /asterisk/variable
func (a *AsteriskVariables) Get(key *ari.Key) (string, error) {
var m struct {
Value string `json:"value"`
}
err := a.client.get(fmt.Sprintf("/asterisk/variable?variable=%s", key.ID), &m)
if err != nil {
return "", eris.Wrapf(err, "Error getting asterisk variable '%v'", key.ID)
}
return m.Value, nil
}
// Set sets a global channel variable
// (Equivalent to POST /asterisk/variable)
func (a *AsteriskVariables) Set(key *ari.Key, value string) (err error) {
req := struct {
Variable string `json:"variable"`
Value string `json:"value,omitempty"`
}{
Variable: key.ID,
Value: value,
}
return eris.Wrapf(
a.client.post("/asterisk/variable", nil, &req),
"Error setting asterisk variable '%s' to '%s'", key.ID, value,
)
}