1package customerinsights
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/tracing"
25	"net/http"
26)
27
28// ImagesClient is the the Azure Customer Insights management API provides a RESTful set of web services that interact
29// with Azure Customer Insights service to manage your resources. The API has entities that capture the relationship
30// between an end user and the Azure Customer Insights service.
31type ImagesClient struct {
32	BaseClient
33}
34
35// NewImagesClient creates an instance of the ImagesClient client.
36func NewImagesClient(subscriptionID string) ImagesClient {
37	return NewImagesClientWithBaseURI(DefaultBaseURI, subscriptionID)
38}
39
40// NewImagesClientWithBaseURI creates an instance of the ImagesClient client.
41func NewImagesClientWithBaseURI(baseURI string, subscriptionID string) ImagesClient {
42	return ImagesClient{NewWithBaseURI(baseURI, subscriptionID)}
43}
44
45// GetUploadURLForData gets data image upload URL.
46// Parameters:
47// resourceGroupName - the name of the resource group.
48// hubName - the name of the hub.
49// parameters - parameters supplied to the GetUploadUrlForData operation.
50func (client ImagesClient) GetUploadURLForData(ctx context.Context, resourceGroupName string, hubName string, parameters GetImageUploadURLInput) (result ImageDefinition, err error) {
51	if tracing.IsEnabled() {
52		ctx = tracing.StartSpan(ctx, fqdn+"/ImagesClient.GetUploadURLForData")
53		defer func() {
54			sc := -1
55			if result.Response.Response != nil {
56				sc = result.Response.Response.StatusCode
57			}
58			tracing.EndSpan(ctx, sc, err)
59		}()
60	}
61	req, err := client.GetUploadURLForDataPreparer(ctx, resourceGroupName, hubName, parameters)
62	if err != nil {
63		err = autorest.NewErrorWithError(err, "customerinsights.ImagesClient", "GetUploadURLForData", nil, "Failure preparing request")
64		return
65	}
66
67	resp, err := client.GetUploadURLForDataSender(req)
68	if err != nil {
69		result.Response = autorest.Response{Response: resp}
70		err = autorest.NewErrorWithError(err, "customerinsights.ImagesClient", "GetUploadURLForData", resp, "Failure sending request")
71		return
72	}
73
74	result, err = client.GetUploadURLForDataResponder(resp)
75	if err != nil {
76		err = autorest.NewErrorWithError(err, "customerinsights.ImagesClient", "GetUploadURLForData", resp, "Failure responding to request")
77	}
78
79	return
80}
81
82// GetUploadURLForDataPreparer prepares the GetUploadURLForData request.
83func (client ImagesClient) GetUploadURLForDataPreparer(ctx context.Context, resourceGroupName string, hubName string, parameters GetImageUploadURLInput) (*http.Request, error) {
84	pathParameters := map[string]interface{}{
85		"hubName":           autorest.Encode("path", hubName),
86		"resourceGroupName": autorest.Encode("path", resourceGroupName),
87		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
88	}
89
90	const APIVersion = "2017-04-26"
91	queryParameters := map[string]interface{}{
92		"api-version": APIVersion,
93	}
94
95	preparer := autorest.CreatePreparer(
96		autorest.AsContentType("application/json; charset=utf-8"),
97		autorest.AsPost(),
98		autorest.WithBaseURL(client.BaseURI),
99		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.CustomerInsights/hubs/{hubName}/images/getDataImageUploadUrl", pathParameters),
100		autorest.WithJSON(parameters),
101		autorest.WithQueryParameters(queryParameters))
102	return preparer.Prepare((&http.Request{}).WithContext(ctx))
103}
104
105// GetUploadURLForDataSender sends the GetUploadURLForData request. The method will close the
106// http.Response Body if it receives an error.
107func (client ImagesClient) GetUploadURLForDataSender(req *http.Request) (*http.Response, error) {
108	sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client))
109	return autorest.SendWithSender(client, req, sd...)
110}
111
112// GetUploadURLForDataResponder handles the response to the GetUploadURLForData request. The method always
113// closes the http.Response Body.
114func (client ImagesClient) GetUploadURLForDataResponder(resp *http.Response) (result ImageDefinition, err error) {
115	err = autorest.Respond(
116		resp,
117		client.ByInspecting(),
118		azure.WithErrorUnlessStatusCode(http.StatusOK),
119		autorest.ByUnmarshallingJSON(&result),
120		autorest.ByClosing())
121	result.Response = autorest.Response{Response: resp}
122	return
123}
124
125// GetUploadURLForEntityType gets entity type (profile or interaction) image upload URL.
126// Parameters:
127// resourceGroupName - the name of the resource group.
128// hubName - the name of the hub.
129// parameters - parameters supplied to the GetUploadUrlForEntityType operation.
130func (client ImagesClient) GetUploadURLForEntityType(ctx context.Context, resourceGroupName string, hubName string, parameters GetImageUploadURLInput) (result ImageDefinition, err error) {
131	if tracing.IsEnabled() {
132		ctx = tracing.StartSpan(ctx, fqdn+"/ImagesClient.GetUploadURLForEntityType")
133		defer func() {
134			sc := -1
135			if result.Response.Response != nil {
136				sc = result.Response.Response.StatusCode
137			}
138			tracing.EndSpan(ctx, sc, err)
139		}()
140	}
141	req, err := client.GetUploadURLForEntityTypePreparer(ctx, resourceGroupName, hubName, parameters)
142	if err != nil {
143		err = autorest.NewErrorWithError(err, "customerinsights.ImagesClient", "GetUploadURLForEntityType", nil, "Failure preparing request")
144		return
145	}
146
147	resp, err := client.GetUploadURLForEntityTypeSender(req)
148	if err != nil {
149		result.Response = autorest.Response{Response: resp}
150		err = autorest.NewErrorWithError(err, "customerinsights.ImagesClient", "GetUploadURLForEntityType", resp, "Failure sending request")
151		return
152	}
153
154	result, err = client.GetUploadURLForEntityTypeResponder(resp)
155	if err != nil {
156		err = autorest.NewErrorWithError(err, "customerinsights.ImagesClient", "GetUploadURLForEntityType", resp, "Failure responding to request")
157	}
158
159	return
160}
161
162// GetUploadURLForEntityTypePreparer prepares the GetUploadURLForEntityType request.
163func (client ImagesClient) GetUploadURLForEntityTypePreparer(ctx context.Context, resourceGroupName string, hubName string, parameters GetImageUploadURLInput) (*http.Request, error) {
164	pathParameters := map[string]interface{}{
165		"hubName":           autorest.Encode("path", hubName),
166		"resourceGroupName": autorest.Encode("path", resourceGroupName),
167		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
168	}
169
170	const APIVersion = "2017-04-26"
171	queryParameters := map[string]interface{}{
172		"api-version": APIVersion,
173	}
174
175	preparer := autorest.CreatePreparer(
176		autorest.AsContentType("application/json; charset=utf-8"),
177		autorest.AsPost(),
178		autorest.WithBaseURL(client.BaseURI),
179		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.CustomerInsights/hubs/{hubName}/images/getEntityTypeImageUploadUrl", pathParameters),
180		autorest.WithJSON(parameters),
181		autorest.WithQueryParameters(queryParameters))
182	return preparer.Prepare((&http.Request{}).WithContext(ctx))
183}
184
185// GetUploadURLForEntityTypeSender sends the GetUploadURLForEntityType request. The method will close the
186// http.Response Body if it receives an error.
187func (client ImagesClient) GetUploadURLForEntityTypeSender(req *http.Request) (*http.Response, error) {
188	sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client))
189	return autorest.SendWithSender(client, req, sd...)
190}
191
192// GetUploadURLForEntityTypeResponder handles the response to the GetUploadURLForEntityType request. The method always
193// closes the http.Response Body.
194func (client ImagesClient) GetUploadURLForEntityTypeResponder(resp *http.Response) (result ImageDefinition, err error) {
195	err = autorest.Respond(
196		resp,
197		client.ByInspecting(),
198		azure.WithErrorUnlessStatusCode(http.StatusOK),
199		autorest.ByUnmarshallingJSON(&result),
200		autorest.ByClosing())
201	result.Response = autorest.Response{Response: resp}
202	return
203}
204