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	"github.com/Azure/go-autorest/autorest/date"
25	"net/http"
26)
27
28// AddsServiceClient is the REST APIs for Azure Active Drectory Connect Health
29type AddsServiceClient struct {
30	BaseClient
31}
32
33// NewAddsServiceClient creates an instance of the AddsServiceClient client.
34func NewAddsServiceClient() AddsServiceClient {
35	return NewAddsServiceClientWithBaseURI(DefaultBaseURI)
36}
37
38// NewAddsServiceClientWithBaseURI creates an instance of the AddsServiceClient client.
39func NewAddsServiceClientWithBaseURI(baseURI string) AddsServiceClient {
40	return AddsServiceClient{NewWithBaseURI(baseURI)}
41}
42
43// GetMetrics gets the server related metrics for a given metric and group combination.
44// Parameters:
45// serviceName - the name of the service.
46// metricName - the metric name
47// groupName - the group name
48// groupKey - the group key
49// fromDate - the start date.
50// toDate - the end date.
51func (client AddsServiceClient) GetMetrics(ctx context.Context, serviceName string, metricName string, groupName string, groupKey string, fromDate *date.Time, toDate *date.Time) (result MetricSets, err error) {
52	req, err := client.GetMetricsPreparer(ctx, serviceName, metricName, groupName, groupKey, fromDate, toDate)
53	if err != nil {
54		err = autorest.NewErrorWithError(err, "adhybridhealthservice.AddsServiceClient", "GetMetrics", nil, "Failure preparing request")
55		return
56	}
57
58	resp, err := client.GetMetricsSender(req)
59	if err != nil {
60		result.Response = autorest.Response{Response: resp}
61		err = autorest.NewErrorWithError(err, "adhybridhealthservice.AddsServiceClient", "GetMetrics", resp, "Failure sending request")
62		return
63	}
64
65	result, err = client.GetMetricsResponder(resp)
66	if err != nil {
67		err = autorest.NewErrorWithError(err, "adhybridhealthservice.AddsServiceClient", "GetMetrics", resp, "Failure responding to request")
68	}
69
70	return
71}
72
73// GetMetricsPreparer prepares the GetMetrics request.
74func (client AddsServiceClient) GetMetricsPreparer(ctx context.Context, serviceName string, metricName string, groupName string, groupKey string, fromDate *date.Time, toDate *date.Time) (*http.Request, error) {
75	pathParameters := map[string]interface{}{
76		"groupName":   autorest.Encode("path", groupName),
77		"metricName":  autorest.Encode("path", metricName),
78		"serviceName": autorest.Encode("path", serviceName),
79	}
80
81	const APIVersion = "2014-01-01"
82	queryParameters := map[string]interface{}{
83		"api-version": APIVersion,
84	}
85	if len(groupKey) > 0 {
86		queryParameters["groupKey"] = autorest.Encode("query", groupKey)
87	}
88	if fromDate != nil {
89		queryParameters["fromDate"] = autorest.Encode("query", *fromDate)
90	}
91	if toDate != nil {
92		queryParameters["toDate"] = autorest.Encode("query", *toDate)
93	}
94
95	preparer := autorest.CreatePreparer(
96		autorest.AsGet(),
97		autorest.WithBaseURL(client.BaseURI),
98		autorest.WithPathParameters("/providers/Microsoft.ADHybridHealthService/addsservices/{serviceName}/metrics/{metricName}/groups/{groupName}", pathParameters),
99		autorest.WithQueryParameters(queryParameters))
100	return preparer.Prepare((&http.Request{}).WithContext(ctx))
101}
102
103// GetMetricsSender sends the GetMetrics request. The method will close the
104// http.Response Body if it receives an error.
105func (client AddsServiceClient) GetMetricsSender(req *http.Request) (*http.Response, error) {
106	return autorest.SendWithSender(client, req,
107		autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
108}
109
110// GetMetricsResponder handles the response to the GetMetrics request. The method always
111// closes the http.Response Body.
112func (client AddsServiceClient) GetMetricsResponder(resp *http.Response) (result MetricSets, err error) {
113	err = autorest.Respond(
114		resp,
115		client.ByInspecting(),
116		azure.WithErrorUnlessStatusCode(http.StatusOK),
117		autorest.ByUnmarshallingJSON(&result),
118		autorest.ByClosing())
119	result.Response = autorest.Response{Response: resp}
120	return
121}
122