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