1package qnamaker 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/autorest/validation" 14 "github.com/Azure/go-autorest/tracing" 15 "net/http" 16) 17 18// AlterationsClient is the an API for QnAMaker Service 19type AlterationsClient struct { 20 BaseClient 21} 22 23// NewAlterationsClient creates an instance of the AlterationsClient client. 24func NewAlterationsClient(endpoint string) AlterationsClient { 25 return AlterationsClient{New(endpoint)} 26} 27 28// Get sends the get request. 29func (client AlterationsClient) Get(ctx context.Context) (result WordAlterationsDTO, err error) { 30 if tracing.IsEnabled() { 31 ctx = tracing.StartSpan(ctx, fqdn+"/AlterationsClient.Get") 32 defer func() { 33 sc := -1 34 if result.Response.Response != nil { 35 sc = result.Response.Response.StatusCode 36 } 37 tracing.EndSpan(ctx, sc, err) 38 }() 39 } 40 req, err := client.GetPreparer(ctx) 41 if err != nil { 42 err = autorest.NewErrorWithError(err, "qnamaker.AlterationsClient", "Get", nil, "Failure preparing request") 43 return 44 } 45 46 resp, err := client.GetSender(req) 47 if err != nil { 48 result.Response = autorest.Response{Response: resp} 49 err = autorest.NewErrorWithError(err, "qnamaker.AlterationsClient", "Get", resp, "Failure sending request") 50 return 51 } 52 53 result, err = client.GetResponder(resp) 54 if err != nil { 55 err = autorest.NewErrorWithError(err, "qnamaker.AlterationsClient", "Get", resp, "Failure responding to request") 56 return 57 } 58 59 return 60} 61 62// GetPreparer prepares the Get request. 63func (client AlterationsClient) GetPreparer(ctx context.Context) (*http.Request, error) { 64 urlParameters := map[string]interface{}{ 65 "Endpoint": client.Endpoint, 66 } 67 68 preparer := autorest.CreatePreparer( 69 autorest.AsGet(), 70 autorest.WithCustomBaseURL("{Endpoint}/qnamaker/v4.0", urlParameters), 71 autorest.WithPath("/alterations")) 72 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 73} 74 75// GetSender sends the Get request. The method will close the 76// http.Response Body if it receives an error. 77func (client AlterationsClient) GetSender(req *http.Request) (*http.Response, error) { 78 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) 79} 80 81// GetResponder handles the response to the Get request. The method always 82// closes the http.Response Body. 83func (client AlterationsClient) GetResponder(resp *http.Response) (result WordAlterationsDTO, err error) { 84 err = autorest.Respond( 85 resp, 86 azure.WithErrorUnlessStatusCode(http.StatusOK), 87 autorest.ByUnmarshallingJSON(&result), 88 autorest.ByClosing()) 89 result.Response = autorest.Response{Response: resp} 90 return 91} 92 93// Replace sends the replace request. 94// Parameters: 95// wordAlterations - new alterations data. 96func (client AlterationsClient) Replace(ctx context.Context, wordAlterations WordAlterationsDTO) (result autorest.Response, err error) { 97 if tracing.IsEnabled() { 98 ctx = tracing.StartSpan(ctx, fqdn+"/AlterationsClient.Replace") 99 defer func() { 100 sc := -1 101 if result.Response != nil { 102 sc = result.Response.StatusCode 103 } 104 tracing.EndSpan(ctx, sc, err) 105 }() 106 } 107 if err := validation.Validate([]validation.Validation{ 108 {TargetValue: wordAlterations, 109 Constraints: []validation.Constraint{{Target: "wordAlterations.WordAlterations", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil { 110 return result, validation.NewError("qnamaker.AlterationsClient", "Replace", err.Error()) 111 } 112 113 req, err := client.ReplacePreparer(ctx, wordAlterations) 114 if err != nil { 115 err = autorest.NewErrorWithError(err, "qnamaker.AlterationsClient", "Replace", nil, "Failure preparing request") 116 return 117 } 118 119 resp, err := client.ReplaceSender(req) 120 if err != nil { 121 result.Response = resp 122 err = autorest.NewErrorWithError(err, "qnamaker.AlterationsClient", "Replace", resp, "Failure sending request") 123 return 124 } 125 126 result, err = client.ReplaceResponder(resp) 127 if err != nil { 128 err = autorest.NewErrorWithError(err, "qnamaker.AlterationsClient", "Replace", resp, "Failure responding to request") 129 return 130 } 131 132 return 133} 134 135// ReplacePreparer prepares the Replace request. 136func (client AlterationsClient) ReplacePreparer(ctx context.Context, wordAlterations WordAlterationsDTO) (*http.Request, error) { 137 urlParameters := map[string]interface{}{ 138 "Endpoint": client.Endpoint, 139 } 140 141 preparer := autorest.CreatePreparer( 142 autorest.AsContentType("application/json; charset=utf-8"), 143 autorest.AsPut(), 144 autorest.WithCustomBaseURL("{Endpoint}/qnamaker/v4.0", urlParameters), 145 autorest.WithPath("/alterations"), 146 autorest.WithJSON(wordAlterations)) 147 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 148} 149 150// ReplaceSender sends the Replace request. The method will close the 151// http.Response Body if it receives an error. 152func (client AlterationsClient) ReplaceSender(req *http.Request) (*http.Response, error) { 153 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) 154} 155 156// ReplaceResponder handles the response to the Replace request. The method always 157// closes the http.Response Body. 158func (client AlterationsClient) ReplaceResponder(resp *http.Response) (result autorest.Response, err error) { 159 err = autorest.Respond( 160 resp, 161 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent), 162 autorest.ByClosing()) 163 result.Response = resp 164 return 165} 166