1package adhybridhealthservice
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// AddsServicesUserPreferenceClient is the REST APIs for Azure Active Drectory Connect Health
28type AddsServicesUserPreferenceClient struct {
29	BaseClient
30}
31
32// NewAddsServicesUserPreferenceClient creates an instance of the AddsServicesUserPreferenceClient client.
33func NewAddsServicesUserPreferenceClient() AddsServicesUserPreferenceClient {
34	return NewAddsServicesUserPreferenceClientWithBaseURI(DefaultBaseURI)
35}
36
37// NewAddsServicesUserPreferenceClientWithBaseURI creates an instance of the AddsServicesUserPreferenceClient client.
38func NewAddsServicesUserPreferenceClientWithBaseURI(baseURI string) AddsServicesUserPreferenceClient {
39	return AddsServicesUserPreferenceClient{NewWithBaseURI(baseURI)}
40}
41
42// Add adds the user preferences for a given feature.
43// Parameters:
44// serviceName - the name of the service.
45// featureName - the name of the feature.
46// setting - the user preference setting.
47func (client AddsServicesUserPreferenceClient) Add(ctx context.Context, serviceName string, featureName string, setting UserPreference) (result autorest.Response, err error) {
48	req, err := client.AddPreparer(ctx, serviceName, featureName, setting)
49	if err != nil {
50		err = autorest.NewErrorWithError(err, "adhybridhealthservice.AddsServicesUserPreferenceClient", "Add", nil, "Failure preparing request")
51		return
52	}
53
54	resp, err := client.AddSender(req)
55	if err != nil {
56		result.Response = resp
57		err = autorest.NewErrorWithError(err, "adhybridhealthservice.AddsServicesUserPreferenceClient", "Add", resp, "Failure sending request")
58		return
59	}
60
61	result, err = client.AddResponder(resp)
62	if err != nil {
63		err = autorest.NewErrorWithError(err, "adhybridhealthservice.AddsServicesUserPreferenceClient", "Add", resp, "Failure responding to request")
64	}
65
66	return
67}
68
69// AddPreparer prepares the Add request.
70func (client AddsServicesUserPreferenceClient) AddPreparer(ctx context.Context, serviceName string, featureName string, setting UserPreference) (*http.Request, error) {
71	pathParameters := map[string]interface{}{
72		"featureName": autorest.Encode("path", featureName),
73		"serviceName": autorest.Encode("path", serviceName),
74	}
75
76	const APIVersion = "2014-01-01"
77	queryParameters := map[string]interface{}{
78		"api-version": APIVersion,
79	}
80
81	preparer := autorest.CreatePreparer(
82		autorest.AsContentType("application/json; charset=utf-8"),
83		autorest.AsPost(),
84		autorest.WithBaseURL(client.BaseURI),
85		autorest.WithPathParameters("/providers/Microsoft.ADHybridHealthService/addsservices/{serviceName}/features/{featureName}/userpreference", pathParameters),
86		autorest.WithJSON(setting),
87		autorest.WithQueryParameters(queryParameters))
88	return preparer.Prepare((&http.Request{}).WithContext(ctx))
89}
90
91// AddSender sends the Add request. The method will close the
92// http.Response Body if it receives an error.
93func (client AddsServicesUserPreferenceClient) AddSender(req *http.Request) (*http.Response, error) {
94	return autorest.SendWithSender(client, req,
95		autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
96}
97
98// AddResponder handles the response to the Add request. The method always
99// closes the http.Response Body.
100func (client AddsServicesUserPreferenceClient) AddResponder(resp *http.Response) (result autorest.Response, err error) {
101	err = autorest.Respond(
102		resp,
103		client.ByInspecting(),
104		azure.WithErrorUnlessStatusCode(http.StatusOK),
105		autorest.ByClosing())
106	result.Response = resp
107	return
108}
109
110// Delete deletes the user preferences for a given feature.
111// Parameters:
112// serviceName - the name of the service.
113// featureName - the name of the feature.
114func (client AddsServicesUserPreferenceClient) Delete(ctx context.Context, serviceName string, featureName string) (result autorest.Response, err error) {
115	req, err := client.DeletePreparer(ctx, serviceName, featureName)
116	if err != nil {
117		err = autorest.NewErrorWithError(err, "adhybridhealthservice.AddsServicesUserPreferenceClient", "Delete", nil, "Failure preparing request")
118		return
119	}
120
121	resp, err := client.DeleteSender(req)
122	if err != nil {
123		result.Response = resp
124		err = autorest.NewErrorWithError(err, "adhybridhealthservice.AddsServicesUserPreferenceClient", "Delete", resp, "Failure sending request")
125		return
126	}
127
128	result, err = client.DeleteResponder(resp)
129	if err != nil {
130		err = autorest.NewErrorWithError(err, "adhybridhealthservice.AddsServicesUserPreferenceClient", "Delete", resp, "Failure responding to request")
131	}
132
133	return
134}
135
136// DeletePreparer prepares the Delete request.
137func (client AddsServicesUserPreferenceClient) DeletePreparer(ctx context.Context, serviceName string, featureName string) (*http.Request, error) {
138	pathParameters := map[string]interface{}{
139		"featureName": autorest.Encode("path", featureName),
140		"serviceName": autorest.Encode("path", serviceName),
141	}
142
143	const APIVersion = "2014-01-01"
144	queryParameters := map[string]interface{}{
145		"api-version": APIVersion,
146	}
147
148	preparer := autorest.CreatePreparer(
149		autorest.AsDelete(),
150		autorest.WithBaseURL(client.BaseURI),
151		autorest.WithPathParameters("/providers/Microsoft.ADHybridHealthService/addsservices/{serviceName}/features/{featureName}/userpreference", pathParameters),
152		autorest.WithQueryParameters(queryParameters))
153	return preparer.Prepare((&http.Request{}).WithContext(ctx))
154}
155
156// DeleteSender sends the Delete request. The method will close the
157// http.Response Body if it receives an error.
158func (client AddsServicesUserPreferenceClient) DeleteSender(req *http.Request) (*http.Response, error) {
159	return autorest.SendWithSender(client, req,
160		autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
161}
162
163// DeleteResponder handles the response to the Delete request. The method always
164// closes the http.Response Body.
165func (client AddsServicesUserPreferenceClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
166	err = autorest.Respond(
167		resp,
168		client.ByInspecting(),
169		azure.WithErrorUnlessStatusCode(http.StatusOK),
170		autorest.ByClosing())
171	result.Response = resp
172	return
173}
174
175// Get gets the user preferences for a given feature.
176// Parameters:
177// serviceName - the name of the service.
178// featureName - the name of the feature.
179func (client AddsServicesUserPreferenceClient) Get(ctx context.Context, serviceName string, featureName string) (result UserPreference, err error) {
180	req, err := client.GetPreparer(ctx, serviceName, featureName)
181	if err != nil {
182		err = autorest.NewErrorWithError(err, "adhybridhealthservice.AddsServicesUserPreferenceClient", "Get", nil, "Failure preparing request")
183		return
184	}
185
186	resp, err := client.GetSender(req)
187	if err != nil {
188		result.Response = autorest.Response{Response: resp}
189		err = autorest.NewErrorWithError(err, "adhybridhealthservice.AddsServicesUserPreferenceClient", "Get", resp, "Failure sending request")
190		return
191	}
192
193	result, err = client.GetResponder(resp)
194	if err != nil {
195		err = autorest.NewErrorWithError(err, "adhybridhealthservice.AddsServicesUserPreferenceClient", "Get", resp, "Failure responding to request")
196	}
197
198	return
199}
200
201// GetPreparer prepares the Get request.
202func (client AddsServicesUserPreferenceClient) GetPreparer(ctx context.Context, serviceName string, featureName string) (*http.Request, error) {
203	pathParameters := map[string]interface{}{
204		"featureName": autorest.Encode("path", featureName),
205		"serviceName": autorest.Encode("path", serviceName),
206	}
207
208	const APIVersion = "2014-01-01"
209	queryParameters := map[string]interface{}{
210		"api-version": APIVersion,
211	}
212
213	preparer := autorest.CreatePreparer(
214		autorest.AsGet(),
215		autorest.WithBaseURL(client.BaseURI),
216		autorest.WithPathParameters("/providers/Microsoft.ADHybridHealthService/addsservices/{serviceName}/features/{featureName}/userpreference", pathParameters),
217		autorest.WithQueryParameters(queryParameters))
218	return preparer.Prepare((&http.Request{}).WithContext(ctx))
219}
220
221// GetSender sends the Get request. The method will close the
222// http.Response Body if it receives an error.
223func (client AddsServicesUserPreferenceClient) GetSender(req *http.Request) (*http.Response, error) {
224	return autorest.SendWithSender(client, req,
225		autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
226}
227
228// GetResponder handles the response to the Get request. The method always
229// closes the http.Response Body.
230func (client AddsServicesUserPreferenceClient) GetResponder(resp *http.Response) (result UserPreference, err error) {
231	err = autorest.Respond(
232		resp,
233		client.ByInspecting(),
234		azure.WithErrorUnlessStatusCode(http.StatusOK),
235		autorest.ByUnmarshallingJSON(&result),
236		autorest.ByClosing())
237	result.Response = autorest.Response{Response: resp}
238	return
239}
240