-
Notifications
You must be signed in to change notification settings - Fork 16
/
phone_call_request.go
37 lines (30 loc) · 865 Bytes
/
phone_call_request.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
package authy
import (
"encoding/json"
"io/ioutil"
"net/http"
)
// PhoneCallRequest encapsulates the response from the Authy API
type PhoneCallRequest struct {
HTTPResponse *http.Response
Message string `json:"message"`
}
// NewPhoneCallRequest returns an instance of a PhoneCallRequest
func NewPhoneCallRequest(response *http.Response) (*PhoneCallRequest, error) {
request := &PhoneCallRequest{HTTPResponse: response}
body, err := ioutil.ReadAll(response.Body)
if err != nil {
Logger.Println("Error reading from API:", err)
return request, err
}
err = json.Unmarshal(body, &request)
if err != nil {
Logger.Println("Error parsing JSON:", err)
return request, err
}
return request, nil
}
// Valid returns true if the request was valid.
func (request *PhoneCallRequest) Valid() bool {
return request.HTTPResponse.StatusCode == 200
}