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