github.com/openshift-online/ocm-sdk-go@v0.1.473/osdfleetmgmt/v1/service_clusters_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/osdfleetmgmt/v1
    21  
    22  import (
    23  	"bufio"
    24  	"context"
    25  	"io"
    26  	"net/http"
    27  	"net/url"
    28  	"path"
    29  
    30  	"github.com/openshift-online/ocm-sdk-go/errors"
    31  	"github.com/openshift-online/ocm-sdk-go/helpers"
    32  )
    33  
    34  // ServiceClustersClient is the client of the 'service_clusters' resource.
    35  //
    36  // Manages the collection of service clusters.
    37  type ServiceClustersClient struct {
    38  	transport http.RoundTripper
    39  	path      string
    40  }
    41  
    42  // NewServiceClustersClient creates a new client for the 'service_clusters'
    43  // resource using the given transport to send the requests and receive the
    44  // responses.
    45  func NewServiceClustersClient(transport http.RoundTripper, path string) *ServiceClustersClient {
    46  	return &ServiceClustersClient{
    47  		transport: transport,
    48  		path:      path,
    49  	}
    50  }
    51  
    52  // List creates a request for the 'list' method.
    53  //
    54  // Retrieves the list of service clusters.
    55  func (c *ServiceClustersClient) List() *ServiceClustersListRequest {
    56  	return &ServiceClustersListRequest{
    57  		transport: c.transport,
    58  		path:      c.path,
    59  	}
    60  }
    61  
    62  // ServiceCluster returns the target 'service_cluster' resource for the given identifier.
    63  //
    64  // Returns a reference to the resource that manages a specific service cluster.
    65  func (c *ServiceClustersClient) ServiceCluster(id string) *ServiceClusterClient {
    66  	return NewServiceClusterClient(
    67  		c.transport,
    68  		path.Join(c.path, id),
    69  	)
    70  }
    71  
    72  // ServiceClustersListRequest is the request for the 'list' method.
    73  type ServiceClustersListRequest struct {
    74  	transport http.RoundTripper
    75  	path      string
    76  	query     url.Values
    77  	header    http.Header
    78  	page      *int
    79  	size      *int
    80  }
    81  
    82  // Parameter adds a query parameter.
    83  func (r *ServiceClustersListRequest) Parameter(name string, value interface{}) *ServiceClustersListRequest {
    84  	helpers.AddValue(&r.query, name, value)
    85  	return r
    86  }
    87  
    88  // Header adds a request header.
    89  func (r *ServiceClustersListRequest) Header(name string, value interface{}) *ServiceClustersListRequest {
    90  	helpers.AddHeader(&r.header, name, value)
    91  	return r
    92  }
    93  
    94  // Impersonate wraps requests on behalf of another user.
    95  // Note: Services that do not support this feature may silently ignore this call.
    96  func (r *ServiceClustersListRequest) Impersonate(user string) *ServiceClustersListRequest {
    97  	helpers.AddImpersonationHeader(&r.header, user)
    98  	return r
    99  }
   100  
   101  // Page sets the value of the 'page' parameter.
   102  //
   103  // Index of the requested page, where one corresponds to the first page.
   104  func (r *ServiceClustersListRequest) Page(value int) *ServiceClustersListRequest {
   105  	r.page = &value
   106  	return r
   107  }
   108  
   109  // Size sets the value of the 'size' parameter.
   110  //
   111  // Maximum number of items that will be contained in the returned page.
   112  func (r *ServiceClustersListRequest) Size(value int) *ServiceClustersListRequest {
   113  	r.size = &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 *ServiceClustersListRequest) Send() (result *ServiceClustersListResponse, 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 *ServiceClustersListRequest) SendContext(ctx context.Context) (result *ServiceClustersListResponse, err error) {
   127  	query := helpers.CopyQuery(r.query)
   128  	if r.page != nil {
   129  		helpers.AddValue(&query, "page", *r.page)
   130  	}
   131  	if r.size != nil {
   132  		helpers.AddValue(&query, "size", *r.size)
   133  	}
   134  	header := helpers.CopyHeader(r.header)
   135  	uri := &url.URL{
   136  		Path:     r.path,
   137  		RawQuery: query.Encode(),
   138  	}
   139  	request := &http.Request{
   140  		Method: "GET",
   141  		URL:    uri,
   142  		Header: header,
   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 = &ServiceClustersListResponse{}
   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 = readServiceClustersListResponse(result, reader)
   170  	if err != nil {
   171  		return
   172  	}
   173  	return
   174  }
   175  
   176  // ServiceClustersListResponse is the response for the 'list' method.
   177  type ServiceClustersListResponse struct {
   178  	status int
   179  	header http.Header
   180  	err    *errors.Error
   181  	items  *ServiceClusterList
   182  	page   *int
   183  	size   *int
   184  	total  *int
   185  }
   186  
   187  // Status returns the response status code.
   188  func (r *ServiceClustersListResponse) Status() int {
   189  	if r == nil {
   190  		return 0
   191  	}
   192  	return r.status
   193  }
   194  
   195  // Header returns header of the response.
   196  func (r *ServiceClustersListResponse) Header() http.Header {
   197  	if r == nil {
   198  		return nil
   199  	}
   200  	return r.header
   201  }
   202  
   203  // Error returns the response error.
   204  func (r *ServiceClustersListResponse) Error() *errors.Error {
   205  	if r == nil {
   206  		return nil
   207  	}
   208  	return r.err
   209  }
   210  
   211  // Items returns the value of the 'items' parameter.
   212  //
   213  // Retrieved a list of service clusters.
   214  func (r *ServiceClustersListResponse) Items() *ServiceClusterList {
   215  	if r == nil {
   216  		return nil
   217  	}
   218  	return r.items
   219  }
   220  
   221  // GetItems returns the value of the 'items' parameter and
   222  // a flag indicating if the parameter has a value.
   223  //
   224  // Retrieved a list of service clusters.
   225  func (r *ServiceClustersListResponse) GetItems() (value *ServiceClusterList, ok bool) {
   226  	ok = r != nil && r.items != nil
   227  	if ok {
   228  		value = r.items
   229  	}
   230  	return
   231  }
   232  
   233  // Page returns the value of the 'page' parameter.
   234  //
   235  // Index of the requested page, where one corresponds to the first page.
   236  func (r *ServiceClustersListResponse) Page() int {
   237  	if r != nil && r.page != nil {
   238  		return *r.page
   239  	}
   240  	return 0
   241  }
   242  
   243  // GetPage returns the value of the 'page' parameter and
   244  // a flag indicating if the parameter has a value.
   245  //
   246  // Index of the requested page, where one corresponds to the first page.
   247  func (r *ServiceClustersListResponse) GetPage() (value int, ok bool) {
   248  	ok = r != nil && r.page != nil
   249  	if ok {
   250  		value = *r.page
   251  	}
   252  	return
   253  }
   254  
   255  // Size returns the value of the 'size' parameter.
   256  //
   257  // Maximum number of items that will be contained in the returned page.
   258  func (r *ServiceClustersListResponse) Size() int {
   259  	if r != nil && r.size != nil {
   260  		return *r.size
   261  	}
   262  	return 0
   263  }
   264  
   265  // GetSize returns the value of the 'size' parameter and
   266  // a flag indicating if the parameter has a value.
   267  //
   268  // Maximum number of items that will be contained in the returned page.
   269  func (r *ServiceClustersListResponse) GetSize() (value int, ok bool) {
   270  	ok = r != nil && r.size != nil
   271  	if ok {
   272  		value = *r.size
   273  	}
   274  	return
   275  }
   276  
   277  // Total returns the value of the 'total' parameter.
   278  //
   279  // Total number of items of the collection that match the search criteria,
   280  // regardless of the size of the page.
   281  func (r *ServiceClustersListResponse) Total() int {
   282  	if r != nil && r.total != nil {
   283  		return *r.total
   284  	}
   285  	return 0
   286  }
   287  
   288  // GetTotal returns the value of the 'total' parameter and
   289  // a flag indicating if the parameter has a value.
   290  //
   291  // Total number of items of the collection that match the search criteria,
   292  // regardless of the size of the page.
   293  func (r *ServiceClustersListResponse) GetTotal() (value int, ok bool) {
   294  	ok = r != nil && r.total != nil
   295  	if ok {
   296  		value = *r.total
   297  	}
   298  	return
   299  }