1package enterpriseknowledgegraphservice
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// OperationsClient is the azure Enterprise Knowledge Graph Service is a platform for creating knowledge graphs at
29// scale.
30type OperationsClient struct {
31	BaseClient
32}
33
34// NewOperationsClient creates an instance of the OperationsClient client.
35func NewOperationsClient(subscriptionID string) OperationsClient {
36	return NewOperationsClientWithBaseURI(DefaultBaseURI, subscriptionID)
37}
38
39// NewOperationsClientWithBaseURI creates an instance of the OperationsClient client using a custom endpoint.  Use this
40// when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
41func NewOperationsClientWithBaseURI(baseURI string, subscriptionID string) OperationsClient {
42	return OperationsClient{NewWithBaseURI(baseURI, subscriptionID)}
43}
44
45// List lists all the available EnterpriseKnowledgeGraph services operations.
46func (client OperationsClient) List(ctx context.Context) (result OperationEntityListResultPage, err error) {
47	if tracing.IsEnabled() {
48		ctx = tracing.StartSpan(ctx, fqdn+"/OperationsClient.List")
49		defer func() {
50			sc := -1
51			if result.oelr.Response.Response != nil {
52				sc = result.oelr.Response.Response.StatusCode
53			}
54			tracing.EndSpan(ctx, sc, err)
55		}()
56	}
57	result.fn = client.listNextResults
58	req, err := client.ListPreparer(ctx)
59	if err != nil {
60		err = autorest.NewErrorWithError(err, "enterpriseknowledgegraphservice.OperationsClient", "List", nil, "Failure preparing request")
61		return
62	}
63
64	resp, err := client.ListSender(req)
65	if err != nil {
66		result.oelr.Response = autorest.Response{Response: resp}
67		err = autorest.NewErrorWithError(err, "enterpriseknowledgegraphservice.OperationsClient", "List", resp, "Failure sending request")
68		return
69	}
70
71	result.oelr, err = client.ListResponder(resp)
72	if err != nil {
73		err = autorest.NewErrorWithError(err, "enterpriseknowledgegraphservice.OperationsClient", "List", resp, "Failure responding to request")
74		return
75	}
76	if result.oelr.hasNextLink() && result.oelr.IsEmpty() {
77		err = result.NextWithContext(ctx)
78		return
79	}
80
81	return
82}
83
84// ListPreparer prepares the List request.
85func (client OperationsClient) ListPreparer(ctx context.Context) (*http.Request, error) {
86	const APIVersion = "2018-12-03"
87	queryParameters := map[string]interface{}{
88		"api-version": APIVersion,
89	}
90
91	preparer := autorest.CreatePreparer(
92		autorest.AsGet(),
93		autorest.WithBaseURL(client.BaseURI),
94		autorest.WithPath("/providers/Microsoft.EnterpriseKnowledgeGraph/operations"),
95		autorest.WithQueryParameters(queryParameters))
96	return preparer.Prepare((&http.Request{}).WithContext(ctx))
97}
98
99// ListSender sends the List request. The method will close the
100// http.Response Body if it receives an error.
101func (client OperationsClient) ListSender(req *http.Request) (*http.Response, error) {
102	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
103}
104
105// ListResponder handles the response to the List request. The method always
106// closes the http.Response Body.
107func (client OperationsClient) ListResponder(resp *http.Response) (result OperationEntityListResult, err error) {
108	err = autorest.Respond(
109		resp,
110		azure.WithErrorUnlessStatusCode(http.StatusOK),
111		autorest.ByUnmarshallingJSON(&result),
112		autorest.ByClosing())
113	result.Response = autorest.Response{Response: resp}
114	return
115}
116
117// listNextResults retrieves the next set of results, if any.
118func (client OperationsClient) listNextResults(ctx context.Context, lastResults OperationEntityListResult) (result OperationEntityListResult, err error) {
119	req, err := lastResults.operationEntityListResultPreparer(ctx)
120	if err != nil {
121		return result, autorest.NewErrorWithError(err, "enterpriseknowledgegraphservice.OperationsClient", "listNextResults", nil, "Failure preparing next results request")
122	}
123	if req == nil {
124		return
125	}
126	resp, err := client.ListSender(req)
127	if err != nil {
128		result.Response = autorest.Response{Response: resp}
129		return result, autorest.NewErrorWithError(err, "enterpriseknowledgegraphservice.OperationsClient", "listNextResults", resp, "Failure sending next results request")
130	}
131	result, err = client.ListResponder(resp)
132	if err != nil {
133		err = autorest.NewErrorWithError(err, "enterpriseknowledgegraphservice.OperationsClient", "listNextResults", resp, "Failure responding to next results request")
134	}
135	return
136}
137
138// ListComplete enumerates all values, automatically crossing page boundaries as required.
139func (client OperationsClient) ListComplete(ctx context.Context) (result OperationEntityListResultIterator, err error) {
140	if tracing.IsEnabled() {
141		ctx = tracing.StartSpan(ctx, fqdn+"/OperationsClient.List")
142		defer func() {
143			sc := -1
144			if result.Response().Response.Response != nil {
145				sc = result.page.Response().Response.Response.StatusCode
146			}
147			tracing.EndSpan(ctx, sc, err)
148		}()
149	}
150	result.page, err = client.List(ctx)
151	return
152}
153