github.com/openshift-online/ocm-sdk-go@v0.1.473/accountsmgmt/v1/quota_cost_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  
    29  	"github.com/openshift-online/ocm-sdk-go/errors"
    30  	"github.com/openshift-online/ocm-sdk-go/helpers"
    31  )
    32  
    33  // QuotaCostClient is the client of the 'quota_cost' resource.
    34  //
    35  // Manages the quota cost for an organization.
    36  type QuotaCostClient struct {
    37  	transport http.RoundTripper
    38  	path      string
    39  }
    40  
    41  // NewQuotaCostClient creates a new client for the 'quota_cost'
    42  // resource using the given transport to send the requests and receive the
    43  // responses.
    44  func NewQuotaCostClient(transport http.RoundTripper, path string) *QuotaCostClient {
    45  	return &QuotaCostClient{
    46  		transport: transport,
    47  		path:      path,
    48  	}
    49  }
    50  
    51  // List creates a request for the 'list' method.
    52  //
    53  // Retrieves the quota cost.
    54  func (c *QuotaCostClient) List() *QuotaCostListRequest {
    55  	return &QuotaCostListRequest{
    56  		transport: c.transport,
    57  		path:      c.path,
    58  	}
    59  }
    60  
    61  // QuotaCostListRequest is the request for the 'list' method.
    62  type QuotaCostListRequest struct {
    63  	transport http.RoundTripper
    64  	path      string
    65  	query     url.Values
    66  	header    http.Header
    67  	page      *int
    68  	search    *string
    69  	size      *int
    70  }
    71  
    72  // Parameter adds a query parameter.
    73  func (r *QuotaCostListRequest) Parameter(name string, value interface{}) *QuotaCostListRequest {
    74  	helpers.AddValue(&r.query, name, value)
    75  	return r
    76  }
    77  
    78  // Header adds a request header.
    79  func (r *QuotaCostListRequest) Header(name string, value interface{}) *QuotaCostListRequest {
    80  	helpers.AddHeader(&r.header, name, value)
    81  	return r
    82  }
    83  
    84  // Impersonate wraps requests on behalf of another user.
    85  // Note: Services that do not support this feature may silently ignore this call.
    86  func (r *QuotaCostListRequest) Impersonate(user string) *QuotaCostListRequest {
    87  	helpers.AddImpersonationHeader(&r.header, user)
    88  	return r
    89  }
    90  
    91  // Page sets the value of the 'page' parameter.
    92  //
    93  // Index of the requested page, where one corresponds to the first page.
    94  func (r *QuotaCostListRequest) Page(value int) *QuotaCostListRequest {
    95  	r.page = &value
    96  	return r
    97  }
    98  
    99  // Search sets the value of the 'search' parameter.
   100  //
   101  // Search criteria.
   102  //
   103  // The syntax of this parameter is similar to the syntax of the _where_ clause
   104  // of an SQL statement, but using the names of the attributes of the quota
   105  // cost instead of the names of the columns of a table. For example, in order
   106  // to retrieve the quota cost for all add-ons:
   107  //
   108  // ```sql
   109  // quota_id LIKE 'add-on%'
   110  // ```
   111  //
   112  // If the parameter isn't provided, or if the value is empty, then all the
   113  // items that the user has permission to see will be returned.
   114  func (r *QuotaCostListRequest) Search(value string) *QuotaCostListRequest {
   115  	r.search = &value
   116  	return r
   117  }
   118  
   119  // Size sets the value of the 'size' parameter.
   120  //
   121  // Maximum number of items that will be contained in the returned page.
   122  func (r *QuotaCostListRequest) Size(value int) *QuotaCostListRequest {
   123  	r.size = &value
   124  	return r
   125  }
   126  
   127  // Send sends this request, waits for the response, and returns it.
   128  //
   129  // This is a potentially lengthy operation, as it requires network communication.
   130  // Consider using a context and the SendContext method.
   131  func (r *QuotaCostListRequest) Send() (result *QuotaCostListResponse, err error) {
   132  	return r.SendContext(context.Background())
   133  }
   134  
   135  // SendContext sends this request, waits for the response, and returns it.
   136  func (r *QuotaCostListRequest) SendContext(ctx context.Context) (result *QuotaCostListResponse, err error) {
   137  	query := helpers.CopyQuery(r.query)
   138  	if r.page != nil {
   139  		helpers.AddValue(&query, "page", *r.page)
   140  	}
   141  	if r.search != nil {
   142  		helpers.AddValue(&query, "search", *r.search)
   143  	}
   144  	if r.size != nil {
   145  		helpers.AddValue(&query, "size", *r.size)
   146  	}
   147  	header := helpers.CopyHeader(r.header)
   148  	uri := &url.URL{
   149  		Path:     r.path,
   150  		RawQuery: query.Encode(),
   151  	}
   152  	request := &http.Request{
   153  		Method: "GET",
   154  		URL:    uri,
   155  		Header: header,
   156  	}
   157  	if ctx != nil {
   158  		request = request.WithContext(ctx)
   159  	}
   160  	response, err := r.transport.RoundTrip(request)
   161  	if err != nil {
   162  		return
   163  	}
   164  	defer response.Body.Close()
   165  	result = &QuotaCostListResponse{}
   166  	result.status = response.StatusCode
   167  	result.header = response.Header
   168  	reader := bufio.NewReader(response.Body)
   169  	_, err = reader.Peek(1)
   170  	if err == io.EOF {
   171  		err = nil
   172  		return
   173  	}
   174  	if result.status >= 400 {
   175  		result.err, err = errors.UnmarshalErrorStatus(reader, result.status)
   176  		if err != nil {
   177  			return
   178  		}
   179  		err = result.err
   180  		return
   181  	}
   182  	err = readQuotaCostListResponse(result, reader)
   183  	if err != nil {
   184  		return
   185  	}
   186  	return
   187  }
   188  
   189  // QuotaCostListResponse is the response for the 'list' method.
   190  type QuotaCostListResponse struct {
   191  	status int
   192  	header http.Header
   193  	err    *errors.Error
   194  	items  *QuotaCostList
   195  	page   *int
   196  	size   *int
   197  	total  *int
   198  }
   199  
   200  // Status returns the response status code.
   201  func (r *QuotaCostListResponse) 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 *QuotaCostListResponse) 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 *QuotaCostListResponse) Error() *errors.Error {
   218  	if r == nil {
   219  		return nil
   220  	}
   221  	return r.err
   222  }
   223  
   224  // Items returns the value of the 'items' parameter.
   225  //
   226  // Retrieved quota cost items.
   227  func (r *QuotaCostListResponse) Items() *QuotaCostList {
   228  	if r == nil {
   229  		return nil
   230  	}
   231  	return r.items
   232  }
   233  
   234  // GetItems returns the value of the 'items' parameter and
   235  // a flag indicating if the parameter has a value.
   236  //
   237  // Retrieved quota cost items.
   238  func (r *QuotaCostListResponse) GetItems() (value *QuotaCostList, ok bool) {
   239  	ok = r != nil && r.items != nil
   240  	if ok {
   241  		value = r.items
   242  	}
   243  	return
   244  }
   245  
   246  // Page returns the value of the 'page' parameter.
   247  //
   248  // Index of the requested page, where one corresponds to the first page.
   249  func (r *QuotaCostListResponse) Page() int {
   250  	if r != nil && r.page != nil {
   251  		return *r.page
   252  	}
   253  	return 0
   254  }
   255  
   256  // GetPage returns the value of the 'page' parameter and
   257  // a flag indicating if the parameter has a value.
   258  //
   259  // Index of the requested page, where one corresponds to the first page.
   260  func (r *QuotaCostListResponse) GetPage() (value int, ok bool) {
   261  	ok = r != nil && r.page != nil
   262  	if ok {
   263  		value = *r.page
   264  	}
   265  	return
   266  }
   267  
   268  // Size returns the value of the 'size' parameter.
   269  //
   270  // Maximum number of items that will be contained in the returned page.
   271  func (r *QuotaCostListResponse) Size() int {
   272  	if r != nil && r.size != nil {
   273  		return *r.size
   274  	}
   275  	return 0
   276  }
   277  
   278  // GetSize returns the value of the 'size' parameter and
   279  // a flag indicating if the parameter has a value.
   280  //
   281  // Maximum number of items that will be contained in the returned page.
   282  func (r *QuotaCostListResponse) GetSize() (value int, ok bool) {
   283  	ok = r != nil && r.size != nil
   284  	if ok {
   285  		value = *r.size
   286  	}
   287  	return
   288  }
   289  
   290  // Total returns the value of the 'total' parameter.
   291  //
   292  // Total number of items of the collection that match the search criteria,
   293  // regardless of the size of the page.
   294  func (r *QuotaCostListResponse) Total() int {
   295  	if r != nil && r.total != nil {
   296  		return *r.total
   297  	}
   298  	return 0
   299  }
   300  
   301  // GetTotal returns the value of the 'total' parameter and
   302  // a flag indicating if the parameter has a value.
   303  //
   304  // Total number of items of the collection that match the search criteria,
   305  // regardless of the size of the page.
   306  func (r *QuotaCostListResponse) GetTotal() (value int, ok bool) {
   307  	ok = r != nil && r.total != nil
   308  	if ok {
   309  		value = *r.total
   310  	}
   311  	return
   312  }