-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.go
108 lines (93 loc) · 2.31 KB
/
api.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
101
102
103
104
105
106
107
108
package main
import (
"fmt"
"net/url"
"os"
"strings"
"text/tabwriter"
"time"
)
func printBalance() {
c := newClient()
v := url.Values{}
b := BalanceResp{}
c.getRequest("getBalance", v, &b)
fmt.Printf("%v\n", b.Balance.CurrentBalance)
}
func blockNumber(phone *string, note *string) {
c := newClient()
m := postParams{}
m["callerid"] = *phone
m["did"] = "all"
m["routing"] = "sys:hangup"
filterNote := time.Now().Format("Jan.02/06")
if *note != "" {
filterNote += " - " + *note
}
m["note"] = filterNote
s := SetCallerIDFilterResp{}
c.postRequest("setCallerIDFiltering", m, &s)
switch s.Status {
case "used_filter":
fmt.Println("Voip.ms reports a filter for this number already exists:", *phone)
case "success":
fmt.Printf("Yay, %s blocked successfully with note [%s]: got filter id %s\n", *phone, filterNote, s.Filtering.String())
default:
fmt.Println("Unknown result:")
fmt.Printf("%+v\n", s)
}
}
func getRecent(dateFrom time.Time) GetCallDataRecord {
c := newClient()
v := url.Values{}
r := GetCallDataRecord{}
timeFormat := "2006-01-02"
now := time.Now()
today := now.Format(timeFormat)
_, offset := now.Zone()
zoneDuration := time.Duration(offset) * time.Second
// I think voip.ms has the wrong idea of what the current time is
zoneDuration -= time.Duration(1) * time.Hour
v.Add("date_to", today)
v.Add("date_from", dateFrom.Format(timeFormat))
v.Add("timezone", fmt.Sprintf("%.2g", zoneDuration.Hours()))
v.Add("answered", "1")
v.Add("noanswer", "1")
v.Add("busy", "1")
v.Add("fail", "1")
c.getRequest("getCDR", v, &r)
return r
}
func printRecent(r GetCallDataRecord) {
switch r.Status {
case "success":
w := tabwriter.NewWriter(os.Stdout, 0, 0, 4, ' ', tabwriter.AlignRight)
header := []string{
"Date",
"CallerID",
"Destination",
"Disposition",
"Description",
"Duration",
}
fmt.Fprintln(w, strings.Join(header, "\t")+"\t")
for _, cdr := range r.CallDataRecords {
fmt.Fprintln(
w,
strings.Join([]string{
cdr.Date,
cdr.CallerID,
string(cdr.Destination),
cdr.Disposition,
cdr.Description,
cdr.Duration,
}, "\t")+"\t")
}
w.Flush()
fmt.Printf("%d calls\n", len(r.CallDataRecords))
case "no_cdr":
fmt.Println("No recent calls found")
default:
fmt.Println("Non-success result getting CDR:", r.Status)
}
}