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