1package batch
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/autorest/date"
25	"net/http"
26)
27
28// ApplicationClient is the a client for issuing REST requests to the Azure Batch service.
29type ApplicationClient struct {
30	BaseClient
31}
32
33// NewApplicationClient creates an instance of the ApplicationClient client.
34func NewApplicationClient() ApplicationClient {
35	return NewApplicationClientWithBaseURI(DefaultBaseURI)
36}
37
38// NewApplicationClientWithBaseURI creates an instance of the ApplicationClient client.
39func NewApplicationClientWithBaseURI(baseURI string) ApplicationClient {
40	return ApplicationClient{NewWithBaseURI(baseURI)}
41}
42
43// Get gets information about the specified application.
44//
45// applicationID is the id of the application. timeout is the maximum time that the server can spend processing the
46// request, in seconds. The default is 30 seconds. clientRequestID is the caller-generated request identity, in the
47// form of a GUID with no decoration such as curly braces, e.g. 9C4D50EE-2D56-4CD3-8152-34347DC9F2B0.
48// returnClientRequestID is whether the server should return the client-request-id identifier in the response.
49// ocpDate is the time the request was issued. If not specified, this header will be automatically populated with
50// the current system clock time.
51func (client ApplicationClient) Get(ctx context.Context, applicationID string, timeout *int32, clientRequestID string, returnClientRequestID *bool, ocpDate *date.TimeRFC1123) (result ApplicationSummary, err error) {
52	req, err := client.GetPreparer(ctx, applicationID, timeout, clientRequestID, returnClientRequestID, ocpDate)
53	if err != nil {
54		err = autorest.NewErrorWithError(err, "batch.ApplicationClient", "Get", nil, "Failure preparing request")
55		return
56	}
57
58	resp, err := client.GetSender(req)
59	if err != nil {
60		result.Response = autorest.Response{Response: resp}
61		err = autorest.NewErrorWithError(err, "batch.ApplicationClient", "Get", resp, "Failure sending request")
62		return
63	}
64
65	result, err = client.GetResponder(resp)
66	if err != nil {
67		err = autorest.NewErrorWithError(err, "batch.ApplicationClient", "Get", resp, "Failure responding to request")
68	}
69
70	return
71}
72
73// GetPreparer prepares the Get request.
74func (client ApplicationClient) GetPreparer(ctx context.Context, applicationID string, timeout *int32, clientRequestID string, returnClientRequestID *bool, ocpDate *date.TimeRFC1123) (*http.Request, error) {
75	pathParameters := map[string]interface{}{
76		"applicationId": autorest.Encode("path", applicationID),
77	}
78
79	const APIVersion = "2016-02-01.3.0"
80	queryParameters := map[string]interface{}{
81		"api-version": APIVersion,
82	}
83	if timeout != nil {
84		queryParameters["timeout"] = autorest.Encode("query", *timeout)
85	} else {
86		queryParameters["timeout"] = autorest.Encode("query", 30)
87	}
88
89	preparer := autorest.CreatePreparer(
90		autorest.AsGet(),
91		autorest.WithBaseURL(client.BaseURI),
92		autorest.WithPathParameters("/applications/{applicationId}", pathParameters),
93		autorest.WithQueryParameters(queryParameters))
94	if len(clientRequestID) > 0 {
95		preparer = autorest.DecoratePreparer(preparer,
96			autorest.WithHeader("client-request-id", autorest.String(clientRequestID)))
97	}
98	if returnClientRequestID != nil {
99		preparer = autorest.DecoratePreparer(preparer,
100			autorest.WithHeader("return-client-request-id", autorest.String(returnClientRequestID)))
101	}
102	if ocpDate != nil {
103		preparer = autorest.DecoratePreparer(preparer,
104			autorest.WithHeader("ocp-date", autorest.String(ocpDate)))
105	}
106	return preparer.Prepare((&http.Request{}).WithContext(ctx))
107}
108
109// GetSender sends the Get request. The method will close the
110// http.Response Body if it receives an error.
111func (client ApplicationClient) GetSender(req *http.Request) (*http.Response, error) {
112	return autorest.SendWithSender(client, req,
113		autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
114}
115
116// GetResponder handles the response to the Get request. The method always
117// closes the http.Response Body.
118func (client ApplicationClient) GetResponder(resp *http.Response) (result ApplicationSummary, err error) {
119	err = autorest.Respond(
120		resp,
121		client.ByInspecting(),
122		azure.WithErrorUnlessStatusCode(http.StatusOK),
123		autorest.ByUnmarshallingJSON(&result),
124		autorest.ByClosing())
125	result.Response = autorest.Response{Response: resp}
126	return
127}
128
129// List lists all of the applications available in the specified account.
130//
131// maxResults is the maximum number of items to return in the response. timeout is the maximum time that the server
132// can spend processing the request, in seconds. The default is 30 seconds. clientRequestID is the caller-generated
133// request identity, in the form of a GUID with no decoration such as curly braces, e.g.
134// 9C4D50EE-2D56-4CD3-8152-34347DC9F2B0. returnClientRequestID is whether the server should return the
135// client-request-id identifier in the response. ocpDate is the time the request was issued. If not specified, this
136// header will be automatically populated with the current system clock time.
137func (client ApplicationClient) List(ctx context.Context, maxResults *int32, timeout *int32, clientRequestID string, returnClientRequestID *bool, ocpDate *date.TimeRFC1123) (result ApplicationListResultPage, err error) {
138	result.fn = client.listNextResults
139	req, err := client.ListPreparer(ctx, maxResults, timeout, clientRequestID, returnClientRequestID, ocpDate)
140	if err != nil {
141		err = autorest.NewErrorWithError(err, "batch.ApplicationClient", "List", nil, "Failure preparing request")
142		return
143	}
144
145	resp, err := client.ListSender(req)
146	if err != nil {
147		result.alr.Response = autorest.Response{Response: resp}
148		err = autorest.NewErrorWithError(err, "batch.ApplicationClient", "List", resp, "Failure sending request")
149		return
150	}
151
152	result.alr, err = client.ListResponder(resp)
153	if err != nil {
154		err = autorest.NewErrorWithError(err, "batch.ApplicationClient", "List", resp, "Failure responding to request")
155	}
156
157	return
158}
159
160// ListPreparer prepares the List request.
161func (client ApplicationClient) ListPreparer(ctx context.Context, maxResults *int32, timeout *int32, clientRequestID string, returnClientRequestID *bool, ocpDate *date.TimeRFC1123) (*http.Request, error) {
162	const APIVersion = "2016-02-01.3.0"
163	queryParameters := map[string]interface{}{
164		"api-version": APIVersion,
165	}
166	if maxResults != nil {
167		queryParameters["maxresults"] = autorest.Encode("query", *maxResults)
168	}
169	if timeout != nil {
170		queryParameters["timeout"] = autorest.Encode("query", *timeout)
171	} else {
172		queryParameters["timeout"] = autorest.Encode("query", 30)
173	}
174
175	preparer := autorest.CreatePreparer(
176		autorest.AsGet(),
177		autorest.WithBaseURL(client.BaseURI),
178		autorest.WithPath("/applications"),
179		autorest.WithQueryParameters(queryParameters))
180	if len(clientRequestID) > 0 {
181		preparer = autorest.DecoratePreparer(preparer,
182			autorest.WithHeader("client-request-id", autorest.String(clientRequestID)))
183	}
184	if returnClientRequestID != nil {
185		preparer = autorest.DecoratePreparer(preparer,
186			autorest.WithHeader("return-client-request-id", autorest.String(returnClientRequestID)))
187	}
188	if ocpDate != nil {
189		preparer = autorest.DecoratePreparer(preparer,
190			autorest.WithHeader("ocp-date", autorest.String(ocpDate)))
191	}
192	return preparer.Prepare((&http.Request{}).WithContext(ctx))
193}
194
195// ListSender sends the List request. The method will close the
196// http.Response Body if it receives an error.
197func (client ApplicationClient) ListSender(req *http.Request) (*http.Response, error) {
198	return autorest.SendWithSender(client, req,
199		autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
200}
201
202// ListResponder handles the response to the List request. The method always
203// closes the http.Response Body.
204func (client ApplicationClient) ListResponder(resp *http.Response) (result ApplicationListResult, err error) {
205	err = autorest.Respond(
206		resp,
207		client.ByInspecting(),
208		azure.WithErrorUnlessStatusCode(http.StatusOK),
209		autorest.ByUnmarshallingJSON(&result),
210		autorest.ByClosing())
211	result.Response = autorest.Response{Response: resp}
212	return
213}
214
215// listNextResults retrieves the next set of results, if any.
216func (client ApplicationClient) listNextResults(lastResults ApplicationListResult) (result ApplicationListResult, err error) {
217	req, err := lastResults.applicationListResultPreparer()
218	if err != nil {
219		return result, autorest.NewErrorWithError(err, "batch.ApplicationClient", "listNextResults", nil, "Failure preparing next results request")
220	}
221	if req == nil {
222		return
223	}
224	resp, err := client.ListSender(req)
225	if err != nil {
226		result.Response = autorest.Response{Response: resp}
227		return result, autorest.NewErrorWithError(err, "batch.ApplicationClient", "listNextResults", resp, "Failure sending next results request")
228	}
229	result, err = client.ListResponder(resp)
230	if err != nil {
231		err = autorest.NewErrorWithError(err, "batch.ApplicationClient", "listNextResults", resp, "Failure responding to next results request")
232	}
233	return
234}
235
236// ListComplete enumerates all values, automatically crossing page boundaries as required.
237func (client ApplicationClient) ListComplete(ctx context.Context, maxResults *int32, timeout *int32, clientRequestID string, returnClientRequestID *bool, ocpDate *date.TimeRFC1123) (result ApplicationListResultIterator, err error) {
238	result.page, err = client.List(ctx, maxResults, timeout, clientRequestID, returnClientRequestID, ocpDate)
239	return
240}
241