github.com/openshift-online/ocm-sdk-go@v0.1.473/clustersmgmt/v1/events_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/clustersmgmt/v1 21 22 import ( 23 "bufio" 24 "bytes" 25 "context" 26 "io" 27 "net/http" 28 "net/url" 29 30 "github.com/openshift-online/ocm-sdk-go/errors" 31 "github.com/openshift-online/ocm-sdk-go/helpers" 32 ) 33 34 // EventsClient is the client of the 'events' resource. 35 // 36 // Manages a collection used to track events reported by external clients. 37 type EventsClient struct { 38 transport http.RoundTripper 39 path string 40 } 41 42 // NewEventsClient creates a new client for the 'events' 43 // resource using the given transport to send the requests and receive the 44 // responses. 45 func NewEventsClient(transport http.RoundTripper, path string) *EventsClient { 46 return &EventsClient{ 47 transport: transport, 48 path: path, 49 } 50 } 51 52 // Add creates a request for the 'add' method. 53 // 54 // Adds a new event to be tracked. When sending a new event request, 55 // it gets tracked in Prometheus, Pendo, CloudWatch, or whichever 56 // analytics client is configured as part of clusters service. This 57 // allows for reporting on events that happen outside of a regular API 58 // request, but are found to be useful for understanding customer 59 // needs and possible blockers. 60 func (c *EventsClient) Add() *EventsAddRequest { 61 return &EventsAddRequest{ 62 transport: c.transport, 63 path: c.path, 64 } 65 } 66 67 // EventsAddRequest is the request for the 'add' method. 68 type EventsAddRequest struct { 69 transport http.RoundTripper 70 path string 71 query url.Values 72 header http.Header 73 body *Event 74 } 75 76 // Parameter adds a query parameter. 77 func (r *EventsAddRequest) Parameter(name string, value interface{}) *EventsAddRequest { 78 helpers.AddValue(&r.query, name, value) 79 return r 80 } 81 82 // Header adds a request header. 83 func (r *EventsAddRequest) Header(name string, value interface{}) *EventsAddRequest { 84 helpers.AddHeader(&r.header, name, value) 85 return r 86 } 87 88 // Impersonate wraps requests on behalf of another user. 89 // Note: Services that do not support this feature may silently ignore this call. 90 func (r *EventsAddRequest) Impersonate(user string) *EventsAddRequest { 91 helpers.AddImpersonationHeader(&r.header, user) 92 return r 93 } 94 95 // Body sets the value of the 'body' parameter. 96 // 97 // Description of the event. 98 func (r *EventsAddRequest) Body(value *Event) *EventsAddRequest { 99 r.body = value 100 return r 101 } 102 103 // Send sends this request, waits for the response, and returns it. 104 // 105 // This is a potentially lengthy operation, as it requires network communication. 106 // Consider using a context and the SendContext method. 107 func (r *EventsAddRequest) Send() (result *EventsAddResponse, err error) { 108 return r.SendContext(context.Background()) 109 } 110 111 // SendContext sends this request, waits for the response, and returns it. 112 func (r *EventsAddRequest) SendContext(ctx context.Context) (result *EventsAddResponse, err error) { 113 query := helpers.CopyQuery(r.query) 114 header := helpers.CopyHeader(r.header) 115 buffer := &bytes.Buffer{} 116 err = writeEventsAddRequest(r, buffer) 117 if err != nil { 118 return 119 } 120 uri := &url.URL{ 121 Path: r.path, 122 RawQuery: query.Encode(), 123 } 124 request := &http.Request{ 125 Method: "POST", 126 URL: uri, 127 Header: header, 128 Body: io.NopCloser(buffer), 129 } 130 if ctx != nil { 131 request = request.WithContext(ctx) 132 } 133 response, err := r.transport.RoundTrip(request) 134 if err != nil { 135 return 136 } 137 defer response.Body.Close() 138 result = &EventsAddResponse{} 139 result.status = response.StatusCode 140 result.header = response.Header 141 reader := bufio.NewReader(response.Body) 142 _, err = reader.Peek(1) 143 if err == io.EOF { 144 err = nil 145 return 146 } 147 if result.status >= 400 { 148 result.err, err = errors.UnmarshalErrorStatus(reader, result.status) 149 if err != nil { 150 return 151 } 152 err = result.err 153 return 154 } 155 err = readEventsAddResponse(result, reader) 156 if err != nil { 157 return 158 } 159 return 160 } 161 162 // EventsAddResponse is the response for the 'add' method. 163 type EventsAddResponse struct { 164 status int 165 header http.Header 166 err *errors.Error 167 body *Event 168 } 169 170 // Status returns the response status code. 171 func (r *EventsAddResponse) Status() int { 172 if r == nil { 173 return 0 174 } 175 return r.status 176 } 177 178 // Header returns header of the response. 179 func (r *EventsAddResponse) Header() http.Header { 180 if r == nil { 181 return nil 182 } 183 return r.header 184 } 185 186 // Error returns the response error. 187 func (r *EventsAddResponse) Error() *errors.Error { 188 if r == nil { 189 return nil 190 } 191 return r.err 192 } 193 194 // Body returns the value of the 'body' parameter. 195 // 196 // Description of the event. 197 func (r *EventsAddResponse) Body() *Event { 198 if r == nil { 199 return nil 200 } 201 return r.body 202 } 203 204 // GetBody returns the value of the 'body' parameter and 205 // a flag indicating if the parameter has a value. 206 // 207 // Description of the event. 208 func (r *EventsAddResponse) GetBody() (value *Event, ok bool) { 209 ok = r != nil && r.body != nil 210 if ok { 211 value = r.body 212 } 213 return 214 }