1// +build go1.13
2
3// Copyright (c) Microsoft Corporation. All rights reserved.
4// Licensed under the MIT License. See License.txt in the project root for license information.
5// Code generated by Microsoft (R) AutoRest Code Generator.
6// Changes may cause incorrect behavior and will be lost if the code is regenerated.
7
8package armeventgrid
9
10import (
11	"context"
12	"errors"
13	"github.com/Azure/azure-sdk-for-go/sdk/armcore"
14	"github.com/Azure/azure-sdk-for-go/sdk/azcore"
15	"net/http"
16)
17
18// OperationsClient contains the methods for the Operations group.
19// Don't use this type directly, use NewOperationsClient() instead.
20type OperationsClient struct {
21	con *armcore.Connection
22}
23
24// NewOperationsClient creates a new instance of OperationsClient with the specified values.
25func NewOperationsClient(con *armcore.Connection) *OperationsClient {
26	return &OperationsClient{con: con}
27}
28
29// List - List the available operations supported by the Microsoft.EventGrid resource provider.
30// If the operation fails it returns a generic error.
31func (client *OperationsClient) List(ctx context.Context, options *OperationsListOptions) (OperationsListResponse, error) {
32	req, err := client.listCreateRequest(ctx, options)
33	if err != nil {
34		return OperationsListResponse{}, err
35	}
36	resp, err := client.con.Pipeline().Do(req)
37	if err != nil {
38		return OperationsListResponse{}, err
39	}
40	if !resp.HasStatusCode(http.StatusOK) {
41		return OperationsListResponse{}, client.listHandleError(resp)
42	}
43	return client.listHandleResponse(resp)
44}
45
46// listCreateRequest creates the List request.
47func (client *OperationsClient) listCreateRequest(ctx context.Context, options *OperationsListOptions) (*azcore.Request, error) {
48	urlPath := "/providers/Microsoft.EventGrid/operations"
49	req, err := azcore.NewRequest(ctx, http.MethodGet, azcore.JoinPaths(client.con.Endpoint(), urlPath))
50	if err != nil {
51		return nil, err
52	}
53	req.Telemetry(telemetryInfo)
54	reqQP := req.URL.Query()
55	reqQP.Set("api-version", "2021-06-01-preview")
56	req.URL.RawQuery = reqQP.Encode()
57	req.Header.Set("Accept", "application/json")
58	return req, nil
59}
60
61// listHandleResponse handles the List response.
62func (client *OperationsClient) listHandleResponse(resp *azcore.Response) (OperationsListResponse, error) {
63	result := OperationsListResponse{RawResponse: resp.Response}
64	if err := resp.UnmarshalAsJSON(&result.OperationsListResult); err != nil {
65		return OperationsListResponse{}, err
66	}
67	return result, nil
68}
69
70// listHandleError handles the List error response.
71func (client *OperationsClient) listHandleError(resp *azcore.Response) error {
72	body, err := resp.Payload()
73	if err != nil {
74		return azcore.NewResponseError(err, resp.Response)
75	}
76	if len(body) == 0 {
77		return azcore.NewResponseError(errors.New(resp.Status), resp.Response)
78	}
79	return azcore.NewResponseError(errors.New(string(body)), resp.Response)
80}
81