-
Notifications
You must be signed in to change notification settings - Fork 0
/
action-configurations.go
126 lines (101 loc) · 4.17 KB
/
action-configurations.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
package authsignal
import (
"bytes"
"encoding/json"
"fmt"
"net/http"
)
type MessagingTemplates interface {
}
type ActionConfiguration struct {
DefaultUserActionResult NullableJsonInput[string] `json:"defaultUserActionResult,omitempty"`
ActionCode NullableJsonInput[string] `json:"actionCode,omitempty"`
MessagingTemplates NullableJsonInput[MessagingTemplates] `json:"messagingTemplates,omitempty"`
VerificationMethods NullableJsonInput[[]string] `json:"verificationMethods,omitempty"`
PromptToEnrollVerificationMethods NullableJsonInput[[]string] `json:"promptToEnrollVerificationMethods,omitempty"`
DefaultVerificationMethod NullableJsonInput[string] `json:"defaultVerificationMethod,omitempty"`
}
type ActionConfigurationResponse struct {
LastActionCreatedAt string `json:"lastActionCreatedAt"`
DefaultUserActionResult string `json:"defaultUserActionResult"`
TenantId string `json:"tenantId"`
ActionCode string `json:"actionCode"`
MessagingTemplates MessagingTemplates `json:"messagingTemplates"`
VerificationMethods []string `json:"verificationMethods"`
PromptToEnrollVerificationMethods []string `json:"promptToEnrollVerificationMethods"`
DefaultVerificationMethod string `json:"defaultVerificationMethod"`
}
func (c Client) CreateActionConfiguration(actionConfiguration ActionConfiguration) (*ActionConfigurationResponse, int, error) {
createBody, err := json.Marshal(actionConfiguration)
if err != nil {
return nil, 0, err
}
request, err := http.NewRequest("POST", fmt.Sprintf("%s/action-configurations", c.Host), bytes.NewReader(createBody))
if err != nil {
return nil, 0, err
}
request.Header.Set("Content-Type", "application/json")
body, statusCode, err := c.makeRequest(request, c.ApiSecret)
if err != nil {
return nil, statusCode, err
}
var createdActionConfiguration ActionConfigurationResponse
err = json.Unmarshal(body, &createdActionConfiguration)
if err != nil {
return nil, statusCode, err
}
return &createdActionConfiguration, statusCode, nil
}
func (c Client) GetActionConfiguration(actionCode string) (*ActionConfigurationResponse, int, error) {
request, err := http.NewRequest("GET", fmt.Sprintf("%s/action-configurations/%s", c.Host, actionCode), nil)
if err != nil {
return nil, 0, err
}
body, statusCode, err := c.makeRequest(request, c.ApiSecret)
if err != nil {
return nil, statusCode, err
}
var actionConfiguration ActionConfigurationResponse
err = json.Unmarshal(body, &actionConfiguration)
if err != nil {
return nil, statusCode, err
}
return &actionConfiguration, statusCode, nil
}
func (c Client) UpdateActionConfiguration(actionCode string, actionConfiguration ActionConfiguration) (*ActionConfigurationResponse, int, error) {
updateBody, err := json.Marshal(actionConfiguration)
if err != nil {
return nil, 0, err
}
request, err := http.NewRequest("PATCH", fmt.Sprintf("%s/action-configurations/%s", c.Host, actionCode), bytes.NewReader(updateBody))
if err != nil {
return nil, 0, err
}
request.Header.Set("Content-Type", "application/json")
body, statusCode, err := c.makeRequest(request, c.ApiSecret)
if err != nil {
return nil, statusCode, err
}
var updatedActionConfiguration ActionConfigurationResponse
err = json.Unmarshal(body, &updatedActionConfiguration)
if err != nil {
return nil, statusCode, err
}
return &updatedActionConfiguration, statusCode, nil
}
func (c Client) DeleteActionConfiguration(actionCode string) (*HttpStatusResponse, int, error) {
request, err := http.NewRequest("DELETE", fmt.Sprintf("%s/action-configurations/%s", c.Host, actionCode), nil)
if err != nil {
return nil, 0, err
}
body, statusCode, err := c.makeRequest(request, c.ApiSecret)
if err != nil {
return nil, statusCode, err
}
var httpStatusResponse HttpStatusResponse
err = json.Unmarshal(body, &httpStatusResponse)
if err != nil {
return nil, statusCode, err
}
return &httpStatusResponse, statusCode, nil
}