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