1package contentmoderator
2
3// Copyright (c) Microsoft and contributors.  All rights reserved.
4//
5// Licensed under the Apache License, Version 2.0 (the "License");
6// you may not use this file except in compliance with the License.
7// You may obtain a copy of the License at
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13//
14// See the License for the specific language governing permissions and
15// limitations under the License.
16//
17// Code generated by Microsoft (R) AutoRest Code Generator.
18// Changes may cause incorrect behavior and will be lost if the code is regenerated.
19
20import (
21	"context"
22	"github.com/Azure/go-autorest/autorest"
23	"github.com/Azure/go-autorest/autorest/azure"
24	"io"
25	"net/http"
26)
27
28// ImageModerationClient is the you use the API to scan your content as it is generated. Content Moderator then
29// processes your content and sends the results along with relevant information either back to your systems or to the
30// built-in review tool. You can use this information to take decisions e.g. take it down, send to human judge, etc.
31//
32// When using the API, images need to have a minimum of 128 pixels and a maximum file size of 4MB.
33// Text can be at most 1024 characters long.
34// If the content passed to the text API or the image API exceeds the size limits, the API will return an error code
35// that informs about the issue.
36type ImageModerationClient struct {
37	BaseClient
38}
39
40// NewImageModerationClient creates an instance of the ImageModerationClient client.
41func NewImageModerationClient(endpoint string) ImageModerationClient {
42	return ImageModerationClient{New(endpoint)}
43}
44
45// EvaluateFileInput returns probabilities of the image containing racy or adult content.
46// Parameters:
47// imageStream - the image file.
48// cacheImage - whether to retain the submitted image for future use; defaults to false if omitted.
49func (client ImageModerationClient) EvaluateFileInput(ctx context.Context, imageStream io.ReadCloser, cacheImage *bool) (result Evaluate, err error) {
50	req, err := client.EvaluateFileInputPreparer(ctx, imageStream, cacheImage)
51	if err != nil {
52		err = autorest.NewErrorWithError(err, "contentmoderator.ImageModerationClient", "EvaluateFileInput", nil, "Failure preparing request")
53		return
54	}
55
56	resp, err := client.EvaluateFileInputSender(req)
57	if err != nil {
58		result.Response = autorest.Response{Response: resp}
59		err = autorest.NewErrorWithError(err, "contentmoderator.ImageModerationClient", "EvaluateFileInput", resp, "Failure sending request")
60		return
61	}
62
63	result, err = client.EvaluateFileInputResponder(resp)
64	if err != nil {
65		err = autorest.NewErrorWithError(err, "contentmoderator.ImageModerationClient", "EvaluateFileInput", resp, "Failure responding to request")
66	}
67
68	return
69}
70
71// EvaluateFileInputPreparer prepares the EvaluateFileInput request.
72func (client ImageModerationClient) EvaluateFileInputPreparer(ctx context.Context, imageStream io.ReadCloser, cacheImage *bool) (*http.Request, error) {
73	urlParameters := map[string]interface{}{
74		"Endpoint": client.Endpoint,
75	}
76
77	queryParameters := map[string]interface{}{}
78	if cacheImage != nil {
79		queryParameters["CacheImage"] = autorest.Encode("query", *cacheImage)
80	}
81
82	preparer := autorest.CreatePreparer(
83		autorest.AsContentType("image/gif"),
84		autorest.AsPost(),
85		autorest.WithCustomBaseURL("{Endpoint}", urlParameters),
86		autorest.WithPath("/contentmoderator/moderate/v1.0/ProcessImage/Evaluate"),
87		autorest.WithFile(imageStream),
88		autorest.WithQueryParameters(queryParameters))
89	return preparer.Prepare((&http.Request{}).WithContext(ctx))
90}
91
92// EvaluateFileInputSender sends the EvaluateFileInput request. The method will close the
93// http.Response Body if it receives an error.
94func (client ImageModerationClient) EvaluateFileInputSender(req *http.Request) (*http.Response, error) {
95	return autorest.SendWithSender(client, req,
96		autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
97}
98
99// EvaluateFileInputResponder handles the response to the EvaluateFileInput request. The method always
100// closes the http.Response Body.
101func (client ImageModerationClient) EvaluateFileInputResponder(resp *http.Response) (result Evaluate, err error) {
102	err = autorest.Respond(
103		resp,
104		client.ByInspecting(),
105		azure.WithErrorUnlessStatusCode(http.StatusOK),
106		autorest.ByUnmarshallingJSON(&result),
107		autorest.ByClosing())
108	result.Response = autorest.Response{Response: resp}
109	return
110}
111
112// EvaluateMethod returns probabilities of the image containing racy or adult content.
113// Parameters:
114// cacheImage - whether to retain the submitted image for future use; defaults to false if omitted.
115func (client ImageModerationClient) EvaluateMethod(ctx context.Context, cacheImage *bool) (result Evaluate, err error) {
116	req, err := client.EvaluateMethodPreparer(ctx, cacheImage)
117	if err != nil {
118		err = autorest.NewErrorWithError(err, "contentmoderator.ImageModerationClient", "EvaluateMethod", nil, "Failure preparing request")
119		return
120	}
121
122	resp, err := client.EvaluateMethodSender(req)
123	if err != nil {
124		result.Response = autorest.Response{Response: resp}
125		err = autorest.NewErrorWithError(err, "contentmoderator.ImageModerationClient", "EvaluateMethod", resp, "Failure sending request")
126		return
127	}
128
129	result, err = client.EvaluateMethodResponder(resp)
130	if err != nil {
131		err = autorest.NewErrorWithError(err, "contentmoderator.ImageModerationClient", "EvaluateMethod", resp, "Failure responding to request")
132	}
133
134	return
135}
136
137// EvaluateMethodPreparer prepares the EvaluateMethod request.
138func (client ImageModerationClient) EvaluateMethodPreparer(ctx context.Context, cacheImage *bool) (*http.Request, error) {
139	urlParameters := map[string]interface{}{
140		"Endpoint": client.Endpoint,
141	}
142
143	queryParameters := map[string]interface{}{}
144	if cacheImage != nil {
145		queryParameters["CacheImage"] = autorest.Encode("query", *cacheImage)
146	}
147
148	preparer := autorest.CreatePreparer(
149		autorest.AsPost(),
150		autorest.WithCustomBaseURL("{Endpoint}", urlParameters),
151		autorest.WithPath("/contentmoderator/moderate/v1.0/ProcessImage/Evaluate"),
152		autorest.WithQueryParameters(queryParameters))
153	return preparer.Prepare((&http.Request{}).WithContext(ctx))
154}
155
156// EvaluateMethodSender sends the EvaluateMethod request. The method will close the
157// http.Response Body if it receives an error.
158func (client ImageModerationClient) EvaluateMethodSender(req *http.Request) (*http.Response, error) {
159	return autorest.SendWithSender(client, req,
160		autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
161}
162
163// EvaluateMethodResponder handles the response to the EvaluateMethod request. The method always
164// closes the http.Response Body.
165func (client ImageModerationClient) EvaluateMethodResponder(resp *http.Response) (result Evaluate, err error) {
166	err = autorest.Respond(
167		resp,
168		client.ByInspecting(),
169		azure.WithErrorUnlessStatusCode(http.StatusOK),
170		autorest.ByUnmarshallingJSON(&result),
171		autorest.ByClosing())
172	result.Response = autorest.Response{Response: resp}
173	return
174}
175
176// EvaluateURLInput returns probabilities of the image containing racy or adult content.
177// Parameters:
178// contentType - the content type.
179// imageURL - the image url.
180// cacheImage - whether to retain the submitted image for future use; defaults to false if omitted.
181func (client ImageModerationClient) EvaluateURLInput(ctx context.Context, contentType string, imageURL BodyModel, cacheImage *bool) (result Evaluate, err error) {
182	req, err := client.EvaluateURLInputPreparer(ctx, contentType, imageURL, cacheImage)
183	if err != nil {
184		err = autorest.NewErrorWithError(err, "contentmoderator.ImageModerationClient", "EvaluateURLInput", nil, "Failure preparing request")
185		return
186	}
187
188	resp, err := client.EvaluateURLInputSender(req)
189	if err != nil {
190		result.Response = autorest.Response{Response: resp}
191		err = autorest.NewErrorWithError(err, "contentmoderator.ImageModerationClient", "EvaluateURLInput", resp, "Failure sending request")
192		return
193	}
194
195	result, err = client.EvaluateURLInputResponder(resp)
196	if err != nil {
197		err = autorest.NewErrorWithError(err, "contentmoderator.ImageModerationClient", "EvaluateURLInput", resp, "Failure responding to request")
198	}
199
200	return
201}
202
203// EvaluateURLInputPreparer prepares the EvaluateURLInput request.
204func (client ImageModerationClient) EvaluateURLInputPreparer(ctx context.Context, contentType string, imageURL BodyModel, cacheImage *bool) (*http.Request, error) {
205	urlParameters := map[string]interface{}{
206		"Endpoint": client.Endpoint,
207	}
208
209	queryParameters := map[string]interface{}{}
210	if cacheImage != nil {
211		queryParameters["CacheImage"] = autorest.Encode("query", *cacheImage)
212	}
213
214	preparer := autorest.CreatePreparer(
215		autorest.AsContentType("application/json; charset=utf-8"),
216		autorest.AsPost(),
217		autorest.WithCustomBaseURL("{Endpoint}", urlParameters),
218		autorest.WithPath("/contentmoderator/moderate/v1.0/ProcessImage/Evaluate"),
219		autorest.WithJSON(imageURL),
220		autorest.WithQueryParameters(queryParameters),
221		autorest.WithHeader("Content-Type", autorest.String(contentType)))
222	return preparer.Prepare((&http.Request{}).WithContext(ctx))
223}
224
225// EvaluateURLInputSender sends the EvaluateURLInput request. The method will close the
226// http.Response Body if it receives an error.
227func (client ImageModerationClient) EvaluateURLInputSender(req *http.Request) (*http.Response, error) {
228	return autorest.SendWithSender(client, req,
229		autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
230}
231
232// EvaluateURLInputResponder handles the response to the EvaluateURLInput request. The method always
233// closes the http.Response Body.
234func (client ImageModerationClient) EvaluateURLInputResponder(resp *http.Response) (result Evaluate, err error) {
235	err = autorest.Respond(
236		resp,
237		client.ByInspecting(),
238		azure.WithErrorUnlessStatusCode(http.StatusOK),
239		autorest.ByUnmarshallingJSON(&result),
240		autorest.ByClosing())
241	result.Response = autorest.Response{Response: resp}
242	return
243}
244
245// FindFaces returns the list of faces found.
246// Parameters:
247// cacheImage - whether to retain the submitted image for future use; defaults to false if omitted.
248func (client ImageModerationClient) FindFaces(ctx context.Context, cacheImage *bool) (result FoundFaces, err error) {
249	req, err := client.FindFacesPreparer(ctx, cacheImage)
250	if err != nil {
251		err = autorest.NewErrorWithError(err, "contentmoderator.ImageModerationClient", "FindFaces", nil, "Failure preparing request")
252		return
253	}
254
255	resp, err := client.FindFacesSender(req)
256	if err != nil {
257		result.Response = autorest.Response{Response: resp}
258		err = autorest.NewErrorWithError(err, "contentmoderator.ImageModerationClient", "FindFaces", resp, "Failure sending request")
259		return
260	}
261
262	result, err = client.FindFacesResponder(resp)
263	if err != nil {
264		err = autorest.NewErrorWithError(err, "contentmoderator.ImageModerationClient", "FindFaces", resp, "Failure responding to request")
265	}
266
267	return
268}
269
270// FindFacesPreparer prepares the FindFaces request.
271func (client ImageModerationClient) FindFacesPreparer(ctx context.Context, cacheImage *bool) (*http.Request, error) {
272	urlParameters := map[string]interface{}{
273		"Endpoint": client.Endpoint,
274	}
275
276	queryParameters := map[string]interface{}{}
277	if cacheImage != nil {
278		queryParameters["CacheImage"] = autorest.Encode("query", *cacheImage)
279	}
280
281	preparer := autorest.CreatePreparer(
282		autorest.AsPost(),
283		autorest.WithCustomBaseURL("{Endpoint}", urlParameters),
284		autorest.WithPath("/contentmoderator/moderate/v1.0/ProcessImage/FindFaces"),
285		autorest.WithQueryParameters(queryParameters))
286	return preparer.Prepare((&http.Request{}).WithContext(ctx))
287}
288
289// FindFacesSender sends the FindFaces request. The method will close the
290// http.Response Body if it receives an error.
291func (client ImageModerationClient) FindFacesSender(req *http.Request) (*http.Response, error) {
292	return autorest.SendWithSender(client, req,
293		autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
294}
295
296// FindFacesResponder handles the response to the FindFaces request. The method always
297// closes the http.Response Body.
298func (client ImageModerationClient) FindFacesResponder(resp *http.Response) (result FoundFaces, err error) {
299	err = autorest.Respond(
300		resp,
301		client.ByInspecting(),
302		azure.WithErrorUnlessStatusCode(http.StatusOK),
303		autorest.ByUnmarshallingJSON(&result),
304		autorest.ByClosing())
305	result.Response = autorest.Response{Response: resp}
306	return
307}
308
309// FindFacesFileInput returns the list of faces found.
310// Parameters:
311// imageStream - the image file.
312// cacheImage - whether to retain the submitted image for future use; defaults to false if omitted.
313func (client ImageModerationClient) FindFacesFileInput(ctx context.Context, imageStream io.ReadCloser, cacheImage *bool) (result FoundFaces, err error) {
314	req, err := client.FindFacesFileInputPreparer(ctx, imageStream, cacheImage)
315	if err != nil {
316		err = autorest.NewErrorWithError(err, "contentmoderator.ImageModerationClient", "FindFacesFileInput", nil, "Failure preparing request")
317		return
318	}
319
320	resp, err := client.FindFacesFileInputSender(req)
321	if err != nil {
322		result.Response = autorest.Response{Response: resp}
323		err = autorest.NewErrorWithError(err, "contentmoderator.ImageModerationClient", "FindFacesFileInput", resp, "Failure sending request")
324		return
325	}
326
327	result, err = client.FindFacesFileInputResponder(resp)
328	if err != nil {
329		err = autorest.NewErrorWithError(err, "contentmoderator.ImageModerationClient", "FindFacesFileInput", resp, "Failure responding to request")
330	}
331
332	return
333}
334
335// FindFacesFileInputPreparer prepares the FindFacesFileInput request.
336func (client ImageModerationClient) FindFacesFileInputPreparer(ctx context.Context, imageStream io.ReadCloser, cacheImage *bool) (*http.Request, error) {
337	urlParameters := map[string]interface{}{
338		"Endpoint": client.Endpoint,
339	}
340
341	queryParameters := map[string]interface{}{}
342	if cacheImage != nil {
343		queryParameters["CacheImage"] = autorest.Encode("query", *cacheImage)
344	}
345
346	preparer := autorest.CreatePreparer(
347		autorest.AsContentType("image/gif"),
348		autorest.AsPost(),
349		autorest.WithCustomBaseURL("{Endpoint}", urlParameters),
350		autorest.WithPath("/contentmoderator/moderate/v1.0/ProcessImage/FindFaces"),
351		autorest.WithFile(imageStream),
352		autorest.WithQueryParameters(queryParameters))
353	return preparer.Prepare((&http.Request{}).WithContext(ctx))
354}
355
356// FindFacesFileInputSender sends the FindFacesFileInput request. The method will close the
357// http.Response Body if it receives an error.
358func (client ImageModerationClient) FindFacesFileInputSender(req *http.Request) (*http.Response, error) {
359	return autorest.SendWithSender(client, req,
360		autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
361}
362
363// FindFacesFileInputResponder handles the response to the FindFacesFileInput request. The method always
364// closes the http.Response Body.
365func (client ImageModerationClient) FindFacesFileInputResponder(resp *http.Response) (result FoundFaces, err error) {
366	err = autorest.Respond(
367		resp,
368		client.ByInspecting(),
369		azure.WithErrorUnlessStatusCode(http.StatusOK),
370		autorest.ByUnmarshallingJSON(&result),
371		autorest.ByClosing())
372	result.Response = autorest.Response{Response: resp}
373	return
374}
375
376// FindFacesURLInput returns the list of faces found.
377// Parameters:
378// contentType - the content type.
379// imageURL - the image url.
380// cacheImage - whether to retain the submitted image for future use; defaults to false if omitted.
381func (client ImageModerationClient) FindFacesURLInput(ctx context.Context, contentType string, imageURL BodyModel, cacheImage *bool) (result FoundFaces, err error) {
382	req, err := client.FindFacesURLInputPreparer(ctx, contentType, imageURL, cacheImage)
383	if err != nil {
384		err = autorest.NewErrorWithError(err, "contentmoderator.ImageModerationClient", "FindFacesURLInput", nil, "Failure preparing request")
385		return
386	}
387
388	resp, err := client.FindFacesURLInputSender(req)
389	if err != nil {
390		result.Response = autorest.Response{Response: resp}
391		err = autorest.NewErrorWithError(err, "contentmoderator.ImageModerationClient", "FindFacesURLInput", resp, "Failure sending request")
392		return
393	}
394
395	result, err = client.FindFacesURLInputResponder(resp)
396	if err != nil {
397		err = autorest.NewErrorWithError(err, "contentmoderator.ImageModerationClient", "FindFacesURLInput", resp, "Failure responding to request")
398	}
399
400	return
401}
402
403// FindFacesURLInputPreparer prepares the FindFacesURLInput request.
404func (client ImageModerationClient) FindFacesURLInputPreparer(ctx context.Context, contentType string, imageURL BodyModel, cacheImage *bool) (*http.Request, error) {
405	urlParameters := map[string]interface{}{
406		"Endpoint": client.Endpoint,
407	}
408
409	queryParameters := map[string]interface{}{}
410	if cacheImage != nil {
411		queryParameters["CacheImage"] = autorest.Encode("query", *cacheImage)
412	}
413
414	preparer := autorest.CreatePreparer(
415		autorest.AsContentType("application/json; charset=utf-8"),
416		autorest.AsPost(),
417		autorest.WithCustomBaseURL("{Endpoint}", urlParameters),
418		autorest.WithPath("/contentmoderator/moderate/v1.0/ProcessImage/FindFaces"),
419		autorest.WithJSON(imageURL),
420		autorest.WithQueryParameters(queryParameters),
421		autorest.WithHeader("Content-Type", autorest.String(contentType)))
422	return preparer.Prepare((&http.Request{}).WithContext(ctx))
423}
424
425// FindFacesURLInputSender sends the FindFacesURLInput request. The method will close the
426// http.Response Body if it receives an error.
427func (client ImageModerationClient) FindFacesURLInputSender(req *http.Request) (*http.Response, error) {
428	return autorest.SendWithSender(client, req,
429		autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
430}
431
432// FindFacesURLInputResponder handles the response to the FindFacesURLInput request. The method always
433// closes the http.Response Body.
434func (client ImageModerationClient) FindFacesURLInputResponder(resp *http.Response) (result FoundFaces, err error) {
435	err = autorest.Respond(
436		resp,
437		client.ByInspecting(),
438		azure.WithErrorUnlessStatusCode(http.StatusOK),
439		autorest.ByUnmarshallingJSON(&result),
440		autorest.ByClosing())
441	result.Response = autorest.Response{Response: resp}
442	return
443}
444
445// MatchFileInput fuzzily match an image against one of your custom Image Lists. You can create and manage your custom
446// image lists using <a href="/docs/services/578ff44d2703741568569ab9/operations/578ff7b12703741568569abe">this</a>
447// API.
448//
449// Returns ID and tags of matching image.<br/>
450// <br/>
451// Note: Refresh Index must be run on the corresponding Image List before additions and removals are reflected in the
452// response.
453// Parameters:
454// imageStream - the image file.
455// listID - the list Id.
456// cacheImage - whether to retain the submitted image for future use; defaults to false if omitted.
457func (client ImageModerationClient) MatchFileInput(ctx context.Context, imageStream io.ReadCloser, listID string, cacheImage *bool) (result MatchResponse, err error) {
458	req, err := client.MatchFileInputPreparer(ctx, imageStream, listID, cacheImage)
459	if err != nil {
460		err = autorest.NewErrorWithError(err, "contentmoderator.ImageModerationClient", "MatchFileInput", nil, "Failure preparing request")
461		return
462	}
463
464	resp, err := client.MatchFileInputSender(req)
465	if err != nil {
466		result.Response = autorest.Response{Response: resp}
467		err = autorest.NewErrorWithError(err, "contentmoderator.ImageModerationClient", "MatchFileInput", resp, "Failure sending request")
468		return
469	}
470
471	result, err = client.MatchFileInputResponder(resp)
472	if err != nil {
473		err = autorest.NewErrorWithError(err, "contentmoderator.ImageModerationClient", "MatchFileInput", resp, "Failure responding to request")
474	}
475
476	return
477}
478
479// MatchFileInputPreparer prepares the MatchFileInput request.
480func (client ImageModerationClient) MatchFileInputPreparer(ctx context.Context, imageStream io.ReadCloser, listID string, cacheImage *bool) (*http.Request, error) {
481	urlParameters := map[string]interface{}{
482		"Endpoint": client.Endpoint,
483	}
484
485	queryParameters := map[string]interface{}{}
486	if len(listID) > 0 {
487		queryParameters["listId"] = autorest.Encode("query", listID)
488	}
489	if cacheImage != nil {
490		queryParameters["CacheImage"] = autorest.Encode("query", *cacheImage)
491	}
492
493	preparer := autorest.CreatePreparer(
494		autorest.AsContentType("image/gif"),
495		autorest.AsPost(),
496		autorest.WithCustomBaseURL("{Endpoint}", urlParameters),
497		autorest.WithPath("/contentmoderator/moderate/v1.0/ProcessImage/Match"),
498		autorest.WithFile(imageStream),
499		autorest.WithQueryParameters(queryParameters))
500	return preparer.Prepare((&http.Request{}).WithContext(ctx))
501}
502
503// MatchFileInputSender sends the MatchFileInput request. The method will close the
504// http.Response Body if it receives an error.
505func (client ImageModerationClient) MatchFileInputSender(req *http.Request) (*http.Response, error) {
506	return autorest.SendWithSender(client, req,
507		autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
508}
509
510// MatchFileInputResponder handles the response to the MatchFileInput request. The method always
511// closes the http.Response Body.
512func (client ImageModerationClient) MatchFileInputResponder(resp *http.Response) (result MatchResponse, err error) {
513	err = autorest.Respond(
514		resp,
515		client.ByInspecting(),
516		azure.WithErrorUnlessStatusCode(http.StatusOK),
517		autorest.ByUnmarshallingJSON(&result),
518		autorest.ByClosing())
519	result.Response = autorest.Response{Response: resp}
520	return
521}
522
523// MatchMethod fuzzily match an image against one of your custom Image Lists. You can create and manage your custom
524// image lists using <a href="/docs/services/578ff44d2703741568569ab9/operations/578ff7b12703741568569abe">this</a>
525// API.
526//
527// Returns ID and tags of matching image.<br/>
528// <br/>
529// Note: Refresh Index must be run on the corresponding Image List before additions and removals are reflected in the
530// response.
531// Parameters:
532// listID - the list Id.
533// cacheImage - whether to retain the submitted image for future use; defaults to false if omitted.
534func (client ImageModerationClient) MatchMethod(ctx context.Context, listID string, cacheImage *bool) (result MatchResponse, err error) {
535	req, err := client.MatchMethodPreparer(ctx, listID, cacheImage)
536	if err != nil {
537		err = autorest.NewErrorWithError(err, "contentmoderator.ImageModerationClient", "MatchMethod", nil, "Failure preparing request")
538		return
539	}
540
541	resp, err := client.MatchMethodSender(req)
542	if err != nil {
543		result.Response = autorest.Response{Response: resp}
544		err = autorest.NewErrorWithError(err, "contentmoderator.ImageModerationClient", "MatchMethod", resp, "Failure sending request")
545		return
546	}
547
548	result, err = client.MatchMethodResponder(resp)
549	if err != nil {
550		err = autorest.NewErrorWithError(err, "contentmoderator.ImageModerationClient", "MatchMethod", resp, "Failure responding to request")
551	}
552
553	return
554}
555
556// MatchMethodPreparer prepares the MatchMethod request.
557func (client ImageModerationClient) MatchMethodPreparer(ctx context.Context, listID string, cacheImage *bool) (*http.Request, error) {
558	urlParameters := map[string]interface{}{
559		"Endpoint": client.Endpoint,
560	}
561
562	queryParameters := map[string]interface{}{}
563	if len(listID) > 0 {
564		queryParameters["listId"] = autorest.Encode("query", listID)
565	}
566	if cacheImage != nil {
567		queryParameters["CacheImage"] = autorest.Encode("query", *cacheImage)
568	}
569
570	preparer := autorest.CreatePreparer(
571		autorest.AsPost(),
572		autorest.WithCustomBaseURL("{Endpoint}", urlParameters),
573		autorest.WithPath("/contentmoderator/moderate/v1.0/ProcessImage/Match"),
574		autorest.WithQueryParameters(queryParameters))
575	return preparer.Prepare((&http.Request{}).WithContext(ctx))
576}
577
578// MatchMethodSender sends the MatchMethod request. The method will close the
579// http.Response Body if it receives an error.
580func (client ImageModerationClient) MatchMethodSender(req *http.Request) (*http.Response, error) {
581	return autorest.SendWithSender(client, req,
582		autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
583}
584
585// MatchMethodResponder handles the response to the MatchMethod request. The method always
586// closes the http.Response Body.
587func (client ImageModerationClient) MatchMethodResponder(resp *http.Response) (result MatchResponse, err error) {
588	err = autorest.Respond(
589		resp,
590		client.ByInspecting(),
591		azure.WithErrorUnlessStatusCode(http.StatusOK),
592		autorest.ByUnmarshallingJSON(&result),
593		autorest.ByClosing())
594	result.Response = autorest.Response{Response: resp}
595	return
596}
597
598// MatchURLInput fuzzily match an image against one of your custom Image Lists. You can create and manage your custom
599// image lists using <a href="/docs/services/578ff44d2703741568569ab9/operations/578ff7b12703741568569abe">this</a>
600// API.
601//
602// Returns ID and tags of matching image.<br/>
603// <br/>
604// Note: Refresh Index must be run on the corresponding Image List before additions and removals are reflected in the
605// response.
606// Parameters:
607// contentType - the content type.
608// imageURL - the image url.
609// listID - the list Id.
610// cacheImage - whether to retain the submitted image for future use; defaults to false if omitted.
611func (client ImageModerationClient) MatchURLInput(ctx context.Context, contentType string, imageURL BodyModel, listID string, cacheImage *bool) (result MatchResponse, err error) {
612	req, err := client.MatchURLInputPreparer(ctx, contentType, imageURL, listID, cacheImage)
613	if err != nil {
614		err = autorest.NewErrorWithError(err, "contentmoderator.ImageModerationClient", "MatchURLInput", nil, "Failure preparing request")
615		return
616	}
617
618	resp, err := client.MatchURLInputSender(req)
619	if err != nil {
620		result.Response = autorest.Response{Response: resp}
621		err = autorest.NewErrorWithError(err, "contentmoderator.ImageModerationClient", "MatchURLInput", resp, "Failure sending request")
622		return
623	}
624
625	result, err = client.MatchURLInputResponder(resp)
626	if err != nil {
627		err = autorest.NewErrorWithError(err, "contentmoderator.ImageModerationClient", "MatchURLInput", resp, "Failure responding to request")
628	}
629
630	return
631}
632
633// MatchURLInputPreparer prepares the MatchURLInput request.
634func (client ImageModerationClient) MatchURLInputPreparer(ctx context.Context, contentType string, imageURL BodyModel, listID string, cacheImage *bool) (*http.Request, error) {
635	urlParameters := map[string]interface{}{
636		"Endpoint": client.Endpoint,
637	}
638
639	queryParameters := map[string]interface{}{}
640	if len(listID) > 0 {
641		queryParameters["listId"] = autorest.Encode("query", listID)
642	}
643	if cacheImage != nil {
644		queryParameters["CacheImage"] = autorest.Encode("query", *cacheImage)
645	}
646
647	preparer := autorest.CreatePreparer(
648		autorest.AsContentType("application/json; charset=utf-8"),
649		autorest.AsPost(),
650		autorest.WithCustomBaseURL("{Endpoint}", urlParameters),
651		autorest.WithPath("/contentmoderator/moderate/v1.0/ProcessImage/Match"),
652		autorest.WithJSON(imageURL),
653		autorest.WithQueryParameters(queryParameters),
654		autorest.WithHeader("Content-Type", autorest.String(contentType)))
655	return preparer.Prepare((&http.Request{}).WithContext(ctx))
656}
657
658// MatchURLInputSender sends the MatchURLInput request. The method will close the
659// http.Response Body if it receives an error.
660func (client ImageModerationClient) MatchURLInputSender(req *http.Request) (*http.Response, error) {
661	return autorest.SendWithSender(client, req,
662		autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
663}
664
665// MatchURLInputResponder handles the response to the MatchURLInput request. The method always
666// closes the http.Response Body.
667func (client ImageModerationClient) MatchURLInputResponder(resp *http.Response) (result MatchResponse, err error) {
668	err = autorest.Respond(
669		resp,
670		client.ByInspecting(),
671		azure.WithErrorUnlessStatusCode(http.StatusOK),
672		autorest.ByUnmarshallingJSON(&result),
673		autorest.ByClosing())
674	result.Response = autorest.Response{Response: resp}
675	return
676}
677
678// OCRFileInput returns any text found in the image for the language specified. If no language is specified in input
679// then the detection defaults to English.
680// Parameters:
681// language - language of the terms.
682// imageStream - the image file.
683// cacheImage - whether to retain the submitted image for future use; defaults to false if omitted.
684// enhanced - when set to True, the image goes through additional processing to come with additional
685// candidates.
686//
687// image/tiff is not supported when enhanced is set to true
688//
689// Note: This impacts the response time.
690func (client ImageModerationClient) OCRFileInput(ctx context.Context, language string, imageStream io.ReadCloser, cacheImage *bool, enhanced *bool) (result OCR, err error) {
691	req, err := client.OCRFileInputPreparer(ctx, language, imageStream, cacheImage, enhanced)
692	if err != nil {
693		err = autorest.NewErrorWithError(err, "contentmoderator.ImageModerationClient", "OCRFileInput", nil, "Failure preparing request")
694		return
695	}
696
697	resp, err := client.OCRFileInputSender(req)
698	if err != nil {
699		result.Response = autorest.Response{Response: resp}
700		err = autorest.NewErrorWithError(err, "contentmoderator.ImageModerationClient", "OCRFileInput", resp, "Failure sending request")
701		return
702	}
703
704	result, err = client.OCRFileInputResponder(resp)
705	if err != nil {
706		err = autorest.NewErrorWithError(err, "contentmoderator.ImageModerationClient", "OCRFileInput", resp, "Failure responding to request")
707	}
708
709	return
710}
711
712// OCRFileInputPreparer prepares the OCRFileInput request.
713func (client ImageModerationClient) OCRFileInputPreparer(ctx context.Context, language string, imageStream io.ReadCloser, cacheImage *bool, enhanced *bool) (*http.Request, error) {
714	urlParameters := map[string]interface{}{
715		"Endpoint": client.Endpoint,
716	}
717
718	queryParameters := map[string]interface{}{
719		"language": autorest.Encode("query", language),
720	}
721	if cacheImage != nil {
722		queryParameters["CacheImage"] = autorest.Encode("query", *cacheImage)
723	}
724	if enhanced != nil {
725		queryParameters["enhanced"] = autorest.Encode("query", *enhanced)
726	} else {
727		queryParameters["enhanced"] = autorest.Encode("query", false)
728	}
729
730	preparer := autorest.CreatePreparer(
731		autorest.AsContentType("image/gif"),
732		autorest.AsPost(),
733		autorest.WithCustomBaseURL("{Endpoint}", urlParameters),
734		autorest.WithPath("/contentmoderator/moderate/v1.0/ProcessImage/OCR"),
735		autorest.WithFile(imageStream),
736		autorest.WithQueryParameters(queryParameters))
737	return preparer.Prepare((&http.Request{}).WithContext(ctx))
738}
739
740// OCRFileInputSender sends the OCRFileInput request. The method will close the
741// http.Response Body if it receives an error.
742func (client ImageModerationClient) OCRFileInputSender(req *http.Request) (*http.Response, error) {
743	return autorest.SendWithSender(client, req,
744		autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
745}
746
747// OCRFileInputResponder handles the response to the OCRFileInput request. The method always
748// closes the http.Response Body.
749func (client ImageModerationClient) OCRFileInputResponder(resp *http.Response) (result OCR, err error) {
750	err = autorest.Respond(
751		resp,
752		client.ByInspecting(),
753		azure.WithErrorUnlessStatusCode(http.StatusOK),
754		autorest.ByUnmarshallingJSON(&result),
755		autorest.ByClosing())
756	result.Response = autorest.Response{Response: resp}
757	return
758}
759
760// OCRMethod returns any text found in the image for the language specified. If no language is specified in input then
761// the detection defaults to English.
762// Parameters:
763// language - language of the terms.
764// cacheImage - whether to retain the submitted image for future use; defaults to false if omitted.
765// enhanced - when set to True, the image goes through additional processing to come with additional
766// candidates.
767//
768// image/tiff is not supported when enhanced is set to true
769//
770// Note: This impacts the response time.
771func (client ImageModerationClient) OCRMethod(ctx context.Context, language string, cacheImage *bool, enhanced *bool) (result OCR, err error) {
772	req, err := client.OCRMethodPreparer(ctx, language, cacheImage, enhanced)
773	if err != nil {
774		err = autorest.NewErrorWithError(err, "contentmoderator.ImageModerationClient", "OCRMethod", nil, "Failure preparing request")
775		return
776	}
777
778	resp, err := client.OCRMethodSender(req)
779	if err != nil {
780		result.Response = autorest.Response{Response: resp}
781		err = autorest.NewErrorWithError(err, "contentmoderator.ImageModerationClient", "OCRMethod", resp, "Failure sending request")
782		return
783	}
784
785	result, err = client.OCRMethodResponder(resp)
786	if err != nil {
787		err = autorest.NewErrorWithError(err, "contentmoderator.ImageModerationClient", "OCRMethod", resp, "Failure responding to request")
788	}
789
790	return
791}
792
793// OCRMethodPreparer prepares the OCRMethod request.
794func (client ImageModerationClient) OCRMethodPreparer(ctx context.Context, language string, cacheImage *bool, enhanced *bool) (*http.Request, error) {
795	urlParameters := map[string]interface{}{
796		"Endpoint": client.Endpoint,
797	}
798
799	queryParameters := map[string]interface{}{
800		"language": autorest.Encode("query", language),
801	}
802	if cacheImage != nil {
803		queryParameters["CacheImage"] = autorest.Encode("query", *cacheImage)
804	}
805	if enhanced != nil {
806		queryParameters["enhanced"] = autorest.Encode("query", *enhanced)
807	} else {
808		queryParameters["enhanced"] = autorest.Encode("query", false)
809	}
810
811	preparer := autorest.CreatePreparer(
812		autorest.AsPost(),
813		autorest.WithCustomBaseURL("{Endpoint}", urlParameters),
814		autorest.WithPath("/contentmoderator/moderate/v1.0/ProcessImage/OCR"),
815		autorest.WithQueryParameters(queryParameters))
816	return preparer.Prepare((&http.Request{}).WithContext(ctx))
817}
818
819// OCRMethodSender sends the OCRMethod request. The method will close the
820// http.Response Body if it receives an error.
821func (client ImageModerationClient) OCRMethodSender(req *http.Request) (*http.Response, error) {
822	return autorest.SendWithSender(client, req,
823		autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
824}
825
826// OCRMethodResponder handles the response to the OCRMethod request. The method always
827// closes the http.Response Body.
828func (client ImageModerationClient) OCRMethodResponder(resp *http.Response) (result OCR, err error) {
829	err = autorest.Respond(
830		resp,
831		client.ByInspecting(),
832		azure.WithErrorUnlessStatusCode(http.StatusOK),
833		autorest.ByUnmarshallingJSON(&result),
834		autorest.ByClosing())
835	result.Response = autorest.Response{Response: resp}
836	return
837}
838
839// OCRURLInput returns any text found in the image for the language specified. If no language is specified in input
840// then the detection defaults to English.
841// Parameters:
842// language - language of the terms.
843// contentType - the content type.
844// imageURL - the image url.
845// cacheImage - whether to retain the submitted image for future use; defaults to false if omitted.
846// enhanced - when set to True, the image goes through additional processing to come with additional
847// candidates.
848//
849// image/tiff is not supported when enhanced is set to true
850//
851// Note: This impacts the response time.
852func (client ImageModerationClient) OCRURLInput(ctx context.Context, language string, contentType string, imageURL BodyModel, cacheImage *bool, enhanced *bool) (result OCR, err error) {
853	req, err := client.OCRURLInputPreparer(ctx, language, contentType, imageURL, cacheImage, enhanced)
854	if err != nil {
855		err = autorest.NewErrorWithError(err, "contentmoderator.ImageModerationClient", "OCRURLInput", nil, "Failure preparing request")
856		return
857	}
858
859	resp, err := client.OCRURLInputSender(req)
860	if err != nil {
861		result.Response = autorest.Response{Response: resp}
862		err = autorest.NewErrorWithError(err, "contentmoderator.ImageModerationClient", "OCRURLInput", resp, "Failure sending request")
863		return
864	}
865
866	result, err = client.OCRURLInputResponder(resp)
867	if err != nil {
868		err = autorest.NewErrorWithError(err, "contentmoderator.ImageModerationClient", "OCRURLInput", resp, "Failure responding to request")
869	}
870
871	return
872}
873
874// OCRURLInputPreparer prepares the OCRURLInput request.
875func (client ImageModerationClient) OCRURLInputPreparer(ctx context.Context, language string, contentType string, imageURL BodyModel, cacheImage *bool, enhanced *bool) (*http.Request, error) {
876	urlParameters := map[string]interface{}{
877		"Endpoint": client.Endpoint,
878	}
879
880	queryParameters := map[string]interface{}{
881		"language": autorest.Encode("query", language),
882	}
883	if cacheImage != nil {
884		queryParameters["CacheImage"] = autorest.Encode("query", *cacheImage)
885	}
886	if enhanced != nil {
887		queryParameters["enhanced"] = autorest.Encode("query", *enhanced)
888	} else {
889		queryParameters["enhanced"] = autorest.Encode("query", false)
890	}
891
892	preparer := autorest.CreatePreparer(
893		autorest.AsContentType("application/json; charset=utf-8"),
894		autorest.AsPost(),
895		autorest.WithCustomBaseURL("{Endpoint}", urlParameters),
896		autorest.WithPath("/contentmoderator/moderate/v1.0/ProcessImage/OCR"),
897		autorest.WithJSON(imageURL),
898		autorest.WithQueryParameters(queryParameters),
899		autorest.WithHeader("Content-Type", autorest.String(contentType)))
900	return preparer.Prepare((&http.Request{}).WithContext(ctx))
901}
902
903// OCRURLInputSender sends the OCRURLInput request. The method will close the
904// http.Response Body if it receives an error.
905func (client ImageModerationClient) OCRURLInputSender(req *http.Request) (*http.Response, error) {
906	return autorest.SendWithSender(client, req,
907		autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
908}
909
910// OCRURLInputResponder handles the response to the OCRURLInput request. The method always
911// closes the http.Response Body.
912func (client ImageModerationClient) OCRURLInputResponder(resp *http.Response) (result OCR, err error) {
913	err = autorest.Respond(
914		resp,
915		client.ByInspecting(),
916		azure.WithErrorUnlessStatusCode(http.StatusOK),
917		autorest.ByUnmarshallingJSON(&result),
918		autorest.ByClosing())
919	result.Response = autorest.Response{Response: resp}
920	return
921}
922