github.com/openshift-online/ocm-sdk-go@v0.1.473/webrca/v1/incidents_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/webrca/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 // IncidentsClient is the client of the 'incidents' resource. 36 // 37 // Manages the collection of incidents. 38 type IncidentsClient struct { 39 transport http.RoundTripper 40 path string 41 } 42 43 // NewIncidentsClient creates a new client for the 'incidents' 44 // resource using the given transport to send the requests and receive the 45 // responses. 46 func NewIncidentsClient(transport http.RoundTripper, path string) *IncidentsClient { 47 return &IncidentsClient{ 48 transport: transport, 49 path: path, 50 } 51 } 52 53 // Add creates a request for the 'add' method. 54 func (c *IncidentsClient) Add() *IncidentsAddRequest { 55 return &IncidentsAddRequest{ 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 incidents. 64 func (c *IncidentsClient) List() *IncidentsListRequest { 65 return &IncidentsListRequest{ 66 transport: c.transport, 67 path: c.path, 68 } 69 } 70 71 // Incident returns the target 'incident' resource for the given identifier. 72 func (c *IncidentsClient) Incident(id string) *IncidentClient { 73 return NewIncidentClient( 74 c.transport, 75 path.Join(c.path, id), 76 ) 77 } 78 79 // IncidentsAddRequest is the request for the 'add' method. 80 type IncidentsAddRequest struct { 81 transport http.RoundTripper 82 path string 83 query url.Values 84 header http.Header 85 body *Incident 86 } 87 88 // Parameter adds a query parameter. 89 func (r *IncidentsAddRequest) Parameter(name string, value interface{}) *IncidentsAddRequest { 90 helpers.AddValue(&r.query, name, value) 91 return r 92 } 93 94 // Header adds a request header. 95 func (r *IncidentsAddRequest) Header(name string, value interface{}) *IncidentsAddRequest { 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 *IncidentsAddRequest) Impersonate(user string) *IncidentsAddRequest { 103 helpers.AddImpersonationHeader(&r.header, user) 104 return r 105 } 106 107 // Body sets the value of the 'body' parameter. 108 func (r *IncidentsAddRequest) Body(value *Incident) *IncidentsAddRequest { 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 *IncidentsAddRequest) Send() (result *IncidentsAddResponse, 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 *IncidentsAddRequest) SendContext(ctx context.Context) (result *IncidentsAddResponse, err error) { 123 query := helpers.CopyQuery(r.query) 124 header := helpers.CopyHeader(r.header) 125 buffer := &bytes.Buffer{} 126 err = writeIncidentsAddRequest(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 = &IncidentsAddResponse{} 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 = readIncidentsAddResponse(result, reader) 166 if err != nil { 167 return 168 } 169 return 170 } 171 172 // IncidentsAddResponse is the response for the 'add' method. 173 type IncidentsAddResponse struct { 174 status int 175 header http.Header 176 err *errors.Error 177 body *Incident 178 } 179 180 // Status returns the response status code. 181 func (r *IncidentsAddResponse) 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 *IncidentsAddResponse) 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 *IncidentsAddResponse) 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 *IncidentsAddResponse) Body() *Incident { 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 *IncidentsAddResponse) GetBody() (value *Incident, ok bool) { 215 ok = r != nil && r.body != nil 216 if ok { 217 value = r.body 218 } 219 return 220 } 221 222 // IncidentsListRequest is the request for the 'list' method. 223 type IncidentsListRequest struct { 224 transport http.RoundTripper 225 path string 226 query url.Values 227 header http.Header 228 creatorId *string 229 incidentCommanderId *string 230 incidentName *string 231 mine *bool 232 onCallId *string 233 orderBy *string 234 page *int 235 participantId *string 236 productId *string 237 publicId *string 238 responsibleManagerId *string 239 size *int 240 status_ *string 241 } 242 243 // Parameter adds a query parameter. 244 func (r *IncidentsListRequest) Parameter(name string, value interface{}) *IncidentsListRequest { 245 helpers.AddValue(&r.query, name, value) 246 return r 247 } 248 249 // Header adds a request header. 250 func (r *IncidentsListRequest) Header(name string, value interface{}) *IncidentsListRequest { 251 helpers.AddHeader(&r.header, name, value) 252 return r 253 } 254 255 // Impersonate wraps requests on behalf of another user. 256 // Note: Services that do not support this feature may silently ignore this call. 257 func (r *IncidentsListRequest) Impersonate(user string) *IncidentsListRequest { 258 helpers.AddImpersonationHeader(&r.header, user) 259 return r 260 } 261 262 // CreatorId sets the value of the 'creator_id' parameter. 263 func (r *IncidentsListRequest) CreatorId(value string) *IncidentsListRequest { 264 r.creatorId = &value 265 return r 266 } 267 268 // IncidentCommanderId sets the value of the 'incident_commander_id' parameter. 269 func (r *IncidentsListRequest) IncidentCommanderId(value string) *IncidentsListRequest { 270 r.incidentCommanderId = &value 271 return r 272 } 273 274 // IncidentName sets the value of the 'incident_name' parameter. 275 func (r *IncidentsListRequest) IncidentName(value string) *IncidentsListRequest { 276 r.incidentName = &value 277 return r 278 } 279 280 // Mine sets the value of the 'mine' parameter. 281 func (r *IncidentsListRequest) Mine(value bool) *IncidentsListRequest { 282 r.mine = &value 283 return r 284 } 285 286 // OnCallId sets the value of the 'on_call_id' parameter. 287 func (r *IncidentsListRequest) OnCallId(value string) *IncidentsListRequest { 288 r.onCallId = &value 289 return r 290 } 291 292 // OrderBy sets the value of the 'order_by' parameter. 293 func (r *IncidentsListRequest) OrderBy(value string) *IncidentsListRequest { 294 r.orderBy = &value 295 return r 296 } 297 298 // Page sets the value of the 'page' parameter. 299 func (r *IncidentsListRequest) Page(value int) *IncidentsListRequest { 300 r.page = &value 301 return r 302 } 303 304 // ParticipantId sets the value of the 'participant_id' parameter. 305 func (r *IncidentsListRequest) ParticipantId(value string) *IncidentsListRequest { 306 r.participantId = &value 307 return r 308 } 309 310 // ProductId sets the value of the 'product_id' parameter. 311 func (r *IncidentsListRequest) ProductId(value string) *IncidentsListRequest { 312 r.productId = &value 313 return r 314 } 315 316 // PublicId sets the value of the 'public_id' parameter. 317 func (r *IncidentsListRequest) PublicId(value string) *IncidentsListRequest { 318 r.publicId = &value 319 return r 320 } 321 322 // ResponsibleManagerId sets the value of the 'responsible_manager_id' parameter. 323 func (r *IncidentsListRequest) ResponsibleManagerId(value string) *IncidentsListRequest { 324 r.responsibleManagerId = &value 325 return r 326 } 327 328 // Size sets the value of the 'size' parameter. 329 func (r *IncidentsListRequest) Size(value int) *IncidentsListRequest { 330 r.size = &value 331 return r 332 } 333 334 // Status sets the value of the 'status' parameter. 335 func (r *IncidentsListRequest) Status(value string) *IncidentsListRequest { 336 r.status_ = &value 337 return r 338 } 339 340 // Send sends this request, waits for the response, and returns it. 341 // 342 // This is a potentially lengthy operation, as it requires network communication. 343 // Consider using a context and the SendContext method. 344 func (r *IncidentsListRequest) Send() (result *IncidentsListResponse, err error) { 345 return r.SendContext(context.Background()) 346 } 347 348 // SendContext sends this request, waits for the response, and returns it. 349 func (r *IncidentsListRequest) SendContext(ctx context.Context) (result *IncidentsListResponse, err error) { 350 query := helpers.CopyQuery(r.query) 351 if r.creatorId != nil { 352 helpers.AddValue(&query, "creator_id", *r.creatorId) 353 } 354 if r.incidentCommanderId != nil { 355 helpers.AddValue(&query, "incident_commander_id", *r.incidentCommanderId) 356 } 357 if r.incidentName != nil { 358 helpers.AddValue(&query, "incident_name", *r.incidentName) 359 } 360 if r.mine != nil { 361 helpers.AddValue(&query, "mine", *r.mine) 362 } 363 if r.onCallId != nil { 364 helpers.AddValue(&query, "on_call_id", *r.onCallId) 365 } 366 if r.orderBy != nil { 367 helpers.AddValue(&query, "order_by", *r.orderBy) 368 } 369 if r.page != nil { 370 helpers.AddValue(&query, "page", *r.page) 371 } 372 if r.participantId != nil { 373 helpers.AddValue(&query, "participant_id", *r.participantId) 374 } 375 if r.productId != nil { 376 helpers.AddValue(&query, "product_id", *r.productId) 377 } 378 if r.publicId != nil { 379 helpers.AddValue(&query, "public_id", *r.publicId) 380 } 381 if r.responsibleManagerId != nil { 382 helpers.AddValue(&query, "responsible_manager_id", *r.responsibleManagerId) 383 } 384 if r.size != nil { 385 helpers.AddValue(&query, "size", *r.size) 386 } 387 if r.status_ != nil { 388 helpers.AddValue(&query, "status", *r.status_) 389 } 390 header := helpers.CopyHeader(r.header) 391 uri := &url.URL{ 392 Path: r.path, 393 RawQuery: query.Encode(), 394 } 395 request := &http.Request{ 396 Method: "GET", 397 URL: uri, 398 Header: header, 399 } 400 if ctx != nil { 401 request = request.WithContext(ctx) 402 } 403 response, err := r.transport.RoundTrip(request) 404 if err != nil { 405 return 406 } 407 defer response.Body.Close() 408 result = &IncidentsListResponse{} 409 result.status = response.StatusCode 410 result.header = response.Header 411 reader := bufio.NewReader(response.Body) 412 _, err = reader.Peek(1) 413 if err == io.EOF { 414 err = nil 415 return 416 } 417 if result.status >= 400 { 418 result.err, err = errors.UnmarshalErrorStatus(reader, result.status) 419 if err != nil { 420 return 421 } 422 err = result.err 423 return 424 } 425 err = readIncidentsListResponse(result, reader) 426 if err != nil { 427 return 428 } 429 return 430 } 431 432 // IncidentsListResponse is the response for the 'list' method. 433 type IncidentsListResponse struct { 434 status int 435 header http.Header 436 err *errors.Error 437 items *IncidentList 438 page *int 439 size *int 440 total *int 441 } 442 443 // Status returns the response status code. 444 func (r *IncidentsListResponse) Status() int { 445 if r == nil { 446 return 0 447 } 448 return r.status 449 } 450 451 // Header returns header of the response. 452 func (r *IncidentsListResponse) Header() http.Header { 453 if r == nil { 454 return nil 455 } 456 return r.header 457 } 458 459 // Error returns the response error. 460 func (r *IncidentsListResponse) Error() *errors.Error { 461 if r == nil { 462 return nil 463 } 464 return r.err 465 } 466 467 // Items returns the value of the 'items' parameter. 468 func (r *IncidentsListResponse) Items() *IncidentList { 469 if r == nil { 470 return nil 471 } 472 return r.items 473 } 474 475 // GetItems returns the value of the 'items' parameter and 476 // a flag indicating if the parameter has a value. 477 func (r *IncidentsListResponse) GetItems() (value *IncidentList, ok bool) { 478 ok = r != nil && r.items != nil 479 if ok { 480 value = r.items 481 } 482 return 483 } 484 485 // Page returns the value of the 'page' parameter. 486 func (r *IncidentsListResponse) Page() int { 487 if r != nil && r.page != nil { 488 return *r.page 489 } 490 return 0 491 } 492 493 // GetPage returns the value of the 'page' parameter and 494 // a flag indicating if the parameter has a value. 495 func (r *IncidentsListResponse) GetPage() (value int, ok bool) { 496 ok = r != nil && r.page != nil 497 if ok { 498 value = *r.page 499 } 500 return 501 } 502 503 // Size returns the value of the 'size' parameter. 504 func (r *IncidentsListResponse) Size() int { 505 if r != nil && r.size != nil { 506 return *r.size 507 } 508 return 0 509 } 510 511 // GetSize returns the value of the 'size' parameter and 512 // a flag indicating if the parameter has a value. 513 func (r *IncidentsListResponse) GetSize() (value int, ok bool) { 514 ok = r != nil && r.size != nil 515 if ok { 516 value = *r.size 517 } 518 return 519 } 520 521 // Total returns the value of the 'total' parameter. 522 func (r *IncidentsListResponse) Total() int { 523 if r != nil && r.total != nil { 524 return *r.total 525 } 526 return 0 527 } 528 529 // GetTotal returns the value of the 'total' parameter and 530 // a flag indicating if the parameter has a value. 531 func (r *IncidentsListResponse) GetTotal() (value int, ok bool) { 532 ok = r != nil && r.total != nil 533 if ok { 534 value = *r.total 535 } 536 return 537 }