-
Notifications
You must be signed in to change notification settings - Fork 18
/
hv.go
39 lines (29 loc) · 829 Bytes
/
hv.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
package proton
import (
"encoding/json"
"errors"
"strings"
"github.com/go-resty/resty/v2"
)
// APIHVDetails contains information related to the human verification requests.
type APIHVDetails struct {
Methods []string `json:"HumanVerificationMethods"`
Token string `json:"HumanVerificationToken"`
}
func addHVToRequest(req *resty.Request, hv *APIHVDetails) *resty.Request {
if hv == nil {
return req
}
return req.SetHeader(hvPMTokenHeaderField, hv.Token).SetHeader(hvPMTokenType, strings.Join(hv.Methods, ","))
}
var ErrAPIErrIsNotHVErr = errors.New("not HV error")
func (err APIError) GetHVDetails() (*APIHVDetails, error) {
if !err.IsHVError() {
return nil, ErrAPIErrIsNotHVErr
}
r := new(APIHVDetails)
if err := json.Unmarshal(err.Details, &r); err != nil {
return nil, err
}
return r, nil
}