github.com/openshift-online/ocm-sdk-go@v0.1.473/statusboard/v1/application_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" 31 32 "github.com/openshift-online/ocm-sdk-go/errors" 33 "github.com/openshift-online/ocm-sdk-go/helpers" 34 ) 35 36 // ApplicationClient is the client of the 'application' resource. 37 // 38 // Provides detailed information about the specified application. 39 type ApplicationClient struct { 40 transport http.RoundTripper 41 path string 42 } 43 44 // NewApplicationClient creates a new client for the 'application' 45 // resource using the given transport to send the requests and receive the 46 // responses. 47 func NewApplicationClient(transport http.RoundTripper, path string) *ApplicationClient { 48 return &ApplicationClient{ 49 transport: transport, 50 path: path, 51 } 52 } 53 54 // Delete creates a request for the 'delete' method. 55 func (c *ApplicationClient) Delete() *ApplicationDeleteRequest { 56 return &ApplicationDeleteRequest{ 57 transport: c.transport, 58 path: c.path, 59 } 60 } 61 62 // Get creates a request for the 'get' method. 63 func (c *ApplicationClient) Get() *ApplicationGetRequest { 64 return &ApplicationGetRequest{ 65 transport: c.transport, 66 path: c.path, 67 } 68 } 69 70 // Update creates a request for the 'update' method. 71 func (c *ApplicationClient) Update() *ApplicationUpdateRequest { 72 return &ApplicationUpdateRequest{ 73 transport: c.transport, 74 path: c.path, 75 } 76 } 77 78 // Services returns the target 'services' resource. 79 func (c *ApplicationClient) Services() *ServicesClient { 80 return NewServicesClient( 81 c.transport, 82 path.Join(c.path, "services"), 83 ) 84 } 85 86 // ApplicationPollRequest is the request for the Poll method. 87 type ApplicationPollRequest struct { 88 request *ApplicationGetRequest 89 interval time.Duration 90 statuses []int 91 predicates []func(interface{}) bool 92 } 93 94 // Parameter adds a query parameter to all the requests that will be used to retrieve the object. 95 func (r *ApplicationPollRequest) Parameter(name string, value interface{}) *ApplicationPollRequest { 96 r.request.Parameter(name, value) 97 return r 98 } 99 100 // Header adds a request header to all the requests that will be used to retrieve the object. 101 func (r *ApplicationPollRequest) Header(name string, value interface{}) *ApplicationPollRequest { 102 r.request.Header(name, value) 103 return r 104 } 105 106 // Interval sets the polling interval. This parameter is mandatory and must be greater than zero. 107 func (r *ApplicationPollRequest) Interval(value time.Duration) *ApplicationPollRequest { 108 r.interval = value 109 return r 110 } 111 112 // Status set the expected status of the response. Multiple values can be set calling this method 113 // multiple times. The response will be considered successful if the status is any of those values. 114 func (r *ApplicationPollRequest) Status(value int) *ApplicationPollRequest { 115 r.statuses = append(r.statuses, value) 116 return r 117 } 118 119 // Predicate adds a predicate that the response should satisfy be considered successful. Multiple 120 // predicates can be set calling this method multiple times. The response will be considered successful 121 // if all the predicates are satisfied. 122 func (r *ApplicationPollRequest) Predicate(value func(*ApplicationGetResponse) bool) *ApplicationPollRequest { 123 r.predicates = append(r.predicates, func(response interface{}) bool { 124 return value(response.(*ApplicationGetResponse)) 125 }) 126 return r 127 } 128 129 // StartContext starts the polling loop. Responses will be considered successful if the status is one of 130 // the values specified with the Status method and if all the predicates specified with the Predicate 131 // method return nil. 132 // 133 // The context must have a timeout or deadline, otherwise this method will immediately return an error. 134 func (r *ApplicationPollRequest) StartContext(ctx context.Context) (response *ApplicationPollResponse, err error) { 135 result, err := helpers.PollContext(ctx, r.interval, r.statuses, r.predicates, r.task) 136 if result != nil { 137 response = &ApplicationPollResponse{ 138 response: result.(*ApplicationGetResponse), 139 } 140 } 141 return 142 } 143 144 // task adapts the types of the request/response types so that they can be used with the generic 145 // polling function from the helpers package. 146 func (r *ApplicationPollRequest) task(ctx context.Context) (status int, result interface{}, err error) { 147 response, err := r.request.SendContext(ctx) 148 if response != nil { 149 status = response.Status() 150 result = response 151 } 152 return 153 } 154 155 // ApplicationPollResponse is the response for the Poll method. 156 type ApplicationPollResponse struct { 157 response *ApplicationGetResponse 158 } 159 160 // Status returns the response status code. 161 func (r *ApplicationPollResponse) Status() int { 162 if r == nil { 163 return 0 164 } 165 return r.response.Status() 166 } 167 168 // Header returns header of the response. 169 func (r *ApplicationPollResponse) Header() http.Header { 170 if r == nil { 171 return nil 172 } 173 return r.response.Header() 174 } 175 176 // Error returns the response error. 177 func (r *ApplicationPollResponse) Error() *errors.Error { 178 if r == nil { 179 return nil 180 } 181 return r.response.Error() 182 } 183 184 // Body returns the value of the 'body' parameter. 185 func (r *ApplicationPollResponse) Body() *Application { 186 return r.response.Body() 187 } 188 189 // GetBody returns the value of the 'body' parameter and 190 // a flag indicating if the parameter has a value. 191 func (r *ApplicationPollResponse) GetBody() (value *Application, ok bool) { 192 return r.response.GetBody() 193 } 194 195 // Poll creates a request to repeatedly retrieve the object till the response has one of a given set 196 // of states and satisfies a set of predicates. 197 func (c *ApplicationClient) Poll() *ApplicationPollRequest { 198 return &ApplicationPollRequest{ 199 request: c.Get(), 200 } 201 } 202 203 // ApplicationDeleteRequest is the request for the 'delete' method. 204 type ApplicationDeleteRequest struct { 205 transport http.RoundTripper 206 path string 207 query url.Values 208 header http.Header 209 } 210 211 // Parameter adds a query parameter. 212 func (r *ApplicationDeleteRequest) Parameter(name string, value interface{}) *ApplicationDeleteRequest { 213 helpers.AddValue(&r.query, name, value) 214 return r 215 } 216 217 // Header adds a request header. 218 func (r *ApplicationDeleteRequest) Header(name string, value interface{}) *ApplicationDeleteRequest { 219 helpers.AddHeader(&r.header, name, value) 220 return r 221 } 222 223 // Impersonate wraps requests on behalf of another user. 224 // Note: Services that do not support this feature may silently ignore this call. 225 func (r *ApplicationDeleteRequest) Impersonate(user string) *ApplicationDeleteRequest { 226 helpers.AddImpersonationHeader(&r.header, user) 227 return r 228 } 229 230 // Send sends this request, waits for the response, and returns it. 231 // 232 // This is a potentially lengthy operation, as it requires network communication. 233 // Consider using a context and the SendContext method. 234 func (r *ApplicationDeleteRequest) Send() (result *ApplicationDeleteResponse, err error) { 235 return r.SendContext(context.Background()) 236 } 237 238 // SendContext sends this request, waits for the response, and returns it. 239 func (r *ApplicationDeleteRequest) SendContext(ctx context.Context) (result *ApplicationDeleteResponse, err error) { 240 query := helpers.CopyQuery(r.query) 241 header := helpers.CopyHeader(r.header) 242 uri := &url.URL{ 243 Path: r.path, 244 RawQuery: query.Encode(), 245 } 246 request := &http.Request{ 247 Method: "DELETE", 248 URL: uri, 249 Header: header, 250 } 251 if ctx != nil { 252 request = request.WithContext(ctx) 253 } 254 response, err := r.transport.RoundTrip(request) 255 if err != nil { 256 return 257 } 258 defer response.Body.Close() 259 result = &ApplicationDeleteResponse{} 260 result.status = response.StatusCode 261 result.header = response.Header 262 reader := bufio.NewReader(response.Body) 263 _, err = reader.Peek(1) 264 if err == io.EOF { 265 err = nil 266 return 267 } 268 if result.status >= 400 { 269 result.err, err = errors.UnmarshalErrorStatus(reader, result.status) 270 if err != nil { 271 return 272 } 273 err = result.err 274 return 275 } 276 return 277 } 278 279 // ApplicationDeleteResponse is the response for the 'delete' method. 280 type ApplicationDeleteResponse struct { 281 status int 282 header http.Header 283 err *errors.Error 284 } 285 286 // Status returns the response status code. 287 func (r *ApplicationDeleteResponse) Status() int { 288 if r == nil { 289 return 0 290 } 291 return r.status 292 } 293 294 // Header returns header of the response. 295 func (r *ApplicationDeleteResponse) Header() http.Header { 296 if r == nil { 297 return nil 298 } 299 return r.header 300 } 301 302 // Error returns the response error. 303 func (r *ApplicationDeleteResponse) Error() *errors.Error { 304 if r == nil { 305 return nil 306 } 307 return r.err 308 } 309 310 // ApplicationGetRequest is the request for the 'get' method. 311 type ApplicationGetRequest struct { 312 transport http.RoundTripper 313 path string 314 query url.Values 315 header http.Header 316 } 317 318 // Parameter adds a query parameter. 319 func (r *ApplicationGetRequest) Parameter(name string, value interface{}) *ApplicationGetRequest { 320 helpers.AddValue(&r.query, name, value) 321 return r 322 } 323 324 // Header adds a request header. 325 func (r *ApplicationGetRequest) Header(name string, value interface{}) *ApplicationGetRequest { 326 helpers.AddHeader(&r.header, name, value) 327 return r 328 } 329 330 // Impersonate wraps requests on behalf of another user. 331 // Note: Services that do not support this feature may silently ignore this call. 332 func (r *ApplicationGetRequest) Impersonate(user string) *ApplicationGetRequest { 333 helpers.AddImpersonationHeader(&r.header, user) 334 return r 335 } 336 337 // Send sends this request, waits for the response, and returns it. 338 // 339 // This is a potentially lengthy operation, as it requires network communication. 340 // Consider using a context and the SendContext method. 341 func (r *ApplicationGetRequest) Send() (result *ApplicationGetResponse, err error) { 342 return r.SendContext(context.Background()) 343 } 344 345 // SendContext sends this request, waits for the response, and returns it. 346 func (r *ApplicationGetRequest) SendContext(ctx context.Context) (result *ApplicationGetResponse, err error) { 347 query := helpers.CopyQuery(r.query) 348 header := helpers.CopyHeader(r.header) 349 uri := &url.URL{ 350 Path: r.path, 351 RawQuery: query.Encode(), 352 } 353 request := &http.Request{ 354 Method: "GET", 355 URL: uri, 356 Header: header, 357 } 358 if ctx != nil { 359 request = request.WithContext(ctx) 360 } 361 response, err := r.transport.RoundTrip(request) 362 if err != nil { 363 return 364 } 365 defer response.Body.Close() 366 result = &ApplicationGetResponse{} 367 result.status = response.StatusCode 368 result.header = response.Header 369 reader := bufio.NewReader(response.Body) 370 _, err = reader.Peek(1) 371 if err == io.EOF { 372 err = nil 373 return 374 } 375 if result.status >= 400 { 376 result.err, err = errors.UnmarshalErrorStatus(reader, result.status) 377 if err != nil { 378 return 379 } 380 err = result.err 381 return 382 } 383 err = readApplicationGetResponse(result, reader) 384 if err != nil { 385 return 386 } 387 return 388 } 389 390 // ApplicationGetResponse is the response for the 'get' method. 391 type ApplicationGetResponse struct { 392 status int 393 header http.Header 394 err *errors.Error 395 body *Application 396 } 397 398 // Status returns the response status code. 399 func (r *ApplicationGetResponse) Status() int { 400 if r == nil { 401 return 0 402 } 403 return r.status 404 } 405 406 // Header returns header of the response. 407 func (r *ApplicationGetResponse) Header() http.Header { 408 if r == nil { 409 return nil 410 } 411 return r.header 412 } 413 414 // Error returns the response error. 415 func (r *ApplicationGetResponse) Error() *errors.Error { 416 if r == nil { 417 return nil 418 } 419 return r.err 420 } 421 422 // Body returns the value of the 'body' parameter. 423 func (r *ApplicationGetResponse) Body() *Application { 424 if r == nil { 425 return nil 426 } 427 return r.body 428 } 429 430 // GetBody returns the value of the 'body' parameter and 431 // a flag indicating if the parameter has a value. 432 func (r *ApplicationGetResponse) GetBody() (value *Application, ok bool) { 433 ok = r != nil && r.body != nil 434 if ok { 435 value = r.body 436 } 437 return 438 } 439 440 // ApplicationUpdateRequest is the request for the 'update' method. 441 type ApplicationUpdateRequest struct { 442 transport http.RoundTripper 443 path string 444 query url.Values 445 header http.Header 446 body *Application 447 } 448 449 // Parameter adds a query parameter. 450 func (r *ApplicationUpdateRequest) Parameter(name string, value interface{}) *ApplicationUpdateRequest { 451 helpers.AddValue(&r.query, name, value) 452 return r 453 } 454 455 // Header adds a request header. 456 func (r *ApplicationUpdateRequest) Header(name string, value interface{}) *ApplicationUpdateRequest { 457 helpers.AddHeader(&r.header, name, value) 458 return r 459 } 460 461 // Impersonate wraps requests on behalf of another user. 462 // Note: Services that do not support this feature may silently ignore this call. 463 func (r *ApplicationUpdateRequest) Impersonate(user string) *ApplicationUpdateRequest { 464 helpers.AddImpersonationHeader(&r.header, user) 465 return r 466 } 467 468 // Body sets the value of the 'body' parameter. 469 func (r *ApplicationUpdateRequest) Body(value *Application) *ApplicationUpdateRequest { 470 r.body = value 471 return r 472 } 473 474 // Send sends this request, waits for the response, and returns it. 475 // 476 // This is a potentially lengthy operation, as it requires network communication. 477 // Consider using a context and the SendContext method. 478 func (r *ApplicationUpdateRequest) Send() (result *ApplicationUpdateResponse, err error) { 479 return r.SendContext(context.Background()) 480 } 481 482 // SendContext sends this request, waits for the response, and returns it. 483 func (r *ApplicationUpdateRequest) SendContext(ctx context.Context) (result *ApplicationUpdateResponse, err error) { 484 query := helpers.CopyQuery(r.query) 485 header := helpers.CopyHeader(r.header) 486 buffer := &bytes.Buffer{} 487 err = writeApplicationUpdateRequest(r, buffer) 488 if err != nil { 489 return 490 } 491 uri := &url.URL{ 492 Path: r.path, 493 RawQuery: query.Encode(), 494 } 495 request := &http.Request{ 496 Method: "PATCH", 497 URL: uri, 498 Header: header, 499 Body: io.NopCloser(buffer), 500 } 501 if ctx != nil { 502 request = request.WithContext(ctx) 503 } 504 response, err := r.transport.RoundTrip(request) 505 if err != nil { 506 return 507 } 508 defer response.Body.Close() 509 result = &ApplicationUpdateResponse{} 510 result.status = response.StatusCode 511 result.header = response.Header 512 reader := bufio.NewReader(response.Body) 513 _, err = reader.Peek(1) 514 if err == io.EOF { 515 err = nil 516 return 517 } 518 if result.status >= 400 { 519 result.err, err = errors.UnmarshalErrorStatus(reader, result.status) 520 if err != nil { 521 return 522 } 523 err = result.err 524 return 525 } 526 err = readApplicationUpdateResponse(result, reader) 527 if err != nil { 528 return 529 } 530 return 531 } 532 533 // ApplicationUpdateResponse is the response for the 'update' method. 534 type ApplicationUpdateResponse struct { 535 status int 536 header http.Header 537 err *errors.Error 538 body *Application 539 } 540 541 // Status returns the response status code. 542 func (r *ApplicationUpdateResponse) Status() int { 543 if r == nil { 544 return 0 545 } 546 return r.status 547 } 548 549 // Header returns header of the response. 550 func (r *ApplicationUpdateResponse) Header() http.Header { 551 if r == nil { 552 return nil 553 } 554 return r.header 555 } 556 557 // Error returns the response error. 558 func (r *ApplicationUpdateResponse) Error() *errors.Error { 559 if r == nil { 560 return nil 561 } 562 return r.err 563 } 564 565 // Body returns the value of the 'body' parameter. 566 func (r *ApplicationUpdateResponse) Body() *Application { 567 if r == nil { 568 return nil 569 } 570 return r.body 571 } 572 573 // GetBody returns the value of the 'body' parameter and 574 // a flag indicating if the parameter has a value. 575 func (r *ApplicationUpdateResponse) GetBody() (value *Application, ok bool) { 576 ok = r != nil && r.body != nil 577 if ok { 578 value = r.body 579 } 580 return 581 }