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