...

Source file src/github.com/Azure/azure-sdk-for-go/services/preview/machinelearning/mgmt/2016-05-01-preview/commitmentplans/usagehistory.go

Documentation: github.com/Azure/azure-sdk-for-go/services/preview/machinelearning/mgmt/2016-05-01-preview/commitmentplans

     1  package commitmentplans
     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/tracing"
    14  	"net/http"
    15  )
    16  
    17  // UsageHistoryClient is the these APIs allow end users to operate on Azure Machine Learning Commitment Plans resources
    18  // and their child Commitment Association resources. They support CRUD operations for commitment plans, get and list
    19  // operations for commitment associations, moving commitment associations between commitment plans, and retrieving
    20  // commitment plan usage history.
    21  type UsageHistoryClient struct {
    22  	BaseClient
    23  }
    24  
    25  // NewUsageHistoryClient creates an instance of the UsageHistoryClient client.
    26  func NewUsageHistoryClient(subscriptionID string) UsageHistoryClient {
    27  	return NewUsageHistoryClientWithBaseURI(DefaultBaseURI, subscriptionID)
    28  }
    29  
    30  // NewUsageHistoryClientWithBaseURI creates an instance of the UsageHistoryClient client using a custom endpoint.  Use
    31  // this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
    32  func NewUsageHistoryClientWithBaseURI(baseURI string, subscriptionID string) UsageHistoryClient {
    33  	return UsageHistoryClient{NewWithBaseURI(baseURI, subscriptionID)}
    34  }
    35  
    36  // List retrieve the usage history for an Azure ML commitment plan.
    37  // Parameters:
    38  // resourceGroupName - the resource group name.
    39  // commitmentPlanName - the Azure ML commitment plan name.
    40  // skipToken - continuation token for pagination.
    41  func (client UsageHistoryClient) List(ctx context.Context, resourceGroupName string, commitmentPlanName string, skipToken string) (result PlanUsageHistoryListResultPage, err error) {
    42  	if tracing.IsEnabled() {
    43  		ctx = tracing.StartSpan(ctx, fqdn+"/UsageHistoryClient.List")
    44  		defer func() {
    45  			sc := -1
    46  			if result.puhlr.Response.Response != nil {
    47  				sc = result.puhlr.Response.Response.StatusCode
    48  			}
    49  			tracing.EndSpan(ctx, sc, err)
    50  		}()
    51  	}
    52  	result.fn = client.listNextResults
    53  	req, err := client.ListPreparer(ctx, resourceGroupName, commitmentPlanName, skipToken)
    54  	if err != nil {
    55  		err = autorest.NewErrorWithError(err, "commitmentplans.UsageHistoryClient", "List", nil, "Failure preparing request")
    56  		return
    57  	}
    58  
    59  	resp, err := client.ListSender(req)
    60  	if err != nil {
    61  		result.puhlr.Response = autorest.Response{Response: resp}
    62  		err = autorest.NewErrorWithError(err, "commitmentplans.UsageHistoryClient", "List", resp, "Failure sending request")
    63  		return
    64  	}
    65  
    66  	result.puhlr, err = client.ListResponder(resp)
    67  	if err != nil {
    68  		err = autorest.NewErrorWithError(err, "commitmentplans.UsageHistoryClient", "List", resp, "Failure responding to request")
    69  		return
    70  	}
    71  	if result.puhlr.hasNextLink() && result.puhlr.IsEmpty() {
    72  		err = result.NextWithContext(ctx)
    73  		return
    74  	}
    75  
    76  	return
    77  }
    78  
    79  // ListPreparer prepares the List request.
    80  func (client UsageHistoryClient) ListPreparer(ctx context.Context, resourceGroupName string, commitmentPlanName string, skipToken string) (*http.Request, error) {
    81  	pathParameters := map[string]interface{}{
    82  		"commitmentPlanName": autorest.Encode("path", commitmentPlanName),
    83  		"resourceGroupName":  autorest.Encode("path", resourceGroupName),
    84  		"subscriptionId":     autorest.Encode("path", client.SubscriptionID),
    85  	}
    86  
    87  	const APIVersion = "2016-05-01-preview"
    88  	queryParameters := map[string]interface{}{
    89  		"api-version": APIVersion,
    90  	}
    91  	if len(skipToken) > 0 {
    92  		queryParameters["$skipToken"] = autorest.Encode("query", skipToken)
    93  	}
    94  
    95  	preparer := autorest.CreatePreparer(
    96  		autorest.AsGet(),
    97  		autorest.WithBaseURL(client.BaseURI),
    98  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.MachineLearning/commitmentPlans/{commitmentPlanName}/usageHistory", pathParameters),
    99  		autorest.WithQueryParameters(queryParameters))
   100  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   101  }
   102  
   103  // ListSender sends the List request. The method will close the
   104  // http.Response Body if it receives an error.
   105  func (client UsageHistoryClient) ListSender(req *http.Request) (*http.Response, error) {
   106  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   107  }
   108  
   109  // ListResponder handles the response to the List request. The method always
   110  // closes the http.Response Body.
   111  func (client UsageHistoryClient) ListResponder(resp *http.Response) (result PlanUsageHistoryListResult, err error) {
   112  	err = autorest.Respond(
   113  		resp,
   114  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   115  		autorest.ByUnmarshallingJSON(&result),
   116  		autorest.ByClosing())
   117  	result.Response = autorest.Response{Response: resp}
   118  	return
   119  }
   120  
   121  // listNextResults retrieves the next set of results, if any.
   122  func (client UsageHistoryClient) listNextResults(ctx context.Context, lastResults PlanUsageHistoryListResult) (result PlanUsageHistoryListResult, err error) {
   123  	req, err := lastResults.planUsageHistoryListResultPreparer(ctx)
   124  	if err != nil {
   125  		return result, autorest.NewErrorWithError(err, "commitmentplans.UsageHistoryClient", "listNextResults", nil, "Failure preparing next results request")
   126  	}
   127  	if req == nil {
   128  		return
   129  	}
   130  	resp, err := client.ListSender(req)
   131  	if err != nil {
   132  		result.Response = autorest.Response{Response: resp}
   133  		return result, autorest.NewErrorWithError(err, "commitmentplans.UsageHistoryClient", "listNextResults", resp, "Failure sending next results request")
   134  	}
   135  	result, err = client.ListResponder(resp)
   136  	if err != nil {
   137  		err = autorest.NewErrorWithError(err, "commitmentplans.UsageHistoryClient", "listNextResults", resp, "Failure responding to next results request")
   138  	}
   139  	return
   140  }
   141  
   142  // ListComplete enumerates all values, automatically crossing page boundaries as required.
   143  func (client UsageHistoryClient) ListComplete(ctx context.Context, resourceGroupName string, commitmentPlanName string, skipToken string) (result PlanUsageHistoryListResultIterator, err error) {
   144  	if tracing.IsEnabled() {
   145  		ctx = tracing.StartSpan(ctx, fqdn+"/UsageHistoryClient.List")
   146  		defer func() {
   147  			sc := -1
   148  			if result.Response().Response.Response != nil {
   149  				sc = result.page.Response().Response.Response.StatusCode
   150  			}
   151  			tracing.EndSpan(ctx, sc, err)
   152  		}()
   153  	}
   154  	result.page, err = client.List(ctx, resourceGroupName, commitmentPlanName, skipToken)
   155  	return
   156  }
   157  

View as plain text