1package logic
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//
6// Code generated by Microsoft (R) AutoRest Code Generator.
7// Changes may cause incorrect behavior and will be lost if the code is regenerated.
8
9import (
10	"context"
11	"github.com/Azure/go-autorest/autorest"
12	"github.com/Azure/go-autorest/autorest/azure"
13	"github.com/Azure/go-autorest/tracing"
14	"net/http"
15)
16
17// WorkflowRunOperationsClient is the REST API for Azure Logic Apps.
18type WorkflowRunOperationsClient struct {
19	BaseClient
20}
21
22// NewWorkflowRunOperationsClient creates an instance of the WorkflowRunOperationsClient client.
23func NewWorkflowRunOperationsClient(subscriptionID string) WorkflowRunOperationsClient {
24	return NewWorkflowRunOperationsClientWithBaseURI(DefaultBaseURI, subscriptionID)
25}
26
27// NewWorkflowRunOperationsClientWithBaseURI creates an instance of the WorkflowRunOperationsClient client using a
28// custom endpoint.  Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds,
29// Azure stack).
30func NewWorkflowRunOperationsClientWithBaseURI(baseURI string, subscriptionID string) WorkflowRunOperationsClient {
31	return WorkflowRunOperationsClient{NewWithBaseURI(baseURI, subscriptionID)}
32}
33
34// Get gets an operation for a run.
35// Parameters:
36// resourceGroupName - the resource group name.
37// workflowName - the workflow name.
38// runName - the workflow run name.
39// operationID - the workflow operation id.
40func (client WorkflowRunOperationsClient) Get(ctx context.Context, resourceGroupName string, workflowName string, runName string, operationID string) (result WorkflowRun, err error) {
41	if tracing.IsEnabled() {
42		ctx = tracing.StartSpan(ctx, fqdn+"/WorkflowRunOperationsClient.Get")
43		defer func() {
44			sc := -1
45			if result.Response.Response != nil {
46				sc = result.Response.Response.StatusCode
47			}
48			tracing.EndSpan(ctx, sc, err)
49		}()
50	}
51	req, err := client.GetPreparer(ctx, resourceGroupName, workflowName, runName, operationID)
52	if err != nil {
53		err = autorest.NewErrorWithError(err, "logic.WorkflowRunOperationsClient", "Get", nil, "Failure preparing request")
54		return
55	}
56
57	resp, err := client.GetSender(req)
58	if err != nil {
59		result.Response = autorest.Response{Response: resp}
60		err = autorest.NewErrorWithError(err, "logic.WorkflowRunOperationsClient", "Get", resp, "Failure sending request")
61		return
62	}
63
64	result, err = client.GetResponder(resp)
65	if err != nil {
66		err = autorest.NewErrorWithError(err, "logic.WorkflowRunOperationsClient", "Get", resp, "Failure responding to request")
67		return
68	}
69
70	return
71}
72
73// GetPreparer prepares the Get request.
74func (client WorkflowRunOperationsClient) GetPreparer(ctx context.Context, resourceGroupName string, workflowName string, runName string, operationID string) (*http.Request, error) {
75	pathParameters := map[string]interface{}{
76		"operationId":       autorest.Encode("path", operationID),
77		"resourceGroupName": autorest.Encode("path", resourceGroupName),
78		"runName":           autorest.Encode("path", runName),
79		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
80		"workflowName":      autorest.Encode("path", workflowName),
81	}
82
83	const APIVersion = "2019-05-01"
84	queryParameters := map[string]interface{}{
85		"api-version": APIVersion,
86	}
87
88	preparer := autorest.CreatePreparer(
89		autorest.AsGet(),
90		autorest.WithBaseURL(client.BaseURI),
91		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Logic/workflows/{workflowName}/runs/{runName}/operations/{operationId}", pathParameters),
92		autorest.WithQueryParameters(queryParameters))
93	return preparer.Prepare((&http.Request{}).WithContext(ctx))
94}
95
96// GetSender sends the Get request. The method will close the
97// http.Response Body if it receives an error.
98func (client WorkflowRunOperationsClient) GetSender(req *http.Request) (*http.Response, error) {
99	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
100}
101
102// GetResponder handles the response to the Get request. The method always
103// closes the http.Response Body.
104func (client WorkflowRunOperationsClient) GetResponder(resp *http.Response) (result WorkflowRun, err error) {
105	err = autorest.Respond(
106		resp,
107		azure.WithErrorUnlessStatusCode(http.StatusOK),
108		autorest.ByUnmarshallingJSON(&result),
109		autorest.ByClosing())
110	result.Response = autorest.Response{Response: resp}
111	return
112}
113