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