github.com/openshift-online/ocm-sdk-go@v0.1.473/statusboard/v1/status_updates_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  // StatusUpdatesClient is the client of the 'status_updates' resource.
    37  //
    38  // Manages the collection of statuses
    39  type StatusUpdatesClient struct {
    40  	transport http.RoundTripper
    41  	path      string
    42  }
    43  
    44  // NewStatusUpdatesClient creates a new client for the 'status_updates'
    45  // resource using the given transport to send the requests and receive the
    46  // responses.
    47  func NewStatusUpdatesClient(transport http.RoundTripper, path string) *StatusUpdatesClient {
    48  	return &StatusUpdatesClient{
    49  		transport: transport,
    50  		path:      path,
    51  	}
    52  }
    53  
    54  // Add creates a request for the 'add' method.
    55  func (c *StatusUpdatesClient) Add() *StatusUpdatesAddRequest {
    56  	return &StatusUpdatesAddRequest{
    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 *StatusUpdatesClient) List() *StatusUpdatesListRequest {
    66  	return &StatusUpdatesListRequest{
    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 *StatusUpdatesClient) Status(id string) *StatusClient {
    74  	return NewStatusClient(
    75  		c.transport,
    76  		path.Join(c.path, id),
    77  	)
    78  }
    79  
    80  // StatusUpdatesAddRequest is the request for the 'add' method.
    81  type StatusUpdatesAddRequest 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 *StatusUpdatesAddRequest) Parameter(name string, value interface{}) *StatusUpdatesAddRequest {
    91  	helpers.AddValue(&r.query, name, value)
    92  	return r
    93  }
    94  
    95  // Header adds a request header.
    96  func (r *StatusUpdatesAddRequest) Header(name string, value interface{}) *StatusUpdatesAddRequest {
    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 *StatusUpdatesAddRequest) Impersonate(user string) *StatusUpdatesAddRequest {
   104  	helpers.AddImpersonationHeader(&r.header, user)
   105  	return r
   106  }
   107  
   108  // Body sets the value of the 'body' parameter.
   109  func (r *StatusUpdatesAddRequest) Body(value *Status) *StatusUpdatesAddRequest {
   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 *StatusUpdatesAddRequest) Send() (result *StatusUpdatesAddResponse, 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 *StatusUpdatesAddRequest) SendContext(ctx context.Context) (result *StatusUpdatesAddResponse, err error) {
   124  	query := helpers.CopyQuery(r.query)
   125  	header := helpers.CopyHeader(r.header)
   126  	buffer := &bytes.Buffer{}
   127  	err = writeStatusUpdatesAddRequest(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 = &StatusUpdatesAddResponse{}
   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 = readStatusUpdatesAddResponse(result, reader)
   167  	if err != nil {
   168  		return
   169  	}
   170  	return
   171  }
   172  
   173  // StatusUpdatesAddResponse is the response for the 'add' method.
   174  type StatusUpdatesAddResponse 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 *StatusUpdatesAddResponse) 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 *StatusUpdatesAddResponse) 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 *StatusUpdatesAddResponse) 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 *StatusUpdatesAddResponse) 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 *StatusUpdatesAddResponse) 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  // StatusUpdatesListRequest is the request for the 'list' method.
   224  type StatusUpdatesListRequest 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  	search        *string
   237  	size          *int
   238  }
   239  
   240  // Parameter adds a query parameter.
   241  func (r *StatusUpdatesListRequest) Parameter(name string, value interface{}) *StatusUpdatesListRequest {
   242  	helpers.AddValue(&r.query, name, value)
   243  	return r
   244  }
   245  
   246  // Header adds a request header.
   247  func (r *StatusUpdatesListRequest) Header(name string, value interface{}) *StatusUpdatesListRequest {
   248  	helpers.AddHeader(&r.header, name, value)
   249  	return r
   250  }
   251  
   252  // Impersonate wraps requests on behalf of another user.
   253  // Note: Services that do not support this feature may silently ignore this call.
   254  func (r *StatusUpdatesListRequest) Impersonate(user string) *StatusUpdatesListRequest {
   255  	helpers.AddImpersonationHeader(&r.header, user)
   256  	return r
   257  }
   258  
   259  // CreatedAfter sets the value of the 'created_after' parameter.
   260  func (r *StatusUpdatesListRequest) CreatedAfter(value time.Time) *StatusUpdatesListRequest {
   261  	r.createdAfter = &value
   262  	return r
   263  }
   264  
   265  // CreatedBefore sets the value of the 'created_before' parameter.
   266  func (r *StatusUpdatesListRequest) CreatedBefore(value time.Time) *StatusUpdatesListRequest {
   267  	r.createdBefore = &value
   268  	return r
   269  }
   270  
   271  // FlapDetection sets the value of the 'flap_detection' parameter.
   272  func (r *StatusUpdatesListRequest) FlapDetection(value bool) *StatusUpdatesListRequest {
   273  	r.flapDetection = &value
   274  	return r
   275  }
   276  
   277  // FullNames sets the value of the 'full_names' parameter.
   278  func (r *StatusUpdatesListRequest) FullNames(value string) *StatusUpdatesListRequest {
   279  	r.fullNames = &value
   280  	return r
   281  }
   282  
   283  // LimitScope sets the value of the 'limit_scope' parameter.
   284  func (r *StatusUpdatesListRequest) LimitScope(value time.Time) *StatusUpdatesListRequest {
   285  	r.limitScope = &value
   286  	return r
   287  }
   288  
   289  // Page sets the value of the 'page' parameter.
   290  func (r *StatusUpdatesListRequest) Page(value int) *StatusUpdatesListRequest {
   291  	r.page = &value
   292  	return r
   293  }
   294  
   295  // ProductIds sets the value of the 'product_ids' parameter.
   296  func (r *StatusUpdatesListRequest) ProductIds(value string) *StatusUpdatesListRequest {
   297  	r.productIds = &value
   298  	return r
   299  }
   300  
   301  // Search sets the value of the 'search' parameter.
   302  func (r *StatusUpdatesListRequest) Search(value string) *StatusUpdatesListRequest {
   303  	r.search = &value
   304  	return r
   305  }
   306  
   307  // Size sets the value of the 'size' parameter.
   308  func (r *StatusUpdatesListRequest) Size(value int) *StatusUpdatesListRequest {
   309  	r.size = &value
   310  	return r
   311  }
   312  
   313  // Send sends this request, waits for the response, and returns it.
   314  //
   315  // This is a potentially lengthy operation, as it requires network communication.
   316  // Consider using a context and the SendContext method.
   317  func (r *StatusUpdatesListRequest) Send() (result *StatusUpdatesListResponse, err error) {
   318  	return r.SendContext(context.Background())
   319  }
   320  
   321  // SendContext sends this request, waits for the response, and returns it.
   322  func (r *StatusUpdatesListRequest) SendContext(ctx context.Context) (result *StatusUpdatesListResponse, err error) {
   323  	query := helpers.CopyQuery(r.query)
   324  	if r.createdAfter != nil {
   325  		helpers.AddValue(&query, "created_after", *r.createdAfter)
   326  	}
   327  	if r.createdBefore != nil {
   328  		helpers.AddValue(&query, "created_before", *r.createdBefore)
   329  	}
   330  	if r.flapDetection != nil {
   331  		helpers.AddValue(&query, "flap_detection", *r.flapDetection)
   332  	}
   333  	if r.fullNames != nil {
   334  		helpers.AddValue(&query, "full_names", *r.fullNames)
   335  	}
   336  	if r.limitScope != nil {
   337  		helpers.AddValue(&query, "limit_scope", *r.limitScope)
   338  	}
   339  	if r.page != nil {
   340  		helpers.AddValue(&query, "page", *r.page)
   341  	}
   342  	if r.productIds != nil {
   343  		helpers.AddValue(&query, "product_ids", *r.productIds)
   344  	}
   345  	if r.search != nil {
   346  		helpers.AddValue(&query, "search", *r.search)
   347  	}
   348  	if r.size != nil {
   349  		helpers.AddValue(&query, "size", *r.size)
   350  	}
   351  	header := helpers.CopyHeader(r.header)
   352  	uri := &url.URL{
   353  		Path:     r.path,
   354  		RawQuery: query.Encode(),
   355  	}
   356  	request := &http.Request{
   357  		Method: "GET",
   358  		URL:    uri,
   359  		Header: header,
   360  	}
   361  	if ctx != nil {
   362  		request = request.WithContext(ctx)
   363  	}
   364  	response, err := r.transport.RoundTrip(request)
   365  	if err != nil {
   366  		return
   367  	}
   368  	defer response.Body.Close()
   369  	result = &StatusUpdatesListResponse{}
   370  	result.status = response.StatusCode
   371  	result.header = response.Header
   372  	reader := bufio.NewReader(response.Body)
   373  	_, err = reader.Peek(1)
   374  	if err == io.EOF {
   375  		err = nil
   376  		return
   377  	}
   378  	if result.status >= 400 {
   379  		result.err, err = errors.UnmarshalErrorStatus(reader, result.status)
   380  		if err != nil {
   381  			return
   382  		}
   383  		err = result.err
   384  		return
   385  	}
   386  	err = readStatusUpdatesListResponse(result, reader)
   387  	if err != nil {
   388  		return
   389  	}
   390  	return
   391  }
   392  
   393  // StatusUpdatesListResponse is the response for the 'list' method.
   394  type StatusUpdatesListResponse struct {
   395  	status int
   396  	header http.Header
   397  	err    *errors.Error
   398  	items  *StatusList
   399  	page   *int
   400  	size   *int
   401  	total  *int
   402  }
   403  
   404  // Status returns the response status code.
   405  func (r *StatusUpdatesListResponse) Status() int {
   406  	if r == nil {
   407  		return 0
   408  	}
   409  	return r.status
   410  }
   411  
   412  // Header returns header of the response.
   413  func (r *StatusUpdatesListResponse) Header() http.Header {
   414  	if r == nil {
   415  		return nil
   416  	}
   417  	return r.header
   418  }
   419  
   420  // Error returns the response error.
   421  func (r *StatusUpdatesListResponse) Error() *errors.Error {
   422  	if r == nil {
   423  		return nil
   424  	}
   425  	return r.err
   426  }
   427  
   428  // Items returns the value of the 'items' parameter.
   429  func (r *StatusUpdatesListResponse) Items() *StatusList {
   430  	if r == nil {
   431  		return nil
   432  	}
   433  	return r.items
   434  }
   435  
   436  // GetItems returns the value of the 'items' parameter and
   437  // a flag indicating if the parameter has a value.
   438  func (r *StatusUpdatesListResponse) GetItems() (value *StatusList, ok bool) {
   439  	ok = r != nil && r.items != nil
   440  	if ok {
   441  		value = r.items
   442  	}
   443  	return
   444  }
   445  
   446  // Page returns the value of the 'page' parameter.
   447  func (r *StatusUpdatesListResponse) Page() int {
   448  	if r != nil && r.page != nil {
   449  		return *r.page
   450  	}
   451  	return 0
   452  }
   453  
   454  // GetPage returns the value of the 'page' parameter and
   455  // a flag indicating if the parameter has a value.
   456  func (r *StatusUpdatesListResponse) GetPage() (value int, ok bool) {
   457  	ok = r != nil && r.page != nil
   458  	if ok {
   459  		value = *r.page
   460  	}
   461  	return
   462  }
   463  
   464  // Size returns the value of the 'size' parameter.
   465  func (r *StatusUpdatesListResponse) Size() int {
   466  	if r != nil && r.size != nil {
   467  		return *r.size
   468  	}
   469  	return 0
   470  }
   471  
   472  // GetSize returns the value of the 'size' parameter and
   473  // a flag indicating if the parameter has a value.
   474  func (r *StatusUpdatesListResponse) GetSize() (value int, ok bool) {
   475  	ok = r != nil && r.size != nil
   476  	if ok {
   477  		value = *r.size
   478  	}
   479  	return
   480  }
   481  
   482  // Total returns the value of the 'total' parameter.
   483  func (r *StatusUpdatesListResponse) Total() int {
   484  	if r != nil && r.total != nil {
   485  		return *r.total
   486  	}
   487  	return 0
   488  }
   489  
   490  // GetTotal returns the value of the 'total' parameter and
   491  // a flag indicating if the parameter has a value.
   492  func (r *StatusUpdatesListResponse) GetTotal() (value int, ok bool) {
   493  	ok = r != nil && r.total != nil
   494  	if ok {
   495  		value = *r.total
   496  	}
   497  	return
   498  }