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