1 package devices
2
3
4
5
6
7
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
18 type OperationsClient struct {
19 BaseClient
20 }
21
22
23 func NewOperationsClient(subscriptionID string) OperationsClient {
24 return NewOperationsClientWithBaseURI(DefaultBaseURI, subscriptionID)
25 }
26
27
28
29 func NewOperationsClientWithBaseURI(baseURI string, subscriptionID string) OperationsClient {
30 return OperationsClient{NewWithBaseURI(baseURI, subscriptionID)}
31 }
32
33
34 func (client OperationsClient) List(ctx context.Context) (result OperationListResultPage, err error) {
35 if tracing.IsEnabled() {
36 ctx = tracing.StartSpan(ctx, fqdn+"/OperationsClient.List")
37 defer func() {
38 sc := -1
39 if result.olr.Response.Response != nil {
40 sc = result.olr.Response.Response.StatusCode
41 }
42 tracing.EndSpan(ctx, sc, err)
43 }()
44 }
45 result.fn = client.listNextResults
46 req, err := client.ListPreparer(ctx)
47 if err != nil {
48 err = autorest.NewErrorWithError(err, "devices.OperationsClient", "List", nil, "Failure preparing request")
49 return
50 }
51
52 resp, err := client.ListSender(req)
53 if err != nil {
54 result.olr.Response = autorest.Response{Response: resp}
55 err = autorest.NewErrorWithError(err, "devices.OperationsClient", "List", resp, "Failure sending request")
56 return
57 }
58
59 result.olr, err = client.ListResponder(resp)
60 if err != nil {
61 err = autorest.NewErrorWithError(err, "devices.OperationsClient", "List", resp, "Failure responding to request")
62 return
63 }
64 if result.olr.hasNextLink() && result.olr.IsEmpty() {
65 err = result.NextWithContext(ctx)
66 return
67 }
68
69 return
70 }
71
72
73 func (client OperationsClient) ListPreparer(ctx context.Context) (*http.Request, error) {
74 const APIVersion = "2018-04-01"
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.WithPath("/providers/Microsoft.Devices/operations"),
83 autorest.WithQueryParameters(queryParameters))
84 return preparer.Prepare((&http.Request{}).WithContext(ctx))
85 }
86
87
88
89 func (client OperationsClient) ListSender(req *http.Request) (*http.Response, error) {
90 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
91 }
92
93
94
95 func (client OperationsClient) ListResponder(resp *http.Response) (result OperationListResult, 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
105
106 func (client OperationsClient) listNextResults(ctx context.Context, lastResults OperationListResult) (result OperationListResult, err error) {
107 req, err := lastResults.operationListResultPreparer(ctx)
108 if err != nil {
109 return result, autorest.NewErrorWithError(err, "devices.OperationsClient", "listNextResults", nil, "Failure preparing next results request")
110 }
111 if req == nil {
112 return
113 }
114 resp, err := client.ListSender(req)
115 if err != nil {
116 result.Response = autorest.Response{Response: resp}
117 return result, autorest.NewErrorWithError(err, "devices.OperationsClient", "listNextResults", resp, "Failure sending next results request")
118 }
119 result, err = client.ListResponder(resp)
120 if err != nil {
121 err = autorest.NewErrorWithError(err, "devices.OperationsClient", "listNextResults", resp, "Failure responding to next results request")
122 }
123 return
124 }
125
126
127 func (client OperationsClient) ListComplete(ctx context.Context) (result OperationListResultIterator, err error) {
128 if tracing.IsEnabled() {
129 ctx = tracing.StartSpan(ctx, fqdn+"/OperationsClient.List")
130 defer func() {
131 sc := -1
132 if result.Response().Response.Response != nil {
133 sc = result.page.Response().Response.Response.StatusCode
134 }
135 tracing.EndSpan(ctx, sc, err)
136 }()
137 }
138 result.page, err = client.List(ctx)
139 return
140 }
141
View as plain text