...

Source file src/github.com/Azure/azure-sdk-for-go/services/cognitiveservices/v3.1/customvision/prediction/client.go

Documentation: github.com/Azure/azure-sdk-for-go/services/cognitiveservices/v3.1/customvision/prediction

     1  // Package prediction implements the Azure ARM Prediction service API version 3.1.
     2  //
     3  //
     4  package prediction
     5  
     6  // Copyright (c) Microsoft Corporation. All rights reserved.
     7  // Licensed under the MIT License. See License.txt in the project root for license information.
     8  //
     9  // Code generated by Microsoft (R) AutoRest Code Generator.
    10  // Changes may cause incorrect behavior and will be lost if the code is regenerated.
    11  
    12  import (
    13  	"context"
    14  	"github.com/Azure/go-autorest/autorest"
    15  	"github.com/Azure/go-autorest/autorest/azure"
    16  	"github.com/Azure/go-autorest/autorest/validation"
    17  	"github.com/Azure/go-autorest/tracing"
    18  	"github.com/gofrs/uuid"
    19  	"io"
    20  	"net/http"
    21  )
    22  
    23  // BaseClient is the base client for Prediction.
    24  type BaseClient struct {
    25  	autorest.Client
    26  	Endpoint string
    27  }
    28  
    29  // New creates an instance of the BaseClient client.
    30  func New(endpoint string) BaseClient {
    31  	return NewWithoutDefaults(endpoint)
    32  }
    33  
    34  // NewWithoutDefaults creates an instance of the BaseClient client.
    35  func NewWithoutDefaults(endpoint string) BaseClient {
    36  	return BaseClient{
    37  		Client:   autorest.NewClientWithUserAgent(UserAgent()),
    38  		Endpoint: endpoint,
    39  	}
    40  }
    41  
    42  // ClassifyImage sends the classify image request.
    43  // Parameters:
    44  // projectID - the project id.
    45  // publishedName - specifies the name of the model to evaluate against.
    46  // imageData - binary image data. Supported formats are JPEG, GIF, PNG, and BMP. Supports images up to 4MB.
    47  // application - optional. Specifies the name of application using the endpoint.
    48  func (client BaseClient) ClassifyImage(ctx context.Context, projectID uuid.UUID, publishedName string, imageData io.ReadCloser, application string) (result ImagePrediction, err error) {
    49  	if tracing.IsEnabled() {
    50  		ctx = tracing.StartSpan(ctx, fqdn+"/BaseClient.ClassifyImage")
    51  		defer func() {
    52  			sc := -1
    53  			if result.Response.Response != nil {
    54  				sc = result.Response.Response.StatusCode
    55  			}
    56  			tracing.EndSpan(ctx, sc, err)
    57  		}()
    58  	}
    59  	req, err := client.ClassifyImagePreparer(ctx, projectID, publishedName, imageData, application)
    60  	if err != nil {
    61  		err = autorest.NewErrorWithError(err, "prediction.BaseClient", "ClassifyImage", nil, "Failure preparing request")
    62  		return
    63  	}
    64  
    65  	resp, err := client.ClassifyImageSender(req)
    66  	if err != nil {
    67  		result.Response = autorest.Response{Response: resp}
    68  		err = autorest.NewErrorWithError(err, "prediction.BaseClient", "ClassifyImage", resp, "Failure sending request")
    69  		return
    70  	}
    71  
    72  	result, err = client.ClassifyImageResponder(resp)
    73  	if err != nil {
    74  		err = autorest.NewErrorWithError(err, "prediction.BaseClient", "ClassifyImage", resp, "Failure responding to request")
    75  		return
    76  	}
    77  
    78  	return
    79  }
    80  
    81  // ClassifyImagePreparer prepares the ClassifyImage request.
    82  func (client BaseClient) ClassifyImagePreparer(ctx context.Context, projectID uuid.UUID, publishedName string, imageData io.ReadCloser, application string) (*http.Request, error) {
    83  	urlParameters := map[string]interface{}{
    84  		"Endpoint": client.Endpoint,
    85  	}
    86  
    87  	pathParameters := map[string]interface{}{
    88  		"projectId":     autorest.Encode("path", projectID),
    89  		"publishedName": autorest.Encode("path", publishedName),
    90  	}
    91  
    92  	queryParameters := map[string]interface{}{}
    93  	if len(application) > 0 {
    94  		queryParameters["application"] = autorest.Encode("query", application)
    95  	}
    96  
    97  	formDataParameters := map[string]interface{}{
    98  		"imageData": imageData,
    99  	}
   100  
   101  	preparer := autorest.CreatePreparer(
   102  		autorest.AsPost(),
   103  		autorest.WithCustomBaseURL("{Endpoint}/customvision/v3.1/prediction", urlParameters),
   104  		autorest.WithPathParameters("/{projectId}/classify/iterations/{publishedName}/image", pathParameters),
   105  		autorest.WithQueryParameters(queryParameters),
   106  		autorest.WithMultiPartFormData(formDataParameters))
   107  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   108  }
   109  
   110  // ClassifyImageSender sends the ClassifyImage request. The method will close the
   111  // http.Response Body if it receives an error.
   112  func (client BaseClient) ClassifyImageSender(req *http.Request) (*http.Response, error) {
   113  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   114  }
   115  
   116  // ClassifyImageResponder handles the response to the ClassifyImage request. The method always
   117  // closes the http.Response Body.
   118  func (client BaseClient) ClassifyImageResponder(resp *http.Response) (result ImagePrediction, err error) {
   119  	err = autorest.Respond(
   120  		resp,
   121  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   122  		autorest.ByUnmarshallingJSON(&result),
   123  		autorest.ByClosing())
   124  	result.Response = autorest.Response{Response: resp}
   125  	return
   126  }
   127  
   128  // ClassifyImageURL sends the classify image url request.
   129  // Parameters:
   130  // projectID - the project id.
   131  // publishedName - specifies the name of the model to evaluate against.
   132  // imageURL - an ImageUrl that contains the url of the image to be evaluated.
   133  // application - optional. Specifies the name of application using the endpoint.
   134  func (client BaseClient) ClassifyImageURL(ctx context.Context, projectID uuid.UUID, publishedName string, imageURL ImageURL, application string) (result ImagePrediction, err error) {
   135  	if tracing.IsEnabled() {
   136  		ctx = tracing.StartSpan(ctx, fqdn+"/BaseClient.ClassifyImageURL")
   137  		defer func() {
   138  			sc := -1
   139  			if result.Response.Response != nil {
   140  				sc = result.Response.Response.StatusCode
   141  			}
   142  			tracing.EndSpan(ctx, sc, err)
   143  		}()
   144  	}
   145  	if err := validation.Validate([]validation.Validation{
   146  		{TargetValue: imageURL,
   147  			Constraints: []validation.Constraint{{Target: "imageURL.URL", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil {
   148  		return result, validation.NewError("prediction.BaseClient", "ClassifyImageURL", err.Error())
   149  	}
   150  
   151  	req, err := client.ClassifyImageURLPreparer(ctx, projectID, publishedName, imageURL, application)
   152  	if err != nil {
   153  		err = autorest.NewErrorWithError(err, "prediction.BaseClient", "ClassifyImageURL", nil, "Failure preparing request")
   154  		return
   155  	}
   156  
   157  	resp, err := client.ClassifyImageURLSender(req)
   158  	if err != nil {
   159  		result.Response = autorest.Response{Response: resp}
   160  		err = autorest.NewErrorWithError(err, "prediction.BaseClient", "ClassifyImageURL", resp, "Failure sending request")
   161  		return
   162  	}
   163  
   164  	result, err = client.ClassifyImageURLResponder(resp)
   165  	if err != nil {
   166  		err = autorest.NewErrorWithError(err, "prediction.BaseClient", "ClassifyImageURL", resp, "Failure responding to request")
   167  		return
   168  	}
   169  
   170  	return
   171  }
   172  
   173  // ClassifyImageURLPreparer prepares the ClassifyImageURL request.
   174  func (client BaseClient) ClassifyImageURLPreparer(ctx context.Context, projectID uuid.UUID, publishedName string, imageURL ImageURL, application string) (*http.Request, error) {
   175  	urlParameters := map[string]interface{}{
   176  		"Endpoint": client.Endpoint,
   177  	}
   178  
   179  	pathParameters := map[string]interface{}{
   180  		"projectId":     autorest.Encode("path", projectID),
   181  		"publishedName": autorest.Encode("path", publishedName),
   182  	}
   183  
   184  	queryParameters := map[string]interface{}{}
   185  	if len(application) > 0 {
   186  		queryParameters["application"] = autorest.Encode("query", application)
   187  	}
   188  
   189  	preparer := autorest.CreatePreparer(
   190  		autorest.AsContentType("application/json; charset=utf-8"),
   191  		autorest.AsPost(),
   192  		autorest.WithCustomBaseURL("{Endpoint}/customvision/v3.1/prediction", urlParameters),
   193  		autorest.WithPathParameters("/{projectId}/classify/iterations/{publishedName}/url", pathParameters),
   194  		autorest.WithJSON(imageURL),
   195  		autorest.WithQueryParameters(queryParameters))
   196  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   197  }
   198  
   199  // ClassifyImageURLSender sends the ClassifyImageURL request. The method will close the
   200  // http.Response Body if it receives an error.
   201  func (client BaseClient) ClassifyImageURLSender(req *http.Request) (*http.Response, error) {
   202  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   203  }
   204  
   205  // ClassifyImageURLResponder handles the response to the ClassifyImageURL request. The method always
   206  // closes the http.Response Body.
   207  func (client BaseClient) ClassifyImageURLResponder(resp *http.Response) (result ImagePrediction, err error) {
   208  	err = autorest.Respond(
   209  		resp,
   210  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   211  		autorest.ByUnmarshallingJSON(&result),
   212  		autorest.ByClosing())
   213  	result.Response = autorest.Response{Response: resp}
   214  	return
   215  }
   216  
   217  // ClassifyImageURLWithNoStore sends the classify image url with no store request.
   218  // Parameters:
   219  // projectID - the project id.
   220  // publishedName - specifies the name of the model to evaluate against.
   221  // imageURL - an {Iris.Web.Api.Models.ImageUrl} that contains the url of the image to be evaluated.
   222  // application - optional. Specifies the name of application using the endpoint.
   223  func (client BaseClient) ClassifyImageURLWithNoStore(ctx context.Context, projectID uuid.UUID, publishedName string, imageURL ImageURL, application string) (result ImagePrediction, err error) {
   224  	if tracing.IsEnabled() {
   225  		ctx = tracing.StartSpan(ctx, fqdn+"/BaseClient.ClassifyImageURLWithNoStore")
   226  		defer func() {
   227  			sc := -1
   228  			if result.Response.Response != nil {
   229  				sc = result.Response.Response.StatusCode
   230  			}
   231  			tracing.EndSpan(ctx, sc, err)
   232  		}()
   233  	}
   234  	if err := validation.Validate([]validation.Validation{
   235  		{TargetValue: imageURL,
   236  			Constraints: []validation.Constraint{{Target: "imageURL.URL", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil {
   237  		return result, validation.NewError("prediction.BaseClient", "ClassifyImageURLWithNoStore", err.Error())
   238  	}
   239  
   240  	req, err := client.ClassifyImageURLWithNoStorePreparer(ctx, projectID, publishedName, imageURL, application)
   241  	if err != nil {
   242  		err = autorest.NewErrorWithError(err, "prediction.BaseClient", "ClassifyImageURLWithNoStore", nil, "Failure preparing request")
   243  		return
   244  	}
   245  
   246  	resp, err := client.ClassifyImageURLWithNoStoreSender(req)
   247  	if err != nil {
   248  		result.Response = autorest.Response{Response: resp}
   249  		err = autorest.NewErrorWithError(err, "prediction.BaseClient", "ClassifyImageURLWithNoStore", resp, "Failure sending request")
   250  		return
   251  	}
   252  
   253  	result, err = client.ClassifyImageURLWithNoStoreResponder(resp)
   254  	if err != nil {
   255  		err = autorest.NewErrorWithError(err, "prediction.BaseClient", "ClassifyImageURLWithNoStore", resp, "Failure responding to request")
   256  		return
   257  	}
   258  
   259  	return
   260  }
   261  
   262  // ClassifyImageURLWithNoStorePreparer prepares the ClassifyImageURLWithNoStore request.
   263  func (client BaseClient) ClassifyImageURLWithNoStorePreparer(ctx context.Context, projectID uuid.UUID, publishedName string, imageURL ImageURL, application string) (*http.Request, error) {
   264  	urlParameters := map[string]interface{}{
   265  		"Endpoint": client.Endpoint,
   266  	}
   267  
   268  	pathParameters := map[string]interface{}{
   269  		"projectId":     autorest.Encode("path", projectID),
   270  		"publishedName": autorest.Encode("path", publishedName),
   271  	}
   272  
   273  	queryParameters := map[string]interface{}{}
   274  	if len(application) > 0 {
   275  		queryParameters["application"] = autorest.Encode("query", application)
   276  	}
   277  
   278  	preparer := autorest.CreatePreparer(
   279  		autorest.AsContentType("application/json; charset=utf-8"),
   280  		autorest.AsPost(),
   281  		autorest.WithCustomBaseURL("{Endpoint}/customvision/v3.1/prediction", urlParameters),
   282  		autorest.WithPathParameters("/{projectId}/classify/iterations/{publishedName}/url/nostore", pathParameters),
   283  		autorest.WithJSON(imageURL),
   284  		autorest.WithQueryParameters(queryParameters))
   285  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   286  }
   287  
   288  // ClassifyImageURLWithNoStoreSender sends the ClassifyImageURLWithNoStore request. The method will close the
   289  // http.Response Body if it receives an error.
   290  func (client BaseClient) ClassifyImageURLWithNoStoreSender(req *http.Request) (*http.Response, error) {
   291  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   292  }
   293  
   294  // ClassifyImageURLWithNoStoreResponder handles the response to the ClassifyImageURLWithNoStore request. The method always
   295  // closes the http.Response Body.
   296  func (client BaseClient) ClassifyImageURLWithNoStoreResponder(resp *http.Response) (result ImagePrediction, err error) {
   297  	err = autorest.Respond(
   298  		resp,
   299  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   300  		autorest.ByUnmarshallingJSON(&result),
   301  		autorest.ByClosing())
   302  	result.Response = autorest.Response{Response: resp}
   303  	return
   304  }
   305  
   306  // ClassifyImageWithNoStore sends the classify image with no store request.
   307  // Parameters:
   308  // projectID - the project id.
   309  // publishedName - specifies the name of the model to evaluate against.
   310  // imageData - binary image data. Supported formats are JPEG, GIF, PNG, and BMP. Supports images up to 4MB.
   311  // application - optional. Specifies the name of application using the endpoint.
   312  func (client BaseClient) ClassifyImageWithNoStore(ctx context.Context, projectID uuid.UUID, publishedName string, imageData io.ReadCloser, application string) (result ImagePrediction, err error) {
   313  	if tracing.IsEnabled() {
   314  		ctx = tracing.StartSpan(ctx, fqdn+"/BaseClient.ClassifyImageWithNoStore")
   315  		defer func() {
   316  			sc := -1
   317  			if result.Response.Response != nil {
   318  				sc = result.Response.Response.StatusCode
   319  			}
   320  			tracing.EndSpan(ctx, sc, err)
   321  		}()
   322  	}
   323  	req, err := client.ClassifyImageWithNoStorePreparer(ctx, projectID, publishedName, imageData, application)
   324  	if err != nil {
   325  		err = autorest.NewErrorWithError(err, "prediction.BaseClient", "ClassifyImageWithNoStore", nil, "Failure preparing request")
   326  		return
   327  	}
   328  
   329  	resp, err := client.ClassifyImageWithNoStoreSender(req)
   330  	if err != nil {
   331  		result.Response = autorest.Response{Response: resp}
   332  		err = autorest.NewErrorWithError(err, "prediction.BaseClient", "ClassifyImageWithNoStore", resp, "Failure sending request")
   333  		return
   334  	}
   335  
   336  	result, err = client.ClassifyImageWithNoStoreResponder(resp)
   337  	if err != nil {
   338  		err = autorest.NewErrorWithError(err, "prediction.BaseClient", "ClassifyImageWithNoStore", resp, "Failure responding to request")
   339  		return
   340  	}
   341  
   342  	return
   343  }
   344  
   345  // ClassifyImageWithNoStorePreparer prepares the ClassifyImageWithNoStore request.
   346  func (client BaseClient) ClassifyImageWithNoStorePreparer(ctx context.Context, projectID uuid.UUID, publishedName string, imageData io.ReadCloser, application string) (*http.Request, error) {
   347  	urlParameters := map[string]interface{}{
   348  		"Endpoint": client.Endpoint,
   349  	}
   350  
   351  	pathParameters := map[string]interface{}{
   352  		"projectId":     autorest.Encode("path", projectID),
   353  		"publishedName": autorest.Encode("path", publishedName),
   354  	}
   355  
   356  	queryParameters := map[string]interface{}{}
   357  	if len(application) > 0 {
   358  		queryParameters["application"] = autorest.Encode("query", application)
   359  	}
   360  
   361  	formDataParameters := map[string]interface{}{
   362  		"imageData": imageData,
   363  	}
   364  
   365  	preparer := autorest.CreatePreparer(
   366  		autorest.AsPost(),
   367  		autorest.WithCustomBaseURL("{Endpoint}/customvision/v3.1/prediction", urlParameters),
   368  		autorest.WithPathParameters("/{projectId}/classify/iterations/{publishedName}/image/nostore", pathParameters),
   369  		autorest.WithQueryParameters(queryParameters),
   370  		autorest.WithMultiPartFormData(formDataParameters))
   371  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   372  }
   373  
   374  // ClassifyImageWithNoStoreSender sends the ClassifyImageWithNoStore request. The method will close the
   375  // http.Response Body if it receives an error.
   376  func (client BaseClient) ClassifyImageWithNoStoreSender(req *http.Request) (*http.Response, error) {
   377  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   378  }
   379  
   380  // ClassifyImageWithNoStoreResponder handles the response to the ClassifyImageWithNoStore request. The method always
   381  // closes the http.Response Body.
   382  func (client BaseClient) ClassifyImageWithNoStoreResponder(resp *http.Response) (result ImagePrediction, err error) {
   383  	err = autorest.Respond(
   384  		resp,
   385  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   386  		autorest.ByUnmarshallingJSON(&result),
   387  		autorest.ByClosing())
   388  	result.Response = autorest.Response{Response: resp}
   389  	return
   390  }
   391  
   392  // DetectImage sends the detect image request.
   393  // Parameters:
   394  // projectID - the project id.
   395  // publishedName - specifies the name of the model to evaluate against.
   396  // imageData - binary image data. Supported formats are JPEG, GIF, PNG, and BMP. Supports images up to 4MB.
   397  // application - optional. Specifies the name of application using the endpoint.
   398  func (client BaseClient) DetectImage(ctx context.Context, projectID uuid.UUID, publishedName string, imageData io.ReadCloser, application string) (result ImagePrediction, err error) {
   399  	if tracing.IsEnabled() {
   400  		ctx = tracing.StartSpan(ctx, fqdn+"/BaseClient.DetectImage")
   401  		defer func() {
   402  			sc := -1
   403  			if result.Response.Response != nil {
   404  				sc = result.Response.Response.StatusCode
   405  			}
   406  			tracing.EndSpan(ctx, sc, err)
   407  		}()
   408  	}
   409  	req, err := client.DetectImagePreparer(ctx, projectID, publishedName, imageData, application)
   410  	if err != nil {
   411  		err = autorest.NewErrorWithError(err, "prediction.BaseClient", "DetectImage", nil, "Failure preparing request")
   412  		return
   413  	}
   414  
   415  	resp, err := client.DetectImageSender(req)
   416  	if err != nil {
   417  		result.Response = autorest.Response{Response: resp}
   418  		err = autorest.NewErrorWithError(err, "prediction.BaseClient", "DetectImage", resp, "Failure sending request")
   419  		return
   420  	}
   421  
   422  	result, err = client.DetectImageResponder(resp)
   423  	if err != nil {
   424  		err = autorest.NewErrorWithError(err, "prediction.BaseClient", "DetectImage", resp, "Failure responding to request")
   425  		return
   426  	}
   427  
   428  	return
   429  }
   430  
   431  // DetectImagePreparer prepares the DetectImage request.
   432  func (client BaseClient) DetectImagePreparer(ctx context.Context, projectID uuid.UUID, publishedName string, imageData io.ReadCloser, application string) (*http.Request, error) {
   433  	urlParameters := map[string]interface{}{
   434  		"Endpoint": client.Endpoint,
   435  	}
   436  
   437  	pathParameters := map[string]interface{}{
   438  		"projectId":     autorest.Encode("path", projectID),
   439  		"publishedName": autorest.Encode("path", publishedName),
   440  	}
   441  
   442  	queryParameters := map[string]interface{}{}
   443  	if len(application) > 0 {
   444  		queryParameters["application"] = autorest.Encode("query", application)
   445  	}
   446  
   447  	formDataParameters := map[string]interface{}{
   448  		"imageData": imageData,
   449  	}
   450  
   451  	preparer := autorest.CreatePreparer(
   452  		autorest.AsPost(),
   453  		autorest.WithCustomBaseURL("{Endpoint}/customvision/v3.1/prediction", urlParameters),
   454  		autorest.WithPathParameters("/{projectId}/detect/iterations/{publishedName}/image", pathParameters),
   455  		autorest.WithQueryParameters(queryParameters),
   456  		autorest.WithMultiPartFormData(formDataParameters))
   457  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   458  }
   459  
   460  // DetectImageSender sends the DetectImage request. The method will close the
   461  // http.Response Body if it receives an error.
   462  func (client BaseClient) DetectImageSender(req *http.Request) (*http.Response, error) {
   463  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   464  }
   465  
   466  // DetectImageResponder handles the response to the DetectImage request. The method always
   467  // closes the http.Response Body.
   468  func (client BaseClient) DetectImageResponder(resp *http.Response) (result ImagePrediction, err error) {
   469  	err = autorest.Respond(
   470  		resp,
   471  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   472  		autorest.ByUnmarshallingJSON(&result),
   473  		autorest.ByClosing())
   474  	result.Response = autorest.Response{Response: resp}
   475  	return
   476  }
   477  
   478  // DetectImageURL sends the detect image url request.
   479  // Parameters:
   480  // projectID - the project id.
   481  // publishedName - specifies the name of the model to evaluate against.
   482  // imageURL - an ImageUrl that contains the url of the image to be evaluated.
   483  // application - optional. Specifies the name of application using the endpoint.
   484  func (client BaseClient) DetectImageURL(ctx context.Context, projectID uuid.UUID, publishedName string, imageURL ImageURL, application string) (result ImagePrediction, err error) {
   485  	if tracing.IsEnabled() {
   486  		ctx = tracing.StartSpan(ctx, fqdn+"/BaseClient.DetectImageURL")
   487  		defer func() {
   488  			sc := -1
   489  			if result.Response.Response != nil {
   490  				sc = result.Response.Response.StatusCode
   491  			}
   492  			tracing.EndSpan(ctx, sc, err)
   493  		}()
   494  	}
   495  	if err := validation.Validate([]validation.Validation{
   496  		{TargetValue: imageURL,
   497  			Constraints: []validation.Constraint{{Target: "imageURL.URL", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil {
   498  		return result, validation.NewError("prediction.BaseClient", "DetectImageURL", err.Error())
   499  	}
   500  
   501  	req, err := client.DetectImageURLPreparer(ctx, projectID, publishedName, imageURL, application)
   502  	if err != nil {
   503  		err = autorest.NewErrorWithError(err, "prediction.BaseClient", "DetectImageURL", nil, "Failure preparing request")
   504  		return
   505  	}
   506  
   507  	resp, err := client.DetectImageURLSender(req)
   508  	if err != nil {
   509  		result.Response = autorest.Response{Response: resp}
   510  		err = autorest.NewErrorWithError(err, "prediction.BaseClient", "DetectImageURL", resp, "Failure sending request")
   511  		return
   512  	}
   513  
   514  	result, err = client.DetectImageURLResponder(resp)
   515  	if err != nil {
   516  		err = autorest.NewErrorWithError(err, "prediction.BaseClient", "DetectImageURL", resp, "Failure responding to request")
   517  		return
   518  	}
   519  
   520  	return
   521  }
   522  
   523  // DetectImageURLPreparer prepares the DetectImageURL request.
   524  func (client BaseClient) DetectImageURLPreparer(ctx context.Context, projectID uuid.UUID, publishedName string, imageURL ImageURL, application string) (*http.Request, error) {
   525  	urlParameters := map[string]interface{}{
   526  		"Endpoint": client.Endpoint,
   527  	}
   528  
   529  	pathParameters := map[string]interface{}{
   530  		"projectId":     autorest.Encode("path", projectID),
   531  		"publishedName": autorest.Encode("path", publishedName),
   532  	}
   533  
   534  	queryParameters := map[string]interface{}{}
   535  	if len(application) > 0 {
   536  		queryParameters["application"] = autorest.Encode("query", application)
   537  	}
   538  
   539  	preparer := autorest.CreatePreparer(
   540  		autorest.AsContentType("application/json; charset=utf-8"),
   541  		autorest.AsPost(),
   542  		autorest.WithCustomBaseURL("{Endpoint}/customvision/v3.1/prediction", urlParameters),
   543  		autorest.WithPathParameters("/{projectId}/detect/iterations/{publishedName}/url", pathParameters),
   544  		autorest.WithJSON(imageURL),
   545  		autorest.WithQueryParameters(queryParameters))
   546  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   547  }
   548  
   549  // DetectImageURLSender sends the DetectImageURL request. The method will close the
   550  // http.Response Body if it receives an error.
   551  func (client BaseClient) DetectImageURLSender(req *http.Request) (*http.Response, error) {
   552  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   553  }
   554  
   555  // DetectImageURLResponder handles the response to the DetectImageURL request. The method always
   556  // closes the http.Response Body.
   557  func (client BaseClient) DetectImageURLResponder(resp *http.Response) (result ImagePrediction, err error) {
   558  	err = autorest.Respond(
   559  		resp,
   560  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   561  		autorest.ByUnmarshallingJSON(&result),
   562  		autorest.ByClosing())
   563  	result.Response = autorest.Response{Response: resp}
   564  	return
   565  }
   566  
   567  // DetectImageURLWithNoStore sends the detect image url with no store request.
   568  // Parameters:
   569  // projectID - the project id.
   570  // publishedName - specifies the name of the model to evaluate against.
   571  // imageURL - an {Iris.Web.Api.Models.ImageUrl} that contains the url of the image to be evaluated.
   572  // application - optional. Specifies the name of application using the endpoint.
   573  func (client BaseClient) DetectImageURLWithNoStore(ctx context.Context, projectID uuid.UUID, publishedName string, imageURL ImageURL, application string) (result ImagePrediction, err error) {
   574  	if tracing.IsEnabled() {
   575  		ctx = tracing.StartSpan(ctx, fqdn+"/BaseClient.DetectImageURLWithNoStore")
   576  		defer func() {
   577  			sc := -1
   578  			if result.Response.Response != nil {
   579  				sc = result.Response.Response.StatusCode
   580  			}
   581  			tracing.EndSpan(ctx, sc, err)
   582  		}()
   583  	}
   584  	if err := validation.Validate([]validation.Validation{
   585  		{TargetValue: imageURL,
   586  			Constraints: []validation.Constraint{{Target: "imageURL.URL", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil {
   587  		return result, validation.NewError("prediction.BaseClient", "DetectImageURLWithNoStore", err.Error())
   588  	}
   589  
   590  	req, err := client.DetectImageURLWithNoStorePreparer(ctx, projectID, publishedName, imageURL, application)
   591  	if err != nil {
   592  		err = autorest.NewErrorWithError(err, "prediction.BaseClient", "DetectImageURLWithNoStore", nil, "Failure preparing request")
   593  		return
   594  	}
   595  
   596  	resp, err := client.DetectImageURLWithNoStoreSender(req)
   597  	if err != nil {
   598  		result.Response = autorest.Response{Response: resp}
   599  		err = autorest.NewErrorWithError(err, "prediction.BaseClient", "DetectImageURLWithNoStore", resp, "Failure sending request")
   600  		return
   601  	}
   602  
   603  	result, err = client.DetectImageURLWithNoStoreResponder(resp)
   604  	if err != nil {
   605  		err = autorest.NewErrorWithError(err, "prediction.BaseClient", "DetectImageURLWithNoStore", resp, "Failure responding to request")
   606  		return
   607  	}
   608  
   609  	return
   610  }
   611  
   612  // DetectImageURLWithNoStorePreparer prepares the DetectImageURLWithNoStore request.
   613  func (client BaseClient) DetectImageURLWithNoStorePreparer(ctx context.Context, projectID uuid.UUID, publishedName string, imageURL ImageURL, application string) (*http.Request, error) {
   614  	urlParameters := map[string]interface{}{
   615  		"Endpoint": client.Endpoint,
   616  	}
   617  
   618  	pathParameters := map[string]interface{}{
   619  		"projectId":     autorest.Encode("path", projectID),
   620  		"publishedName": autorest.Encode("path", publishedName),
   621  	}
   622  
   623  	queryParameters := map[string]interface{}{}
   624  	if len(application) > 0 {
   625  		queryParameters["application"] = autorest.Encode("query", application)
   626  	}
   627  
   628  	preparer := autorest.CreatePreparer(
   629  		autorest.AsContentType("application/json; charset=utf-8"),
   630  		autorest.AsPost(),
   631  		autorest.WithCustomBaseURL("{Endpoint}/customvision/v3.1/prediction", urlParameters),
   632  		autorest.WithPathParameters("/{projectId}/detect/iterations/{publishedName}/url/nostore", pathParameters),
   633  		autorest.WithJSON(imageURL),
   634  		autorest.WithQueryParameters(queryParameters))
   635  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   636  }
   637  
   638  // DetectImageURLWithNoStoreSender sends the DetectImageURLWithNoStore request. The method will close the
   639  // http.Response Body if it receives an error.
   640  func (client BaseClient) DetectImageURLWithNoStoreSender(req *http.Request) (*http.Response, error) {
   641  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   642  }
   643  
   644  // DetectImageURLWithNoStoreResponder handles the response to the DetectImageURLWithNoStore request. The method always
   645  // closes the http.Response Body.
   646  func (client BaseClient) DetectImageURLWithNoStoreResponder(resp *http.Response) (result ImagePrediction, err error) {
   647  	err = autorest.Respond(
   648  		resp,
   649  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   650  		autorest.ByUnmarshallingJSON(&result),
   651  		autorest.ByClosing())
   652  	result.Response = autorest.Response{Response: resp}
   653  	return
   654  }
   655  
   656  // DetectImageWithNoStore sends the detect image with no store request.
   657  // Parameters:
   658  // projectID - the project id.
   659  // publishedName - specifies the name of the model to evaluate against.
   660  // imageData - binary image data. Supported formats are JPEG, GIF, PNG, and BMP. Supports images up to 4MB.
   661  // application - optional. Specifies the name of application using the endpoint.
   662  func (client BaseClient) DetectImageWithNoStore(ctx context.Context, projectID uuid.UUID, publishedName string, imageData io.ReadCloser, application string) (result ImagePrediction, err error) {
   663  	if tracing.IsEnabled() {
   664  		ctx = tracing.StartSpan(ctx, fqdn+"/BaseClient.DetectImageWithNoStore")
   665  		defer func() {
   666  			sc := -1
   667  			if result.Response.Response != nil {
   668  				sc = result.Response.Response.StatusCode
   669  			}
   670  			tracing.EndSpan(ctx, sc, err)
   671  		}()
   672  	}
   673  	req, err := client.DetectImageWithNoStorePreparer(ctx, projectID, publishedName, imageData, application)
   674  	if err != nil {
   675  		err = autorest.NewErrorWithError(err, "prediction.BaseClient", "DetectImageWithNoStore", nil, "Failure preparing request")
   676  		return
   677  	}
   678  
   679  	resp, err := client.DetectImageWithNoStoreSender(req)
   680  	if err != nil {
   681  		result.Response = autorest.Response{Response: resp}
   682  		err = autorest.NewErrorWithError(err, "prediction.BaseClient", "DetectImageWithNoStore", resp, "Failure sending request")
   683  		return
   684  	}
   685  
   686  	result, err = client.DetectImageWithNoStoreResponder(resp)
   687  	if err != nil {
   688  		err = autorest.NewErrorWithError(err, "prediction.BaseClient", "DetectImageWithNoStore", resp, "Failure responding to request")
   689  		return
   690  	}
   691  
   692  	return
   693  }
   694  
   695  // DetectImageWithNoStorePreparer prepares the DetectImageWithNoStore request.
   696  func (client BaseClient) DetectImageWithNoStorePreparer(ctx context.Context, projectID uuid.UUID, publishedName string, imageData io.ReadCloser, application string) (*http.Request, error) {
   697  	urlParameters := map[string]interface{}{
   698  		"Endpoint": client.Endpoint,
   699  	}
   700  
   701  	pathParameters := map[string]interface{}{
   702  		"projectId":     autorest.Encode("path", projectID),
   703  		"publishedName": autorest.Encode("path", publishedName),
   704  	}
   705  
   706  	queryParameters := map[string]interface{}{}
   707  	if len(application) > 0 {
   708  		queryParameters["application"] = autorest.Encode("query", application)
   709  	}
   710  
   711  	formDataParameters := map[string]interface{}{
   712  		"imageData": imageData,
   713  	}
   714  
   715  	preparer := autorest.CreatePreparer(
   716  		autorest.AsPost(),
   717  		autorest.WithCustomBaseURL("{Endpoint}/customvision/v3.1/prediction", urlParameters),
   718  		autorest.WithPathParameters("/{projectId}/detect/iterations/{publishedName}/image/nostore", pathParameters),
   719  		autorest.WithQueryParameters(queryParameters),
   720  		autorest.WithMultiPartFormData(formDataParameters))
   721  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   722  }
   723  
   724  // DetectImageWithNoStoreSender sends the DetectImageWithNoStore request. The method will close the
   725  // http.Response Body if it receives an error.
   726  func (client BaseClient) DetectImageWithNoStoreSender(req *http.Request) (*http.Response, error) {
   727  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   728  }
   729  
   730  // DetectImageWithNoStoreResponder handles the response to the DetectImageWithNoStore request. The method always
   731  // closes the http.Response Body.
   732  func (client BaseClient) DetectImageWithNoStoreResponder(resp *http.Response) (result ImagePrediction, err error) {
   733  	err = autorest.Respond(
   734  		resp,
   735  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   736  		autorest.ByUnmarshallingJSON(&result),
   737  		autorest.ByClosing())
   738  	result.Response = autorest.Response{Response: resp}
   739  	return
   740  }
   741  

View as plain text