-
Notifications
You must be signed in to change notification settings - Fork 16
/
phone_verification.go
57 lines (46 loc) · 1.62 KB
/
phone_verification.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
package authy
import (
"encoding/json"
"io/ioutil"
"net/http"
)
// PhoneVerificationStart encapsulates the response from the Authy API when requesting a phone verification.
type PhoneVerificationStart struct {
HTTPResponse *http.Response
UUID string `json:"uuid"`
Message string `json:"message"`
Success bool `json:"success"`
Carrier string `json:"carrier"`
}
// NewPhoneVerificationStart receives a http request, parses the body and return an instance of PhoneVerification
func NewPhoneVerificationStart(response *http.Response) (*PhoneVerificationStart, error) {
phoneVerification := &PhoneVerificationStart{HTTPResponse: response}
body, err := ioutil.ReadAll(response.Body)
if err != nil {
return phoneVerification, err
}
err = json.Unmarshal(body, &phoneVerification)
if err != nil {
return phoneVerification, err
}
return phoneVerification, nil
}
// PhoneVerificationCheck encapsulates the response from the Authy API when checking a phone verification.
type PhoneVerificationCheck struct {
HTTPResponse *http.Response
Message string `json:"message"`
Success bool `json:"success"`
}
// NewPhoneVerificationCheck receives a http request, parses the body and return an instance of PhoneVerification
func NewPhoneVerificationCheck(response *http.Response) (*PhoneVerificationCheck, error) {
phoneVerification := &PhoneVerificationCheck{HTTPResponse: response}
body, err := ioutil.ReadAll(response.Body)
if err != nil {
return phoneVerification, err
}
err = json.Unmarshal(body, &phoneVerification)
if err != nil {
return phoneVerification, err
}
return phoneVerification, nil
}