github.com/openshift-online/ocm-sdk-go@v0.1.473/clustersmgmt/v1/available_regions_inquiry_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 "bytes" 25 "context" 26 "io" 27 "net/http" 28 "net/url" 29 30 "github.com/openshift-online/ocm-sdk-go/errors" 31 "github.com/openshift-online/ocm-sdk-go/helpers" 32 ) 33 34 // AvailableRegionsInquiryClient is the client of the 'available_regions_inquiry' resource. 35 // 36 // Manages a specific available regions inquiry. 37 type AvailableRegionsInquiryClient struct { 38 transport http.RoundTripper 39 path string 40 } 41 42 // NewAvailableRegionsInquiryClient creates a new client for the 'available_regions_inquiry' 43 // resource using the given transport to send the requests and receive the 44 // responses. 45 func NewAvailableRegionsInquiryClient(transport http.RoundTripper, path string) *AvailableRegionsInquiryClient { 46 return &AvailableRegionsInquiryClient{ 47 transport: transport, 48 path: path, 49 } 50 } 51 52 // Search creates a request for the 'search' method. 53 // 54 // Retrieves the list of available regions of the cloud provider. 55 // IMPORTANT: This list doesn't currently support paging or searching, so the returned 56 // `page` will always be 1 and `size` and `total` will always be the total number of available regions 57 // of the provider. 58 func (c *AvailableRegionsInquiryClient) Search() *AvailableRegionsInquirySearchRequest { 59 return &AvailableRegionsInquirySearchRequest{ 60 transport: c.transport, 61 path: c.path, 62 } 63 } 64 65 // AvailableRegionsInquirySearchRequest is the request for the 'search' method. 66 type AvailableRegionsInquirySearchRequest struct { 67 transport http.RoundTripper 68 path string 69 query url.Values 70 header http.Header 71 body *CloudProviderData 72 page *int 73 size *int 74 } 75 76 // Parameter adds a query parameter. 77 func (r *AvailableRegionsInquirySearchRequest) Parameter(name string, value interface{}) *AvailableRegionsInquirySearchRequest { 78 helpers.AddValue(&r.query, name, value) 79 return r 80 } 81 82 // Header adds a request header. 83 func (r *AvailableRegionsInquirySearchRequest) Header(name string, value interface{}) *AvailableRegionsInquirySearchRequest { 84 helpers.AddHeader(&r.header, name, value) 85 return r 86 } 87 88 // Impersonate wraps requests on behalf of another user. 89 // Note: Services that do not support this feature may silently ignore this call. 90 func (r *AvailableRegionsInquirySearchRequest) Impersonate(user string) *AvailableRegionsInquirySearchRequest { 91 helpers.AddImpersonationHeader(&r.header, user) 92 return r 93 } 94 95 // Body sets the value of the 'body' parameter. 96 // 97 // Cloud provider data needed for the inquiry 98 func (r *AvailableRegionsInquirySearchRequest) Body(value *CloudProviderData) *AvailableRegionsInquirySearchRequest { 99 r.body = value 100 return r 101 } 102 103 // Page sets the value of the 'page' parameter. 104 // 105 // Index of the returned page, where one corresponds to the first page. As this 106 // collection doesn't support paging the result will always be `1`. 107 func (r *AvailableRegionsInquirySearchRequest) Page(value int) *AvailableRegionsInquirySearchRequest { 108 r.page = &value 109 return r 110 } 111 112 // Size sets the value of the 'size' parameter. 113 // 114 // Number of items that will be contained in the returned page. As this collection 115 // doesn't support paging or searching the result will always be the total number of 116 // regions of the provider. 117 func (r *AvailableRegionsInquirySearchRequest) Size(value int) *AvailableRegionsInquirySearchRequest { 118 r.size = &value 119 return r 120 } 121 122 // Send sends this request, waits for the response, and returns it. 123 // 124 // This is a potentially lengthy operation, as it requires network communication. 125 // Consider using a context and the SendContext method. 126 func (r *AvailableRegionsInquirySearchRequest) Send() (result *AvailableRegionsInquirySearchResponse, err error) { 127 return r.SendContext(context.Background()) 128 } 129 130 // SendContext sends this request, waits for the response, and returns it. 131 func (r *AvailableRegionsInquirySearchRequest) SendContext(ctx context.Context) (result *AvailableRegionsInquirySearchResponse, err error) { 132 query := helpers.CopyQuery(r.query) 133 if r.page != nil { 134 helpers.AddValue(&query, "page", *r.page) 135 } 136 if r.size != nil { 137 helpers.AddValue(&query, "size", *r.size) 138 } 139 header := helpers.CopyHeader(r.header) 140 buffer := &bytes.Buffer{} 141 err = writeAvailableRegionsInquirySearchRequest(r, buffer) 142 if err != nil { 143 return 144 } 145 uri := &url.URL{ 146 Path: r.path, 147 RawQuery: query.Encode(), 148 } 149 request := &http.Request{ 150 Method: "POST", 151 URL: uri, 152 Header: header, 153 Body: io.NopCloser(buffer), 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 = &AvailableRegionsInquirySearchResponse{} 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 = readAvailableRegionsInquirySearchResponse(result, reader) 181 if err != nil { 182 return 183 } 184 return 185 } 186 187 // AvailableRegionsInquirySearchResponse is the response for the 'search' method. 188 type AvailableRegionsInquirySearchResponse struct { 189 status int 190 header http.Header 191 err *errors.Error 192 items *CloudRegionList 193 page *int 194 size *int 195 total *int 196 } 197 198 // Status returns the response status code. 199 func (r *AvailableRegionsInquirySearchResponse) 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 *AvailableRegionsInquirySearchResponse) 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 *AvailableRegionsInquirySearchResponse) 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 regions. 225 func (r *AvailableRegionsInquirySearchResponse) Items() *CloudRegionList { 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 regions. 236 func (r *AvailableRegionsInquirySearchResponse) GetItems() (value *CloudRegionList, 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 returned page, where one corresponds to the first page. As this 247 // collection doesn't support paging the result will always be `1`. 248 func (r *AvailableRegionsInquirySearchResponse) Page() int { 249 if r != nil && r.page != nil { 250 return *r.page 251 } 252 return 0 253 } 254 255 // GetPage returns the value of the 'page' parameter and 256 // a flag indicating if the parameter has a value. 257 // 258 // Index of the returned page, where one corresponds to the first page. As this 259 // collection doesn't support paging the result will always be `1`. 260 func (r *AvailableRegionsInquirySearchResponse) 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 // Number of items that will be contained in the returned page. As this collection 271 // doesn't support paging or searching the result will always be the total number of 272 // regions of the provider. 273 func (r *AvailableRegionsInquirySearchResponse) Size() int { 274 if r != nil && r.size != nil { 275 return *r.size 276 } 277 return 0 278 } 279 280 // GetSize returns the value of the 'size' parameter and 281 // a flag indicating if the parameter has a value. 282 // 283 // Number of items that will be contained in the returned page. As this collection 284 // doesn't support paging or searching the result will always be the total number of 285 // regions of the provider. 286 func (r *AvailableRegionsInquirySearchResponse) GetSize() (value int, ok bool) { 287 ok = r != nil && r.size != nil 288 if ok { 289 value = *r.size 290 } 291 return 292 } 293 294 // Total returns the value of the 'total' parameter. 295 // 296 // Total number of items of the collection that match the search criteria, 297 // regardless of the size of the page. As this collection doesn't support paging or 298 // searching the result will always be the total number of available regions of the provider. 299 func (r *AvailableRegionsInquirySearchResponse) Total() int { 300 if r != nil && r.total != nil { 301 return *r.total 302 } 303 return 0 304 } 305 306 // GetTotal returns the value of the 'total' parameter and 307 // a flag indicating if the parameter has a value. 308 // 309 // Total number of items of the collection that match the search criteria, 310 // regardless of the size of the page. As this collection doesn't support paging or 311 // searching the result will always be the total number of available regions of the provider. 312 func (r *AvailableRegionsInquirySearchResponse) GetTotal() (value int, ok bool) { 313 ok = r != nil && r.total != nil 314 if ok { 315 value = *r.total 316 } 317 return 318 }