...

Source file src/github.com/Azure/azure-sdk-for-go/services/cognitiveservices/v2.0/luis/authoring/settings.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  // SettingsClient is the client for the Settings methods of the Authoring service.
    20  type SettingsClient struct {
    21  	BaseClient
    22  }
    23  
    24  // NewSettingsClient creates an instance of the SettingsClient client.
    25  func NewSettingsClient(endpoint string) SettingsClient {
    26  	return SettingsClient{New(endpoint)}
    27  }
    28  
    29  // List gets the settings in a version of the application.
    30  // Parameters:
    31  // appID - the application ID.
    32  // versionID - the version ID.
    33  func (client SettingsClient) List(ctx context.Context, appID uuid.UUID, versionID string) (result ListAppVersionSettingObject, err error) {
    34  	if tracing.IsEnabled() {
    35  		ctx = tracing.StartSpan(ctx, fqdn+"/SettingsClient.List")
    36  		defer func() {
    37  			sc := -1
    38  			if result.Response.Response != nil {
    39  				sc = result.Response.Response.StatusCode
    40  			}
    41  			tracing.EndSpan(ctx, sc, err)
    42  		}()
    43  	}
    44  	req, err := client.ListPreparer(ctx, appID, versionID)
    45  	if err != nil {
    46  		err = autorest.NewErrorWithError(err, "authoring.SettingsClient", "List", nil, "Failure preparing request")
    47  		return
    48  	}
    49  
    50  	resp, err := client.ListSender(req)
    51  	if err != nil {
    52  		result.Response = autorest.Response{Response: resp}
    53  		err = autorest.NewErrorWithError(err, "authoring.SettingsClient", "List", resp, "Failure sending request")
    54  		return
    55  	}
    56  
    57  	result, err = client.ListResponder(resp)
    58  	if err != nil {
    59  		err = autorest.NewErrorWithError(err, "authoring.SettingsClient", "List", resp, "Failure responding to request")
    60  		return
    61  	}
    62  
    63  	return
    64  }
    65  
    66  // ListPreparer prepares the List request.
    67  func (client SettingsClient) ListPreparer(ctx context.Context, appID uuid.UUID, versionID string) (*http.Request, error) {
    68  	urlParameters := map[string]interface{}{
    69  		"Endpoint": client.Endpoint,
    70  	}
    71  
    72  	pathParameters := map[string]interface{}{
    73  		"appId":     autorest.Encode("path", appID),
    74  		"versionId": autorest.Encode("path", versionID),
    75  	}
    76  
    77  	preparer := autorest.CreatePreparer(
    78  		autorest.AsGet(),
    79  		autorest.WithCustomBaseURL("{Endpoint}/luis/api/v2.0", urlParameters),
    80  		autorest.WithPathParameters("/apps/{appId}/versions/{versionId}/settings", pathParameters))
    81  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
    82  }
    83  
    84  // ListSender sends the List request. The method will close the
    85  // http.Response Body if it receives an error.
    86  func (client SettingsClient) ListSender(req *http.Request) (*http.Response, error) {
    87  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
    88  }
    89  
    90  // ListResponder handles the response to the List request. The method always
    91  // closes the http.Response Body.
    92  func (client SettingsClient) ListResponder(resp *http.Response) (result ListAppVersionSettingObject, err error) {
    93  	err = autorest.Respond(
    94  		resp,
    95  		azure.WithErrorUnlessStatusCode(http.StatusOK),
    96  		autorest.ByUnmarshallingJSON(&result.Value),
    97  		autorest.ByClosing())
    98  	result.Response = autorest.Response{Response: resp}
    99  	return
   100  }
   101  
   102  // Update updates the settings in a version of the application.
   103  // Parameters:
   104  // appID - the application ID.
   105  // versionID - the version ID.
   106  // listOfAppVersionSettingObject - a list of the updated application version settings.
   107  func (client SettingsClient) Update(ctx context.Context, appID uuid.UUID, versionID string, listOfAppVersionSettingObject []AppVersionSettingObject) (result OperationStatus, err error) {
   108  	if tracing.IsEnabled() {
   109  		ctx = tracing.StartSpan(ctx, fqdn+"/SettingsClient.Update")
   110  		defer func() {
   111  			sc := -1
   112  			if result.Response.Response != nil {
   113  				sc = result.Response.Response.StatusCode
   114  			}
   115  			tracing.EndSpan(ctx, sc, err)
   116  		}()
   117  	}
   118  	if err := validation.Validate([]validation.Validation{
   119  		{TargetValue: listOfAppVersionSettingObject,
   120  			Constraints: []validation.Constraint{{Target: "listOfAppVersionSettingObject", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil {
   121  		return result, validation.NewError("authoring.SettingsClient", "Update", err.Error())
   122  	}
   123  
   124  	req, err := client.UpdatePreparer(ctx, appID, versionID, listOfAppVersionSettingObject)
   125  	if err != nil {
   126  		err = autorest.NewErrorWithError(err, "authoring.SettingsClient", "Update", nil, "Failure preparing request")
   127  		return
   128  	}
   129  
   130  	resp, err := client.UpdateSender(req)
   131  	if err != nil {
   132  		result.Response = autorest.Response{Response: resp}
   133  		err = autorest.NewErrorWithError(err, "authoring.SettingsClient", "Update", resp, "Failure sending request")
   134  		return
   135  	}
   136  
   137  	result, err = client.UpdateResponder(resp)
   138  	if err != nil {
   139  		err = autorest.NewErrorWithError(err, "authoring.SettingsClient", "Update", resp, "Failure responding to request")
   140  		return
   141  	}
   142  
   143  	return
   144  }
   145  
   146  // UpdatePreparer prepares the Update request.
   147  func (client SettingsClient) UpdatePreparer(ctx context.Context, appID uuid.UUID, versionID string, listOfAppVersionSettingObject []AppVersionSettingObject) (*http.Request, error) {
   148  	urlParameters := map[string]interface{}{
   149  		"Endpoint": client.Endpoint,
   150  	}
   151  
   152  	pathParameters := map[string]interface{}{
   153  		"appId":     autorest.Encode("path", appID),
   154  		"versionId": autorest.Encode("path", versionID),
   155  	}
   156  
   157  	preparer := autorest.CreatePreparer(
   158  		autorest.AsContentType("application/json; charset=utf-8"),
   159  		autorest.AsPut(),
   160  		autorest.WithCustomBaseURL("{Endpoint}/luis/api/v2.0", urlParameters),
   161  		autorest.WithPathParameters("/apps/{appId}/versions/{versionId}/settings", pathParameters),
   162  		autorest.WithJSON(listOfAppVersionSettingObject))
   163  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   164  }
   165  
   166  // UpdateSender sends the Update request. The method will close the
   167  // http.Response Body if it receives an error.
   168  func (client SettingsClient) UpdateSender(req *http.Request) (*http.Response, error) {
   169  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   170  }
   171  
   172  // UpdateResponder handles the response to the Update request. The method always
   173  // closes the http.Response Body.
   174  func (client SettingsClient) UpdateResponder(resp *http.Response) (result OperationStatus, 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  

View as plain text