github.com/openshift-online/ocm-sdk-go@v0.1.473/clustersmgmt/v1/flavours_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 "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 // FlavoursClient is the client of the 'flavours' resource. 35 // 36 // Manages the collection of cluster flavours. 37 type FlavoursClient struct { 38 transport http.RoundTripper 39 path string 40 } 41 42 // NewFlavoursClient creates a new client for the 'flavours' 43 // resource using the given transport to send the requests and receive the 44 // responses. 45 func NewFlavoursClient(transport http.RoundTripper, path string) *FlavoursClient { 46 return &FlavoursClient{ 47 transport: transport, 48 path: path, 49 } 50 } 51 52 // List creates a request for the 'list' method. 53 func (c *FlavoursClient) List() *FlavoursListRequest { 54 return &FlavoursListRequest{ 55 transport: c.transport, 56 path: c.path, 57 } 58 } 59 60 // Flavour returns the target 'flavour' resource for the given identifier. 61 // 62 // Reference to the resource that manages a specific flavour. 63 func (c *FlavoursClient) Flavour(id string) *FlavourClient { 64 return NewFlavourClient( 65 c.transport, 66 path.Join(c.path, id), 67 ) 68 } 69 70 // FlavoursListRequest is the request for the 'list' method. 71 type FlavoursListRequest struct { 72 transport http.RoundTripper 73 path string 74 query url.Values 75 header http.Header 76 order *string 77 page *int 78 search *string 79 size *int 80 } 81 82 // Parameter adds a query parameter. 83 func (r *FlavoursListRequest) Parameter(name string, value interface{}) *FlavoursListRequest { 84 helpers.AddValue(&r.query, name, value) 85 return r 86 } 87 88 // Header adds a request header. 89 func (r *FlavoursListRequest) Header(name string, value interface{}) *FlavoursListRequest { 90 helpers.AddHeader(&r.header, name, value) 91 return r 92 } 93 94 // Impersonate wraps requests on behalf of another user. 95 // Note: Services that do not support this feature may silently ignore this call. 96 func (r *FlavoursListRequest) Impersonate(user string) *FlavoursListRequest { 97 helpers.AddImpersonationHeader(&r.header, user) 98 return r 99 } 100 101 // Order sets the value of the 'order' parameter. 102 // 103 // Order criteria. 104 // 105 // The syntax of this parameter is similar to the syntax of the _order by_ clause of 106 // a SQL statement, but using the names of the attributes of the flavour instead of 107 // the names of the columns of a table. For example, in order to sort the flavours 108 // descending by name the value should be: 109 // 110 // ```sql 111 // name desc 112 // ``` 113 // 114 // If the parameter isn't provided, or if the value is empty, then the order of the 115 // results is undefined. 116 func (r *FlavoursListRequest) Order(value string) *FlavoursListRequest { 117 r.order = &value 118 return r 119 } 120 121 // Page sets the value of the 'page' parameter. 122 // 123 // Index of the requested page, where one corresponds to the first page. 124 func (r *FlavoursListRequest) Page(value int) *FlavoursListRequest { 125 r.page = &value 126 return r 127 } 128 129 // Search sets the value of the 'search' parameter. 130 // 131 // Search criteria. 132 // 133 // The syntax of this parameter is similar to the syntax of the _where_ clause of an 134 // SQL statement, but using the names of the attributes of the flavour instead of 135 // the names of the columns of a table. For example, in order to retrieve all the 136 // flavours with a name starting with `my`the value should be: 137 // 138 // ```sql 139 // name like 'my%' 140 // ``` 141 // 142 // If the parameter isn't provided, or if the value is empty, then all the flavours 143 // that the user has permission to see will be returned. 144 func (r *FlavoursListRequest) Search(value string) *FlavoursListRequest { 145 r.search = &value 146 return r 147 } 148 149 // Size sets the value of the 'size' parameter. 150 // 151 // Maximum number of items that will be contained in the returned page. 152 func (r *FlavoursListRequest) Size(value int) *FlavoursListRequest { 153 r.size = &value 154 return r 155 } 156 157 // Send sends this request, waits for the response, and returns it. 158 // 159 // This is a potentially lengthy operation, as it requires network communication. 160 // Consider using a context and the SendContext method. 161 func (r *FlavoursListRequest) Send() (result *FlavoursListResponse, err error) { 162 return r.SendContext(context.Background()) 163 } 164 165 // SendContext sends this request, waits for the response, and returns it. 166 func (r *FlavoursListRequest) SendContext(ctx context.Context) (result *FlavoursListResponse, err error) { 167 query := helpers.CopyQuery(r.query) 168 if r.order != nil { 169 helpers.AddValue(&query, "order", *r.order) 170 } 171 if r.page != nil { 172 helpers.AddValue(&query, "page", *r.page) 173 } 174 if r.search != nil { 175 helpers.AddValue(&query, "search", *r.search) 176 } 177 if r.size != nil { 178 helpers.AddValue(&query, "size", *r.size) 179 } 180 header := helpers.CopyHeader(r.header) 181 uri := &url.URL{ 182 Path: r.path, 183 RawQuery: query.Encode(), 184 } 185 request := &http.Request{ 186 Method: "GET", 187 URL: uri, 188 Header: header, 189 } 190 if ctx != nil { 191 request = request.WithContext(ctx) 192 } 193 response, err := r.transport.RoundTrip(request) 194 if err != nil { 195 return 196 } 197 defer response.Body.Close() 198 result = &FlavoursListResponse{} 199 result.status = response.StatusCode 200 result.header = response.Header 201 reader := bufio.NewReader(response.Body) 202 _, err = reader.Peek(1) 203 if err == io.EOF { 204 err = nil 205 return 206 } 207 if result.status >= 400 { 208 result.err, err = errors.UnmarshalErrorStatus(reader, result.status) 209 if err != nil { 210 return 211 } 212 err = result.err 213 return 214 } 215 err = readFlavoursListResponse(result, reader) 216 if err != nil { 217 return 218 } 219 return 220 } 221 222 // FlavoursListResponse is the response for the 'list' method. 223 type FlavoursListResponse struct { 224 status int 225 header http.Header 226 err *errors.Error 227 items *FlavourList 228 page *int 229 size *int 230 total *int 231 } 232 233 // Status returns the response status code. 234 func (r *FlavoursListResponse) Status() int { 235 if r == nil { 236 return 0 237 } 238 return r.status 239 } 240 241 // Header returns header of the response. 242 func (r *FlavoursListResponse) Header() http.Header { 243 if r == nil { 244 return nil 245 } 246 return r.header 247 } 248 249 // Error returns the response error. 250 func (r *FlavoursListResponse) Error() *errors.Error { 251 if r == nil { 252 return nil 253 } 254 return r.err 255 } 256 257 // Items returns the value of the 'items' parameter. 258 // 259 // Retrieved list of flavours. 260 func (r *FlavoursListResponse) Items() *FlavourList { 261 if r == nil { 262 return nil 263 } 264 return r.items 265 } 266 267 // GetItems returns the value of the 'items' parameter and 268 // a flag indicating if the parameter has a value. 269 // 270 // Retrieved list of flavours. 271 func (r *FlavoursListResponse) GetItems() (value *FlavourList, ok bool) { 272 ok = r != nil && r.items != nil 273 if ok { 274 value = r.items 275 } 276 return 277 } 278 279 // Page returns the value of the 'page' parameter. 280 // 281 // Index of the requested page, where one corresponds to the first page. 282 func (r *FlavoursListResponse) Page() int { 283 if r != nil && r.page != nil { 284 return *r.page 285 } 286 return 0 287 } 288 289 // GetPage returns the value of the 'page' parameter and 290 // a flag indicating if the parameter has a value. 291 // 292 // Index of the requested page, where one corresponds to the first page. 293 func (r *FlavoursListResponse) GetPage() (value int, ok bool) { 294 ok = r != nil && r.page != nil 295 if ok { 296 value = *r.page 297 } 298 return 299 } 300 301 // Size returns the value of the 'size' parameter. 302 // 303 // Maximum number of items that will be contained in the returned page. 304 func (r *FlavoursListResponse) Size() int { 305 if r != nil && r.size != nil { 306 return *r.size 307 } 308 return 0 309 } 310 311 // GetSize returns the value of the 'size' parameter and 312 // a flag indicating if the parameter has a value. 313 // 314 // Maximum number of items that will be contained in the returned page. 315 func (r *FlavoursListResponse) GetSize() (value int, ok bool) { 316 ok = r != nil && r.size != nil 317 if ok { 318 value = *r.size 319 } 320 return 321 } 322 323 // Total returns the value of the 'total' parameter. 324 // 325 // Total number of items of the collection that match the search criteria, 326 // regardless of the size of the page. 327 func (r *FlavoursListResponse) Total() int { 328 if r != nil && r.total != nil { 329 return *r.total 330 } 331 return 0 332 } 333 334 // GetTotal returns the value of the 'total' parameter and 335 // a flag indicating if the parameter has a value. 336 // 337 // Total number of items of the collection that match the search criteria, 338 // regardless of the size of the page. 339 func (r *FlavoursListResponse) GetTotal() (value int, ok bool) { 340 ok = r != nil && r.total != nil 341 if ok { 342 value = *r.total 343 } 344 return 345 }