github.com/openshift-online/ocm-sdk-go@v0.1.473/statusboard/v1/statuses_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/statusboard/v1
    21  
    22  import (
    23  	"bufio"
    24  	"bytes"
    25  	"context"
    26  	"io"
    27  	"net/http"
    28  	"net/url"
    29  	"path"
    30  	time "time"
    31  
    32  	"github.com/openshift-online/ocm-sdk-go/errors"
    33  	"github.com/openshift-online/ocm-sdk-go/helpers"
    34  )
    35  
    36  // StatusesClient is the client of the 'statuses' resource.
    37  //
    38  // Manages the collection of statuses
    39  type StatusesClient struct {
    40  	transport http.RoundTripper
    41  	path      string
    42  }
    43  
    44  // NewStatusesClient creates a new client for the 'statuses'
    45  // resource using the given transport to send the requests and receive the
    46  // responses.
    47  func NewStatusesClient(transport http.RoundTripper, path string) *StatusesClient {
    48  	return &StatusesClient{
    49  		transport: transport,
    50  		path:      path,
    51  	}
    52  }
    53  
    54  // Add creates a request for the 'add' method.
    55  func (c *StatusesClient) Add() *StatusesAddRequest {
    56  	return &StatusesAddRequest{
    57  		transport: c.transport,
    58  		path:      c.path,
    59  	}
    60  }
    61  
    62  // List creates a request for the 'list' method.
    63  //
    64  // Retrieves the list of statuses.
    65  func (c *StatusesClient) List() *StatusesListRequest {
    66  	return &StatusesListRequest{
    67  		transport: c.transport,
    68  		path:      c.path,
    69  	}
    70  }
    71  
    72  // Status returns the target 'status' resource for the given identifier.
    73  func (c *StatusesClient) Status(id string) *StatusClient {
    74  	return NewStatusClient(
    75  		c.transport,
    76  		path.Join(c.path, id),
    77  	)
    78  }
    79  
    80  // StatusesAddRequest is the request for the 'add' method.
    81  type StatusesAddRequest struct {
    82  	transport http.RoundTripper
    83  	path      string
    84  	query     url.Values
    85  	header    http.Header
    86  	body      *Status
    87  }
    88  
    89  // Parameter adds a query parameter.
    90  func (r *StatusesAddRequest) Parameter(name string, value interface{}) *StatusesAddRequest {
    91  	helpers.AddValue(&r.query, name, value)
    92  	return r
    93  }
    94  
    95  // Header adds a request header.
    96  func (r *StatusesAddRequest) Header(name string, value interface{}) *StatusesAddRequest {
    97  	helpers.AddHeader(&r.header, name, value)
    98  	return r
    99  }
   100  
   101  // Impersonate wraps requests on behalf of another user.
   102  // Note: Services that do not support this feature may silently ignore this call.
   103  func (r *StatusesAddRequest) Impersonate(user string) *StatusesAddRequest {
   104  	helpers.AddImpersonationHeader(&r.header, user)
   105  	return r
   106  }
   107  
   108  // Body sets the value of the 'body' parameter.
   109  func (r *StatusesAddRequest) Body(value *Status) *StatusesAddRequest {
   110  	r.body = value
   111  	return r
   112  }
   113  
   114  // Send sends this request, waits for the response, and returns it.
   115  //
   116  // This is a potentially lengthy operation, as it requires network communication.
   117  // Consider using a context and the SendContext method.
   118  func (r *StatusesAddRequest) Send() (result *StatusesAddResponse, err error) {
   119  	return r.SendContext(context.Background())
   120  }
   121  
   122  // SendContext sends this request, waits for the response, and returns it.
   123  func (r *StatusesAddRequest) SendContext(ctx context.Context) (result *StatusesAddResponse, err error) {
   124  	query := helpers.CopyQuery(r.query)
   125  	header := helpers.CopyHeader(r.header)
   126  	buffer := &bytes.Buffer{}
   127  	err = writeStatusesAddRequest(r, buffer)
   128  	if err != nil {
   129  		return
   130  	}
   131  	uri := &url.URL{
   132  		Path:     r.path,
   133  		RawQuery: query.Encode(),
   134  	}
   135  	request := &http.Request{
   136  		Method: "POST",
   137  		URL:    uri,
   138  		Header: header,
   139  		Body:   io.NopCloser(buffer),
   140  	}
   141  	if ctx != nil {
   142  		request = request.WithContext(ctx)
   143  	}
   144  	response, err := r.transport.RoundTrip(request)
   145  	if err != nil {
   146  		return
   147  	}
   148  	defer response.Body.Close()
   149  	result = &StatusesAddResponse{}
   150  	result.status = response.StatusCode
   151  	result.header = response.Header
   152  	reader := bufio.NewReader(response.Body)
   153  	_, err = reader.Peek(1)
   154  	if err == io.EOF {
   155  		err = nil
   156  		return
   157  	}
   158  	if result.status >= 400 {
   159  		result.err, err = errors.UnmarshalErrorStatus(reader, result.status)
   160  		if err != nil {
   161  			return
   162  		}
   163  		err = result.err
   164  		return
   165  	}
   166  	err = readStatusesAddResponse(result, reader)
   167  	if err != nil {
   168  		return
   169  	}
   170  	return
   171  }
   172  
   173  // StatusesAddResponse is the response for the 'add' method.
   174  type StatusesAddResponse struct {
   175  	status int
   176  	header http.Header
   177  	err    *errors.Error
   178  	body   *Status
   179  }
   180  
   181  // Status returns the response status code.
   182  func (r *StatusesAddResponse) Status() int {
   183  	if r == nil {
   184  		return 0
   185  	}
   186  	return r.status
   187  }
   188  
   189  // Header returns header of the response.
   190  func (r *StatusesAddResponse) Header() http.Header {
   191  	if r == nil {
   192  		return nil
   193  	}
   194  	return r.header
   195  }
   196  
   197  // Error returns the response error.
   198  func (r *StatusesAddResponse) Error() *errors.Error {
   199  	if r == nil {
   200  		return nil
   201  	}
   202  	return r.err
   203  }
   204  
   205  // Body returns the value of the 'body' parameter.
   206  func (r *StatusesAddResponse) Body() *Status {
   207  	if r == nil {
   208  		return nil
   209  	}
   210  	return r.body
   211  }
   212  
   213  // GetBody returns the value of the 'body' parameter and
   214  // a flag indicating if the parameter has a value.
   215  func (r *StatusesAddResponse) GetBody() (value *Status, ok bool) {
   216  	ok = r != nil && r.body != nil
   217  	if ok {
   218  		value = r.body
   219  	}
   220  	return
   221  }
   222  
   223  // StatusesListRequest is the request for the 'list' method.
   224  type StatusesListRequest struct {
   225  	transport     http.RoundTripper
   226  	path          string
   227  	query         url.Values
   228  	header        http.Header
   229  	createdAfter  *time.Time
   230  	createdBefore *time.Time
   231  	flapDetection *bool
   232  	fullNames     *string
   233  	limitScope    *time.Time
   234  	page          *int
   235  	productIds    *string
   236  	size          *int
   237  }
   238  
   239  // Parameter adds a query parameter.
   240  func (r *StatusesListRequest) Parameter(name string, value interface{}) *StatusesListRequest {
   241  	helpers.AddValue(&r.query, name, value)
   242  	return r
   243  }
   244  
   245  // Header adds a request header.
   246  func (r *StatusesListRequest) Header(name string, value interface{}) *StatusesListRequest {
   247  	helpers.AddHeader(&r.header, name, value)
   248  	return r
   249  }
   250  
   251  // Impersonate wraps requests on behalf of another user.
   252  // Note: Services that do not support this feature may silently ignore this call.
   253  func (r *StatusesListRequest) Impersonate(user string) *StatusesListRequest {
   254  	helpers.AddImpersonationHeader(&r.header, user)
   255  	return r
   256  }
   257  
   258  // CreatedAfter sets the value of the 'created_after' parameter.
   259  func (r *StatusesListRequest) CreatedAfter(value time.Time) *StatusesListRequest {
   260  	r.createdAfter = &value
   261  	return r
   262  }
   263  
   264  // CreatedBefore sets the value of the 'created_before' parameter.
   265  func (r *StatusesListRequest) CreatedBefore(value time.Time) *StatusesListRequest {
   266  	r.createdBefore = &value
   267  	return r
   268  }
   269  
   270  // FlapDetection sets the value of the 'flap_detection' parameter.
   271  func (r *StatusesListRequest) FlapDetection(value bool) *StatusesListRequest {
   272  	r.flapDetection = &value
   273  	return r
   274  }
   275  
   276  // FullNames sets the value of the 'full_names' parameter.
   277  func (r *StatusesListRequest) FullNames(value string) *StatusesListRequest {
   278  	r.fullNames = &value
   279  	return r
   280  }
   281  
   282  // LimitScope sets the value of the 'limit_scope' parameter.
   283  func (r *StatusesListRequest) LimitScope(value time.Time) *StatusesListRequest {
   284  	r.limitScope = &value
   285  	return r
   286  }
   287  
   288  // Page sets the value of the 'page' parameter.
   289  func (r *StatusesListRequest) Page(value int) *StatusesListRequest {
   290  	r.page = &value
   291  	return r
   292  }
   293  
   294  // ProductIds sets the value of the 'product_ids' parameter.
   295  func (r *StatusesListRequest) ProductIds(value string) *StatusesListRequest {
   296  	r.productIds = &value
   297  	return r
   298  }
   299  
   300  // Size sets the value of the 'size' parameter.
   301  func (r *StatusesListRequest) Size(value int) *StatusesListRequest {
   302  	r.size = &value
   303  	return r
   304  }
   305  
   306  // Send sends this request, waits for the response, and returns it.
   307  //
   308  // This is a potentially lengthy operation, as it requires network communication.
   309  // Consider using a context and the SendContext method.
   310  func (r *StatusesListRequest) Send() (result *StatusesListResponse, err error) {
   311  	return r.SendContext(context.Background())
   312  }
   313  
   314  // SendContext sends this request, waits for the response, and returns it.
   315  func (r *StatusesListRequest) SendContext(ctx context.Context) (result *StatusesListResponse, err error) {
   316  	query := helpers.CopyQuery(r.query)
   317  	if r.createdAfter != nil {
   318  		helpers.AddValue(&query, "created_after", *r.createdAfter)
   319  	}
   320  	if r.createdBefore != nil {
   321  		helpers.AddValue(&query, "created_before", *r.createdBefore)
   322  	}
   323  	if r.flapDetection != nil {
   324  		helpers.AddValue(&query, "flap_detection", *r.flapDetection)
   325  	}
   326  	if r.fullNames != nil {
   327  		helpers.AddValue(&query, "full_names", *r.fullNames)
   328  	}
   329  	if r.limitScope != nil {
   330  		helpers.AddValue(&query, "limit_scope", *r.limitScope)
   331  	}
   332  	if r.page != nil {
   333  		helpers.AddValue(&query, "page", *r.page)
   334  	}
   335  	if r.productIds != nil {
   336  		helpers.AddValue(&query, "product_ids", *r.productIds)
   337  	}
   338  	if r.size != nil {
   339  		helpers.AddValue(&query, "size", *r.size)
   340  	}
   341  	header := helpers.CopyHeader(r.header)
   342  	uri := &url.URL{
   343  		Path:     r.path,
   344  		RawQuery: query.Encode(),
   345  	}
   346  	request := &http.Request{
   347  		Method: "GET",
   348  		URL:    uri,
   349  		Header: header,
   350  	}
   351  	if ctx != nil {
   352  		request = request.WithContext(ctx)
   353  	}
   354  	response, err := r.transport.RoundTrip(request)
   355  	if err != nil {
   356  		return
   357  	}
   358  	defer response.Body.Close()
   359  	result = &StatusesListResponse{}
   360  	result.status = response.StatusCode
   361  	result.header = response.Header
   362  	reader := bufio.NewReader(response.Body)
   363  	_, err = reader.Peek(1)
   364  	if err == io.EOF {
   365  		err = nil
   366  		return
   367  	}
   368  	if result.status >= 400 {
   369  		result.err, err = errors.UnmarshalErrorStatus(reader, result.status)
   370  		if err != nil {
   371  			return
   372  		}
   373  		err = result.err
   374  		return
   375  	}
   376  	err = readStatusesListResponse(result, reader)
   377  	if err != nil {
   378  		return
   379  	}
   380  	return
   381  }
   382  
   383  // StatusesListResponse is the response for the 'list' method.
   384  type StatusesListResponse struct {
   385  	status int
   386  	header http.Header
   387  	err    *errors.Error
   388  	items  *StatusList
   389  	page   *int
   390  	size   *int
   391  	total  *int
   392  }
   393  
   394  // Status returns the response status code.
   395  func (r *StatusesListResponse) Status() int {
   396  	if r == nil {
   397  		return 0
   398  	}
   399  	return r.status
   400  }
   401  
   402  // Header returns header of the response.
   403  func (r *StatusesListResponse) Header() http.Header {
   404  	if r == nil {
   405  		return nil
   406  	}
   407  	return r.header
   408  }
   409  
   410  // Error returns the response error.
   411  func (r *StatusesListResponse) Error() *errors.Error {
   412  	if r == nil {
   413  		return nil
   414  	}
   415  	return r.err
   416  }
   417  
   418  // Items returns the value of the 'items' parameter.
   419  func (r *StatusesListResponse) Items() *StatusList {
   420  	if r == nil {
   421  		return nil
   422  	}
   423  	return r.items
   424  }
   425  
   426  // GetItems returns the value of the 'items' parameter and
   427  // a flag indicating if the parameter has a value.
   428  func (r *StatusesListResponse) GetItems() (value *StatusList, ok bool) {
   429  	ok = r != nil && r.items != nil
   430  	if ok {
   431  		value = r.items
   432  	}
   433  	return
   434  }
   435  
   436  // Page returns the value of the 'page' parameter.
   437  func (r *StatusesListResponse) Page() int {
   438  	if r != nil && r.page != nil {
   439  		return *r.page
   440  	}
   441  	return 0
   442  }
   443  
   444  // GetPage returns the value of the 'page' parameter and
   445  // a flag indicating if the parameter has a value.
   446  func (r *StatusesListResponse) GetPage() (value int, ok bool) {
   447  	ok = r != nil && r.page != nil
   448  	if ok {
   449  		value = *r.page
   450  	}
   451  	return
   452  }
   453  
   454  // Size returns the value of the 'size' parameter.
   455  func (r *StatusesListResponse) Size() int {
   456  	if r != nil && r.size != nil {
   457  		return *r.size
   458  	}
   459  	return 0
   460  }
   461  
   462  // GetSize returns the value of the 'size' parameter and
   463  // a flag indicating if the parameter has a value.
   464  func (r *StatusesListResponse) GetSize() (value int, ok bool) {
   465  	ok = r != nil && r.size != nil
   466  	if ok {
   467  		value = *r.size
   468  	}
   469  	return
   470  }
   471  
   472  // Total returns the value of the 'total' parameter.
   473  func (r *StatusesListResponse) Total() int {
   474  	if r != nil && r.total != nil {
   475  		return *r.total
   476  	}
   477  	return 0
   478  }
   479  
   480  // GetTotal returns the value of the 'total' parameter and
   481  // a flag indicating if the parameter has a value.
   482  func (r *StatusesListResponse) GetTotal() (value int, ok bool) {
   483  	ok = r != nil && r.total != nil
   484  	if ok {
   485  		value = *r.total
   486  	}
   487  	return
   488  }