github.com/openshift-online/ocm-sdk-go@v0.1.473/accountsmgmt/v1/billing_models_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  	"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  // BillingModelsClient is the client of the 'billing_models' resource.
    35  type BillingModelsClient struct {
    36  	transport http.RoundTripper
    37  	path      string
    38  }
    39  
    40  // NewBillingModelsClient creates a new client for the 'billing_models'
    41  // resource using the given transport to send the requests and receive the
    42  // responses.
    43  func NewBillingModelsClient(transport http.RoundTripper, path string) *BillingModelsClient {
    44  	return &BillingModelsClient{
    45  		transport: transport,
    46  		path:      path,
    47  	}
    48  }
    49  
    50  // List creates a request for the 'list' method.
    51  //
    52  // Retrieves a list of BillingModels.
    53  func (c *BillingModelsClient) List() *BillingModelsListRequest {
    54  	return &BillingModelsListRequest{
    55  		transport: c.transport,
    56  		path:      c.path,
    57  	}
    58  }
    59  
    60  // BillingModel returns the target 'billing_model' resource for the given identifier.
    61  //
    62  // Reference to the service that manages a specific billing model.
    63  func (c *BillingModelsClient) BillingModel(id string) *BillingModelClient {
    64  	return NewBillingModelClient(
    65  		c.transport,
    66  		path.Join(c.path, id),
    67  	)
    68  }
    69  
    70  // BillingModelsListRequest is the request for the 'list' method.
    71  type BillingModelsListRequest struct {
    72  	transport http.RoundTripper
    73  	path      string
    74  	query     url.Values
    75  	header    http.Header
    76  	page      *int
    77  	size      *int
    78  }
    79  
    80  // Parameter adds a query parameter.
    81  func (r *BillingModelsListRequest) Parameter(name string, value interface{}) *BillingModelsListRequest {
    82  	helpers.AddValue(&r.query, name, value)
    83  	return r
    84  }
    85  
    86  // Header adds a request header.
    87  func (r *BillingModelsListRequest) Header(name string, value interface{}) *BillingModelsListRequest {
    88  	helpers.AddHeader(&r.header, name, value)
    89  	return r
    90  }
    91  
    92  // Impersonate wraps requests on behalf of another user.
    93  // Note: Services that do not support this feature may silently ignore this call.
    94  func (r *BillingModelsListRequest) Impersonate(user string) *BillingModelsListRequest {
    95  	helpers.AddImpersonationHeader(&r.header, user)
    96  	return r
    97  }
    98  
    99  // Page sets the value of the 'page' parameter.
   100  //
   101  // Index of the requested page, where one corresponds to the first page.
   102  func (r *BillingModelsListRequest) Page(value int) *BillingModelsListRequest {
   103  	r.page = &value
   104  	return r
   105  }
   106  
   107  // Size sets the value of the 'size' parameter.
   108  //
   109  // Maximum number of items that will be contained in the returned page.
   110  func (r *BillingModelsListRequest) Size(value int) *BillingModelsListRequest {
   111  	r.size = &value
   112  	return r
   113  }
   114  
   115  // Send sends this request, waits for the response, and returns it.
   116  //
   117  // This is a potentially lengthy operation, as it requires network communication.
   118  // Consider using a context and the SendContext method.
   119  func (r *BillingModelsListRequest) Send() (result *BillingModelsListResponse, err error) {
   120  	return r.SendContext(context.Background())
   121  }
   122  
   123  // SendContext sends this request, waits for the response, and returns it.
   124  func (r *BillingModelsListRequest) SendContext(ctx context.Context) (result *BillingModelsListResponse, err error) {
   125  	query := helpers.CopyQuery(r.query)
   126  	if r.page != nil {
   127  		helpers.AddValue(&query, "page", *r.page)
   128  	}
   129  	if r.size != nil {
   130  		helpers.AddValue(&query, "size", *r.size)
   131  	}
   132  	header := helpers.CopyHeader(r.header)
   133  	uri := &url.URL{
   134  		Path:     r.path,
   135  		RawQuery: query.Encode(),
   136  	}
   137  	request := &http.Request{
   138  		Method: "GET",
   139  		URL:    uri,
   140  		Header: header,
   141  	}
   142  	if ctx != nil {
   143  		request = request.WithContext(ctx)
   144  	}
   145  	response, err := r.transport.RoundTrip(request)
   146  	if err != nil {
   147  		return
   148  	}
   149  	defer response.Body.Close()
   150  	result = &BillingModelsListResponse{}
   151  	result.status = response.StatusCode
   152  	result.header = response.Header
   153  	reader := bufio.NewReader(response.Body)
   154  	_, err = reader.Peek(1)
   155  	if err == io.EOF {
   156  		err = nil
   157  		return
   158  	}
   159  	if result.status >= 400 {
   160  		result.err, err = errors.UnmarshalErrorStatus(reader, result.status)
   161  		if err != nil {
   162  			return
   163  		}
   164  		err = result.err
   165  		return
   166  	}
   167  	err = readBillingModelsListResponse(result, reader)
   168  	if err != nil {
   169  		return
   170  	}
   171  	return
   172  }
   173  
   174  // BillingModelsListResponse is the response for the 'list' method.
   175  type BillingModelsListResponse struct {
   176  	status int
   177  	header http.Header
   178  	err    *errors.Error
   179  	items  *BillingModelItemList
   180  	page   *int
   181  	size   *int
   182  	total  *int
   183  }
   184  
   185  // Status returns the response status code.
   186  func (r *BillingModelsListResponse) Status() int {
   187  	if r == nil {
   188  		return 0
   189  	}
   190  	return r.status
   191  }
   192  
   193  // Header returns header of the response.
   194  func (r *BillingModelsListResponse) Header() http.Header {
   195  	if r == nil {
   196  		return nil
   197  	}
   198  	return r.header
   199  }
   200  
   201  // Error returns the response error.
   202  func (r *BillingModelsListResponse) Error() *errors.Error {
   203  	if r == nil {
   204  		return nil
   205  	}
   206  	return r.err
   207  }
   208  
   209  // Items returns the value of the 'items' parameter.
   210  //
   211  // Retrieve list of Billing Models.
   212  func (r *BillingModelsListResponse) Items() *BillingModelItemList {
   213  	if r == nil {
   214  		return nil
   215  	}
   216  	return r.items
   217  }
   218  
   219  // GetItems returns the value of the 'items' parameter and
   220  // a flag indicating if the parameter has a value.
   221  //
   222  // Retrieve list of Billing Models.
   223  func (r *BillingModelsListResponse) GetItems() (value *BillingModelItemList, ok bool) {
   224  	ok = r != nil && r.items != nil
   225  	if ok {
   226  		value = r.items
   227  	}
   228  	return
   229  }
   230  
   231  // Page returns the value of the 'page' parameter.
   232  //
   233  // Index of the requested page, where one corresponds to the first page.
   234  func (r *BillingModelsListResponse) Page() int {
   235  	if r != nil && r.page != nil {
   236  		return *r.page
   237  	}
   238  	return 0
   239  }
   240  
   241  // GetPage returns the value of the 'page' parameter and
   242  // a flag indicating if the parameter has a value.
   243  //
   244  // Index of the requested page, where one corresponds to the first page.
   245  func (r *BillingModelsListResponse) GetPage() (value int, ok bool) {
   246  	ok = r != nil && r.page != nil
   247  	if ok {
   248  		value = *r.page
   249  	}
   250  	return
   251  }
   252  
   253  // Size returns the value of the 'size' parameter.
   254  //
   255  // Maximum number of items that will be contained in the returned page.
   256  func (r *BillingModelsListResponse) Size() int {
   257  	if r != nil && r.size != nil {
   258  		return *r.size
   259  	}
   260  	return 0
   261  }
   262  
   263  // GetSize returns the value of the 'size' parameter and
   264  // a flag indicating if the parameter has a value.
   265  //
   266  // Maximum number of items that will be contained in the returned page.
   267  func (r *BillingModelsListResponse) GetSize() (value int, ok bool) {
   268  	ok = r != nil && r.size != nil
   269  	if ok {
   270  		value = *r.size
   271  	}
   272  	return
   273  }
   274  
   275  // Total returns the value of the 'total' parameter.
   276  //
   277  // Total number of items of the collection, regardless of the size of the page.
   278  func (r *BillingModelsListResponse) Total() int {
   279  	if r != nil && r.total != nil {
   280  		return *r.total
   281  	}
   282  	return 0
   283  }
   284  
   285  // GetTotal returns the value of the 'total' parameter and
   286  // a flag indicating if the parameter has a value.
   287  //
   288  // Total number of items of the collection, regardless of the size of the page.
   289  func (r *BillingModelsListResponse) GetTotal() (value int, ok bool) {
   290  	ok = r != nil && r.total != nil
   291  	if ok {
   292  		value = *r.total
   293  	}
   294  	return
   295  }