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