github.com/openshift-online/ocm-sdk-go@v0.1.473/arohcp/v1alpha1/versions_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 v1alpha1 // github.com/openshift-online/ocm-sdk-go/arohcp/v1alpha1
    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  // VersionsClient is the client of the 'versions' resource.
    35  //
    36  // Manages the collection of versions.
    37  type VersionsClient struct {
    38  	transport http.RoundTripper
    39  	path      string
    40  }
    41  
    42  // NewVersionsClient creates a new client for the 'versions'
    43  // resource using the given transport to send the requests and receive the
    44  // responses.
    45  func NewVersionsClient(transport http.RoundTripper, path string) *VersionsClient {
    46  	return &VersionsClient{
    47  		transport: transport,
    48  		path:      path,
    49  	}
    50  }
    51  
    52  // List creates a request for the 'list' method.
    53  //
    54  // Retrieves a list of versions.
    55  func (c *VersionsClient) List() *VersionsListRequest {
    56  	return &VersionsListRequest{
    57  		transport: c.transport,
    58  		path:      c.path,
    59  	}
    60  }
    61  
    62  // Version returns the target 'version' resource for the given identifier.
    63  //
    64  // Reference to the resource that manages a specific version.
    65  func (c *VersionsClient) Version(id string) *VersionClient {
    66  	return NewVersionClient(
    67  		c.transport,
    68  		path.Join(c.path, id),
    69  	)
    70  }
    71  
    72  // VersionsListRequest is the request for the 'list' method.
    73  type VersionsListRequest 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 *VersionsListRequest) Parameter(name string, value interface{}) *VersionsListRequest {
    86  	helpers.AddValue(&r.query, name, value)
    87  	return r
    88  }
    89  
    90  // Header adds a request header.
    91  func (r *VersionsListRequest) Header(name string, value interface{}) *VersionsListRequest {
    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 *VersionsListRequest) Impersonate(user string) *VersionsListRequest {
    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 version instead of
   109  // the names of the columns of a table. For example, in order to sort the versions
   110  // descending by identifier the value should be:
   111  //
   112  // ```sql
   113  // id 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 *VersionsListRequest) Order(value string) *VersionsListRequest {
   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 *VersionsListRequest) Page(value int) *VersionsListRequest {
   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 a
   136  // SQL statement, but using the names of the attributes of the version instead of
   137  // the names of the columns of a table. For example, in order to retrieve all the
   138  // versions that are enabled:
   139  //
   140  // ```sql
   141  // enabled = 't'
   142  // ```
   143  //
   144  // If the parameter isn't provided, or if the value is empty, then all the versions
   145  // that the user has permission to see will be returned.
   146  func (r *VersionsListRequest) Search(value string) *VersionsListRequest {
   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  //
   155  // Default value is `100`.
   156  func (r *VersionsListRequest) Size(value int) *VersionsListRequest {
   157  	r.size = &value
   158  	return r
   159  }
   160  
   161  // Send sends this request, waits for the response, and returns it.
   162  //
   163  // This is a potentially lengthy operation, as it requires network communication.
   164  // Consider using a context and the SendContext method.
   165  func (r *VersionsListRequest) Send() (result *VersionsListResponse, err error) {
   166  	return r.SendContext(context.Background())
   167  }
   168  
   169  // SendContext sends this request, waits for the response, and returns it.
   170  func (r *VersionsListRequest) SendContext(ctx context.Context) (result *VersionsListResponse, err error) {
   171  	query := helpers.CopyQuery(r.query)
   172  	if r.order != nil {
   173  		helpers.AddValue(&query, "order", *r.order)
   174  	}
   175  	if r.page != nil {
   176  		helpers.AddValue(&query, "page", *r.page)
   177  	}
   178  	if r.search != nil {
   179  		helpers.AddValue(&query, "search", *r.search)
   180  	}
   181  	if r.size != nil {
   182  		helpers.AddValue(&query, "size", *r.size)
   183  	}
   184  	header := helpers.CopyHeader(r.header)
   185  	uri := &url.URL{
   186  		Path:     r.path,
   187  		RawQuery: query.Encode(),
   188  	}
   189  	request := &http.Request{
   190  		Method: "GET",
   191  		URL:    uri,
   192  		Header: header,
   193  	}
   194  	if ctx != nil {
   195  		request = request.WithContext(ctx)
   196  	}
   197  	response, err := r.transport.RoundTrip(request)
   198  	if err != nil {
   199  		return
   200  	}
   201  	defer response.Body.Close()
   202  	result = &VersionsListResponse{}
   203  	result.status = response.StatusCode
   204  	result.header = response.Header
   205  	reader := bufio.NewReader(response.Body)
   206  	_, err = reader.Peek(1)
   207  	if err == io.EOF {
   208  		err = nil
   209  		return
   210  	}
   211  	if result.status >= 400 {
   212  		result.err, err = errors.UnmarshalErrorStatus(reader, result.status)
   213  		if err != nil {
   214  			return
   215  		}
   216  		err = result.err
   217  		return
   218  	}
   219  	err = readVersionsListResponse(result, reader)
   220  	if err != nil {
   221  		return
   222  	}
   223  	return
   224  }
   225  
   226  // VersionsListResponse is the response for the 'list' method.
   227  type VersionsListResponse struct {
   228  	status int
   229  	header http.Header
   230  	err    *errors.Error
   231  	items  *VersionList
   232  	page   *int
   233  	size   *int
   234  	total  *int
   235  }
   236  
   237  // Status returns the response status code.
   238  func (r *VersionsListResponse) Status() int {
   239  	if r == nil {
   240  		return 0
   241  	}
   242  	return r.status
   243  }
   244  
   245  // Header returns header of the response.
   246  func (r *VersionsListResponse) Header() http.Header {
   247  	if r == nil {
   248  		return nil
   249  	}
   250  	return r.header
   251  }
   252  
   253  // Error returns the response error.
   254  func (r *VersionsListResponse) Error() *errors.Error {
   255  	if r == nil {
   256  		return nil
   257  	}
   258  	return r.err
   259  }
   260  
   261  // Items returns the value of the 'items' parameter.
   262  //
   263  // Retrieved list of versions.
   264  func (r *VersionsListResponse) Items() *VersionList {
   265  	if r == nil {
   266  		return nil
   267  	}
   268  	return r.items
   269  }
   270  
   271  // GetItems returns the value of the 'items' parameter and
   272  // a flag indicating if the parameter has a value.
   273  //
   274  // Retrieved list of versions.
   275  func (r *VersionsListResponse) GetItems() (value *VersionList, ok bool) {
   276  	ok = r != nil && r.items != nil
   277  	if ok {
   278  		value = r.items
   279  	}
   280  	return
   281  }
   282  
   283  // Page returns the value of the 'page' parameter.
   284  //
   285  // Index of the requested page, where one corresponds to the first page.
   286  func (r *VersionsListResponse) Page() int {
   287  	if r != nil && r.page != nil {
   288  		return *r.page
   289  	}
   290  	return 0
   291  }
   292  
   293  // GetPage returns the value of the 'page' parameter and
   294  // a flag indicating if the parameter has a value.
   295  //
   296  // Index of the requested page, where one corresponds to the first page.
   297  func (r *VersionsListResponse) GetPage() (value int, ok bool) {
   298  	ok = r != nil && r.page != nil
   299  	if ok {
   300  		value = *r.page
   301  	}
   302  	return
   303  }
   304  
   305  // Size returns the value of the 'size' parameter.
   306  //
   307  // Maximum number of items that will be contained in the returned page.
   308  //
   309  // Default value is `100`.
   310  func (r *VersionsListResponse) Size() int {
   311  	if r != nil && r.size != nil {
   312  		return *r.size
   313  	}
   314  	return 0
   315  }
   316  
   317  // GetSize returns the value of the 'size' parameter and
   318  // a flag indicating if the parameter has a value.
   319  //
   320  // Maximum number of items that will be contained in the returned page.
   321  //
   322  // Default value is `100`.
   323  func (r *VersionsListResponse) GetSize() (value int, ok bool) {
   324  	ok = r != nil && r.size != nil
   325  	if ok {
   326  		value = *r.size
   327  	}
   328  	return
   329  }
   330  
   331  // Total returns the value of the 'total' parameter.
   332  //
   333  // Total number of items of the collection that match the search criteria,
   334  // regardless of the size of the page.
   335  func (r *VersionsListResponse) Total() int {
   336  	if r != nil && r.total != nil {
   337  		return *r.total
   338  	}
   339  	return 0
   340  }
   341  
   342  // GetTotal returns the value of the 'total' parameter and
   343  // a flag indicating if the parameter has a value.
   344  //
   345  // Total number of items of the collection that match the search criteria,
   346  // regardless of the size of the page.
   347  func (r *VersionsListResponse) GetTotal() (value int, ok bool) {
   348  	ok = r != nil && r.total != nil
   349  	if ok {
   350  		value = *r.total
   351  	}
   352  	return
   353  }