github.com/openshift-online/ocm-sdk-go@v0.1.473/accountsmgmt/v1/default_capability_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/accountsmgmt/v1
    21  
    22  import (
    23  	"bufio"
    24  	"bytes"
    25  	"context"
    26  	"io"
    27  	"net/http"
    28  	"net/url"
    29  	"time"
    30  
    31  	"github.com/openshift-online/ocm-sdk-go/errors"
    32  	"github.com/openshift-online/ocm-sdk-go/helpers"
    33  )
    34  
    35  // DefaultCapabilityClient is the client of the 'default_capability' resource.
    36  //
    37  // Manages a specific default capability.
    38  type DefaultCapabilityClient struct {
    39  	transport http.RoundTripper
    40  	path      string
    41  }
    42  
    43  // NewDefaultCapabilityClient creates a new client for the 'default_capability'
    44  // resource using the given transport to send the requests and receive the
    45  // responses.
    46  func NewDefaultCapabilityClient(transport http.RoundTripper, path string) *DefaultCapabilityClient {
    47  	return &DefaultCapabilityClient{
    48  		transport: transport,
    49  		path:      path,
    50  	}
    51  }
    52  
    53  // Delete creates a request for the 'delete' method.
    54  func (c *DefaultCapabilityClient) Delete() *DefaultCapabilityDeleteRequest {
    55  	return &DefaultCapabilityDeleteRequest{
    56  		transport: c.transport,
    57  		path:      c.path,
    58  	}
    59  }
    60  
    61  // Get creates a request for the 'get' method.
    62  //
    63  // Retrieves the details of the default capability.
    64  func (c *DefaultCapabilityClient) Get() *DefaultCapabilityGetRequest {
    65  	return &DefaultCapabilityGetRequest{
    66  		transport: c.transport,
    67  		path:      c.path,
    68  	}
    69  }
    70  
    71  // Update creates a request for the 'update' method.
    72  //
    73  // Updates the default capability.
    74  func (c *DefaultCapabilityClient) Update() *DefaultCapabilityUpdateRequest {
    75  	return &DefaultCapabilityUpdateRequest{
    76  		transport: c.transport,
    77  		path:      c.path,
    78  	}
    79  }
    80  
    81  // DefaultCapabilityPollRequest is the request for the Poll method.
    82  type DefaultCapabilityPollRequest struct {
    83  	request    *DefaultCapabilityGetRequest
    84  	interval   time.Duration
    85  	statuses   []int
    86  	predicates []func(interface{}) bool
    87  }
    88  
    89  // Parameter adds a query parameter to all the requests that will be used to retrieve the object.
    90  func (r *DefaultCapabilityPollRequest) Parameter(name string, value interface{}) *DefaultCapabilityPollRequest {
    91  	r.request.Parameter(name, value)
    92  	return r
    93  }
    94  
    95  // Header adds a request header to all the requests that will be used to retrieve the object.
    96  func (r *DefaultCapabilityPollRequest) Header(name string, value interface{}) *DefaultCapabilityPollRequest {
    97  	r.request.Header(name, value)
    98  	return r
    99  }
   100  
   101  // Interval sets the polling interval. This parameter is mandatory and must be greater than zero.
   102  func (r *DefaultCapabilityPollRequest) Interval(value time.Duration) *DefaultCapabilityPollRequest {
   103  	r.interval = value
   104  	return r
   105  }
   106  
   107  // Status set the expected status of the response. Multiple values can be set calling this method
   108  // multiple times. The response will be considered successful if the status is any of those values.
   109  func (r *DefaultCapabilityPollRequest) Status(value int) *DefaultCapabilityPollRequest {
   110  	r.statuses = append(r.statuses, value)
   111  	return r
   112  }
   113  
   114  // Predicate adds a predicate that the response should satisfy be considered successful. Multiple
   115  // predicates can be set calling this method multiple times. The response will be considered successful
   116  // if all the predicates are satisfied.
   117  func (r *DefaultCapabilityPollRequest) Predicate(value func(*DefaultCapabilityGetResponse) bool) *DefaultCapabilityPollRequest {
   118  	r.predicates = append(r.predicates, func(response interface{}) bool {
   119  		return value(response.(*DefaultCapabilityGetResponse))
   120  	})
   121  	return r
   122  }
   123  
   124  // StartContext starts the polling loop. Responses will be considered successful if the status is one of
   125  // the values specified with the Status method and if all the predicates specified with the Predicate
   126  // method return nil.
   127  //
   128  // The context must have a timeout or deadline, otherwise this method will immediately return an error.
   129  func (r *DefaultCapabilityPollRequest) StartContext(ctx context.Context) (response *DefaultCapabilityPollResponse, err error) {
   130  	result, err := helpers.PollContext(ctx, r.interval, r.statuses, r.predicates, r.task)
   131  	if result != nil {
   132  		response = &DefaultCapabilityPollResponse{
   133  			response: result.(*DefaultCapabilityGetResponse),
   134  		}
   135  	}
   136  	return
   137  }
   138  
   139  // task adapts the types of the request/response types so that they can be used with the generic
   140  // polling function from the helpers package.
   141  func (r *DefaultCapabilityPollRequest) task(ctx context.Context) (status int, result interface{}, err error) {
   142  	response, err := r.request.SendContext(ctx)
   143  	if response != nil {
   144  		status = response.Status()
   145  		result = response
   146  	}
   147  	return
   148  }
   149  
   150  // DefaultCapabilityPollResponse is the response for the Poll method.
   151  type DefaultCapabilityPollResponse struct {
   152  	response *DefaultCapabilityGetResponse
   153  }
   154  
   155  // Status returns the response status code.
   156  func (r *DefaultCapabilityPollResponse) Status() int {
   157  	if r == nil {
   158  		return 0
   159  	}
   160  	return r.response.Status()
   161  }
   162  
   163  // Header returns header of the response.
   164  func (r *DefaultCapabilityPollResponse) Header() http.Header {
   165  	if r == nil {
   166  		return nil
   167  	}
   168  	return r.response.Header()
   169  }
   170  
   171  // Error returns the response error.
   172  func (r *DefaultCapabilityPollResponse) Error() *errors.Error {
   173  	if r == nil {
   174  		return nil
   175  	}
   176  	return r.response.Error()
   177  }
   178  
   179  // Body returns the value of the 'body' parameter.
   180  func (r *DefaultCapabilityPollResponse) Body() *DefaultCapability {
   181  	return r.response.Body()
   182  }
   183  
   184  // GetBody returns the value of the 'body' parameter and
   185  // a flag indicating if the parameter has a value.
   186  func (r *DefaultCapabilityPollResponse) GetBody() (value *DefaultCapability, ok bool) {
   187  	return r.response.GetBody()
   188  }
   189  
   190  // Poll creates a request to repeatedly retrieve the object till the response has one of a given set
   191  // of states and satisfies a set of predicates.
   192  func (c *DefaultCapabilityClient) Poll() *DefaultCapabilityPollRequest {
   193  	return &DefaultCapabilityPollRequest{
   194  		request: c.Get(),
   195  	}
   196  }
   197  
   198  // DefaultCapabilityDeleteRequest is the request for the 'delete' method.
   199  type DefaultCapabilityDeleteRequest struct {
   200  	transport http.RoundTripper
   201  	path      string
   202  	query     url.Values
   203  	header    http.Header
   204  }
   205  
   206  // Parameter adds a query parameter.
   207  func (r *DefaultCapabilityDeleteRequest) Parameter(name string, value interface{}) *DefaultCapabilityDeleteRequest {
   208  	helpers.AddValue(&r.query, name, value)
   209  	return r
   210  }
   211  
   212  // Header adds a request header.
   213  func (r *DefaultCapabilityDeleteRequest) Header(name string, value interface{}) *DefaultCapabilityDeleteRequest {
   214  	helpers.AddHeader(&r.header, name, value)
   215  	return r
   216  }
   217  
   218  // Impersonate wraps requests on behalf of another user.
   219  // Note: Services that do not support this feature may silently ignore this call.
   220  func (r *DefaultCapabilityDeleteRequest) Impersonate(user string) *DefaultCapabilityDeleteRequest {
   221  	helpers.AddImpersonationHeader(&r.header, user)
   222  	return r
   223  }
   224  
   225  // Send sends this request, waits for the response, and returns it.
   226  //
   227  // This is a potentially lengthy operation, as it requires network communication.
   228  // Consider using a context and the SendContext method.
   229  func (r *DefaultCapabilityDeleteRequest) Send() (result *DefaultCapabilityDeleteResponse, err error) {
   230  	return r.SendContext(context.Background())
   231  }
   232  
   233  // SendContext sends this request, waits for the response, and returns it.
   234  func (r *DefaultCapabilityDeleteRequest) SendContext(ctx context.Context) (result *DefaultCapabilityDeleteResponse, err error) {
   235  	query := helpers.CopyQuery(r.query)
   236  	header := helpers.CopyHeader(r.header)
   237  	uri := &url.URL{
   238  		Path:     r.path,
   239  		RawQuery: query.Encode(),
   240  	}
   241  	request := &http.Request{
   242  		Method: "DELETE",
   243  		URL:    uri,
   244  		Header: header,
   245  	}
   246  	if ctx != nil {
   247  		request = request.WithContext(ctx)
   248  	}
   249  	response, err := r.transport.RoundTrip(request)
   250  	if err != nil {
   251  		return
   252  	}
   253  	defer response.Body.Close()
   254  	result = &DefaultCapabilityDeleteResponse{}
   255  	result.status = response.StatusCode
   256  	result.header = response.Header
   257  	reader := bufio.NewReader(response.Body)
   258  	_, err = reader.Peek(1)
   259  	if err == io.EOF {
   260  		err = nil
   261  		return
   262  	}
   263  	if result.status >= 400 {
   264  		result.err, err = errors.UnmarshalErrorStatus(reader, result.status)
   265  		if err != nil {
   266  			return
   267  		}
   268  		err = result.err
   269  		return
   270  	}
   271  	return
   272  }
   273  
   274  // DefaultCapabilityDeleteResponse is the response for the 'delete' method.
   275  type DefaultCapabilityDeleteResponse struct {
   276  	status int
   277  	header http.Header
   278  	err    *errors.Error
   279  }
   280  
   281  // Status returns the response status code.
   282  func (r *DefaultCapabilityDeleteResponse) Status() int {
   283  	if r == nil {
   284  		return 0
   285  	}
   286  	return r.status
   287  }
   288  
   289  // Header returns header of the response.
   290  func (r *DefaultCapabilityDeleteResponse) Header() http.Header {
   291  	if r == nil {
   292  		return nil
   293  	}
   294  	return r.header
   295  }
   296  
   297  // Error returns the response error.
   298  func (r *DefaultCapabilityDeleteResponse) Error() *errors.Error {
   299  	if r == nil {
   300  		return nil
   301  	}
   302  	return r.err
   303  }
   304  
   305  // DefaultCapabilityGetRequest is the request for the 'get' method.
   306  type DefaultCapabilityGetRequest struct {
   307  	transport http.RoundTripper
   308  	path      string
   309  	query     url.Values
   310  	header    http.Header
   311  }
   312  
   313  // Parameter adds a query parameter.
   314  func (r *DefaultCapabilityGetRequest) Parameter(name string, value interface{}) *DefaultCapabilityGetRequest {
   315  	helpers.AddValue(&r.query, name, value)
   316  	return r
   317  }
   318  
   319  // Header adds a request header.
   320  func (r *DefaultCapabilityGetRequest) Header(name string, value interface{}) *DefaultCapabilityGetRequest {
   321  	helpers.AddHeader(&r.header, name, value)
   322  	return r
   323  }
   324  
   325  // Impersonate wraps requests on behalf of another user.
   326  // Note: Services that do not support this feature may silently ignore this call.
   327  func (r *DefaultCapabilityGetRequest) Impersonate(user string) *DefaultCapabilityGetRequest {
   328  	helpers.AddImpersonationHeader(&r.header, user)
   329  	return r
   330  }
   331  
   332  // Send sends this request, waits for the response, and returns it.
   333  //
   334  // This is a potentially lengthy operation, as it requires network communication.
   335  // Consider using a context and the SendContext method.
   336  func (r *DefaultCapabilityGetRequest) Send() (result *DefaultCapabilityGetResponse, err error) {
   337  	return r.SendContext(context.Background())
   338  }
   339  
   340  // SendContext sends this request, waits for the response, and returns it.
   341  func (r *DefaultCapabilityGetRequest) SendContext(ctx context.Context) (result *DefaultCapabilityGetResponse, err error) {
   342  	query := helpers.CopyQuery(r.query)
   343  	header := helpers.CopyHeader(r.header)
   344  	uri := &url.URL{
   345  		Path:     r.path,
   346  		RawQuery: query.Encode(),
   347  	}
   348  	request := &http.Request{
   349  		Method: "GET",
   350  		URL:    uri,
   351  		Header: header,
   352  	}
   353  	if ctx != nil {
   354  		request = request.WithContext(ctx)
   355  	}
   356  	response, err := r.transport.RoundTrip(request)
   357  	if err != nil {
   358  		return
   359  	}
   360  	defer response.Body.Close()
   361  	result = &DefaultCapabilityGetResponse{}
   362  	result.status = response.StatusCode
   363  	result.header = response.Header
   364  	reader := bufio.NewReader(response.Body)
   365  	_, err = reader.Peek(1)
   366  	if err == io.EOF {
   367  		err = nil
   368  		return
   369  	}
   370  	if result.status >= 400 {
   371  		result.err, err = errors.UnmarshalErrorStatus(reader, result.status)
   372  		if err != nil {
   373  			return
   374  		}
   375  		err = result.err
   376  		return
   377  	}
   378  	err = readDefaultCapabilityGetResponse(result, reader)
   379  	if err != nil {
   380  		return
   381  	}
   382  	return
   383  }
   384  
   385  // DefaultCapabilityGetResponse is the response for the 'get' method.
   386  type DefaultCapabilityGetResponse struct {
   387  	status int
   388  	header http.Header
   389  	err    *errors.Error
   390  	body   *DefaultCapability
   391  }
   392  
   393  // Status returns the response status code.
   394  func (r *DefaultCapabilityGetResponse) Status() int {
   395  	if r == nil {
   396  		return 0
   397  	}
   398  	return r.status
   399  }
   400  
   401  // Header returns header of the response.
   402  func (r *DefaultCapabilityGetResponse) Header() http.Header {
   403  	if r == nil {
   404  		return nil
   405  	}
   406  	return r.header
   407  }
   408  
   409  // Error returns the response error.
   410  func (r *DefaultCapabilityGetResponse) Error() *errors.Error {
   411  	if r == nil {
   412  		return nil
   413  	}
   414  	return r.err
   415  }
   416  
   417  // Body returns the value of the 'body' parameter.
   418  func (r *DefaultCapabilityGetResponse) Body() *DefaultCapability {
   419  	if r == nil {
   420  		return nil
   421  	}
   422  	return r.body
   423  }
   424  
   425  // GetBody returns the value of the 'body' parameter and
   426  // a flag indicating if the parameter has a value.
   427  func (r *DefaultCapabilityGetResponse) GetBody() (value *DefaultCapability, ok bool) {
   428  	ok = r != nil && r.body != nil
   429  	if ok {
   430  		value = r.body
   431  	}
   432  	return
   433  }
   434  
   435  // DefaultCapabilityUpdateRequest is the request for the 'update' method.
   436  type DefaultCapabilityUpdateRequest struct {
   437  	transport http.RoundTripper
   438  	path      string
   439  	query     url.Values
   440  	header    http.Header
   441  	body      *DefaultCapability
   442  }
   443  
   444  // Parameter adds a query parameter.
   445  func (r *DefaultCapabilityUpdateRequest) Parameter(name string, value interface{}) *DefaultCapabilityUpdateRequest {
   446  	helpers.AddValue(&r.query, name, value)
   447  	return r
   448  }
   449  
   450  // Header adds a request header.
   451  func (r *DefaultCapabilityUpdateRequest) Header(name string, value interface{}) *DefaultCapabilityUpdateRequest {
   452  	helpers.AddHeader(&r.header, name, value)
   453  	return r
   454  }
   455  
   456  // Impersonate wraps requests on behalf of another user.
   457  // Note: Services that do not support this feature may silently ignore this call.
   458  func (r *DefaultCapabilityUpdateRequest) Impersonate(user string) *DefaultCapabilityUpdateRequest {
   459  	helpers.AddImpersonationHeader(&r.header, user)
   460  	return r
   461  }
   462  
   463  // Body sets the value of the 'body' parameter.
   464  func (r *DefaultCapabilityUpdateRequest) Body(value *DefaultCapability) *DefaultCapabilityUpdateRequest {
   465  	r.body = value
   466  	return r
   467  }
   468  
   469  // Send sends this request, waits for the response, and returns it.
   470  //
   471  // This is a potentially lengthy operation, as it requires network communication.
   472  // Consider using a context and the SendContext method.
   473  func (r *DefaultCapabilityUpdateRequest) Send() (result *DefaultCapabilityUpdateResponse, err error) {
   474  	return r.SendContext(context.Background())
   475  }
   476  
   477  // SendContext sends this request, waits for the response, and returns it.
   478  func (r *DefaultCapabilityUpdateRequest) SendContext(ctx context.Context) (result *DefaultCapabilityUpdateResponse, err error) {
   479  	query := helpers.CopyQuery(r.query)
   480  	header := helpers.CopyHeader(r.header)
   481  	buffer := &bytes.Buffer{}
   482  	err = writeDefaultCapabilityUpdateRequest(r, buffer)
   483  	if err != nil {
   484  		return
   485  	}
   486  	uri := &url.URL{
   487  		Path:     r.path,
   488  		RawQuery: query.Encode(),
   489  	}
   490  	request := &http.Request{
   491  		Method: "PATCH",
   492  		URL:    uri,
   493  		Header: header,
   494  		Body:   io.NopCloser(buffer),
   495  	}
   496  	if ctx != nil {
   497  		request = request.WithContext(ctx)
   498  	}
   499  	response, err := r.transport.RoundTrip(request)
   500  	if err != nil {
   501  		return
   502  	}
   503  	defer response.Body.Close()
   504  	result = &DefaultCapabilityUpdateResponse{}
   505  	result.status = response.StatusCode
   506  	result.header = response.Header
   507  	reader := bufio.NewReader(response.Body)
   508  	_, err = reader.Peek(1)
   509  	if err == io.EOF {
   510  		err = nil
   511  		return
   512  	}
   513  	if result.status >= 400 {
   514  		result.err, err = errors.UnmarshalErrorStatus(reader, result.status)
   515  		if err != nil {
   516  			return
   517  		}
   518  		err = result.err
   519  		return
   520  	}
   521  	err = readDefaultCapabilityUpdateResponse(result, reader)
   522  	if err != nil {
   523  		return
   524  	}
   525  	return
   526  }
   527  
   528  // DefaultCapabilityUpdateResponse is the response for the 'update' method.
   529  type DefaultCapabilityUpdateResponse struct {
   530  	status int
   531  	header http.Header
   532  	err    *errors.Error
   533  	body   *DefaultCapability
   534  }
   535  
   536  // Status returns the response status code.
   537  func (r *DefaultCapabilityUpdateResponse) Status() int {
   538  	if r == nil {
   539  		return 0
   540  	}
   541  	return r.status
   542  }
   543  
   544  // Header returns header of the response.
   545  func (r *DefaultCapabilityUpdateResponse) Header() http.Header {
   546  	if r == nil {
   547  		return nil
   548  	}
   549  	return r.header
   550  }
   551  
   552  // Error returns the response error.
   553  func (r *DefaultCapabilityUpdateResponse) Error() *errors.Error {
   554  	if r == nil {
   555  		return nil
   556  	}
   557  	return r.err
   558  }
   559  
   560  // Body returns the value of the 'body' parameter.
   561  func (r *DefaultCapabilityUpdateResponse) Body() *DefaultCapability {
   562  	if r == nil {
   563  		return nil
   564  	}
   565  	return r.body
   566  }
   567  
   568  // GetBody returns the value of the 'body' parameter and
   569  // a flag indicating if the parameter has a value.
   570  func (r *DefaultCapabilityUpdateResponse) GetBody() (value *DefaultCapability, ok bool) {
   571  	ok = r != nil && r.body != nil
   572  	if ok {
   573  		value = r.body
   574  	}
   575  	return
   576  }