...

Source file src/github.com/Azure/azure-sdk-for-go/services/cognitiveservices/v2.0/luis/authoring/pattern.go

Documentation: github.com/Azure/azure-sdk-for-go/services/cognitiveservices/v2.0/luis/authoring

     1  package authoring
     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  
     9  import (
    10  	"context"
    11  	"github.com/Azure/go-autorest/autorest"
    12  	"github.com/Azure/go-autorest/autorest/azure"
    13  	"github.com/Azure/go-autorest/autorest/validation"
    14  	"github.com/Azure/go-autorest/tracing"
    15  	"github.com/gofrs/uuid"
    16  	"net/http"
    17  )
    18  
    19  // PatternClient is the client for the Pattern methods of the Authoring service.
    20  type PatternClient struct {
    21  	BaseClient
    22  }
    23  
    24  // NewPatternClient creates an instance of the PatternClient client.
    25  func NewPatternClient(endpoint string) PatternClient {
    26  	return PatternClient{New(endpoint)}
    27  }
    28  
    29  // AddPattern sends the add pattern request.
    30  // Parameters:
    31  // appID - the application ID.
    32  // versionID - the version ID.
    33  // pattern - the input pattern.
    34  func (client PatternClient) AddPattern(ctx context.Context, appID uuid.UUID, versionID string, pattern PatternRuleCreateObject) (result PatternRuleInfo, err error) {
    35  	if tracing.IsEnabled() {
    36  		ctx = tracing.StartSpan(ctx, fqdn+"/PatternClient.AddPattern")
    37  		defer func() {
    38  			sc := -1
    39  			if result.Response.Response != nil {
    40  				sc = result.Response.Response.StatusCode
    41  			}
    42  			tracing.EndSpan(ctx, sc, err)
    43  		}()
    44  	}
    45  	req, err := client.AddPatternPreparer(ctx, appID, versionID, pattern)
    46  	if err != nil {
    47  		err = autorest.NewErrorWithError(err, "authoring.PatternClient", "AddPattern", nil, "Failure preparing request")
    48  		return
    49  	}
    50  
    51  	resp, err := client.AddPatternSender(req)
    52  	if err != nil {
    53  		result.Response = autorest.Response{Response: resp}
    54  		err = autorest.NewErrorWithError(err, "authoring.PatternClient", "AddPattern", resp, "Failure sending request")
    55  		return
    56  	}
    57  
    58  	result, err = client.AddPatternResponder(resp)
    59  	if err != nil {
    60  		err = autorest.NewErrorWithError(err, "authoring.PatternClient", "AddPattern", resp, "Failure responding to request")
    61  		return
    62  	}
    63  
    64  	return
    65  }
    66  
    67  // AddPatternPreparer prepares the AddPattern request.
    68  func (client PatternClient) AddPatternPreparer(ctx context.Context, appID uuid.UUID, versionID string, pattern PatternRuleCreateObject) (*http.Request, error) {
    69  	urlParameters := map[string]interface{}{
    70  		"Endpoint": client.Endpoint,
    71  	}
    72  
    73  	pathParameters := map[string]interface{}{
    74  		"appId":     autorest.Encode("path", appID),
    75  		"versionId": autorest.Encode("path", versionID),
    76  	}
    77  
    78  	preparer := autorest.CreatePreparer(
    79  		autorest.AsContentType("application/json; charset=utf-8"),
    80  		autorest.AsPost(),
    81  		autorest.WithCustomBaseURL("{Endpoint}/luis/api/v2.0", urlParameters),
    82  		autorest.WithPathParameters("/apps/{appId}/versions/{versionId}/patternrule", pathParameters),
    83  		autorest.WithJSON(pattern))
    84  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
    85  }
    86  
    87  // AddPatternSender sends the AddPattern request. The method will close the
    88  // http.Response Body if it receives an error.
    89  func (client PatternClient) AddPatternSender(req *http.Request) (*http.Response, error) {
    90  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
    91  }
    92  
    93  // AddPatternResponder handles the response to the AddPattern request. The method always
    94  // closes the http.Response Body.
    95  func (client PatternClient) AddPatternResponder(resp *http.Response) (result PatternRuleInfo, err error) {
    96  	err = autorest.Respond(
    97  		resp,
    98  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
    99  		autorest.ByUnmarshallingJSON(&result),
   100  		autorest.ByClosing())
   101  	result.Response = autorest.Response{Response: resp}
   102  	return
   103  }
   104  
   105  // BatchAddPatterns sends the batch add patterns request.
   106  // Parameters:
   107  // appID - the application ID.
   108  // versionID - the version ID.
   109  // patterns - a JSON array containing patterns.
   110  func (client PatternClient) BatchAddPatterns(ctx context.Context, appID uuid.UUID, versionID string, patterns []PatternRuleCreateObject) (result ListPatternRuleInfo, err error) {
   111  	if tracing.IsEnabled() {
   112  		ctx = tracing.StartSpan(ctx, fqdn+"/PatternClient.BatchAddPatterns")
   113  		defer func() {
   114  			sc := -1
   115  			if result.Response.Response != nil {
   116  				sc = result.Response.Response.StatusCode
   117  			}
   118  			tracing.EndSpan(ctx, sc, err)
   119  		}()
   120  	}
   121  	if err := validation.Validate([]validation.Validation{
   122  		{TargetValue: patterns,
   123  			Constraints: []validation.Constraint{{Target: "patterns", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil {
   124  		return result, validation.NewError("authoring.PatternClient", "BatchAddPatterns", err.Error())
   125  	}
   126  
   127  	req, err := client.BatchAddPatternsPreparer(ctx, appID, versionID, patterns)
   128  	if err != nil {
   129  		err = autorest.NewErrorWithError(err, "authoring.PatternClient", "BatchAddPatterns", nil, "Failure preparing request")
   130  		return
   131  	}
   132  
   133  	resp, err := client.BatchAddPatternsSender(req)
   134  	if err != nil {
   135  		result.Response = autorest.Response{Response: resp}
   136  		err = autorest.NewErrorWithError(err, "authoring.PatternClient", "BatchAddPatterns", resp, "Failure sending request")
   137  		return
   138  	}
   139  
   140  	result, err = client.BatchAddPatternsResponder(resp)
   141  	if err != nil {
   142  		err = autorest.NewErrorWithError(err, "authoring.PatternClient", "BatchAddPatterns", resp, "Failure responding to request")
   143  		return
   144  	}
   145  
   146  	return
   147  }
   148  
   149  // BatchAddPatternsPreparer prepares the BatchAddPatterns request.
   150  func (client PatternClient) BatchAddPatternsPreparer(ctx context.Context, appID uuid.UUID, versionID string, patterns []PatternRuleCreateObject) (*http.Request, error) {
   151  	urlParameters := map[string]interface{}{
   152  		"Endpoint": client.Endpoint,
   153  	}
   154  
   155  	pathParameters := map[string]interface{}{
   156  		"appId":     autorest.Encode("path", appID),
   157  		"versionId": autorest.Encode("path", versionID),
   158  	}
   159  
   160  	preparer := autorest.CreatePreparer(
   161  		autorest.AsContentType("application/json; charset=utf-8"),
   162  		autorest.AsPost(),
   163  		autorest.WithCustomBaseURL("{Endpoint}/luis/api/v2.0", urlParameters),
   164  		autorest.WithPathParameters("/apps/{appId}/versions/{versionId}/patternrules", pathParameters),
   165  		autorest.WithJSON(patterns))
   166  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   167  }
   168  
   169  // BatchAddPatternsSender sends the BatchAddPatterns request. The method will close the
   170  // http.Response Body if it receives an error.
   171  func (client PatternClient) BatchAddPatternsSender(req *http.Request) (*http.Response, error) {
   172  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   173  }
   174  
   175  // BatchAddPatternsResponder handles the response to the BatchAddPatterns request. The method always
   176  // closes the http.Response Body.
   177  func (client PatternClient) BatchAddPatternsResponder(resp *http.Response) (result ListPatternRuleInfo, err error) {
   178  	err = autorest.Respond(
   179  		resp,
   180  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
   181  		autorest.ByUnmarshallingJSON(&result.Value),
   182  		autorest.ByClosing())
   183  	result.Response = autorest.Response{Response: resp}
   184  	return
   185  }
   186  
   187  // DeletePattern sends the delete pattern request.
   188  // Parameters:
   189  // appID - the application ID.
   190  // versionID - the version ID.
   191  // patternID - the pattern ID.
   192  func (client PatternClient) DeletePattern(ctx context.Context, appID uuid.UUID, versionID string, patternID uuid.UUID) (result OperationStatus, err error) {
   193  	if tracing.IsEnabled() {
   194  		ctx = tracing.StartSpan(ctx, fqdn+"/PatternClient.DeletePattern")
   195  		defer func() {
   196  			sc := -1
   197  			if result.Response.Response != nil {
   198  				sc = result.Response.Response.StatusCode
   199  			}
   200  			tracing.EndSpan(ctx, sc, err)
   201  		}()
   202  	}
   203  	req, err := client.DeletePatternPreparer(ctx, appID, versionID, patternID)
   204  	if err != nil {
   205  		err = autorest.NewErrorWithError(err, "authoring.PatternClient", "DeletePattern", nil, "Failure preparing request")
   206  		return
   207  	}
   208  
   209  	resp, err := client.DeletePatternSender(req)
   210  	if err != nil {
   211  		result.Response = autorest.Response{Response: resp}
   212  		err = autorest.NewErrorWithError(err, "authoring.PatternClient", "DeletePattern", resp, "Failure sending request")
   213  		return
   214  	}
   215  
   216  	result, err = client.DeletePatternResponder(resp)
   217  	if err != nil {
   218  		err = autorest.NewErrorWithError(err, "authoring.PatternClient", "DeletePattern", resp, "Failure responding to request")
   219  		return
   220  	}
   221  
   222  	return
   223  }
   224  
   225  // DeletePatternPreparer prepares the DeletePattern request.
   226  func (client PatternClient) DeletePatternPreparer(ctx context.Context, appID uuid.UUID, versionID string, patternID uuid.UUID) (*http.Request, error) {
   227  	urlParameters := map[string]interface{}{
   228  		"Endpoint": client.Endpoint,
   229  	}
   230  
   231  	pathParameters := map[string]interface{}{
   232  		"appId":     autorest.Encode("path", appID),
   233  		"patternId": autorest.Encode("path", patternID),
   234  		"versionId": autorest.Encode("path", versionID),
   235  	}
   236  
   237  	preparer := autorest.CreatePreparer(
   238  		autorest.AsDelete(),
   239  		autorest.WithCustomBaseURL("{Endpoint}/luis/api/v2.0", urlParameters),
   240  		autorest.WithPathParameters("/apps/{appId}/versions/{versionId}/patternrules/{patternId}", pathParameters))
   241  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   242  }
   243  
   244  // DeletePatternSender sends the DeletePattern request. The method will close the
   245  // http.Response Body if it receives an error.
   246  func (client PatternClient) DeletePatternSender(req *http.Request) (*http.Response, error) {
   247  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   248  }
   249  
   250  // DeletePatternResponder handles the response to the DeletePattern request. The method always
   251  // closes the http.Response Body.
   252  func (client PatternClient) DeletePatternResponder(resp *http.Response) (result OperationStatus, err error) {
   253  	err = autorest.Respond(
   254  		resp,
   255  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   256  		autorest.ByUnmarshallingJSON(&result),
   257  		autorest.ByClosing())
   258  	result.Response = autorest.Response{Response: resp}
   259  	return
   260  }
   261  
   262  // DeletePatterns sends the delete patterns request.
   263  // Parameters:
   264  // appID - the application ID.
   265  // versionID - the version ID.
   266  // patternIds - the patterns IDs.
   267  func (client PatternClient) DeletePatterns(ctx context.Context, appID uuid.UUID, versionID string, patternIds []uuid.UUID) (result OperationStatus, err error) {
   268  	if tracing.IsEnabled() {
   269  		ctx = tracing.StartSpan(ctx, fqdn+"/PatternClient.DeletePatterns")
   270  		defer func() {
   271  			sc := -1
   272  			if result.Response.Response != nil {
   273  				sc = result.Response.Response.StatusCode
   274  			}
   275  			tracing.EndSpan(ctx, sc, err)
   276  		}()
   277  	}
   278  	if err := validation.Validate([]validation.Validation{
   279  		{TargetValue: patternIds,
   280  			Constraints: []validation.Constraint{{Target: "patternIds", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil {
   281  		return result, validation.NewError("authoring.PatternClient", "DeletePatterns", err.Error())
   282  	}
   283  
   284  	req, err := client.DeletePatternsPreparer(ctx, appID, versionID, patternIds)
   285  	if err != nil {
   286  		err = autorest.NewErrorWithError(err, "authoring.PatternClient", "DeletePatterns", nil, "Failure preparing request")
   287  		return
   288  	}
   289  
   290  	resp, err := client.DeletePatternsSender(req)
   291  	if err != nil {
   292  		result.Response = autorest.Response{Response: resp}
   293  		err = autorest.NewErrorWithError(err, "authoring.PatternClient", "DeletePatterns", resp, "Failure sending request")
   294  		return
   295  	}
   296  
   297  	result, err = client.DeletePatternsResponder(resp)
   298  	if err != nil {
   299  		err = autorest.NewErrorWithError(err, "authoring.PatternClient", "DeletePatterns", resp, "Failure responding to request")
   300  		return
   301  	}
   302  
   303  	return
   304  }
   305  
   306  // DeletePatternsPreparer prepares the DeletePatterns request.
   307  func (client PatternClient) DeletePatternsPreparer(ctx context.Context, appID uuid.UUID, versionID string, patternIds []uuid.UUID) (*http.Request, error) {
   308  	urlParameters := map[string]interface{}{
   309  		"Endpoint": client.Endpoint,
   310  	}
   311  
   312  	pathParameters := map[string]interface{}{
   313  		"appId":     autorest.Encode("path", appID),
   314  		"versionId": autorest.Encode("path", versionID),
   315  	}
   316  
   317  	preparer := autorest.CreatePreparer(
   318  		autorest.AsContentType("application/json; charset=utf-8"),
   319  		autorest.AsDelete(),
   320  		autorest.WithCustomBaseURL("{Endpoint}/luis/api/v2.0", urlParameters),
   321  		autorest.WithPathParameters("/apps/{appId}/versions/{versionId}/patternrules", pathParameters),
   322  		autorest.WithJSON(patternIds))
   323  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   324  }
   325  
   326  // DeletePatternsSender sends the DeletePatterns request. The method will close the
   327  // http.Response Body if it receives an error.
   328  func (client PatternClient) DeletePatternsSender(req *http.Request) (*http.Response, error) {
   329  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   330  }
   331  
   332  // DeletePatternsResponder handles the response to the DeletePatterns request. The method always
   333  // closes the http.Response Body.
   334  func (client PatternClient) DeletePatternsResponder(resp *http.Response) (result OperationStatus, err error) {
   335  	err = autorest.Respond(
   336  		resp,
   337  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   338  		autorest.ByUnmarshallingJSON(&result),
   339  		autorest.ByClosing())
   340  	result.Response = autorest.Response{Response: resp}
   341  	return
   342  }
   343  
   344  // ListIntentPatterns sends the list intent patterns request.
   345  // Parameters:
   346  // appID - the application ID.
   347  // versionID - the version ID.
   348  // intentID - the intent classifier ID.
   349  // skip - the number of entries to skip. Default value is 0.
   350  // take - the number of entries to return. Maximum page size is 500. Default is 100.
   351  func (client PatternClient) ListIntentPatterns(ctx context.Context, appID uuid.UUID, versionID string, intentID uuid.UUID, skip *int32, take *int32) (result ListPatternRuleInfo, err error) {
   352  	if tracing.IsEnabled() {
   353  		ctx = tracing.StartSpan(ctx, fqdn+"/PatternClient.ListIntentPatterns")
   354  		defer func() {
   355  			sc := -1
   356  			if result.Response.Response != nil {
   357  				sc = result.Response.Response.StatusCode
   358  			}
   359  			tracing.EndSpan(ctx, sc, err)
   360  		}()
   361  	}
   362  	if err := validation.Validate([]validation.Validation{
   363  		{TargetValue: skip,
   364  			Constraints: []validation.Constraint{{Target: "skip", Name: validation.Null, Rule: false,
   365  				Chain: []validation.Constraint{{Target: "skip", Name: validation.InclusiveMinimum, Rule: int64(0), Chain: nil}}}}},
   366  		{TargetValue: take,
   367  			Constraints: []validation.Constraint{{Target: "take", Name: validation.Null, Rule: false,
   368  				Chain: []validation.Constraint{{Target: "take", Name: validation.InclusiveMaximum, Rule: int64(500), Chain: nil},
   369  					{Target: "take", Name: validation.InclusiveMinimum, Rule: int64(0), Chain: nil},
   370  				}}}}}); err != nil {
   371  		return result, validation.NewError("authoring.PatternClient", "ListIntentPatterns", err.Error())
   372  	}
   373  
   374  	req, err := client.ListIntentPatternsPreparer(ctx, appID, versionID, intentID, skip, take)
   375  	if err != nil {
   376  		err = autorest.NewErrorWithError(err, "authoring.PatternClient", "ListIntentPatterns", nil, "Failure preparing request")
   377  		return
   378  	}
   379  
   380  	resp, err := client.ListIntentPatternsSender(req)
   381  	if err != nil {
   382  		result.Response = autorest.Response{Response: resp}
   383  		err = autorest.NewErrorWithError(err, "authoring.PatternClient", "ListIntentPatterns", resp, "Failure sending request")
   384  		return
   385  	}
   386  
   387  	result, err = client.ListIntentPatternsResponder(resp)
   388  	if err != nil {
   389  		err = autorest.NewErrorWithError(err, "authoring.PatternClient", "ListIntentPatterns", resp, "Failure responding to request")
   390  		return
   391  	}
   392  
   393  	return
   394  }
   395  
   396  // ListIntentPatternsPreparer prepares the ListIntentPatterns request.
   397  func (client PatternClient) ListIntentPatternsPreparer(ctx context.Context, appID uuid.UUID, versionID string, intentID uuid.UUID, skip *int32, take *int32) (*http.Request, error) {
   398  	urlParameters := map[string]interface{}{
   399  		"Endpoint": client.Endpoint,
   400  	}
   401  
   402  	pathParameters := map[string]interface{}{
   403  		"appId":     autorest.Encode("path", appID),
   404  		"intentId":  autorest.Encode("path", intentID),
   405  		"versionId": autorest.Encode("path", versionID),
   406  	}
   407  
   408  	queryParameters := map[string]interface{}{}
   409  	if skip != nil {
   410  		queryParameters["skip"] = autorest.Encode("query", *skip)
   411  	} else {
   412  		queryParameters["skip"] = autorest.Encode("query", 0)
   413  	}
   414  	if take != nil {
   415  		queryParameters["take"] = autorest.Encode("query", *take)
   416  	} else {
   417  		queryParameters["take"] = autorest.Encode("query", 100)
   418  	}
   419  
   420  	preparer := autorest.CreatePreparer(
   421  		autorest.AsGet(),
   422  		autorest.WithCustomBaseURL("{Endpoint}/luis/api/v2.0", urlParameters),
   423  		autorest.WithPathParameters("/apps/{appId}/versions/{versionId}/intents/{intentId}/patternrules", pathParameters),
   424  		autorest.WithQueryParameters(queryParameters))
   425  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   426  }
   427  
   428  // ListIntentPatternsSender sends the ListIntentPatterns request. The method will close the
   429  // http.Response Body if it receives an error.
   430  func (client PatternClient) ListIntentPatternsSender(req *http.Request) (*http.Response, error) {
   431  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   432  }
   433  
   434  // ListIntentPatternsResponder handles the response to the ListIntentPatterns request. The method always
   435  // closes the http.Response Body.
   436  func (client PatternClient) ListIntentPatternsResponder(resp *http.Response) (result ListPatternRuleInfo, err error) {
   437  	err = autorest.Respond(
   438  		resp,
   439  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   440  		autorest.ByUnmarshallingJSON(&result.Value),
   441  		autorest.ByClosing())
   442  	result.Response = autorest.Response{Response: resp}
   443  	return
   444  }
   445  
   446  // ListPatterns sends the list patterns request.
   447  // Parameters:
   448  // appID - the application ID.
   449  // versionID - the version ID.
   450  // skip - the number of entries to skip. Default value is 0.
   451  // take - the number of entries to return. Maximum page size is 500. Default is 100.
   452  func (client PatternClient) ListPatterns(ctx context.Context, appID uuid.UUID, versionID string, skip *int32, take *int32) (result ListPatternRuleInfo, err error) {
   453  	if tracing.IsEnabled() {
   454  		ctx = tracing.StartSpan(ctx, fqdn+"/PatternClient.ListPatterns")
   455  		defer func() {
   456  			sc := -1
   457  			if result.Response.Response != nil {
   458  				sc = result.Response.Response.StatusCode
   459  			}
   460  			tracing.EndSpan(ctx, sc, err)
   461  		}()
   462  	}
   463  	if err := validation.Validate([]validation.Validation{
   464  		{TargetValue: skip,
   465  			Constraints: []validation.Constraint{{Target: "skip", Name: validation.Null, Rule: false,
   466  				Chain: []validation.Constraint{{Target: "skip", Name: validation.InclusiveMinimum, Rule: int64(0), Chain: nil}}}}},
   467  		{TargetValue: take,
   468  			Constraints: []validation.Constraint{{Target: "take", Name: validation.Null, Rule: false,
   469  				Chain: []validation.Constraint{{Target: "take", Name: validation.InclusiveMaximum, Rule: int64(500), Chain: nil},
   470  					{Target: "take", Name: validation.InclusiveMinimum, Rule: int64(0), Chain: nil},
   471  				}}}}}); err != nil {
   472  		return result, validation.NewError("authoring.PatternClient", "ListPatterns", err.Error())
   473  	}
   474  
   475  	req, err := client.ListPatternsPreparer(ctx, appID, versionID, skip, take)
   476  	if err != nil {
   477  		err = autorest.NewErrorWithError(err, "authoring.PatternClient", "ListPatterns", nil, "Failure preparing request")
   478  		return
   479  	}
   480  
   481  	resp, err := client.ListPatternsSender(req)
   482  	if err != nil {
   483  		result.Response = autorest.Response{Response: resp}
   484  		err = autorest.NewErrorWithError(err, "authoring.PatternClient", "ListPatterns", resp, "Failure sending request")
   485  		return
   486  	}
   487  
   488  	result, err = client.ListPatternsResponder(resp)
   489  	if err != nil {
   490  		err = autorest.NewErrorWithError(err, "authoring.PatternClient", "ListPatterns", resp, "Failure responding to request")
   491  		return
   492  	}
   493  
   494  	return
   495  }
   496  
   497  // ListPatternsPreparer prepares the ListPatterns request.
   498  func (client PatternClient) ListPatternsPreparer(ctx context.Context, appID uuid.UUID, versionID string, skip *int32, take *int32) (*http.Request, error) {
   499  	urlParameters := map[string]interface{}{
   500  		"Endpoint": client.Endpoint,
   501  	}
   502  
   503  	pathParameters := map[string]interface{}{
   504  		"appId":     autorest.Encode("path", appID),
   505  		"versionId": autorest.Encode("path", versionID),
   506  	}
   507  
   508  	queryParameters := map[string]interface{}{}
   509  	if skip != nil {
   510  		queryParameters["skip"] = autorest.Encode("query", *skip)
   511  	} else {
   512  		queryParameters["skip"] = autorest.Encode("query", 0)
   513  	}
   514  	if take != nil {
   515  		queryParameters["take"] = autorest.Encode("query", *take)
   516  	} else {
   517  		queryParameters["take"] = autorest.Encode("query", 100)
   518  	}
   519  
   520  	preparer := autorest.CreatePreparer(
   521  		autorest.AsGet(),
   522  		autorest.WithCustomBaseURL("{Endpoint}/luis/api/v2.0", urlParameters),
   523  		autorest.WithPathParameters("/apps/{appId}/versions/{versionId}/patternrules", pathParameters),
   524  		autorest.WithQueryParameters(queryParameters))
   525  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   526  }
   527  
   528  // ListPatternsSender sends the ListPatterns request. The method will close the
   529  // http.Response Body if it receives an error.
   530  func (client PatternClient) ListPatternsSender(req *http.Request) (*http.Response, error) {
   531  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   532  }
   533  
   534  // ListPatternsResponder handles the response to the ListPatterns request. The method always
   535  // closes the http.Response Body.
   536  func (client PatternClient) ListPatternsResponder(resp *http.Response) (result ListPatternRuleInfo, err error) {
   537  	err = autorest.Respond(
   538  		resp,
   539  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   540  		autorest.ByUnmarshallingJSON(&result.Value),
   541  		autorest.ByClosing())
   542  	result.Response = autorest.Response{Response: resp}
   543  	return
   544  }
   545  
   546  // UpdatePattern sends the update pattern request.
   547  // Parameters:
   548  // appID - the application ID.
   549  // versionID - the version ID.
   550  // patternID - the pattern ID.
   551  // pattern - an object representing a pattern.
   552  func (client PatternClient) UpdatePattern(ctx context.Context, appID uuid.UUID, versionID string, patternID uuid.UUID, pattern PatternRuleUpdateObject) (result PatternRuleInfo, err error) {
   553  	if tracing.IsEnabled() {
   554  		ctx = tracing.StartSpan(ctx, fqdn+"/PatternClient.UpdatePattern")
   555  		defer func() {
   556  			sc := -1
   557  			if result.Response.Response != nil {
   558  				sc = result.Response.Response.StatusCode
   559  			}
   560  			tracing.EndSpan(ctx, sc, err)
   561  		}()
   562  	}
   563  	req, err := client.UpdatePatternPreparer(ctx, appID, versionID, patternID, pattern)
   564  	if err != nil {
   565  		err = autorest.NewErrorWithError(err, "authoring.PatternClient", "UpdatePattern", nil, "Failure preparing request")
   566  		return
   567  	}
   568  
   569  	resp, err := client.UpdatePatternSender(req)
   570  	if err != nil {
   571  		result.Response = autorest.Response{Response: resp}
   572  		err = autorest.NewErrorWithError(err, "authoring.PatternClient", "UpdatePattern", resp, "Failure sending request")
   573  		return
   574  	}
   575  
   576  	result, err = client.UpdatePatternResponder(resp)
   577  	if err != nil {
   578  		err = autorest.NewErrorWithError(err, "authoring.PatternClient", "UpdatePattern", resp, "Failure responding to request")
   579  		return
   580  	}
   581  
   582  	return
   583  }
   584  
   585  // UpdatePatternPreparer prepares the UpdatePattern request.
   586  func (client PatternClient) UpdatePatternPreparer(ctx context.Context, appID uuid.UUID, versionID string, patternID uuid.UUID, pattern PatternRuleUpdateObject) (*http.Request, error) {
   587  	urlParameters := map[string]interface{}{
   588  		"Endpoint": client.Endpoint,
   589  	}
   590  
   591  	pathParameters := map[string]interface{}{
   592  		"appId":     autorest.Encode("path", appID),
   593  		"patternId": autorest.Encode("path", patternID),
   594  		"versionId": autorest.Encode("path", versionID),
   595  	}
   596  
   597  	preparer := autorest.CreatePreparer(
   598  		autorest.AsContentType("application/json; charset=utf-8"),
   599  		autorest.AsPut(),
   600  		autorest.WithCustomBaseURL("{Endpoint}/luis/api/v2.0", urlParameters),
   601  		autorest.WithPathParameters("/apps/{appId}/versions/{versionId}/patternrules/{patternId}", pathParameters),
   602  		autorest.WithJSON(pattern))
   603  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   604  }
   605  
   606  // UpdatePatternSender sends the UpdatePattern request. The method will close the
   607  // http.Response Body if it receives an error.
   608  func (client PatternClient) UpdatePatternSender(req *http.Request) (*http.Response, error) {
   609  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   610  }
   611  
   612  // UpdatePatternResponder handles the response to the UpdatePattern request. The method always
   613  // closes the http.Response Body.
   614  func (client PatternClient) UpdatePatternResponder(resp *http.Response) (result PatternRuleInfo, err error) {
   615  	err = autorest.Respond(
   616  		resp,
   617  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   618  		autorest.ByUnmarshallingJSON(&result),
   619  		autorest.ByClosing())
   620  	result.Response = autorest.Response{Response: resp}
   621  	return
   622  }
   623  
   624  // UpdatePatterns sends the update patterns request.
   625  // Parameters:
   626  // appID - the application ID.
   627  // versionID - the version ID.
   628  // patterns - an array represents the patterns.
   629  func (client PatternClient) UpdatePatterns(ctx context.Context, appID uuid.UUID, versionID string, patterns []PatternRuleUpdateObject) (result ListPatternRuleInfo, err error) {
   630  	if tracing.IsEnabled() {
   631  		ctx = tracing.StartSpan(ctx, fqdn+"/PatternClient.UpdatePatterns")
   632  		defer func() {
   633  			sc := -1
   634  			if result.Response.Response != nil {
   635  				sc = result.Response.Response.StatusCode
   636  			}
   637  			tracing.EndSpan(ctx, sc, err)
   638  		}()
   639  	}
   640  	if err := validation.Validate([]validation.Validation{
   641  		{TargetValue: patterns,
   642  			Constraints: []validation.Constraint{{Target: "patterns", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil {
   643  		return result, validation.NewError("authoring.PatternClient", "UpdatePatterns", err.Error())
   644  	}
   645  
   646  	req, err := client.UpdatePatternsPreparer(ctx, appID, versionID, patterns)
   647  	if err != nil {
   648  		err = autorest.NewErrorWithError(err, "authoring.PatternClient", "UpdatePatterns", nil, "Failure preparing request")
   649  		return
   650  	}
   651  
   652  	resp, err := client.UpdatePatternsSender(req)
   653  	if err != nil {
   654  		result.Response = autorest.Response{Response: resp}
   655  		err = autorest.NewErrorWithError(err, "authoring.PatternClient", "UpdatePatterns", resp, "Failure sending request")
   656  		return
   657  	}
   658  
   659  	result, err = client.UpdatePatternsResponder(resp)
   660  	if err != nil {
   661  		err = autorest.NewErrorWithError(err, "authoring.PatternClient", "UpdatePatterns", resp, "Failure responding to request")
   662  		return
   663  	}
   664  
   665  	return
   666  }
   667  
   668  // UpdatePatternsPreparer prepares the UpdatePatterns request.
   669  func (client PatternClient) UpdatePatternsPreparer(ctx context.Context, appID uuid.UUID, versionID string, patterns []PatternRuleUpdateObject) (*http.Request, error) {
   670  	urlParameters := map[string]interface{}{
   671  		"Endpoint": client.Endpoint,
   672  	}
   673  
   674  	pathParameters := map[string]interface{}{
   675  		"appId":     autorest.Encode("path", appID),
   676  		"versionId": autorest.Encode("path", versionID),
   677  	}
   678  
   679  	preparer := autorest.CreatePreparer(
   680  		autorest.AsContentType("application/json; charset=utf-8"),
   681  		autorest.AsPut(),
   682  		autorest.WithCustomBaseURL("{Endpoint}/luis/api/v2.0", urlParameters),
   683  		autorest.WithPathParameters("/apps/{appId}/versions/{versionId}/patternrules", pathParameters),
   684  		autorest.WithJSON(patterns))
   685  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   686  }
   687  
   688  // UpdatePatternsSender sends the UpdatePatterns request. The method will close the
   689  // http.Response Body if it receives an error.
   690  func (client PatternClient) UpdatePatternsSender(req *http.Request) (*http.Response, error) {
   691  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   692  }
   693  
   694  // UpdatePatternsResponder handles the response to the UpdatePatterns request. The method always
   695  // closes the http.Response Body.
   696  func (client PatternClient) UpdatePatternsResponder(resp *http.Response) (result ListPatternRuleInfo, err error) {
   697  	err = autorest.Respond(
   698  		resp,
   699  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   700  		autorest.ByUnmarshallingJSON(&result.Value),
   701  		autorest.ByClosing())
   702  	result.Response = autorest.Response{Response: resp}
   703  	return
   704  }
   705  

View as plain text