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