1package resourcehealth
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/tracing"
14	"net/http"
15)
16
17// EmergingIssuesClient is the the Resource Health Client.
18type EmergingIssuesClient struct {
19	BaseClient
20}
21
22// NewEmergingIssuesClient creates an instance of the EmergingIssuesClient client.
23func NewEmergingIssuesClient(subscriptionID string) EmergingIssuesClient {
24	return NewEmergingIssuesClientWithBaseURI(DefaultBaseURI, subscriptionID)
25}
26
27// NewEmergingIssuesClientWithBaseURI creates an instance of the EmergingIssuesClient client using a custom endpoint.
28// Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
29func NewEmergingIssuesClientWithBaseURI(baseURI string, subscriptionID string) EmergingIssuesClient {
30	return EmergingIssuesClient{NewWithBaseURI(baseURI, subscriptionID)}
31}
32
33// Get gets Azure services' emerging issues.
34func (client EmergingIssuesClient) Get(ctx context.Context) (result EmergingIssuesGetResult, err error) {
35	if tracing.IsEnabled() {
36		ctx = tracing.StartSpan(ctx, fqdn+"/EmergingIssuesClient.Get")
37		defer func() {
38			sc := -1
39			if result.Response.Response != nil {
40				sc = result.Response.Response.StatusCode
41			}
42			tracing.EndSpan(ctx, sc, err)
43		}()
44	}
45	req, err := client.GetPreparer(ctx)
46	if err != nil {
47		err = autorest.NewErrorWithError(err, "resourcehealth.EmergingIssuesClient", "Get", nil, "Failure preparing request")
48		return
49	}
50
51	resp, err := client.GetSender(req)
52	if err != nil {
53		result.Response = autorest.Response{Response: resp}
54		err = autorest.NewErrorWithError(err, "resourcehealth.EmergingIssuesClient", "Get", resp, "Failure sending request")
55		return
56	}
57
58	result, err = client.GetResponder(resp)
59	if err != nil {
60		err = autorest.NewErrorWithError(err, "resourcehealth.EmergingIssuesClient", "Get", resp, "Failure responding to request")
61		return
62	}
63
64	return
65}
66
67// GetPreparer prepares the Get request.
68func (client EmergingIssuesClient) GetPreparer(ctx context.Context) (*http.Request, error) {
69	pathParameters := map[string]interface{}{
70		"issueName": autorest.Encode("path", "default"),
71	}
72
73	const APIVersion = "2017-07-01"
74	queryParameters := map[string]interface{}{
75		"api-version": APIVersion,
76	}
77
78	preparer := autorest.CreatePreparer(
79		autorest.AsGet(),
80		autorest.WithBaseURL(client.BaseURI),
81		autorest.WithPathParameters("/providers/Microsoft.ResourceHealth/emergingIssues/{issueName}", pathParameters),
82		autorest.WithQueryParameters(queryParameters))
83	return preparer.Prepare((&http.Request{}).WithContext(ctx))
84}
85
86// GetSender sends the Get request. The method will close the
87// http.Response Body if it receives an error.
88func (client EmergingIssuesClient) GetSender(req *http.Request) (*http.Response, error) {
89	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
90}
91
92// GetResponder handles the response to the Get request. The method always
93// closes the http.Response Body.
94func (client EmergingIssuesClient) GetResponder(resp *http.Response) (result EmergingIssuesGetResult, err error) {
95	err = autorest.Respond(
96		resp,
97		azure.WithErrorUnlessStatusCode(http.StatusOK),
98		autorest.ByUnmarshallingJSON(&result),
99		autorest.ByClosing())
100	result.Response = autorest.Response{Response: resp}
101	return
102}
103
104// List lists Azure services' emerging issues.
105func (client EmergingIssuesClient) List(ctx context.Context) (result EmergingIssueListResultPage, err error) {
106	if tracing.IsEnabled() {
107		ctx = tracing.StartSpan(ctx, fqdn+"/EmergingIssuesClient.List")
108		defer func() {
109			sc := -1
110			if result.eilr.Response.Response != nil {
111				sc = result.eilr.Response.Response.StatusCode
112			}
113			tracing.EndSpan(ctx, sc, err)
114		}()
115	}
116	result.fn = client.listNextResults
117	req, err := client.ListPreparer(ctx)
118	if err != nil {
119		err = autorest.NewErrorWithError(err, "resourcehealth.EmergingIssuesClient", "List", nil, "Failure preparing request")
120		return
121	}
122
123	resp, err := client.ListSender(req)
124	if err != nil {
125		result.eilr.Response = autorest.Response{Response: resp}
126		err = autorest.NewErrorWithError(err, "resourcehealth.EmergingIssuesClient", "List", resp, "Failure sending request")
127		return
128	}
129
130	result.eilr, err = client.ListResponder(resp)
131	if err != nil {
132		err = autorest.NewErrorWithError(err, "resourcehealth.EmergingIssuesClient", "List", resp, "Failure responding to request")
133		return
134	}
135	if result.eilr.hasNextLink() && result.eilr.IsEmpty() {
136		err = result.NextWithContext(ctx)
137		return
138	}
139
140	return
141}
142
143// ListPreparer prepares the List request.
144func (client EmergingIssuesClient) ListPreparer(ctx context.Context) (*http.Request, error) {
145	const APIVersion = "2017-07-01"
146	queryParameters := map[string]interface{}{
147		"api-version": APIVersion,
148	}
149
150	preparer := autorest.CreatePreparer(
151		autorest.AsGet(),
152		autorest.WithBaseURL(client.BaseURI),
153		autorest.WithPath("/providers/Microsoft.ResourceHealth/emergingIssues"),
154		autorest.WithQueryParameters(queryParameters))
155	return preparer.Prepare((&http.Request{}).WithContext(ctx))
156}
157
158// ListSender sends the List request. The method will close the
159// http.Response Body if it receives an error.
160func (client EmergingIssuesClient) ListSender(req *http.Request) (*http.Response, error) {
161	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
162}
163
164// ListResponder handles the response to the List request. The method always
165// closes the http.Response Body.
166func (client EmergingIssuesClient) ListResponder(resp *http.Response) (result EmergingIssueListResult, err error) {
167	err = autorest.Respond(
168		resp,
169		azure.WithErrorUnlessStatusCode(http.StatusOK),
170		autorest.ByUnmarshallingJSON(&result),
171		autorest.ByClosing())
172	result.Response = autorest.Response{Response: resp}
173	return
174}
175
176// listNextResults retrieves the next set of results, if any.
177func (client EmergingIssuesClient) listNextResults(ctx context.Context, lastResults EmergingIssueListResult) (result EmergingIssueListResult, err error) {
178	req, err := lastResults.emergingIssueListResultPreparer(ctx)
179	if err != nil {
180		return result, autorest.NewErrorWithError(err, "resourcehealth.EmergingIssuesClient", "listNextResults", nil, "Failure preparing next results request")
181	}
182	if req == nil {
183		return
184	}
185	resp, err := client.ListSender(req)
186	if err != nil {
187		result.Response = autorest.Response{Response: resp}
188		return result, autorest.NewErrorWithError(err, "resourcehealth.EmergingIssuesClient", "listNextResults", resp, "Failure sending next results request")
189	}
190	result, err = client.ListResponder(resp)
191	if err != nil {
192		err = autorest.NewErrorWithError(err, "resourcehealth.EmergingIssuesClient", "listNextResults", resp, "Failure responding to next results request")
193	}
194	return
195}
196
197// ListComplete enumerates all values, automatically crossing page boundaries as required.
198func (client EmergingIssuesClient) ListComplete(ctx context.Context) (result EmergingIssueListResultIterator, err error) {
199	if tracing.IsEnabled() {
200		ctx = tracing.StartSpan(ctx, fqdn+"/EmergingIssuesClient.List")
201		defer func() {
202			sc := -1
203			if result.Response().Response.Response != nil {
204				sc = result.page.Response().Response.Response.StatusCode
205			}
206			tracing.EndSpan(ctx, sc, err)
207		}()
208	}
209	result.page, err = client.List(ctx)
210	return
211}
212