github.com/openshift-online/ocm-sdk-go@v0.1.473/clustersmgmt/v1/clusterdeployment_client.go (about)

     1  /*
     2  Copyright (c) 2020 Red Hat, Inc.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     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  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  // IMPORTANT: This file has been generated automatically, refrain from modifying it manually as all
    18  // your changes will be lost when the file is generated again.
    19  
    20  package v1 // github.com/openshift-online/ocm-sdk-go/clustersmgmt/v1
    21  
    22  import (
    23  	"bufio"
    24  	"context"
    25  	"io"
    26  	"net/http"
    27  	"net/url"
    28  
    29  	"github.com/openshift-online/ocm-sdk-go/errors"
    30  	"github.com/openshift-online/ocm-sdk-go/helpers"
    31  )
    32  
    33  // ClusterdeploymentClient is the client of the 'clusterdeployment' resource.
    34  //
    35  // Manages a specific clusterdeployment.
    36  type ClusterdeploymentClient struct {
    37  	transport http.RoundTripper
    38  	path      string
    39  }
    40  
    41  // NewClusterdeploymentClient creates a new client for the 'clusterdeployment'
    42  // resource using the given transport to send the requests and receive the
    43  // responses.
    44  func NewClusterdeploymentClient(transport http.RoundTripper, path string) *ClusterdeploymentClient {
    45  	return &ClusterdeploymentClient{
    46  		transport: transport,
    47  		path:      path,
    48  	}
    49  }
    50  
    51  // Delete creates a request for the 'delete' method.
    52  //
    53  // Deletes the clusterdeployment.
    54  func (c *ClusterdeploymentClient) Delete() *ClusterdeploymentDeleteRequest {
    55  	return &ClusterdeploymentDeleteRequest{
    56  		transport: c.transport,
    57  		path:      c.path,
    58  	}
    59  }
    60  
    61  // ClusterdeploymentDeleteRequest is the request for the 'delete' method.
    62  type ClusterdeploymentDeleteRequest struct {
    63  	transport http.RoundTripper
    64  	path      string
    65  	query     url.Values
    66  	header    http.Header
    67  }
    68  
    69  // Parameter adds a query parameter.
    70  func (r *ClusterdeploymentDeleteRequest) Parameter(name string, value interface{}) *ClusterdeploymentDeleteRequest {
    71  	helpers.AddValue(&r.query, name, value)
    72  	return r
    73  }
    74  
    75  // Header adds a request header.
    76  func (r *ClusterdeploymentDeleteRequest) Header(name string, value interface{}) *ClusterdeploymentDeleteRequest {
    77  	helpers.AddHeader(&r.header, name, value)
    78  	return r
    79  }
    80  
    81  // Impersonate wraps requests on behalf of another user.
    82  // Note: Services that do not support this feature may silently ignore this call.
    83  func (r *ClusterdeploymentDeleteRequest) Impersonate(user string) *ClusterdeploymentDeleteRequest {
    84  	helpers.AddImpersonationHeader(&r.header, user)
    85  	return r
    86  }
    87  
    88  // Send sends this request, waits for the response, and returns it.
    89  //
    90  // This is a potentially lengthy operation, as it requires network communication.
    91  // Consider using a context and the SendContext method.
    92  func (r *ClusterdeploymentDeleteRequest) Send() (result *ClusterdeploymentDeleteResponse, err error) {
    93  	return r.SendContext(context.Background())
    94  }
    95  
    96  // SendContext sends this request, waits for the response, and returns it.
    97  func (r *ClusterdeploymentDeleteRequest) SendContext(ctx context.Context) (result *ClusterdeploymentDeleteResponse, err error) {
    98  	query := helpers.CopyQuery(r.query)
    99  	header := helpers.CopyHeader(r.header)
   100  	uri := &url.URL{
   101  		Path:     r.path,
   102  		RawQuery: query.Encode(),
   103  	}
   104  	request := &http.Request{
   105  		Method: "DELETE",
   106  		URL:    uri,
   107  		Header: header,
   108  	}
   109  	if ctx != nil {
   110  		request = request.WithContext(ctx)
   111  	}
   112  	response, err := r.transport.RoundTrip(request)
   113  	if err != nil {
   114  		return
   115  	}
   116  	defer response.Body.Close()
   117  	result = &ClusterdeploymentDeleteResponse{}
   118  	result.status = response.StatusCode
   119  	result.header = response.Header
   120  	reader := bufio.NewReader(response.Body)
   121  	_, err = reader.Peek(1)
   122  	if err == io.EOF {
   123  		err = nil
   124  		return
   125  	}
   126  	if result.status >= 400 {
   127  		result.err, err = errors.UnmarshalErrorStatus(reader, result.status)
   128  		if err != nil {
   129  			return
   130  		}
   131  		err = result.err
   132  		return
   133  	}
   134  	return
   135  }
   136  
   137  // ClusterdeploymentDeleteResponse is the response for the 'delete' method.
   138  type ClusterdeploymentDeleteResponse struct {
   139  	status int
   140  	header http.Header
   141  	err    *errors.Error
   142  }
   143  
   144  // Status returns the response status code.
   145  func (r *ClusterdeploymentDeleteResponse) Status() int {
   146  	if r == nil {
   147  		return 0
   148  	}
   149  	return r.status
   150  }
   151  
   152  // Header returns header of the response.
   153  func (r *ClusterdeploymentDeleteResponse) Header() http.Header {
   154  	if r == nil {
   155  		return nil
   156  	}
   157  	return r.header
   158  }
   159  
   160  // Error returns the response error.
   161  func (r *ClusterdeploymentDeleteResponse) Error() *errors.Error {
   162  	if r == nil {
   163  		return nil
   164  	}
   165  	return r.err
   166  }