github.com/openshift-online/ocm-sdk-go@v0.1.473/authorizations/v1/self_capability_review_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/authorizations/v1
    21  
    22  import (
    23  	"bufio"
    24  	"bytes"
    25  	"context"
    26  	"io"
    27  	"net/http"
    28  	"net/url"
    29  
    30  	"github.com/openshift-online/ocm-sdk-go/errors"
    31  	"github.com/openshift-online/ocm-sdk-go/helpers"
    32  )
    33  
    34  // SelfCapabilityReviewClient is the client of the 'self_capability_review' resource.
    35  //
    36  // Manages capability review.
    37  type SelfCapabilityReviewClient struct {
    38  	transport http.RoundTripper
    39  	path      string
    40  }
    41  
    42  // NewSelfCapabilityReviewClient creates a new client for the 'self_capability_review'
    43  // resource using the given transport to send the requests and receive the
    44  // responses.
    45  func NewSelfCapabilityReviewClient(transport http.RoundTripper, path string) *SelfCapabilityReviewClient {
    46  	return &SelfCapabilityReviewClient{
    47  		transport: transport,
    48  		path:      path,
    49  	}
    50  }
    51  
    52  // Post creates a request for the 'post' method.
    53  //
    54  // Reviews a user's capability to a resource.
    55  func (c *SelfCapabilityReviewClient) Post() *SelfCapabilityReviewPostRequest {
    56  	return &SelfCapabilityReviewPostRequest{
    57  		transport: c.transport,
    58  		path:      c.path,
    59  	}
    60  }
    61  
    62  // SelfCapabilityReviewPostRequest is the request for the 'post' method.
    63  type SelfCapabilityReviewPostRequest struct {
    64  	transport http.RoundTripper
    65  	path      string
    66  	query     url.Values
    67  	header    http.Header
    68  	request   *SelfCapabilityReviewRequest
    69  }
    70  
    71  // Parameter adds a query parameter.
    72  func (r *SelfCapabilityReviewPostRequest) Parameter(name string, value interface{}) *SelfCapabilityReviewPostRequest {
    73  	helpers.AddValue(&r.query, name, value)
    74  	return r
    75  }
    76  
    77  // Header adds a request header.
    78  func (r *SelfCapabilityReviewPostRequest) Header(name string, value interface{}) *SelfCapabilityReviewPostRequest {
    79  	helpers.AddHeader(&r.header, name, value)
    80  	return r
    81  }
    82  
    83  // Impersonate wraps requests on behalf of another user.
    84  // Note: Services that do not support this feature may silently ignore this call.
    85  func (r *SelfCapabilityReviewPostRequest) Impersonate(user string) *SelfCapabilityReviewPostRequest {
    86  	helpers.AddImpersonationHeader(&r.header, user)
    87  	return r
    88  }
    89  
    90  // Request sets the value of the 'request' parameter.
    91  func (r *SelfCapabilityReviewPostRequest) Request(value *SelfCapabilityReviewRequest) *SelfCapabilityReviewPostRequest {
    92  	r.request = value
    93  	return r
    94  }
    95  
    96  // Send sends this request, waits for the response, and returns it.
    97  //
    98  // This is a potentially lengthy operation, as it requires network communication.
    99  // Consider using a context and the SendContext method.
   100  func (r *SelfCapabilityReviewPostRequest) Send() (result *SelfCapabilityReviewPostResponse, err error) {
   101  	return r.SendContext(context.Background())
   102  }
   103  
   104  // SendContext sends this request, waits for the response, and returns it.
   105  func (r *SelfCapabilityReviewPostRequest) SendContext(ctx context.Context) (result *SelfCapabilityReviewPostResponse, err error) {
   106  	query := helpers.CopyQuery(r.query)
   107  	header := helpers.CopyHeader(r.header)
   108  	buffer := &bytes.Buffer{}
   109  	err = writeSelfCapabilityReviewPostRequest(r, buffer)
   110  	if err != nil {
   111  		return
   112  	}
   113  	uri := &url.URL{
   114  		Path:     r.path,
   115  		RawQuery: query.Encode(),
   116  	}
   117  	request := &http.Request{
   118  		Method: "POST",
   119  		URL:    uri,
   120  		Header: header,
   121  		Body:   io.NopCloser(buffer),
   122  	}
   123  	if ctx != nil {
   124  		request = request.WithContext(ctx)
   125  	}
   126  	response, err := r.transport.RoundTrip(request)
   127  	if err != nil {
   128  		return
   129  	}
   130  	defer response.Body.Close()
   131  	result = &SelfCapabilityReviewPostResponse{}
   132  	result.status = response.StatusCode
   133  	result.header = response.Header
   134  	reader := bufio.NewReader(response.Body)
   135  	_, err = reader.Peek(1)
   136  	if err == io.EOF {
   137  		err = nil
   138  		return
   139  	}
   140  	if result.status >= 400 {
   141  		result.err, err = errors.UnmarshalErrorStatus(reader, result.status)
   142  		if err != nil {
   143  			return
   144  		}
   145  		err = result.err
   146  		return
   147  	}
   148  	err = readSelfCapabilityReviewPostResponse(result, reader)
   149  	if err != nil {
   150  		return
   151  	}
   152  	return
   153  }
   154  
   155  // SelfCapabilityReviewPostResponse is the response for the 'post' method.
   156  type SelfCapabilityReviewPostResponse struct {
   157  	status   int
   158  	header   http.Header
   159  	err      *errors.Error
   160  	response *SelfCapabilityReviewResponse
   161  }
   162  
   163  // Status returns the response status code.
   164  func (r *SelfCapabilityReviewPostResponse) Status() int {
   165  	if r == nil {
   166  		return 0
   167  	}
   168  	return r.status
   169  }
   170  
   171  // Header returns header of the response.
   172  func (r *SelfCapabilityReviewPostResponse) Header() http.Header {
   173  	if r == nil {
   174  		return nil
   175  	}
   176  	return r.header
   177  }
   178  
   179  // Error returns the response error.
   180  func (r *SelfCapabilityReviewPostResponse) Error() *errors.Error {
   181  	if r == nil {
   182  		return nil
   183  	}
   184  	return r.err
   185  }
   186  
   187  // Response returns the value of the 'response' parameter.
   188  func (r *SelfCapabilityReviewPostResponse) Response() *SelfCapabilityReviewResponse {
   189  	if r == nil {
   190  		return nil
   191  	}
   192  	return r.response
   193  }
   194  
   195  // GetResponse returns the value of the 'response' parameter and
   196  // a flag indicating if the parameter has a value.
   197  func (r *SelfCapabilityReviewPostResponse) GetResponse() (value *SelfCapabilityReviewResponse, ok bool) {
   198  	ok = r != nil && r.response != nil
   199  	if ok {
   200  		value = r.response
   201  	}
   202  	return
   203  }