1package cdn
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	"net/http"
25)
26
27// EdgeNodesClient is the use these APIs to manage Azure CDN resources through the Azure Resource Manager. You must
28// make sure that requests made to these resources are secure.
29type EdgeNodesClient struct {
30	BaseClient
31}
32
33// NewEdgeNodesClient creates an instance of the EdgeNodesClient client.
34func NewEdgeNodesClient(subscriptionID string) EdgeNodesClient {
35	return NewEdgeNodesClientWithBaseURI(DefaultBaseURI, subscriptionID)
36}
37
38// NewEdgeNodesClientWithBaseURI creates an instance of the EdgeNodesClient client.
39func NewEdgeNodesClientWithBaseURI(baseURI string, subscriptionID string) EdgeNodesClient {
40	return EdgeNodesClient{NewWithBaseURI(baseURI, subscriptionID)}
41}
42
43// List edgenodes are the global Point of Presence (POP) locations used to deliver CDN content to end users.
44func (client EdgeNodesClient) List(ctx context.Context) (result EdgenodeResultPage, err error) {
45	result.fn = client.listNextResults
46	req, err := client.ListPreparer(ctx)
47	if err != nil {
48		err = autorest.NewErrorWithError(err, "cdn.EdgeNodesClient", "List", nil, "Failure preparing request")
49		return
50	}
51
52	resp, err := client.ListSender(req)
53	if err != nil {
54		result.er.Response = autorest.Response{Response: resp}
55		err = autorest.NewErrorWithError(err, "cdn.EdgeNodesClient", "List", resp, "Failure sending request")
56		return
57	}
58
59	result.er, err = client.ListResponder(resp)
60	if err != nil {
61		err = autorest.NewErrorWithError(err, "cdn.EdgeNodesClient", "List", resp, "Failure responding to request")
62	}
63
64	return
65}
66
67// ListPreparer prepares the List request.
68func (client EdgeNodesClient) ListPreparer(ctx context.Context) (*http.Request, error) {
69	const APIVersion = "2017-04-02"
70	queryParameters := map[string]interface{}{
71		"api-version": APIVersion,
72	}
73
74	preparer := autorest.CreatePreparer(
75		autorest.AsGet(),
76		autorest.WithBaseURL(client.BaseURI),
77		autorest.WithPath("/providers/Microsoft.Cdn/edgenodes"),
78		autorest.WithQueryParameters(queryParameters))
79	return preparer.Prepare((&http.Request{}).WithContext(ctx))
80}
81
82// ListSender sends the List request. The method will close the
83// http.Response Body if it receives an error.
84func (client EdgeNodesClient) ListSender(req *http.Request) (*http.Response, error) {
85	return autorest.SendWithSender(client, req,
86		autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
87}
88
89// ListResponder handles the response to the List request. The method always
90// closes the http.Response Body.
91func (client EdgeNodesClient) ListResponder(resp *http.Response) (result EdgenodeResult, err error) {
92	err = autorest.Respond(
93		resp,
94		client.ByInspecting(),
95		azure.WithErrorUnlessStatusCode(http.StatusOK),
96		autorest.ByUnmarshallingJSON(&result),
97		autorest.ByClosing())
98	result.Response = autorest.Response{Response: resp}
99	return
100}
101
102// listNextResults retrieves the next set of results, if any.
103func (client EdgeNodesClient) listNextResults(lastResults EdgenodeResult) (result EdgenodeResult, err error) {
104	req, err := lastResults.edgenodeResultPreparer()
105	if err != nil {
106		return result, autorest.NewErrorWithError(err, "cdn.EdgeNodesClient", "listNextResults", nil, "Failure preparing next results request")
107	}
108	if req == nil {
109		return
110	}
111	resp, err := client.ListSender(req)
112	if err != nil {
113		result.Response = autorest.Response{Response: resp}
114		return result, autorest.NewErrorWithError(err, "cdn.EdgeNodesClient", "listNextResults", resp, "Failure sending next results request")
115	}
116	result, err = client.ListResponder(resp)
117	if err != nil {
118		err = autorest.NewErrorWithError(err, "cdn.EdgeNodesClient", "listNextResults", resp, "Failure responding to next results request")
119	}
120	return
121}
122
123// ListComplete enumerates all values, automatically crossing page boundaries as required.
124func (client EdgeNodesClient) ListComplete(ctx context.Context) (result EdgenodeResultIterator, err error) {
125	result.page, err = client.List(ctx)
126	return
127}
128