github.com/openshift-online/ocm-sdk-go@v0.1.473/webrca/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/webrca/v1 21 22 import ( 23 "bufio" 24 "context" 25 "io" 26 "net/http" 27 "net/url" 28 "path" 29 time "time" 30 31 "github.com/openshift-online/ocm-sdk-go/errors" 32 "github.com/openshift-online/ocm-sdk-go/helpers" 33 ) 34 35 // EventsClient is the client of the 'events' resource. 36 // 37 // Manages the collection of events. 38 type EventsClient struct { 39 transport http.RoundTripper 40 path string 41 } 42 43 // NewEventsClient creates a new client for the 'events' 44 // resource using the given transport to send the requests and receive the 45 // responses. 46 func NewEventsClient(transport http.RoundTripper, path string) *EventsClient { 47 return &EventsClient{ 48 transport: transport, 49 path: path, 50 } 51 } 52 53 // List creates a request for the 'list' method. 54 // 55 // Retrieves the list of events 56 func (c *EventsClient) List() *EventsListRequest { 57 return &EventsListRequest{ 58 transport: c.transport, 59 path: c.path, 60 } 61 } 62 63 // Event returns the target 'event' resource for the given identifier. 64 func (c *EventsClient) Event(id string) *EventClient { 65 return NewEventClient( 66 c.transport, 67 path.Join(c.path, id), 68 ) 69 } 70 71 // EventsListRequest is the request for the 'list' method. 72 type EventsListRequest struct { 73 transport http.RoundTripper 74 path string 75 query url.Values 76 header http.Header 77 createdAfter *time.Time 78 createdBefore *time.Time 79 eventType *string 80 note *string 81 orderBy *string 82 page *int 83 showSystemEvents *bool 84 size *int 85 } 86 87 // Parameter adds a query parameter. 88 func (r *EventsListRequest) Parameter(name string, value interface{}) *EventsListRequest { 89 helpers.AddValue(&r.query, name, value) 90 return r 91 } 92 93 // Header adds a request header. 94 func (r *EventsListRequest) Header(name string, value interface{}) *EventsListRequest { 95 helpers.AddHeader(&r.header, name, value) 96 return r 97 } 98 99 // Impersonate wraps requests on behalf of another user. 100 // Note: Services that do not support this feature may silently ignore this call. 101 func (r *EventsListRequest) Impersonate(user string) *EventsListRequest { 102 helpers.AddImpersonationHeader(&r.header, user) 103 return r 104 } 105 106 // CreatedAfter sets the value of the 'created_after' parameter. 107 func (r *EventsListRequest) CreatedAfter(value time.Time) *EventsListRequest { 108 r.createdAfter = &value 109 return r 110 } 111 112 // CreatedBefore sets the value of the 'created_before' parameter. 113 func (r *EventsListRequest) CreatedBefore(value time.Time) *EventsListRequest { 114 r.createdBefore = &value 115 return r 116 } 117 118 // EventType sets the value of the 'event_type' parameter. 119 func (r *EventsListRequest) EventType(value string) *EventsListRequest { 120 r.eventType = &value 121 return r 122 } 123 124 // Note sets the value of the 'note' parameter. 125 func (r *EventsListRequest) Note(value string) *EventsListRequest { 126 r.note = &value 127 return r 128 } 129 130 // OrderBy sets the value of the 'order_by' parameter. 131 func (r *EventsListRequest) OrderBy(value string) *EventsListRequest { 132 r.orderBy = &value 133 return r 134 } 135 136 // Page sets the value of the 'page' parameter. 137 func (r *EventsListRequest) Page(value int) *EventsListRequest { 138 r.page = &value 139 return r 140 } 141 142 // ShowSystemEvents sets the value of the 'show_system_events' parameter. 143 func (r *EventsListRequest) ShowSystemEvents(value bool) *EventsListRequest { 144 r.showSystemEvents = &value 145 return r 146 } 147 148 // Size sets the value of the 'size' parameter. 149 func (r *EventsListRequest) Size(value int) *EventsListRequest { 150 r.size = &value 151 return r 152 } 153 154 // Send sends this request, waits for the response, and returns it. 155 // 156 // This is a potentially lengthy operation, as it requires network communication. 157 // Consider using a context and the SendContext method. 158 func (r *EventsListRequest) Send() (result *EventsListResponse, err error) { 159 return r.SendContext(context.Background()) 160 } 161 162 // SendContext sends this request, waits for the response, and returns it. 163 func (r *EventsListRequest) SendContext(ctx context.Context) (result *EventsListResponse, err error) { 164 query := helpers.CopyQuery(r.query) 165 if r.createdAfter != nil { 166 helpers.AddValue(&query, "created_after", *r.createdAfter) 167 } 168 if r.createdBefore != nil { 169 helpers.AddValue(&query, "created_before", *r.createdBefore) 170 } 171 if r.eventType != nil { 172 helpers.AddValue(&query, "event_type", *r.eventType) 173 } 174 if r.note != nil { 175 helpers.AddValue(&query, "note", *r.note) 176 } 177 if r.orderBy != nil { 178 helpers.AddValue(&query, "order_by", *r.orderBy) 179 } 180 if r.page != nil { 181 helpers.AddValue(&query, "page", *r.page) 182 } 183 if r.showSystemEvents != nil { 184 helpers.AddValue(&query, "show_system_events", *r.showSystemEvents) 185 } 186 if r.size != nil { 187 helpers.AddValue(&query, "size", *r.size) 188 } 189 header := helpers.CopyHeader(r.header) 190 uri := &url.URL{ 191 Path: r.path, 192 RawQuery: query.Encode(), 193 } 194 request := &http.Request{ 195 Method: "GET", 196 URL: uri, 197 Header: header, 198 } 199 if ctx != nil { 200 request = request.WithContext(ctx) 201 } 202 response, err := r.transport.RoundTrip(request) 203 if err != nil { 204 return 205 } 206 defer response.Body.Close() 207 result = &EventsListResponse{} 208 result.status = response.StatusCode 209 result.header = response.Header 210 reader := bufio.NewReader(response.Body) 211 _, err = reader.Peek(1) 212 if err == io.EOF { 213 err = nil 214 return 215 } 216 if result.status >= 400 { 217 result.err, err = errors.UnmarshalErrorStatus(reader, result.status) 218 if err != nil { 219 return 220 } 221 err = result.err 222 return 223 } 224 err = readEventsListResponse(result, reader) 225 if err != nil { 226 return 227 } 228 return 229 } 230 231 // EventsListResponse is the response for the 'list' method. 232 type EventsListResponse struct { 233 status int 234 header http.Header 235 err *errors.Error 236 items *EventList 237 page *int 238 size *int 239 total *int 240 } 241 242 // Status returns the response status code. 243 func (r *EventsListResponse) Status() int { 244 if r == nil { 245 return 0 246 } 247 return r.status 248 } 249 250 // Header returns header of the response. 251 func (r *EventsListResponse) Header() http.Header { 252 if r == nil { 253 return nil 254 } 255 return r.header 256 } 257 258 // Error returns the response error. 259 func (r *EventsListResponse) Error() *errors.Error { 260 if r == nil { 261 return nil 262 } 263 return r.err 264 } 265 266 // Items returns the value of the 'items' parameter. 267 func (r *EventsListResponse) Items() *EventList { 268 if r == nil { 269 return nil 270 } 271 return r.items 272 } 273 274 // GetItems returns the value of the 'items' parameter and 275 // a flag indicating if the parameter has a value. 276 func (r *EventsListResponse) GetItems() (value *EventList, ok bool) { 277 ok = r != nil && r.items != nil 278 if ok { 279 value = r.items 280 } 281 return 282 } 283 284 // Page returns the value of the 'page' parameter. 285 func (r *EventsListResponse) Page() int { 286 if r != nil && r.page != nil { 287 return *r.page 288 } 289 return 0 290 } 291 292 // GetPage returns the value of the 'page' parameter and 293 // a flag indicating if the parameter has a value. 294 func (r *EventsListResponse) GetPage() (value int, ok bool) { 295 ok = r != nil && r.page != nil 296 if ok { 297 value = *r.page 298 } 299 return 300 } 301 302 // Size returns the value of the 'size' parameter. 303 func (r *EventsListResponse) Size() int { 304 if r != nil && r.size != nil { 305 return *r.size 306 } 307 return 0 308 } 309 310 // GetSize returns the value of the 'size' parameter and 311 // a flag indicating if the parameter has a value. 312 func (r *EventsListResponse) GetSize() (value int, ok bool) { 313 ok = r != nil && r.size != nil 314 if ok { 315 value = *r.size 316 } 317 return 318 } 319 320 // Total returns the value of the 'total' parameter. 321 func (r *EventsListResponse) Total() int { 322 if r != nil && r.total != nil { 323 return *r.total 324 } 325 return 0 326 } 327 328 // GetTotal returns the value of the 'total' parameter and 329 // a flag indicating if the parameter has a value. 330 func (r *EventsListResponse) GetTotal() (value int, ok bool) { 331 ok = r != nil && r.total != nil 332 if ok { 333 value = *r.total 334 } 335 return 336 }