forked from linode/linodego
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprofile_phone_number.go
84 lines (69 loc) · 1.95 KB
/
profile_phone_number.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
package linodego
import (
"context"
"encoding/json"
"fmt"
)
// SendPhoneNumberVerificationCodeOptions fields are those accepted by SendPhoneNumberVerificationCode
type SendPhoneNumberVerificationCodeOptions struct {
ISOCode string `json:"iso_code"`
PhoneNumber string `json:"phone_number"`
}
// VerifyPhoneNumberOptions fields are those accepted by VerifyPhoneNumber
type VerifyPhoneNumberOptions struct {
OTPCode string `json:"otp_code"`
}
// SendPhoneNumberVerificationCode sends a one-time verification code via SMS message to the submitted phone number.
func (c *Client) SendPhoneNumberVerificationCode(ctx context.Context, opts SendPhoneNumberVerificationCodeOptions) error {
var body string
e, err := c.ProfilePhoneNumber.Endpoint()
if err != nil {
return err
}
req := c.R(ctx)
if bodyData, err := json.Marshal(opts); err == nil {
body = string(bodyData)
} else {
return NewError(err)
}
if _, err := coupleAPIErrors(req.
SetBody(body).
Post(e)); err != nil {
return err
}
return nil
}
// DeletePhoneNumber deletes the verified phone number for the User making this request.
func (c *Client) DeletePhoneNumber(ctx context.Context) error {
e, err := c.ProfilePhoneNumber.Endpoint()
if err != nil {
return err
}
req := c.R(ctx)
if _, err := coupleAPIErrors(req.
Delete(e)); err != nil {
return err
}
return nil
}
// VerifyPhoneNumber verifies a phone number by confirming the one-time code received via SMS message after accessing the Phone Verification Code Send command.
func (c *Client) VerifyPhoneNumber(ctx context.Context, opts VerifyPhoneNumberOptions) error {
var body string
e, err := c.ProfilePhoneNumber.Endpoint()
if err != nil {
return err
}
e = fmt.Sprintf("%s/verify", e)
req := c.R(ctx)
if bodyData, err := json.Marshal(opts); err == nil {
body = string(bodyData)
} else {
return NewError(err)
}
if _, err := coupleAPIErrors(req.
SetBody(body).
Post(e)); err != nil {
return err
}
return nil
}