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