-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlogRetriever.go
54 lines (45 loc) · 1.23 KB
/
logRetriever.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
package convoso
import (
"encoding/json"
"errors"
"io/ioutil"
"net/url"
"time"
)
// LogResponse The payload that is sent back when requesting call logs from
// Convoso
type LogResponse struct {
Success bool `json:"success"`
Data struct {
Offset int `json:"offset"`
Limit int `json:"limit"`
TotalFound interface{} `json:"total_found"`
Entries int `json:"entries"`
Results []CallLog `json:"results"`
} `json:"data"`
}
// GetLogs return the result of requsting logs from a certain time frame,
// represented by two date structs
func GetLogs(start, end time.Time) (LogResponse, error) {
result := LogResponse{}
if start.After(end) {
return result, errors.New("Starting time can not be before ending time")
}
data := url.Values{}
data.Add("start_time", start.Format("2006-01-02 15:04:05"))
data.Add("end_time", end.Format("2006-01-02 15:04:05"))
r, err := postFormRequest("https://api.convoso.com/v1/log/retrieve", data)
if err != nil {
return result, err
}
body, err := ioutil.ReadAll(r.Body)
if err != nil {
return result, err
}
err = json.Unmarshal(body, &result)
if err != nil {
log.Errorf("RAW JSON: " + string(body))
return result, err
}
return result, nil
}