github.com/openshift-online/ocm-sdk-go@v0.1.473/statusboard/v1/applications_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 // ApplicationsClient is the client of the 'applications' resource. 36 // 37 // Manages the collection of applications. 38 type ApplicationsClient struct { 39 transport http.RoundTripper 40 path string 41 } 42 43 // NewApplicationsClient creates a new client for the 'applications' 44 // resource using the given transport to send the requests and receive the 45 // responses. 46 func NewApplicationsClient(transport http.RoundTripper, path string) *ApplicationsClient { 47 return &ApplicationsClient{ 48 transport: transport, 49 path: path, 50 } 51 } 52 53 // Add creates a request for the 'add' method. 54 func (c *ApplicationsClient) Add() *ApplicationsAddRequest { 55 return &ApplicationsAddRequest{ 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 applications. 64 func (c *ApplicationsClient) List() *ApplicationsListRequest { 65 return &ApplicationsListRequest{ 66 transport: c.transport, 67 path: c.path, 68 } 69 } 70 71 // Application returns the target 'application' resource for the given identifier. 72 func (c *ApplicationsClient) Application(id string) *ApplicationClient { 73 return NewApplicationClient( 74 c.transport, 75 path.Join(c.path, id), 76 ) 77 } 78 79 // ApplicationsAddRequest is the request for the 'add' method. 80 type ApplicationsAddRequest struct { 81 transport http.RoundTripper 82 path string 83 query url.Values 84 header http.Header 85 body *Application 86 } 87 88 // Parameter adds a query parameter. 89 func (r *ApplicationsAddRequest) Parameter(name string, value interface{}) *ApplicationsAddRequest { 90 helpers.AddValue(&r.query, name, value) 91 return r 92 } 93 94 // Header adds a request header. 95 func (r *ApplicationsAddRequest) Header(name string, value interface{}) *ApplicationsAddRequest { 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 *ApplicationsAddRequest) Impersonate(user string) *ApplicationsAddRequest { 103 helpers.AddImpersonationHeader(&r.header, user) 104 return r 105 } 106 107 // Body sets the value of the 'body' parameter. 108 func (r *ApplicationsAddRequest) Body(value *Application) *ApplicationsAddRequest { 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 *ApplicationsAddRequest) Send() (result *ApplicationsAddResponse, 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 *ApplicationsAddRequest) SendContext(ctx context.Context) (result *ApplicationsAddResponse, err error) { 123 query := helpers.CopyQuery(r.query) 124 header := helpers.CopyHeader(r.header) 125 buffer := &bytes.Buffer{} 126 err = writeApplicationsAddRequest(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 = &ApplicationsAddResponse{} 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 = readApplicationsAddResponse(result, reader) 166 if err != nil { 167 return 168 } 169 return 170 } 171 172 // ApplicationsAddResponse is the response for the 'add' method. 173 type ApplicationsAddResponse struct { 174 status int 175 header http.Header 176 err *errors.Error 177 body *Application 178 } 179 180 // Status returns the response status code. 181 func (r *ApplicationsAddResponse) 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 *ApplicationsAddResponse) 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 *ApplicationsAddResponse) 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 *ApplicationsAddResponse) Body() *Application { 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 *ApplicationsAddResponse) GetBody() (value *Application, ok bool) { 215 ok = r != nil && r.body != nil 216 if ok { 217 value = r.body 218 } 219 return 220 } 221 222 // ApplicationsListRequest is the request for the 'list' method. 223 type ApplicationsListRequest struct { 224 transport http.RoundTripper 225 path string 226 query url.Values 227 header http.Header 228 orderBy *string 229 page *int 230 search *string 231 size *int 232 } 233 234 // Parameter adds a query parameter. 235 func (r *ApplicationsListRequest) Parameter(name string, value interface{}) *ApplicationsListRequest { 236 helpers.AddValue(&r.query, name, value) 237 return r 238 } 239 240 // Header adds a request header. 241 func (r *ApplicationsListRequest) Header(name string, value interface{}) *ApplicationsListRequest { 242 helpers.AddHeader(&r.header, name, value) 243 return r 244 } 245 246 // Impersonate wraps requests on behalf of another user. 247 // Note: Services that do not support this feature may silently ignore this call. 248 func (r *ApplicationsListRequest) Impersonate(user string) *ApplicationsListRequest { 249 helpers.AddImpersonationHeader(&r.header, user) 250 return r 251 } 252 253 // OrderBy sets the value of the 'order_by' parameter. 254 func (r *ApplicationsListRequest) OrderBy(value string) *ApplicationsListRequest { 255 r.orderBy = &value 256 return r 257 } 258 259 // Page sets the value of the 'page' parameter. 260 func (r *ApplicationsListRequest) Page(value int) *ApplicationsListRequest { 261 r.page = &value 262 return r 263 } 264 265 // Search sets the value of the 'search' parameter. 266 func (r *ApplicationsListRequest) Search(value string) *ApplicationsListRequest { 267 r.search = &value 268 return r 269 } 270 271 // Size sets the value of the 'size' parameter. 272 func (r *ApplicationsListRequest) Size(value int) *ApplicationsListRequest { 273 r.size = &value 274 return r 275 } 276 277 // Send sends this request, waits for the response, and returns it. 278 // 279 // This is a potentially lengthy operation, as it requires network communication. 280 // Consider using a context and the SendContext method. 281 func (r *ApplicationsListRequest) Send() (result *ApplicationsListResponse, err error) { 282 return r.SendContext(context.Background()) 283 } 284 285 // SendContext sends this request, waits for the response, and returns it. 286 func (r *ApplicationsListRequest) SendContext(ctx context.Context) (result *ApplicationsListResponse, err error) { 287 query := helpers.CopyQuery(r.query) 288 if r.orderBy != nil { 289 helpers.AddValue(&query, "order_by", *r.orderBy) 290 } 291 if r.page != nil { 292 helpers.AddValue(&query, "page", *r.page) 293 } 294 if r.search != nil { 295 helpers.AddValue(&query, "search", *r.search) 296 } 297 if r.size != nil { 298 helpers.AddValue(&query, "size", *r.size) 299 } 300 header := helpers.CopyHeader(r.header) 301 uri := &url.URL{ 302 Path: r.path, 303 RawQuery: query.Encode(), 304 } 305 request := &http.Request{ 306 Method: "GET", 307 URL: uri, 308 Header: header, 309 } 310 if ctx != nil { 311 request = request.WithContext(ctx) 312 } 313 response, err := r.transport.RoundTrip(request) 314 if err != nil { 315 return 316 } 317 defer response.Body.Close() 318 result = &ApplicationsListResponse{} 319 result.status = response.StatusCode 320 result.header = response.Header 321 reader := bufio.NewReader(response.Body) 322 _, err = reader.Peek(1) 323 if err == io.EOF { 324 err = nil 325 return 326 } 327 if result.status >= 400 { 328 result.err, err = errors.UnmarshalErrorStatus(reader, result.status) 329 if err != nil { 330 return 331 } 332 err = result.err 333 return 334 } 335 err = readApplicationsListResponse(result, reader) 336 if err != nil { 337 return 338 } 339 return 340 } 341 342 // ApplicationsListResponse is the response for the 'list' method. 343 type ApplicationsListResponse struct { 344 status int 345 header http.Header 346 err *errors.Error 347 items *ApplicationList 348 page *int 349 size *int 350 total *int 351 } 352 353 // Status returns the response status code. 354 func (r *ApplicationsListResponse) Status() int { 355 if r == nil { 356 return 0 357 } 358 return r.status 359 } 360 361 // Header returns header of the response. 362 func (r *ApplicationsListResponse) Header() http.Header { 363 if r == nil { 364 return nil 365 } 366 return r.header 367 } 368 369 // Error returns the response error. 370 func (r *ApplicationsListResponse) Error() *errors.Error { 371 if r == nil { 372 return nil 373 } 374 return r.err 375 } 376 377 // Items returns the value of the 'items' parameter. 378 func (r *ApplicationsListResponse) Items() *ApplicationList { 379 if r == nil { 380 return nil 381 } 382 return r.items 383 } 384 385 // GetItems returns the value of the 'items' parameter and 386 // a flag indicating if the parameter has a value. 387 func (r *ApplicationsListResponse) GetItems() (value *ApplicationList, ok bool) { 388 ok = r != nil && r.items != nil 389 if ok { 390 value = r.items 391 } 392 return 393 } 394 395 // Page returns the value of the 'page' parameter. 396 func (r *ApplicationsListResponse) Page() int { 397 if r != nil && r.page != nil { 398 return *r.page 399 } 400 return 0 401 } 402 403 // GetPage returns the value of the 'page' parameter and 404 // a flag indicating if the parameter has a value. 405 func (r *ApplicationsListResponse) GetPage() (value int, ok bool) { 406 ok = r != nil && r.page != nil 407 if ok { 408 value = *r.page 409 } 410 return 411 } 412 413 // Size returns the value of the 'size' parameter. 414 func (r *ApplicationsListResponse) Size() int { 415 if r != nil && r.size != nil { 416 return *r.size 417 } 418 return 0 419 } 420 421 // GetSize returns the value of the 'size' parameter and 422 // a flag indicating if the parameter has a value. 423 func (r *ApplicationsListResponse) GetSize() (value int, ok bool) { 424 ok = r != nil && r.size != nil 425 if ok { 426 value = *r.size 427 } 428 return 429 } 430 431 // Total returns the value of the 'total' parameter. 432 func (r *ApplicationsListResponse) Total() int { 433 if r != nil && r.total != nil { 434 return *r.total 435 } 436 return 0 437 } 438 439 // GetTotal returns the value of the 'total' parameter and 440 // a flag indicating if the parameter has a value. 441 func (r *ApplicationsListResponse) GetTotal() (value int, ok bool) { 442 ok = r != nil && r.total != nil 443 if ok { 444 value = *r.total 445 } 446 return 447 }