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 ExamplesClient struct {
21 BaseClient
22 }
23
24
25 func NewExamplesClient(endpoint string) ExamplesClient {
26 return ExamplesClient{New(endpoint)}
27 }
28
29
30
31
32
33
34 func (client ExamplesClient) Add(ctx context.Context, appID uuid.UUID, versionID string, exampleLabelObject ExampleLabelObject) (result LabelExampleResponse, err error) {
35 if tracing.IsEnabled() {
36 ctx = tracing.StartSpan(ctx, fqdn+"/ExamplesClient.Add")
37 defer func() {
38 sc := -1
39 if result.Response.Response != nil {
40 sc = result.Response.Response.StatusCode
41 }
42 tracing.EndSpan(ctx, sc, err)
43 }()
44 }
45 req, err := client.AddPreparer(ctx, appID, versionID, exampleLabelObject)
46 if err != nil {
47 err = autorest.NewErrorWithError(err, "authoring.ExamplesClient", "Add", nil, "Failure preparing request")
48 return
49 }
50
51 resp, err := client.AddSender(req)
52 if err != nil {
53 result.Response = autorest.Response{Response: resp}
54 err = autorest.NewErrorWithError(err, "authoring.ExamplesClient", "Add", resp, "Failure sending request")
55 return
56 }
57
58 result, err = client.AddResponder(resp)
59 if err != nil {
60 err = autorest.NewErrorWithError(err, "authoring.ExamplesClient", "Add", resp, "Failure responding to request")
61 return
62 }
63
64 return
65 }
66
67
68 func (client ExamplesClient) AddPreparer(ctx context.Context, appID uuid.UUID, versionID string, exampleLabelObject ExampleLabelObject) (*http.Request, error) {
69 urlParameters := map[string]interface{}{
70 "Endpoint": client.Endpoint,
71 }
72
73 pathParameters := map[string]interface{}{
74 "appId": autorest.Encode("path", appID),
75 "versionId": autorest.Encode("path", versionID),
76 }
77
78 preparer := autorest.CreatePreparer(
79 autorest.AsContentType("application/json; charset=utf-8"),
80 autorest.AsPost(),
81 autorest.WithCustomBaseURL("{Endpoint}/luis/api/v2.0", urlParameters),
82 autorest.WithPathParameters("/apps/{appId}/versions/{versionId}/example", pathParameters),
83 autorest.WithJSON(exampleLabelObject))
84 return preparer.Prepare((&http.Request{}).WithContext(ctx))
85 }
86
87
88
89 func (client ExamplesClient) AddSender(req *http.Request) (*http.Response, error) {
90 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
91 }
92
93
94
95 func (client ExamplesClient) AddResponder(resp *http.Response) (result LabelExampleResponse, err error) {
96 err = autorest.Respond(
97 resp,
98 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
99 autorest.ByUnmarshallingJSON(&result),
100 autorest.ByClosing())
101 result.Response = autorest.Response{Response: resp}
102 return
103 }
104
105
106
107
108
109
110 func (client ExamplesClient) Batch(ctx context.Context, appID uuid.UUID, versionID string, exampleLabelObjectArray []ExampleLabelObject) (result ListBatchLabelExample, err error) {
111 if tracing.IsEnabled() {
112 ctx = tracing.StartSpan(ctx, fqdn+"/ExamplesClient.Batch")
113 defer func() {
114 sc := -1
115 if result.Response.Response != nil {
116 sc = result.Response.Response.StatusCode
117 }
118 tracing.EndSpan(ctx, sc, err)
119 }()
120 }
121 if err := validation.Validate([]validation.Validation{
122 {TargetValue: exampleLabelObjectArray,
123 Constraints: []validation.Constraint{{Target: "exampleLabelObjectArray", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil {
124 return result, validation.NewError("authoring.ExamplesClient", "Batch", err.Error())
125 }
126
127 req, err := client.BatchPreparer(ctx, appID, versionID, exampleLabelObjectArray)
128 if err != nil {
129 err = autorest.NewErrorWithError(err, "authoring.ExamplesClient", "Batch", nil, "Failure preparing request")
130 return
131 }
132
133 resp, err := client.BatchSender(req)
134 if err != nil {
135 result.Response = autorest.Response{Response: resp}
136 err = autorest.NewErrorWithError(err, "authoring.ExamplesClient", "Batch", resp, "Failure sending request")
137 return
138 }
139
140 result, err = client.BatchResponder(resp)
141 if err != nil {
142 err = autorest.NewErrorWithError(err, "authoring.ExamplesClient", "Batch", resp, "Failure responding to request")
143 return
144 }
145
146 return
147 }
148
149
150 func (client ExamplesClient) BatchPreparer(ctx context.Context, appID uuid.UUID, versionID string, exampleLabelObjectArray []ExampleLabelObject) (*http.Request, error) {
151 urlParameters := map[string]interface{}{
152 "Endpoint": client.Endpoint,
153 }
154
155 pathParameters := map[string]interface{}{
156 "appId": autorest.Encode("path", appID),
157 "versionId": autorest.Encode("path", versionID),
158 }
159
160 preparer := autorest.CreatePreparer(
161 autorest.AsContentType("application/json; charset=utf-8"),
162 autorest.AsPost(),
163 autorest.WithCustomBaseURL("{Endpoint}/luis/api/v2.0", urlParameters),
164 autorest.WithPathParameters("/apps/{appId}/versions/{versionId}/examples", pathParameters),
165 autorest.WithJSON(exampleLabelObjectArray))
166 return preparer.Prepare((&http.Request{}).WithContext(ctx))
167 }
168
169
170
171 func (client ExamplesClient) BatchSender(req *http.Request) (*http.Response, error) {
172 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
173 }
174
175
176
177 func (client ExamplesClient) BatchResponder(resp *http.Response) (result ListBatchLabelExample, err error) {
178 err = autorest.Respond(
179 resp,
180 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated, http.StatusMultiStatus),
181 autorest.ByUnmarshallingJSON(&result.Value),
182 autorest.ByClosing())
183 result.Response = autorest.Response{Response: resp}
184 return
185 }
186
187
188
189
190
191
192 func (client ExamplesClient) Delete(ctx context.Context, appID uuid.UUID, versionID string, exampleID int32) (result OperationStatus, err error) {
193 if tracing.IsEnabled() {
194 ctx = tracing.StartSpan(ctx, fqdn+"/ExamplesClient.Delete")
195 defer func() {
196 sc := -1
197 if result.Response.Response != nil {
198 sc = result.Response.Response.StatusCode
199 }
200 tracing.EndSpan(ctx, sc, err)
201 }()
202 }
203 req, err := client.DeletePreparer(ctx, appID, versionID, exampleID)
204 if err != nil {
205 err = autorest.NewErrorWithError(err, "authoring.ExamplesClient", "Delete", nil, "Failure preparing request")
206 return
207 }
208
209 resp, err := client.DeleteSender(req)
210 if err != nil {
211 result.Response = autorest.Response{Response: resp}
212 err = autorest.NewErrorWithError(err, "authoring.ExamplesClient", "Delete", resp, "Failure sending request")
213 return
214 }
215
216 result, err = client.DeleteResponder(resp)
217 if err != nil {
218 err = autorest.NewErrorWithError(err, "authoring.ExamplesClient", "Delete", resp, "Failure responding to request")
219 return
220 }
221
222 return
223 }
224
225
226 func (client ExamplesClient) DeletePreparer(ctx context.Context, appID uuid.UUID, versionID string, exampleID int32) (*http.Request, error) {
227 urlParameters := map[string]interface{}{
228 "Endpoint": client.Endpoint,
229 }
230
231 pathParameters := map[string]interface{}{
232 "appId": autorest.Encode("path", appID),
233 "exampleId": autorest.Encode("path", exampleID),
234 "versionId": autorest.Encode("path", versionID),
235 }
236
237 preparer := autorest.CreatePreparer(
238 autorest.AsDelete(),
239 autorest.WithCustomBaseURL("{Endpoint}/luis/api/v2.0", urlParameters),
240 autorest.WithPathParameters("/apps/{appId}/versions/{versionId}/examples/{exampleId}", pathParameters))
241 return preparer.Prepare((&http.Request{}).WithContext(ctx))
242 }
243
244
245
246 func (client ExamplesClient) DeleteSender(req *http.Request) (*http.Response, error) {
247 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
248 }
249
250
251
252 func (client ExamplesClient) DeleteResponder(resp *http.Response) (result OperationStatus, err error) {
253 err = autorest.Respond(
254 resp,
255 azure.WithErrorUnlessStatusCode(http.StatusOK),
256 autorest.ByUnmarshallingJSON(&result),
257 autorest.ByClosing())
258 result.Response = autorest.Response{Response: resp}
259 return
260 }
261
262
263
264
265
266
267
268 func (client ExamplesClient) List(ctx context.Context, appID uuid.UUID, versionID string, skip *int32, take *int32) (result ListLabeledUtterance, err error) {
269 if tracing.IsEnabled() {
270 ctx = tracing.StartSpan(ctx, fqdn+"/ExamplesClient.List")
271 defer func() {
272 sc := -1
273 if result.Response.Response != nil {
274 sc = result.Response.Response.StatusCode
275 }
276 tracing.EndSpan(ctx, sc, err)
277 }()
278 }
279 if err := validation.Validate([]validation.Validation{
280 {TargetValue: skip,
281 Constraints: []validation.Constraint{{Target: "skip", Name: validation.Null, Rule: false,
282 Chain: []validation.Constraint{{Target: "skip", Name: validation.InclusiveMinimum, Rule: int64(0), Chain: nil}}}}},
283 {TargetValue: take,
284 Constraints: []validation.Constraint{{Target: "take", Name: validation.Null, Rule: false,
285 Chain: []validation.Constraint{{Target: "take", Name: validation.InclusiveMaximum, Rule: int64(500), Chain: nil},
286 {Target: "take", Name: validation.InclusiveMinimum, Rule: int64(0), Chain: nil},
287 }}}}}); err != nil {
288 return result, validation.NewError("authoring.ExamplesClient", "List", err.Error())
289 }
290
291 req, err := client.ListPreparer(ctx, appID, versionID, skip, take)
292 if err != nil {
293 err = autorest.NewErrorWithError(err, "authoring.ExamplesClient", "List", nil, "Failure preparing request")
294 return
295 }
296
297 resp, err := client.ListSender(req)
298 if err != nil {
299 result.Response = autorest.Response{Response: resp}
300 err = autorest.NewErrorWithError(err, "authoring.ExamplesClient", "List", resp, "Failure sending request")
301 return
302 }
303
304 result, err = client.ListResponder(resp)
305 if err != nil {
306 err = autorest.NewErrorWithError(err, "authoring.ExamplesClient", "List", resp, "Failure responding to request")
307 return
308 }
309
310 return
311 }
312
313
314 func (client ExamplesClient) ListPreparer(ctx context.Context, appID uuid.UUID, versionID string, skip *int32, take *int32) (*http.Request, error) {
315 urlParameters := map[string]interface{}{
316 "Endpoint": client.Endpoint,
317 }
318
319 pathParameters := map[string]interface{}{
320 "appId": autorest.Encode("path", appID),
321 "versionId": autorest.Encode("path", versionID),
322 }
323
324 queryParameters := map[string]interface{}{}
325 if skip != nil {
326 queryParameters["skip"] = autorest.Encode("query", *skip)
327 } else {
328 queryParameters["skip"] = autorest.Encode("query", 0)
329 }
330 if take != nil {
331 queryParameters["take"] = autorest.Encode("query", *take)
332 } else {
333 queryParameters["take"] = autorest.Encode("query", 100)
334 }
335
336 preparer := autorest.CreatePreparer(
337 autorest.AsGet(),
338 autorest.WithCustomBaseURL("{Endpoint}/luis/api/v2.0", urlParameters),
339 autorest.WithPathParameters("/apps/{appId}/versions/{versionId}/examples", pathParameters),
340 autorest.WithQueryParameters(queryParameters))
341 return preparer.Prepare((&http.Request{}).WithContext(ctx))
342 }
343
344
345
346 func (client ExamplesClient) ListSender(req *http.Request) (*http.Response, error) {
347 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
348 }
349
350
351
352 func (client ExamplesClient) ListResponder(resp *http.Response) (result ListLabeledUtterance, err error) {
353 err = autorest.Respond(
354 resp,
355 azure.WithErrorUnlessStatusCode(http.StatusOK),
356 autorest.ByUnmarshallingJSON(&result.Value),
357 autorest.ByClosing())
358 result.Response = autorest.Response{Response: resp}
359 return
360 }
361
View as plain text