github.com/openshift-online/ocm-sdk-go@v0.1.473/accountsmgmt/v1/support_cases_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 "bytes" 25 "context" 26 "io" 27 "net/http" 28 "net/url" 29 "path" 30 31 "github.com/openshift-online/ocm-sdk-go/errors" 32 "github.com/openshift-online/ocm-sdk-go/helpers" 33 ) 34 35 // SupportCasesClient is the client of the 'support_cases' resource. 36 // 37 // Manages the support cases endpoint 38 type SupportCasesClient struct { 39 transport http.RoundTripper 40 path string 41 } 42 43 // NewSupportCasesClient creates a new client for the 'support_cases' 44 // resource using the given transport to send the requests and receive the 45 // responses. 46 func NewSupportCasesClient(transport http.RoundTripper, path string) *SupportCasesClient { 47 return &SupportCasesClient{ 48 transport: transport, 49 path: path, 50 } 51 } 52 53 // Post creates a request for the 'post' method. 54 // 55 // Create a support case related to Hydra 56 func (c *SupportCasesClient) Post() *SupportCasesPostRequest { 57 return &SupportCasesPostRequest{ 58 transport: c.transport, 59 path: c.path, 60 } 61 } 62 63 // SupportCase returns the target 'support_case' resource for the given identifier. 64 // 65 // Reference to the service that manages a specific support case. 66 func (c *SupportCasesClient) SupportCase(id string) *SupportCaseClient { 67 return NewSupportCaseClient( 68 c.transport, 69 path.Join(c.path, id), 70 ) 71 } 72 73 // SupportCasesPostRequest is the request for the 'post' method. 74 type SupportCasesPostRequest struct { 75 transport http.RoundTripper 76 path string 77 query url.Values 78 header http.Header 79 request *SupportCaseRequest 80 } 81 82 // Parameter adds a query parameter. 83 func (r *SupportCasesPostRequest) Parameter(name string, value interface{}) *SupportCasesPostRequest { 84 helpers.AddValue(&r.query, name, value) 85 return r 86 } 87 88 // Header adds a request header. 89 func (r *SupportCasesPostRequest) Header(name string, value interface{}) *SupportCasesPostRequest { 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 *SupportCasesPostRequest) Impersonate(user string) *SupportCasesPostRequest { 97 helpers.AddImpersonationHeader(&r.header, user) 98 return r 99 } 100 101 // Request sets the value of the 'request' parameter. 102 func (r *SupportCasesPostRequest) Request(value *SupportCaseRequest) *SupportCasesPostRequest { 103 r.request = value 104 return r 105 } 106 107 // Send sends this request, waits for the response, and returns it. 108 // 109 // This is a potentially lengthy operation, as it requires network communication. 110 // Consider using a context and the SendContext method. 111 func (r *SupportCasesPostRequest) Send() (result *SupportCasesPostResponse, err error) { 112 return r.SendContext(context.Background()) 113 } 114 115 // SendContext sends this request, waits for the response, and returns it. 116 func (r *SupportCasesPostRequest) SendContext(ctx context.Context) (result *SupportCasesPostResponse, err error) { 117 query := helpers.CopyQuery(r.query) 118 header := helpers.CopyHeader(r.header) 119 buffer := &bytes.Buffer{} 120 err = writeSupportCasesPostRequest(r, buffer) 121 if err != nil { 122 return 123 } 124 uri := &url.URL{ 125 Path: r.path, 126 RawQuery: query.Encode(), 127 } 128 request := &http.Request{ 129 Method: "POST", 130 URL: uri, 131 Header: header, 132 Body: io.NopCloser(buffer), 133 } 134 if ctx != nil { 135 request = request.WithContext(ctx) 136 } 137 response, err := r.transport.RoundTrip(request) 138 if err != nil { 139 return 140 } 141 defer response.Body.Close() 142 result = &SupportCasesPostResponse{} 143 result.status = response.StatusCode 144 result.header = response.Header 145 reader := bufio.NewReader(response.Body) 146 _, err = reader.Peek(1) 147 if err == io.EOF { 148 err = nil 149 return 150 } 151 if result.status >= 400 { 152 result.err, err = errors.UnmarshalErrorStatus(reader, result.status) 153 if err != nil { 154 return 155 } 156 err = result.err 157 return 158 } 159 err = readSupportCasesPostResponse(result, reader) 160 if err != nil { 161 return 162 } 163 return 164 } 165 166 // SupportCasesPostResponse is the response for the 'post' method. 167 type SupportCasesPostResponse struct { 168 status int 169 header http.Header 170 err *errors.Error 171 response *SupportCaseResponse 172 } 173 174 // Status returns the response status code. 175 func (r *SupportCasesPostResponse) Status() int { 176 if r == nil { 177 return 0 178 } 179 return r.status 180 } 181 182 // Header returns header of the response. 183 func (r *SupportCasesPostResponse) Header() http.Header { 184 if r == nil { 185 return nil 186 } 187 return r.header 188 } 189 190 // Error returns the response error. 191 func (r *SupportCasesPostResponse) Error() *errors.Error { 192 if r == nil { 193 return nil 194 } 195 return r.err 196 } 197 198 // Response returns the value of the 'response' parameter. 199 func (r *SupportCasesPostResponse) Response() *SupportCaseResponse { 200 if r == nil { 201 return nil 202 } 203 return r.response 204 } 205 206 // GetResponse returns the value of the 'response' parameter and 207 // a flag indicating if the parameter has a value. 208 func (r *SupportCasesPostResponse) GetResponse() (value *SupportCaseResponse, ok bool) { 209 ok = r != nil && r.response != nil 210 if ok { 211 value = r.response 212 } 213 return 214 }