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