...

Source file src/github.com/Azure/azure-sdk-for-go/services/consumption/mgmt/2018-03-31/consumption/marketplacesbydepartment.go

Documentation: github.com/Azure/azure-sdk-for-go/services/consumption/mgmt/2018-03-31/consumption

     1  package consumption
     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  	"net/http"
    16  )
    17  
    18  // MarketplacesByDepartmentClient is the consumption management client provides access to consumption resources for
    19  // Azure Enterprise Subscriptions.
    20  type MarketplacesByDepartmentClient struct {
    21  	BaseClient
    22  }
    23  
    24  // NewMarketplacesByDepartmentClient creates an instance of the MarketplacesByDepartmentClient client.
    25  func NewMarketplacesByDepartmentClient(subscriptionID string) MarketplacesByDepartmentClient {
    26  	return NewMarketplacesByDepartmentClientWithBaseURI(DefaultBaseURI, subscriptionID)
    27  }
    28  
    29  // NewMarketplacesByDepartmentClientWithBaseURI creates an instance of the MarketplacesByDepartmentClient client using
    30  // a custom endpoint.  Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign
    31  // clouds, Azure stack).
    32  func NewMarketplacesByDepartmentClientWithBaseURI(baseURI string, subscriptionID string) MarketplacesByDepartmentClient {
    33  	return MarketplacesByDepartmentClient{NewWithBaseURI(baseURI, subscriptionID)}
    34  }
    35  
    36  // List lists the marketplaces for a scope by departmentId and current billing period. Marketplaces are available via
    37  // this API only for May 1, 2014 or later.
    38  // Parameters:
    39  // departmentID - department ID
    40  // filter - may be used to filter marketplaces by properties/usageEnd (Utc time), properties/usageStart (Utc
    41  // time), properties/resourceGroup, properties/instanceName or properties/instanceId. The filter supports 'eq',
    42  // 'lt', 'gt', 'le', 'ge', and 'and'. It does not currently support 'ne', 'or', or 'not'.
    43  // top - may be used to limit the number of results to the most recent N marketplaces.
    44  // skiptoken - skiptoken is only used if a previous operation returned a partial result. If a previous response
    45  // contains a nextLink element, the value of the nextLink element will include a skiptoken parameter that
    46  // specifies a starting point to use for subsequent calls.
    47  func (client MarketplacesByDepartmentClient) List(ctx context.Context, departmentID string, filter string, top *int32, skiptoken string) (result MarketplacesListResultPage, err error) {
    48  	if tracing.IsEnabled() {
    49  		ctx = tracing.StartSpan(ctx, fqdn+"/MarketplacesByDepartmentClient.List")
    50  		defer func() {
    51  			sc := -1
    52  			if result.mlr.Response.Response != nil {
    53  				sc = result.mlr.Response.Response.StatusCode
    54  			}
    55  			tracing.EndSpan(ctx, sc, err)
    56  		}()
    57  	}
    58  	if err := validation.Validate([]validation.Validation{
    59  		{TargetValue: top,
    60  			Constraints: []validation.Constraint{{Target: "top", Name: validation.Null, Rule: false,
    61  				Chain: []validation.Constraint{{Target: "top", Name: validation.InclusiveMaximum, Rule: int64(1000), Chain: nil},
    62  					{Target: "top", Name: validation.InclusiveMinimum, Rule: int64(1), Chain: nil},
    63  				}}}}}); err != nil {
    64  		return result, validation.NewError("consumption.MarketplacesByDepartmentClient", "List", err.Error())
    65  	}
    66  
    67  	result.fn = client.listNextResults
    68  	req, err := client.ListPreparer(ctx, departmentID, filter, top, skiptoken)
    69  	if err != nil {
    70  		err = autorest.NewErrorWithError(err, "consumption.MarketplacesByDepartmentClient", "List", nil, "Failure preparing request")
    71  		return
    72  	}
    73  
    74  	resp, err := client.ListSender(req)
    75  	if err != nil {
    76  		result.mlr.Response = autorest.Response{Response: resp}
    77  		err = autorest.NewErrorWithError(err, "consumption.MarketplacesByDepartmentClient", "List", resp, "Failure sending request")
    78  		return
    79  	}
    80  
    81  	result.mlr, err = client.ListResponder(resp)
    82  	if err != nil {
    83  		err = autorest.NewErrorWithError(err, "consumption.MarketplacesByDepartmentClient", "List", resp, "Failure responding to request")
    84  		return
    85  	}
    86  	if result.mlr.hasNextLink() && result.mlr.IsEmpty() {
    87  		err = result.NextWithContext(ctx)
    88  		return
    89  	}
    90  
    91  	return
    92  }
    93  
    94  // ListPreparer prepares the List request.
    95  func (client MarketplacesByDepartmentClient) ListPreparer(ctx context.Context, departmentID string, filter string, top *int32, skiptoken string) (*http.Request, error) {
    96  	pathParameters := map[string]interface{}{
    97  		"departmentId": autorest.Encode("path", departmentID),
    98  	}
    99  
   100  	const APIVersion = "2018-03-31"
   101  	queryParameters := map[string]interface{}{
   102  		"api-version": APIVersion,
   103  	}
   104  	if len(filter) > 0 {
   105  		queryParameters["$filter"] = autorest.Encode("query", filter)
   106  	}
   107  	if top != nil {
   108  		queryParameters["$top"] = autorest.Encode("query", *top)
   109  	}
   110  	if len(skiptoken) > 0 {
   111  		queryParameters["$skiptoken"] = autorest.Encode("query", skiptoken)
   112  	}
   113  
   114  	preparer := autorest.CreatePreparer(
   115  		autorest.AsGet(),
   116  		autorest.WithBaseURL(client.BaseURI),
   117  		autorest.WithPathParameters("/providers/Microsoft.Billing/departments/{departmentId}/providers/Microsoft.Consumption/marketplaces", pathParameters),
   118  		autorest.WithQueryParameters(queryParameters))
   119  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   120  }
   121  
   122  // ListSender sends the List request. The method will close the
   123  // http.Response Body if it receives an error.
   124  func (client MarketplacesByDepartmentClient) ListSender(req *http.Request) (*http.Response, error) {
   125  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   126  }
   127  
   128  // ListResponder handles the response to the List request. The method always
   129  // closes the http.Response Body.
   130  func (client MarketplacesByDepartmentClient) ListResponder(resp *http.Response) (result MarketplacesListResult, err error) {
   131  	err = autorest.Respond(
   132  		resp,
   133  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   134  		autorest.ByUnmarshallingJSON(&result),
   135  		autorest.ByClosing())
   136  	result.Response = autorest.Response{Response: resp}
   137  	return
   138  }
   139  
   140  // listNextResults retrieves the next set of results, if any.
   141  func (client MarketplacesByDepartmentClient) listNextResults(ctx context.Context, lastResults MarketplacesListResult) (result MarketplacesListResult, err error) {
   142  	req, err := lastResults.marketplacesListResultPreparer(ctx)
   143  	if err != nil {
   144  		return result, autorest.NewErrorWithError(err, "consumption.MarketplacesByDepartmentClient", "listNextResults", nil, "Failure preparing next results request")
   145  	}
   146  	if req == nil {
   147  		return
   148  	}
   149  	resp, err := client.ListSender(req)
   150  	if err != nil {
   151  		result.Response = autorest.Response{Response: resp}
   152  		return result, autorest.NewErrorWithError(err, "consumption.MarketplacesByDepartmentClient", "listNextResults", resp, "Failure sending next results request")
   153  	}
   154  	result, err = client.ListResponder(resp)
   155  	if err != nil {
   156  		err = autorest.NewErrorWithError(err, "consumption.MarketplacesByDepartmentClient", "listNextResults", resp, "Failure responding to next results request")
   157  	}
   158  	return
   159  }
   160  
   161  // ListComplete enumerates all values, automatically crossing page boundaries as required.
   162  func (client MarketplacesByDepartmentClient) ListComplete(ctx context.Context, departmentID string, filter string, top *int32, skiptoken string) (result MarketplacesListResultIterator, err error) {
   163  	if tracing.IsEnabled() {
   164  		ctx = tracing.StartSpan(ctx, fqdn+"/MarketplacesByDepartmentClient.List")
   165  		defer func() {
   166  			sc := -1
   167  			if result.Response().Response.Response != nil {
   168  				sc = result.page.Response().Response.Response.StatusCode
   169  			}
   170  			tracing.EndSpan(ctx, sc, err)
   171  		}()
   172  	}
   173  	result.page, err = client.List(ctx, departmentID, filter, top, skiptoken)
   174  	return
   175  }
   176  
   177  // ListByBillingPeriod lists the marketplaces for a scope by billing period and departmentId. Marketplaces are
   178  // available via this API only for May 1, 2014 or later.
   179  // Parameters:
   180  // departmentID - department ID
   181  // billingPeriodName - billing Period Name.
   182  // filter - may be used to filter marketplaces by properties/usageEnd (Utc time), properties/usageStart (Utc
   183  // time), properties/resourceGroup, properties/instanceName or properties/instanceId. The filter supports 'eq',
   184  // 'lt', 'gt', 'le', 'ge', and 'and'. It does not currently support 'ne', 'or', or 'not'.
   185  // top - may be used to limit the number of results to the most recent N marketplaces.
   186  // skiptoken - skiptoken is only used if a previous operation returned a partial result. If a previous response
   187  // contains a nextLink element, the value of the nextLink element will include a skiptoken parameter that
   188  // specifies a starting point to use for subsequent calls.
   189  func (client MarketplacesByDepartmentClient) ListByBillingPeriod(ctx context.Context, departmentID string, billingPeriodName string, filter string, top *int32, skiptoken string) (result MarketplacesListResultPage, err error) {
   190  	if tracing.IsEnabled() {
   191  		ctx = tracing.StartSpan(ctx, fqdn+"/MarketplacesByDepartmentClient.ListByBillingPeriod")
   192  		defer func() {
   193  			sc := -1
   194  			if result.mlr.Response.Response != nil {
   195  				sc = result.mlr.Response.Response.StatusCode
   196  			}
   197  			tracing.EndSpan(ctx, sc, err)
   198  		}()
   199  	}
   200  	if err := validation.Validate([]validation.Validation{
   201  		{TargetValue: top,
   202  			Constraints: []validation.Constraint{{Target: "top", Name: validation.Null, Rule: false,
   203  				Chain: []validation.Constraint{{Target: "top", Name: validation.InclusiveMaximum, Rule: int64(1000), Chain: nil},
   204  					{Target: "top", Name: validation.InclusiveMinimum, Rule: int64(1), Chain: nil},
   205  				}}}}}); err != nil {
   206  		return result, validation.NewError("consumption.MarketplacesByDepartmentClient", "ListByBillingPeriod", err.Error())
   207  	}
   208  
   209  	result.fn = client.listByBillingPeriodNextResults
   210  	req, err := client.ListByBillingPeriodPreparer(ctx, departmentID, billingPeriodName, filter, top, skiptoken)
   211  	if err != nil {
   212  		err = autorest.NewErrorWithError(err, "consumption.MarketplacesByDepartmentClient", "ListByBillingPeriod", nil, "Failure preparing request")
   213  		return
   214  	}
   215  
   216  	resp, err := client.ListByBillingPeriodSender(req)
   217  	if err != nil {
   218  		result.mlr.Response = autorest.Response{Response: resp}
   219  		err = autorest.NewErrorWithError(err, "consumption.MarketplacesByDepartmentClient", "ListByBillingPeriod", resp, "Failure sending request")
   220  		return
   221  	}
   222  
   223  	result.mlr, err = client.ListByBillingPeriodResponder(resp)
   224  	if err != nil {
   225  		err = autorest.NewErrorWithError(err, "consumption.MarketplacesByDepartmentClient", "ListByBillingPeriod", resp, "Failure responding to request")
   226  		return
   227  	}
   228  	if result.mlr.hasNextLink() && result.mlr.IsEmpty() {
   229  		err = result.NextWithContext(ctx)
   230  		return
   231  	}
   232  
   233  	return
   234  }
   235  
   236  // ListByBillingPeriodPreparer prepares the ListByBillingPeriod request.
   237  func (client MarketplacesByDepartmentClient) ListByBillingPeriodPreparer(ctx context.Context, departmentID string, billingPeriodName string, filter string, top *int32, skiptoken string) (*http.Request, error) {
   238  	pathParameters := map[string]interface{}{
   239  		"billingPeriodName": autorest.Encode("path", billingPeriodName),
   240  		"departmentId":      autorest.Encode("path", departmentID),
   241  	}
   242  
   243  	const APIVersion = "2018-03-31"
   244  	queryParameters := map[string]interface{}{
   245  		"api-version": APIVersion,
   246  	}
   247  	if len(filter) > 0 {
   248  		queryParameters["$filter"] = autorest.Encode("query", filter)
   249  	}
   250  	if top != nil {
   251  		queryParameters["$top"] = autorest.Encode("query", *top)
   252  	}
   253  	if len(skiptoken) > 0 {
   254  		queryParameters["$skiptoken"] = autorest.Encode("query", skiptoken)
   255  	}
   256  
   257  	preparer := autorest.CreatePreparer(
   258  		autorest.AsGet(),
   259  		autorest.WithBaseURL(client.BaseURI),
   260  		autorest.WithPathParameters("/providers/Microsoft.Billing/departments/{departmentId}/providers/Microsoft.Billing/billingPeriods/{billingPeriodName}/providers/Microsoft.Consumption/marketplaces", pathParameters),
   261  		autorest.WithQueryParameters(queryParameters))
   262  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   263  }
   264  
   265  // ListByBillingPeriodSender sends the ListByBillingPeriod request. The method will close the
   266  // http.Response Body if it receives an error.
   267  func (client MarketplacesByDepartmentClient) ListByBillingPeriodSender(req *http.Request) (*http.Response, error) {
   268  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   269  }
   270  
   271  // ListByBillingPeriodResponder handles the response to the ListByBillingPeriod request. The method always
   272  // closes the http.Response Body.
   273  func (client MarketplacesByDepartmentClient) ListByBillingPeriodResponder(resp *http.Response) (result MarketplacesListResult, err error) {
   274  	err = autorest.Respond(
   275  		resp,
   276  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   277  		autorest.ByUnmarshallingJSON(&result),
   278  		autorest.ByClosing())
   279  	result.Response = autorest.Response{Response: resp}
   280  	return
   281  }
   282  
   283  // listByBillingPeriodNextResults retrieves the next set of results, if any.
   284  func (client MarketplacesByDepartmentClient) listByBillingPeriodNextResults(ctx context.Context, lastResults MarketplacesListResult) (result MarketplacesListResult, err error) {
   285  	req, err := lastResults.marketplacesListResultPreparer(ctx)
   286  	if err != nil {
   287  		return result, autorest.NewErrorWithError(err, "consumption.MarketplacesByDepartmentClient", "listByBillingPeriodNextResults", nil, "Failure preparing next results request")
   288  	}
   289  	if req == nil {
   290  		return
   291  	}
   292  	resp, err := client.ListByBillingPeriodSender(req)
   293  	if err != nil {
   294  		result.Response = autorest.Response{Response: resp}
   295  		return result, autorest.NewErrorWithError(err, "consumption.MarketplacesByDepartmentClient", "listByBillingPeriodNextResults", resp, "Failure sending next results request")
   296  	}
   297  	result, err = client.ListByBillingPeriodResponder(resp)
   298  	if err != nil {
   299  		err = autorest.NewErrorWithError(err, "consumption.MarketplacesByDepartmentClient", "listByBillingPeriodNextResults", resp, "Failure responding to next results request")
   300  	}
   301  	return
   302  }
   303  
   304  // ListByBillingPeriodComplete enumerates all values, automatically crossing page boundaries as required.
   305  func (client MarketplacesByDepartmentClient) ListByBillingPeriodComplete(ctx context.Context, departmentID string, billingPeriodName string, filter string, top *int32, skiptoken string) (result MarketplacesListResultIterator, err error) {
   306  	if tracing.IsEnabled() {
   307  		ctx = tracing.StartSpan(ctx, fqdn+"/MarketplacesByDepartmentClient.ListByBillingPeriod")
   308  		defer func() {
   309  			sc := -1
   310  			if result.Response().Response.Response != nil {
   311  				sc = result.page.Response().Response.Response.StatusCode
   312  			}
   313  			tracing.EndSpan(ctx, sc, err)
   314  		}()
   315  	}
   316  	result.page, err = client.ListByBillingPeriod(ctx, departmentID, billingPeriodName, filter, top, skiptoken)
   317  	return
   318  }
   319  

View as plain text