forked from Vonage/vonage-go-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
reports.go
36 lines (30 loc) · 1.04 KB
/
reports.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
package nexmo
import (
"fmt"
"net/http"
"github.com/fabriziomanunta/nexmo-go/sling"
)
func (c *ReportErrorResponse) Error() string {
return fmt.Sprintf("%s: %s", c.ErrorTitle, c.Type)
}
// Load Records gets the list of records with the given search criterias
func (c *ReportService) LoadRecords(request LoadRecordsRequest) (*LoadRecordsResponse, *http.Response, error) {
sling := c.sling.New().Get("records").BodyJSON(request)
reportResponse := new(LoadRecordsResponse)
httpResponse, err := c.makeRequest(sling, reportResponse)
return reportResponse, httpResponse, err
}
func (c *ReportService) makeRequest(s *sling.Sling, successV interface{}) (*http.Response, error) {
errorV := new(ReportErrorResponse)
if err := c.authSet.ApplyJWT(s); err != nil {
return nil, fmt.Errorf("%s - error applying JWT", err)
}
httpResponse, err := s.Receive(successV, errorV)
if err != nil {
return httpResponse, fmt.Errorf("%s - error receiving data from server", err)
}
if errorV.Type != "" {
return httpResponse, errorV
}
return httpResponse, nil
}