1 package authoring
2
3
4
5
6
7
8
9 import (
10 "context"
11 "github.com/Azure/go-autorest/autorest"
12 "github.com/Azure/go-autorest/autorest/azure"
13 "github.com/Azure/go-autorest/autorest/validation"
14 "github.com/Azure/go-autorest/tracing"
15 "github.com/gofrs/uuid"
16 "net/http"
17 )
18
19
20 type SettingsClient struct {
21 BaseClient
22 }
23
24
25 func NewSettingsClient(endpoint string) SettingsClient {
26 return SettingsClient{New(endpoint)}
27 }
28
29
30
31
32
33 func (client SettingsClient) List(ctx context.Context, appID uuid.UUID, versionID string) (result ListAppVersionSettingObject, err error) {
34 if tracing.IsEnabled() {
35 ctx = tracing.StartSpan(ctx, fqdn+"/SettingsClient.List")
36 defer func() {
37 sc := -1
38 if result.Response.Response != nil {
39 sc = result.Response.Response.StatusCode
40 }
41 tracing.EndSpan(ctx, sc, err)
42 }()
43 }
44 req, err := client.ListPreparer(ctx, appID, versionID)
45 if err != nil {
46 err = autorest.NewErrorWithError(err, "authoring.SettingsClient", "List", nil, "Failure preparing request")
47 return
48 }
49
50 resp, err := client.ListSender(req)
51 if err != nil {
52 result.Response = autorest.Response{Response: resp}
53 err = autorest.NewErrorWithError(err, "authoring.SettingsClient", "List", resp, "Failure sending request")
54 return
55 }
56
57 result, err = client.ListResponder(resp)
58 if err != nil {
59 err = autorest.NewErrorWithError(err, "authoring.SettingsClient", "List", resp, "Failure responding to request")
60 return
61 }
62
63 return
64 }
65
66
67 func (client SettingsClient) ListPreparer(ctx context.Context, appID uuid.UUID, versionID string) (*http.Request, error) {
68 urlParameters := map[string]interface{}{
69 "Endpoint": client.Endpoint,
70 }
71
72 pathParameters := map[string]interface{}{
73 "appId": autorest.Encode("path", appID),
74 "versionId": autorest.Encode("path", versionID),
75 }
76
77 preparer := autorest.CreatePreparer(
78 autorest.AsGet(),
79 autorest.WithCustomBaseURL("{Endpoint}/luis/authoring/v3.0-preview", urlParameters),
80 autorest.WithPathParameters("/apps/{appId}/versions/{versionId}/settings", pathParameters))
81 return preparer.Prepare((&http.Request{}).WithContext(ctx))
82 }
83
84
85
86 func (client SettingsClient) ListSender(req *http.Request) (*http.Response, error) {
87 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
88 }
89
90
91
92 func (client SettingsClient) ListResponder(resp *http.Response) (result ListAppVersionSettingObject, err error) {
93 err = autorest.Respond(
94 resp,
95 azure.WithErrorUnlessStatusCode(http.StatusOK),
96 autorest.ByUnmarshallingJSON(&result.Value),
97 autorest.ByClosing())
98 result.Response = autorest.Response{Response: resp}
99 return
100 }
101
102
103
104
105
106
107 func (client SettingsClient) Update(ctx context.Context, appID uuid.UUID, versionID string, listOfAppVersionSettingObject []AppVersionSettingObject) (result OperationStatus, err error) {
108 if tracing.IsEnabled() {
109 ctx = tracing.StartSpan(ctx, fqdn+"/SettingsClient.Update")
110 defer func() {
111 sc := -1
112 if result.Response.Response != nil {
113 sc = result.Response.Response.StatusCode
114 }
115 tracing.EndSpan(ctx, sc, err)
116 }()
117 }
118 if err := validation.Validate([]validation.Validation{
119 {TargetValue: listOfAppVersionSettingObject,
120 Constraints: []validation.Constraint{{Target: "listOfAppVersionSettingObject", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil {
121 return result, validation.NewError("authoring.SettingsClient", "Update", err.Error())
122 }
123
124 req, err := client.UpdatePreparer(ctx, appID, versionID, listOfAppVersionSettingObject)
125 if err != nil {
126 err = autorest.NewErrorWithError(err, "authoring.SettingsClient", "Update", nil, "Failure preparing request")
127 return
128 }
129
130 resp, err := client.UpdateSender(req)
131 if err != nil {
132 result.Response = autorest.Response{Response: resp}
133 err = autorest.NewErrorWithError(err, "authoring.SettingsClient", "Update", resp, "Failure sending request")
134 return
135 }
136
137 result, err = client.UpdateResponder(resp)
138 if err != nil {
139 err = autorest.NewErrorWithError(err, "authoring.SettingsClient", "Update", resp, "Failure responding to request")
140 return
141 }
142
143 return
144 }
145
146
147 func (client SettingsClient) UpdatePreparer(ctx context.Context, appID uuid.UUID, versionID string, listOfAppVersionSettingObject []AppVersionSettingObject) (*http.Request, error) {
148 urlParameters := map[string]interface{}{
149 "Endpoint": client.Endpoint,
150 }
151
152 pathParameters := map[string]interface{}{
153 "appId": autorest.Encode("path", appID),
154 "versionId": autorest.Encode("path", versionID),
155 }
156
157 preparer := autorest.CreatePreparer(
158 autorest.AsContentType("application/json; charset=utf-8"),
159 autorest.AsPut(),
160 autorest.WithCustomBaseURL("{Endpoint}/luis/authoring/v3.0-preview", urlParameters),
161 autorest.WithPathParameters("/apps/{appId}/versions/{versionId}/settings", pathParameters),
162 autorest.WithJSON(listOfAppVersionSettingObject))
163 return preparer.Prepare((&http.Request{}).WithContext(ctx))
164 }
165
166
167
168 func (client SettingsClient) UpdateSender(req *http.Request) (*http.Response, error) {
169 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
170 }
171
172
173
174 func (client SettingsClient) UpdateResponder(resp *http.Response) (result OperationStatus, err error) {
175 err = autorest.Respond(
176 resp,
177 azure.WithErrorUnlessStatusCode(http.StatusOK),
178 autorest.ByUnmarshallingJSON(&result),
179 autorest.ByClosing())
180 result.Response = autorest.Response{Response: resp}
181 return
182 }
183
View as plain text