github.com/openshift-online/ocm-sdk-go@v0.1.473/jobqueue/v1/queues_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/jobqueue/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  // QueuesClient is the client of the 'queues' resource.
    35  //
    36  // Manages collection of job queues.
    37  type QueuesClient struct {
    38  	transport http.RoundTripper
    39  	path      string
    40  }
    41  
    42  // NewQueuesClient creates a new client for the 'queues'
    43  // resource using the given transport to send the requests and receive the
    44  // responses.
    45  func NewQueuesClient(transport http.RoundTripper, path string) *QueuesClient {
    46  	return &QueuesClient{
    47  		transport: transport,
    48  		path:      path,
    49  	}
    50  }
    51  
    52  // List creates a request for the 'list' method.
    53  //
    54  // Retrieves a list of job queues.
    55  func (c *QueuesClient) List() *QueuesListRequest {
    56  	return &QueuesListRequest{
    57  		transport: c.transport,
    58  		path:      c.path,
    59  	}
    60  }
    61  
    62  // Queue returns the target 'queue' resource for the given identifier.
    63  //
    64  // Returns a reference to the service that manages a specific job queue.
    65  func (c *QueuesClient) Queue(id string) *QueueClient {
    66  	return NewQueueClient(
    67  		c.transport,
    68  		path.Join(c.path, id),
    69  	)
    70  }
    71  
    72  // QueuesListRequest is the request for the 'list' method.
    73  type QueuesListRequest struct {
    74  	transport http.RoundTripper
    75  	path      string
    76  	query     url.Values
    77  	header    http.Header
    78  	page      *int
    79  	size      *int
    80  }
    81  
    82  // Parameter adds a query parameter.
    83  func (r *QueuesListRequest) Parameter(name string, value interface{}) *QueuesListRequest {
    84  	helpers.AddValue(&r.query, name, value)
    85  	return r
    86  }
    87  
    88  // Header adds a request header.
    89  func (r *QueuesListRequest) Header(name string, value interface{}) *QueuesListRequest {
    90  	helpers.AddHeader(&r.header, name, value)
    91  	return r
    92  }
    93  
    94  // Impersonate wraps requests on behalf of another user.
    95  // Note: Services that do not support this feature may silently ignore this call.
    96  func (r *QueuesListRequest) Impersonate(user string) *QueuesListRequest {
    97  	helpers.AddImpersonationHeader(&r.header, user)
    98  	return r
    99  }
   100  
   101  // Page sets the value of the 'page' parameter.
   102  //
   103  // Index of the requested page, where one corresponds to the first page.
   104  // Page may be a token to the next page
   105  func (r *QueuesListRequest) Page(value int) *QueuesListRequest {
   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 *QueuesListRequest) Size(value int) *QueuesListRequest {
   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 *QueuesListRequest) Send() (result *QueuesListResponse, 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 *QueuesListRequest) SendContext(ctx context.Context) (result *QueuesListResponse, 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 = &QueuesListResponse{}
   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 = readQueuesListResponse(result, reader)
   171  	if err != nil {
   172  		return
   173  	}
   174  	return
   175  }
   176  
   177  // QueuesListResponse is the response for the 'list' method.
   178  type QueuesListResponse struct {
   179  	status int
   180  	header http.Header
   181  	err    *errors.Error
   182  	items  *QueueList
   183  	page   *int
   184  	size   *int
   185  	total  *int
   186  }
   187  
   188  // Status returns the response status code.
   189  func (r *QueuesListResponse) 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 *QueuesListResponse) 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 *QueuesListResponse) 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 job queues.
   215  func (r *QueuesListResponse) Items() *QueueList {
   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 job queues.
   226  func (r *QueuesListResponse) GetItems() (value *QueueList, 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  // Page may be a token to the next page
   238  func (r *QueuesListResponse) Page() int {
   239  	if r != nil && r.page != nil {
   240  		return *r.page
   241  	}
   242  	return 0
   243  }
   244  
   245  // GetPage returns the value of the 'page' parameter and
   246  // a flag indicating if the parameter has a value.
   247  //
   248  // Index of the requested page, where one corresponds to the first page.
   249  // Page may be a token to the next page
   250  func (r *QueuesListResponse) GetPage() (value int, ok bool) {
   251  	ok = r != nil && r.page != nil
   252  	if ok {
   253  		value = *r.page
   254  	}
   255  	return
   256  }
   257  
   258  // Size returns the value of the 'size' parameter.
   259  //
   260  // Maximum number of items that will be contained in the returned page.
   261  func (r *QueuesListResponse) Size() int {
   262  	if r != nil && r.size != nil {
   263  		return *r.size
   264  	}
   265  	return 0
   266  }
   267  
   268  // GetSize returns the value of the 'size' parameter and
   269  // a flag indicating if the parameter has a value.
   270  //
   271  // Maximum number of items that will be contained in the returned page.
   272  func (r *QueuesListResponse) GetSize() (value int, ok bool) {
   273  	ok = r != nil && r.size != nil
   274  	if ok {
   275  		value = *r.size
   276  	}
   277  	return
   278  }
   279  
   280  // Total returns the value of the 'total' parameter.
   281  //
   282  // Total number of items of the collection regardless of the size of the page.
   283  func (r *QueuesListResponse) Total() int {
   284  	if r != nil && r.total != nil {
   285  		return *r.total
   286  	}
   287  	return 0
   288  }
   289  
   290  // GetTotal returns the value of the 'total' parameter and
   291  // a flag indicating if the parameter has a value.
   292  //
   293  // Total number of items of the collection regardless of the size of the page.
   294  func (r *QueuesListResponse) GetTotal() (value int, ok bool) {
   295  	ok = r != nil && r.total != nil
   296  	if ok {
   297  		value = *r.total
   298  	}
   299  	return
   300  }