1package signalr
2
3// Copyright (c) Microsoft and contributors.  All rights reserved.
4//
5// Licensed under the Apache License, Version 2.0 (the "License");
6// you may not use this file except in compliance with the License.
7// You may obtain a copy of the License at
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13//
14// See the License for the specific language governing permissions and
15// limitations under the License.
16//
17// Code generated by Microsoft (R) AutoRest Code Generator.
18// Changes may cause incorrect behavior and will be lost if the code is regenerated.
19
20import (
21	"context"
22	"github.com/Azure/go-autorest/autorest"
23	"github.com/Azure/go-autorest/autorest/azure"
24	"github.com/Azure/go-autorest/tracing"
25	"net/http"
26)
27
28// UsagesClient is the REST API for Azure SignalR Service
29type UsagesClient struct {
30	BaseClient
31}
32
33// NewUsagesClient creates an instance of the UsagesClient client.
34func NewUsagesClient(subscriptionID string) UsagesClient {
35	return NewUsagesClientWithBaseURI(DefaultBaseURI, subscriptionID)
36}
37
38// NewUsagesClientWithBaseURI creates an instance of the UsagesClient client using a custom endpoint.  Use this when
39// interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
40func NewUsagesClientWithBaseURI(baseURI string, subscriptionID string) UsagesClient {
41	return UsagesClient{NewWithBaseURI(baseURI, subscriptionID)}
42}
43
44// List list usage quotas for Azure SignalR service by location.
45// Parameters:
46// location - the location like "eastus"
47func (client UsagesClient) List(ctx context.Context, location string) (result UsageListPage, err error) {
48	if tracing.IsEnabled() {
49		ctx = tracing.StartSpan(ctx, fqdn+"/UsagesClient.List")
50		defer func() {
51			sc := -1
52			if result.ul.Response.Response != nil {
53				sc = result.ul.Response.Response.StatusCode
54			}
55			tracing.EndSpan(ctx, sc, err)
56		}()
57	}
58	result.fn = client.listNextResults
59	req, err := client.ListPreparer(ctx, location)
60	if err != nil {
61		err = autorest.NewErrorWithError(err, "signalr.UsagesClient", "List", nil, "Failure preparing request")
62		return
63	}
64
65	resp, err := client.ListSender(req)
66	if err != nil {
67		result.ul.Response = autorest.Response{Response: resp}
68		err = autorest.NewErrorWithError(err, "signalr.UsagesClient", "List", resp, "Failure sending request")
69		return
70	}
71
72	result.ul, err = client.ListResponder(resp)
73	if err != nil {
74		err = autorest.NewErrorWithError(err, "signalr.UsagesClient", "List", resp, "Failure responding to request")
75	}
76
77	return
78}
79
80// ListPreparer prepares the List request.
81func (client UsagesClient) ListPreparer(ctx context.Context, location string) (*http.Request, error) {
82	pathParameters := map[string]interface{}{
83		"location":       autorest.Encode("path", location),
84		"subscriptionId": autorest.Encode("path", client.SubscriptionID),
85	}
86
87	const APIVersion = "2018-10-01"
88	queryParameters := map[string]interface{}{
89		"api-version": APIVersion,
90	}
91
92	preparer := autorest.CreatePreparer(
93		autorest.AsGet(),
94		autorest.WithBaseURL(client.BaseURI),
95		autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.SignalRService/locations/{location}/usages", pathParameters),
96		autorest.WithQueryParameters(queryParameters))
97	return preparer.Prepare((&http.Request{}).WithContext(ctx))
98}
99
100// ListSender sends the List request. The method will close the
101// http.Response Body if it receives an error.
102func (client UsagesClient) ListSender(req *http.Request) (*http.Response, error) {
103	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
104}
105
106// ListResponder handles the response to the List request. The method always
107// closes the http.Response Body.
108func (client UsagesClient) ListResponder(resp *http.Response) (result UsageList, err error) {
109	err = autorest.Respond(
110		resp,
111		client.ByInspecting(),
112		azure.WithErrorUnlessStatusCode(http.StatusOK),
113		autorest.ByUnmarshallingJSON(&result),
114		autorest.ByClosing())
115	result.Response = autorest.Response{Response: resp}
116	return
117}
118
119// listNextResults retrieves the next set of results, if any.
120func (client UsagesClient) listNextResults(ctx context.Context, lastResults UsageList) (result UsageList, err error) {
121	req, err := lastResults.usageListPreparer(ctx)
122	if err != nil {
123		return result, autorest.NewErrorWithError(err, "signalr.UsagesClient", "listNextResults", nil, "Failure preparing next results request")
124	}
125	if req == nil {
126		return
127	}
128	resp, err := client.ListSender(req)
129	if err != nil {
130		result.Response = autorest.Response{Response: resp}
131		return result, autorest.NewErrorWithError(err, "signalr.UsagesClient", "listNextResults", resp, "Failure sending next results request")
132	}
133	result, err = client.ListResponder(resp)
134	if err != nil {
135		err = autorest.NewErrorWithError(err, "signalr.UsagesClient", "listNextResults", resp, "Failure responding to next results request")
136	}
137	return
138}
139
140// ListComplete enumerates all values, automatically crossing page boundaries as required.
141func (client UsagesClient) ListComplete(ctx context.Context, location string) (result UsageListIterator, err error) {
142	if tracing.IsEnabled() {
143		ctx = tracing.StartSpan(ctx, fqdn+"/UsagesClient.List")
144		defer func() {
145			sc := -1
146			if result.Response().Response.Response != nil {
147				sc = result.page.Response().Response.Response.StatusCode
148			}
149			tracing.EndSpan(ctx, sc, err)
150		}()
151	}
152	result.page, err = client.List(ctx, location)
153	return
154}
155