github.com/openshift-online/ocm-sdk-go@v0.1.473/accountsmgmt/v1/default_capabilities_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  	"path"
    30  
    31  	"github.com/openshift-online/ocm-sdk-go/errors"
    32  	"github.com/openshift-online/ocm-sdk-go/helpers"
    33  )
    34  
    35  // DefaultCapabilitiesClient is the client of the 'default_capabilities' resource.
    36  type DefaultCapabilitiesClient struct {
    37  	transport http.RoundTripper
    38  	path      string
    39  }
    40  
    41  // NewDefaultCapabilitiesClient creates a new client for the 'default_capabilities'
    42  // resource using the given transport to send the requests and receive the
    43  // responses.
    44  func NewDefaultCapabilitiesClient(transport http.RoundTripper, path string) *DefaultCapabilitiesClient {
    45  	return &DefaultCapabilitiesClient{
    46  		transport: transport,
    47  		path:      path,
    48  	}
    49  }
    50  
    51  // Add creates a request for the 'add' method.
    52  //
    53  // Creates a new default capability.
    54  func (c *DefaultCapabilitiesClient) Add() *DefaultCapabilitiesAddRequest {
    55  	return &DefaultCapabilitiesAddRequest{
    56  		transport: c.transport,
    57  		path:      c.path,
    58  	}
    59  }
    60  
    61  // List creates a request for the 'list' method.
    62  //
    63  // Retrieves a list of Dedfault Capabilities.
    64  func (c *DefaultCapabilitiesClient) List() *DefaultCapabilitiesListRequest {
    65  	return &DefaultCapabilitiesListRequest{
    66  		transport: c.transport,
    67  		path:      c.path,
    68  	}
    69  }
    70  
    71  // DefaultCapability returns the target 'default_capability' resource for the given identifier.
    72  //
    73  // Reference to the service that manages an specific default capability.
    74  func (c *DefaultCapabilitiesClient) DefaultCapability(id string) *DefaultCapabilityClient {
    75  	return NewDefaultCapabilityClient(
    76  		c.transport,
    77  		path.Join(c.path, id),
    78  	)
    79  }
    80  
    81  // DefaultCapabilitiesAddRequest is the request for the 'add' method.
    82  type DefaultCapabilitiesAddRequest struct {
    83  	transport http.RoundTripper
    84  	path      string
    85  	query     url.Values
    86  	header    http.Header
    87  	body      *DefaultCapability
    88  }
    89  
    90  // Parameter adds a query parameter.
    91  func (r *DefaultCapabilitiesAddRequest) Parameter(name string, value interface{}) *DefaultCapabilitiesAddRequest {
    92  	helpers.AddValue(&r.query, name, value)
    93  	return r
    94  }
    95  
    96  // Header adds a request header.
    97  func (r *DefaultCapabilitiesAddRequest) Header(name string, value interface{}) *DefaultCapabilitiesAddRequest {
    98  	helpers.AddHeader(&r.header, name, value)
    99  	return r
   100  }
   101  
   102  // Impersonate wraps requests on behalf of another user.
   103  // Note: Services that do not support this feature may silently ignore this call.
   104  func (r *DefaultCapabilitiesAddRequest) Impersonate(user string) *DefaultCapabilitiesAddRequest {
   105  	helpers.AddImpersonationHeader(&r.header, user)
   106  	return r
   107  }
   108  
   109  // Body sets the value of the 'body' parameter.
   110  //
   111  // Default capability data.
   112  func (r *DefaultCapabilitiesAddRequest) Body(value *DefaultCapability) *DefaultCapabilitiesAddRequest {
   113  	r.body = value
   114  	return r
   115  }
   116  
   117  // Send sends this request, waits for the response, and returns it.
   118  //
   119  // This is a potentially lengthy operation, as it requires network communication.
   120  // Consider using a context and the SendContext method.
   121  func (r *DefaultCapabilitiesAddRequest) Send() (result *DefaultCapabilitiesAddResponse, err error) {
   122  	return r.SendContext(context.Background())
   123  }
   124  
   125  // SendContext sends this request, waits for the response, and returns it.
   126  func (r *DefaultCapabilitiesAddRequest) SendContext(ctx context.Context) (result *DefaultCapabilitiesAddResponse, err error) {
   127  	query := helpers.CopyQuery(r.query)
   128  	header := helpers.CopyHeader(r.header)
   129  	buffer := &bytes.Buffer{}
   130  	err = writeDefaultCapabilitiesAddRequest(r, buffer)
   131  	if err != nil {
   132  		return
   133  	}
   134  	uri := &url.URL{
   135  		Path:     r.path,
   136  		RawQuery: query.Encode(),
   137  	}
   138  	request := &http.Request{
   139  		Method: "POST",
   140  		URL:    uri,
   141  		Header: header,
   142  		Body:   io.NopCloser(buffer),
   143  	}
   144  	if ctx != nil {
   145  		request = request.WithContext(ctx)
   146  	}
   147  	response, err := r.transport.RoundTrip(request)
   148  	if err != nil {
   149  		return
   150  	}
   151  	defer response.Body.Close()
   152  	result = &DefaultCapabilitiesAddResponse{}
   153  	result.status = response.StatusCode
   154  	result.header = response.Header
   155  	reader := bufio.NewReader(response.Body)
   156  	_, err = reader.Peek(1)
   157  	if err == io.EOF {
   158  		err = nil
   159  		return
   160  	}
   161  	if result.status >= 400 {
   162  		result.err, err = errors.UnmarshalErrorStatus(reader, result.status)
   163  		if err != nil {
   164  			return
   165  		}
   166  		err = result.err
   167  		return
   168  	}
   169  	err = readDefaultCapabilitiesAddResponse(result, reader)
   170  	if err != nil {
   171  		return
   172  	}
   173  	return
   174  }
   175  
   176  // DefaultCapabilitiesAddResponse is the response for the 'add' method.
   177  type DefaultCapabilitiesAddResponse struct {
   178  	status int
   179  	header http.Header
   180  	err    *errors.Error
   181  	body   *DefaultCapability
   182  }
   183  
   184  // Status returns the response status code.
   185  func (r *DefaultCapabilitiesAddResponse) Status() int {
   186  	if r == nil {
   187  		return 0
   188  	}
   189  	return r.status
   190  }
   191  
   192  // Header returns header of the response.
   193  func (r *DefaultCapabilitiesAddResponse) Header() http.Header {
   194  	if r == nil {
   195  		return nil
   196  	}
   197  	return r.header
   198  }
   199  
   200  // Error returns the response error.
   201  func (r *DefaultCapabilitiesAddResponse) Error() *errors.Error {
   202  	if r == nil {
   203  		return nil
   204  	}
   205  	return r.err
   206  }
   207  
   208  // Body returns the value of the 'body' parameter.
   209  //
   210  // Default capability data.
   211  func (r *DefaultCapabilitiesAddResponse) Body() *DefaultCapability {
   212  	if r == nil {
   213  		return nil
   214  	}
   215  	return r.body
   216  }
   217  
   218  // GetBody returns the value of the 'body' parameter and
   219  // a flag indicating if the parameter has a value.
   220  //
   221  // Default capability data.
   222  func (r *DefaultCapabilitiesAddResponse) GetBody() (value *DefaultCapability, ok bool) {
   223  	ok = r != nil && r.body != nil
   224  	if ok {
   225  		value = r.body
   226  	}
   227  	return
   228  }
   229  
   230  // DefaultCapabilitiesListRequest is the request for the 'list' method.
   231  type DefaultCapabilitiesListRequest struct {
   232  	transport http.RoundTripper
   233  	path      string
   234  	query     url.Values
   235  	header    http.Header
   236  	page      *int
   237  	search    *string
   238  	size      *int
   239  }
   240  
   241  // Parameter adds a query parameter.
   242  func (r *DefaultCapabilitiesListRequest) Parameter(name string, value interface{}) *DefaultCapabilitiesListRequest {
   243  	helpers.AddValue(&r.query, name, value)
   244  	return r
   245  }
   246  
   247  // Header adds a request header.
   248  func (r *DefaultCapabilitiesListRequest) Header(name string, value interface{}) *DefaultCapabilitiesListRequest {
   249  	helpers.AddHeader(&r.header, name, value)
   250  	return r
   251  }
   252  
   253  // Impersonate wraps requests on behalf of another user.
   254  // Note: Services that do not support this feature may silently ignore this call.
   255  func (r *DefaultCapabilitiesListRequest) Impersonate(user string) *DefaultCapabilitiesListRequest {
   256  	helpers.AddImpersonationHeader(&r.header, user)
   257  	return r
   258  }
   259  
   260  // Page sets the value of the 'page' parameter.
   261  //
   262  // Index of the requested page, where one corresponds to the first page.
   263  func (r *DefaultCapabilitiesListRequest) Page(value int) *DefaultCapabilitiesListRequest {
   264  	r.page = &value
   265  	return r
   266  }
   267  
   268  // Search sets the value of the 'search' parameter.
   269  //
   270  // Search criteria.
   271  //
   272  // The syntax of this parameter is similar to the syntax of the _where_ clause
   273  // of an SQL statement, but using the names of the attributes of the organization
   274  // instead of the names of the columns of a table. For example, in order to
   275  // retrieve organizations with name starting with my:
   276  //
   277  // ```sql
   278  // name like 'my%'
   279  // ```
   280  //
   281  // If the parameter isn't provided, or if the value is empty, then all the
   282  // items that the user has permission to see will be returned.
   283  func (r *DefaultCapabilitiesListRequest) Search(value string) *DefaultCapabilitiesListRequest {
   284  	r.search = &value
   285  	return r
   286  }
   287  
   288  // Size sets the value of the 'size' parameter.
   289  //
   290  // Maximum number of items that will be contained in the returned page.
   291  func (r *DefaultCapabilitiesListRequest) Size(value int) *DefaultCapabilitiesListRequest {
   292  	r.size = &value
   293  	return r
   294  }
   295  
   296  // Send sends this request, waits for the response, and returns it.
   297  //
   298  // This is a potentially lengthy operation, as it requires network communication.
   299  // Consider using a context and the SendContext method.
   300  func (r *DefaultCapabilitiesListRequest) Send() (result *DefaultCapabilitiesListResponse, err error) {
   301  	return r.SendContext(context.Background())
   302  }
   303  
   304  // SendContext sends this request, waits for the response, and returns it.
   305  func (r *DefaultCapabilitiesListRequest) SendContext(ctx context.Context) (result *DefaultCapabilitiesListResponse, err error) {
   306  	query := helpers.CopyQuery(r.query)
   307  	if r.page != nil {
   308  		helpers.AddValue(&query, "page", *r.page)
   309  	}
   310  	if r.search != nil {
   311  		helpers.AddValue(&query, "search", *r.search)
   312  	}
   313  	if r.size != nil {
   314  		helpers.AddValue(&query, "size", *r.size)
   315  	}
   316  	header := helpers.CopyHeader(r.header)
   317  	uri := &url.URL{
   318  		Path:     r.path,
   319  		RawQuery: query.Encode(),
   320  	}
   321  	request := &http.Request{
   322  		Method: "GET",
   323  		URL:    uri,
   324  		Header: header,
   325  	}
   326  	if ctx != nil {
   327  		request = request.WithContext(ctx)
   328  	}
   329  	response, err := r.transport.RoundTrip(request)
   330  	if err != nil {
   331  		return
   332  	}
   333  	defer response.Body.Close()
   334  	result = &DefaultCapabilitiesListResponse{}
   335  	result.status = response.StatusCode
   336  	result.header = response.Header
   337  	reader := bufio.NewReader(response.Body)
   338  	_, err = reader.Peek(1)
   339  	if err == io.EOF {
   340  		err = nil
   341  		return
   342  	}
   343  	if result.status >= 400 {
   344  		result.err, err = errors.UnmarshalErrorStatus(reader, result.status)
   345  		if err != nil {
   346  			return
   347  		}
   348  		err = result.err
   349  		return
   350  	}
   351  	err = readDefaultCapabilitiesListResponse(result, reader)
   352  	if err != nil {
   353  		return
   354  	}
   355  	return
   356  }
   357  
   358  // DefaultCapabilitiesListResponse is the response for the 'list' method.
   359  type DefaultCapabilitiesListResponse struct {
   360  	status int
   361  	header http.Header
   362  	err    *errors.Error
   363  	items  *DefaultCapabilityList
   364  	page   *int
   365  	size   *int
   366  	total  *int
   367  }
   368  
   369  // Status returns the response status code.
   370  func (r *DefaultCapabilitiesListResponse) Status() int {
   371  	if r == nil {
   372  		return 0
   373  	}
   374  	return r.status
   375  }
   376  
   377  // Header returns header of the response.
   378  func (r *DefaultCapabilitiesListResponse) Header() http.Header {
   379  	if r == nil {
   380  		return nil
   381  	}
   382  	return r.header
   383  }
   384  
   385  // Error returns the response error.
   386  func (r *DefaultCapabilitiesListResponse) Error() *errors.Error {
   387  	if r == nil {
   388  		return nil
   389  	}
   390  	return r.err
   391  }
   392  
   393  // Items returns the value of the 'items' parameter.
   394  //
   395  // Retrieved list of Default Capabilities.
   396  func (r *DefaultCapabilitiesListResponse) Items() *DefaultCapabilityList {
   397  	if r == nil {
   398  		return nil
   399  	}
   400  	return r.items
   401  }
   402  
   403  // GetItems returns the value of the 'items' parameter and
   404  // a flag indicating if the parameter has a value.
   405  //
   406  // Retrieved list of Default Capabilities.
   407  func (r *DefaultCapabilitiesListResponse) GetItems() (value *DefaultCapabilityList, ok bool) {
   408  	ok = r != nil && r.items != nil
   409  	if ok {
   410  		value = r.items
   411  	}
   412  	return
   413  }
   414  
   415  // Page returns the value of the 'page' parameter.
   416  //
   417  // Index of the requested page, where one corresponds to the first page.
   418  func (r *DefaultCapabilitiesListResponse) Page() int {
   419  	if r != nil && r.page != nil {
   420  		return *r.page
   421  	}
   422  	return 0
   423  }
   424  
   425  // GetPage returns the value of the 'page' parameter and
   426  // a flag indicating if the parameter has a value.
   427  //
   428  // Index of the requested page, where one corresponds to the first page.
   429  func (r *DefaultCapabilitiesListResponse) GetPage() (value int, ok bool) {
   430  	ok = r != nil && r.page != nil
   431  	if ok {
   432  		value = *r.page
   433  	}
   434  	return
   435  }
   436  
   437  // Size returns the value of the 'size' parameter.
   438  //
   439  // Maximum number of items that will be contained in the returned page.
   440  func (r *DefaultCapabilitiesListResponse) Size() int {
   441  	if r != nil && r.size != nil {
   442  		return *r.size
   443  	}
   444  	return 0
   445  }
   446  
   447  // GetSize returns the value of the 'size' parameter and
   448  // a flag indicating if the parameter has a value.
   449  //
   450  // Maximum number of items that will be contained in the returned page.
   451  func (r *DefaultCapabilitiesListResponse) GetSize() (value int, ok bool) {
   452  	ok = r != nil && r.size != nil
   453  	if ok {
   454  		value = *r.size
   455  	}
   456  	return
   457  }
   458  
   459  // Total returns the value of the 'total' parameter.
   460  //
   461  // Total number of items of the collection that match the search criteria,
   462  // regardless of the size of the page.
   463  func (r *DefaultCapabilitiesListResponse) Total() int {
   464  	if r != nil && r.total != nil {
   465  		return *r.total
   466  	}
   467  	return 0
   468  }
   469  
   470  // GetTotal returns the value of the 'total' parameter and
   471  // a flag indicating if the parameter has a value.
   472  //
   473  // Total number of items of the collection that match the search criteria,
   474  // regardless of the size of the page.
   475  func (r *DefaultCapabilitiesListResponse) GetTotal() (value int, ok bool) {
   476  	ok = r != nil && r.total != nil
   477  	if ok {
   478  		value = *r.total
   479  	}
   480  	return
   481  }