...

Source file src/github.com/Azure/azure-sdk-for-go/services/preview/iothub/mgmt/2019-07-01-preview/devices/resourceprovidercommon.go

Documentation: github.com/Azure/azure-sdk-for-go/services/preview/iothub/mgmt/2019-07-01-preview/devices

     1  package devices
     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  // ResourceProviderCommonClient is the use this API to manage the IoT hubs in your Azure subscription.
    18  type ResourceProviderCommonClient struct {
    19  	BaseClient
    20  }
    21  
    22  // NewResourceProviderCommonClient creates an instance of the ResourceProviderCommonClient client.
    23  func NewResourceProviderCommonClient(subscriptionID string) ResourceProviderCommonClient {
    24  	return NewResourceProviderCommonClientWithBaseURI(DefaultBaseURI, subscriptionID)
    25  }
    26  
    27  // NewResourceProviderCommonClientWithBaseURI creates an instance of the ResourceProviderCommonClient client using a
    28  // custom endpoint.  Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds,
    29  // Azure stack).
    30  func NewResourceProviderCommonClientWithBaseURI(baseURI string, subscriptionID string) ResourceProviderCommonClient {
    31  	return ResourceProviderCommonClient{NewWithBaseURI(baseURI, subscriptionID)}
    32  }
    33  
    34  // GetSubscriptionQuota get the number of free and paid iot hubs in the subscription
    35  func (client ResourceProviderCommonClient) GetSubscriptionQuota(ctx context.Context) (result UserSubscriptionQuotaListResult, err error) {
    36  	if tracing.IsEnabled() {
    37  		ctx = tracing.StartSpan(ctx, fqdn+"/ResourceProviderCommonClient.GetSubscriptionQuota")
    38  		defer func() {
    39  			sc := -1
    40  			if result.Response.Response != nil {
    41  				sc = result.Response.Response.StatusCode
    42  			}
    43  			tracing.EndSpan(ctx, sc, err)
    44  		}()
    45  	}
    46  	req, err := client.GetSubscriptionQuotaPreparer(ctx)
    47  	if err != nil {
    48  		err = autorest.NewErrorWithError(err, "devices.ResourceProviderCommonClient", "GetSubscriptionQuota", nil, "Failure preparing request")
    49  		return
    50  	}
    51  
    52  	resp, err := client.GetSubscriptionQuotaSender(req)
    53  	if err != nil {
    54  		result.Response = autorest.Response{Response: resp}
    55  		err = autorest.NewErrorWithError(err, "devices.ResourceProviderCommonClient", "GetSubscriptionQuota", resp, "Failure sending request")
    56  		return
    57  	}
    58  
    59  	result, err = client.GetSubscriptionQuotaResponder(resp)
    60  	if err != nil {
    61  		err = autorest.NewErrorWithError(err, "devices.ResourceProviderCommonClient", "GetSubscriptionQuota", resp, "Failure responding to request")
    62  		return
    63  	}
    64  
    65  	return
    66  }
    67  
    68  // GetSubscriptionQuotaPreparer prepares the GetSubscriptionQuota request.
    69  func (client ResourceProviderCommonClient) GetSubscriptionQuotaPreparer(ctx context.Context) (*http.Request, error) {
    70  	pathParameters := map[string]interface{}{
    71  		"subscriptionId": autorest.Encode("path", client.SubscriptionID),
    72  	}
    73  
    74  	const APIVersion = "2019-07-01-preview"
    75  	queryParameters := map[string]interface{}{
    76  		"api-version": APIVersion,
    77  	}
    78  
    79  	preparer := autorest.CreatePreparer(
    80  		autorest.AsGet(),
    81  		autorest.WithBaseURL(client.BaseURI),
    82  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Devices/usages", pathParameters),
    83  		autorest.WithQueryParameters(queryParameters))
    84  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
    85  }
    86  
    87  // GetSubscriptionQuotaSender sends the GetSubscriptionQuota request. The method will close the
    88  // http.Response Body if it receives an error.
    89  func (client ResourceProviderCommonClient) GetSubscriptionQuotaSender(req *http.Request) (*http.Response, error) {
    90  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
    91  }
    92  
    93  // GetSubscriptionQuotaResponder handles the response to the GetSubscriptionQuota request. The method always
    94  // closes the http.Response Body.
    95  func (client ResourceProviderCommonClient) GetSubscriptionQuotaResponder(resp *http.Response) (result UserSubscriptionQuotaListResult, err error) {
    96  	err = autorest.Respond(
    97  		resp,
    98  		azure.WithErrorUnlessStatusCode(http.StatusOK),
    99  		autorest.ByUnmarshallingJSON(&result),
   100  		autorest.ByClosing())
   101  	result.Response = autorest.Response{Response: resp}
   102  	return
   103  }
   104  

View as plain text