github.com/twilio/twilio-go@v1.20.1/rest/flex/v1/insights_quality_management_questions.go (about) 1 /* 2 * This code was generated by 3 * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ 4 * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ 5 * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ 6 * 7 * Twilio - Flex 8 * This is the public Twilio REST API. 9 * 10 * NOTE: This class is auto generated by OpenAPI Generator. 11 * https://openapi-generator.tech 12 * Do not edit the class manually. 13 */ 14 15 package openapi 16 17 import ( 18 "encoding/json" 19 "fmt" 20 "net/url" 21 "strings" 22 23 "github.com/twilio/twilio-go/client" 24 ) 25 26 // Optional parameters for the method 'CreateInsightsQuestionnairesQuestion' 27 type CreateInsightsQuestionnairesQuestionParams struct { 28 // The Authorization HTTP request header 29 Authorization *string `json:"Authorization,omitempty"` 30 // The SID of the category 31 CategorySid *string `json:"CategorySid,omitempty"` 32 // The question. 33 Question *string `json:"Question,omitempty"` 34 // The answer_set for the question. 35 AnswerSetId *string `json:"AnswerSetId,omitempty"` 36 // The flag to enable for disable NA for answer. 37 AllowNa *bool `json:"AllowNa,omitempty"` 38 // The description for the question. 39 Description *string `json:"Description,omitempty"` 40 } 41 42 func (params *CreateInsightsQuestionnairesQuestionParams) SetAuthorization(Authorization string) *CreateInsightsQuestionnairesQuestionParams { 43 params.Authorization = &Authorization 44 return params 45 } 46 func (params *CreateInsightsQuestionnairesQuestionParams) SetCategorySid(CategorySid string) *CreateInsightsQuestionnairesQuestionParams { 47 params.CategorySid = &CategorySid 48 return params 49 } 50 func (params *CreateInsightsQuestionnairesQuestionParams) SetQuestion(Question string) *CreateInsightsQuestionnairesQuestionParams { 51 params.Question = &Question 52 return params 53 } 54 func (params *CreateInsightsQuestionnairesQuestionParams) SetAnswerSetId(AnswerSetId string) *CreateInsightsQuestionnairesQuestionParams { 55 params.AnswerSetId = &AnswerSetId 56 return params 57 } 58 func (params *CreateInsightsQuestionnairesQuestionParams) SetAllowNa(AllowNa bool) *CreateInsightsQuestionnairesQuestionParams { 59 params.AllowNa = &AllowNa 60 return params 61 } 62 func (params *CreateInsightsQuestionnairesQuestionParams) SetDescription(Description string) *CreateInsightsQuestionnairesQuestionParams { 63 params.Description = &Description 64 return params 65 } 66 67 // To create a question for a Category 68 func (c *ApiService) CreateInsightsQuestionnairesQuestion(params *CreateInsightsQuestionnairesQuestionParams) (*FlexV1InsightsQuestionnairesQuestion, error) { 69 path := "/v1/Insights/QualityManagement/Questions" 70 71 data := url.Values{} 72 headers := make(map[string]interface{}) 73 74 if params != nil && params.CategorySid != nil { 75 data.Set("CategorySid", *params.CategorySid) 76 } 77 if params != nil && params.Question != nil { 78 data.Set("Question", *params.Question) 79 } 80 if params != nil && params.AnswerSetId != nil { 81 data.Set("AnswerSetId", *params.AnswerSetId) 82 } 83 if params != nil && params.AllowNa != nil { 84 data.Set("AllowNa", fmt.Sprint(*params.AllowNa)) 85 } 86 if params != nil && params.Description != nil { 87 data.Set("Description", *params.Description) 88 } 89 90 if params != nil && params.Authorization != nil { 91 headers["Authorization"] = *params.Authorization 92 } 93 resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) 94 if err != nil { 95 return nil, err 96 } 97 98 defer resp.Body.Close() 99 100 ps := &FlexV1InsightsQuestionnairesQuestion{} 101 if err := json.NewDecoder(resp.Body).Decode(ps); err != nil { 102 return nil, err 103 } 104 105 return ps, err 106 } 107 108 // Optional parameters for the method 'DeleteInsightsQuestionnairesQuestion' 109 type DeleteInsightsQuestionnairesQuestionParams struct { 110 // The Authorization HTTP request header 111 Authorization *string `json:"Authorization,omitempty"` 112 } 113 114 func (params *DeleteInsightsQuestionnairesQuestionParams) SetAuthorization(Authorization string) *DeleteInsightsQuestionnairesQuestionParams { 115 params.Authorization = &Authorization 116 return params 117 } 118 119 // 120 func (c *ApiService) DeleteInsightsQuestionnairesQuestion(QuestionSid string, params *DeleteInsightsQuestionnairesQuestionParams) error { 121 path := "/v1/Insights/QualityManagement/Questions/{QuestionSid}" 122 path = strings.Replace(path, "{"+"QuestionSid"+"}", QuestionSid, -1) 123 124 data := url.Values{} 125 headers := make(map[string]interface{}) 126 127 if params != nil && params.Authorization != nil { 128 headers["Authorization"] = *params.Authorization 129 } 130 resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) 131 if err != nil { 132 return err 133 } 134 135 defer resp.Body.Close() 136 137 return nil 138 } 139 140 // Optional parameters for the method 'ListInsightsQuestionnairesQuestion' 141 type ListInsightsQuestionnairesQuestionParams struct { 142 // The Authorization HTTP request header 143 Authorization *string `json:"Authorization,omitempty"` 144 // The list of category SIDs 145 CategorySid *[]string `json:"CategorySid,omitempty"` 146 // How many resources to return in each list page. The default is 50, and the maximum is 1000. 147 PageSize *int `json:"PageSize,omitempty"` 148 // Max number of records to return. 149 Limit *int `json:"limit,omitempty"` 150 } 151 152 func (params *ListInsightsQuestionnairesQuestionParams) SetAuthorization(Authorization string) *ListInsightsQuestionnairesQuestionParams { 153 params.Authorization = &Authorization 154 return params 155 } 156 func (params *ListInsightsQuestionnairesQuestionParams) SetCategorySid(CategorySid []string) *ListInsightsQuestionnairesQuestionParams { 157 params.CategorySid = &CategorySid 158 return params 159 } 160 func (params *ListInsightsQuestionnairesQuestionParams) SetPageSize(PageSize int) *ListInsightsQuestionnairesQuestionParams { 161 params.PageSize = &PageSize 162 return params 163 } 164 func (params *ListInsightsQuestionnairesQuestionParams) SetLimit(Limit int) *ListInsightsQuestionnairesQuestionParams { 165 params.Limit = &Limit 166 return params 167 } 168 169 // Retrieve a single page of InsightsQuestionnairesQuestion records from the API. Request is executed immediately. 170 func (c *ApiService) PageInsightsQuestionnairesQuestion(params *ListInsightsQuestionnairesQuestionParams, pageToken, pageNumber string) (*ListInsightsQuestionnairesQuestionResponse, error) { 171 path := "/v1/Insights/QualityManagement/Questions" 172 173 data := url.Values{} 174 headers := make(map[string]interface{}) 175 176 if params != nil && params.CategorySid != nil { 177 for _, item := range *params.CategorySid { 178 data.Add("CategorySid", item) 179 } 180 } 181 if params != nil && params.PageSize != nil { 182 data.Set("PageSize", fmt.Sprint(*params.PageSize)) 183 } 184 185 if pageToken != "" { 186 data.Set("PageToken", pageToken) 187 } 188 if pageNumber != "" { 189 data.Set("Page", pageNumber) 190 } 191 192 resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) 193 if err != nil { 194 return nil, err 195 } 196 197 defer resp.Body.Close() 198 199 ps := &ListInsightsQuestionnairesQuestionResponse{} 200 if err := json.NewDecoder(resp.Body).Decode(ps); err != nil { 201 return nil, err 202 } 203 204 return ps, err 205 } 206 207 // Lists InsightsQuestionnairesQuestion records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. 208 func (c *ApiService) ListInsightsQuestionnairesQuestion(params *ListInsightsQuestionnairesQuestionParams) ([]FlexV1InsightsQuestionnairesQuestion, error) { 209 response, errors := c.StreamInsightsQuestionnairesQuestion(params) 210 211 records := make([]FlexV1InsightsQuestionnairesQuestion, 0) 212 for record := range response { 213 records = append(records, record) 214 } 215 216 if err := <-errors; err != nil { 217 return nil, err 218 } 219 220 return records, nil 221 } 222 223 // Streams InsightsQuestionnairesQuestion records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. 224 func (c *ApiService) StreamInsightsQuestionnairesQuestion(params *ListInsightsQuestionnairesQuestionParams) (chan FlexV1InsightsQuestionnairesQuestion, chan error) { 225 if params == nil { 226 params = &ListInsightsQuestionnairesQuestionParams{} 227 } 228 params.SetPageSize(client.ReadLimits(params.PageSize, params.Limit)) 229 230 recordChannel := make(chan FlexV1InsightsQuestionnairesQuestion, 1) 231 errorChannel := make(chan error, 1) 232 233 response, err := c.PageInsightsQuestionnairesQuestion(params, "", "") 234 if err != nil { 235 errorChannel <- err 236 close(recordChannel) 237 close(errorChannel) 238 } else { 239 go c.streamInsightsQuestionnairesQuestion(response, params, recordChannel, errorChannel) 240 } 241 242 return recordChannel, errorChannel 243 } 244 245 func (c *ApiService) streamInsightsQuestionnairesQuestion(response *ListInsightsQuestionnairesQuestionResponse, params *ListInsightsQuestionnairesQuestionParams, recordChannel chan FlexV1InsightsQuestionnairesQuestion, errorChannel chan error) { 246 curRecord := 1 247 248 for response != nil { 249 responseRecords := response.Questions 250 for item := range responseRecords { 251 recordChannel <- responseRecords[item] 252 curRecord += 1 253 if params.Limit != nil && *params.Limit < curRecord { 254 close(recordChannel) 255 close(errorChannel) 256 return 257 } 258 } 259 260 record, err := client.GetNext(c.baseURL, response, c.getNextListInsightsQuestionnairesQuestionResponse) 261 if err != nil { 262 errorChannel <- err 263 break 264 } else if record == nil { 265 break 266 } 267 268 response = record.(*ListInsightsQuestionnairesQuestionResponse) 269 } 270 271 close(recordChannel) 272 close(errorChannel) 273 } 274 275 func (c *ApiService) getNextListInsightsQuestionnairesQuestionResponse(nextPageUrl string) (interface{}, error) { 276 if nextPageUrl == "" { 277 return nil, nil 278 } 279 resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) 280 if err != nil { 281 return nil, err 282 } 283 284 defer resp.Body.Close() 285 286 ps := &ListInsightsQuestionnairesQuestionResponse{} 287 if err := json.NewDecoder(resp.Body).Decode(ps); err != nil { 288 return nil, err 289 } 290 return ps, nil 291 } 292 293 // Optional parameters for the method 'UpdateInsightsQuestionnairesQuestion' 294 type UpdateInsightsQuestionnairesQuestionParams struct { 295 // The Authorization HTTP request header 296 Authorization *string `json:"Authorization,omitempty"` 297 // The flag to enable for disable NA for answer. 298 AllowNa *bool `json:"AllowNa,omitempty"` 299 // The SID of the category 300 CategorySid *string `json:"CategorySid,omitempty"` 301 // The question. 302 Question *string `json:"Question,omitempty"` 303 // The description for the question. 304 Description *string `json:"Description,omitempty"` 305 // The answer_set for the question. 306 AnswerSetId *string `json:"AnswerSetId,omitempty"` 307 } 308 309 func (params *UpdateInsightsQuestionnairesQuestionParams) SetAuthorization(Authorization string) *UpdateInsightsQuestionnairesQuestionParams { 310 params.Authorization = &Authorization 311 return params 312 } 313 func (params *UpdateInsightsQuestionnairesQuestionParams) SetAllowNa(AllowNa bool) *UpdateInsightsQuestionnairesQuestionParams { 314 params.AllowNa = &AllowNa 315 return params 316 } 317 func (params *UpdateInsightsQuestionnairesQuestionParams) SetCategorySid(CategorySid string) *UpdateInsightsQuestionnairesQuestionParams { 318 params.CategorySid = &CategorySid 319 return params 320 } 321 func (params *UpdateInsightsQuestionnairesQuestionParams) SetQuestion(Question string) *UpdateInsightsQuestionnairesQuestionParams { 322 params.Question = &Question 323 return params 324 } 325 func (params *UpdateInsightsQuestionnairesQuestionParams) SetDescription(Description string) *UpdateInsightsQuestionnairesQuestionParams { 326 params.Description = &Description 327 return params 328 } 329 func (params *UpdateInsightsQuestionnairesQuestionParams) SetAnswerSetId(AnswerSetId string) *UpdateInsightsQuestionnairesQuestionParams { 330 params.AnswerSetId = &AnswerSetId 331 return params 332 } 333 334 // To update the question 335 func (c *ApiService) UpdateInsightsQuestionnairesQuestion(QuestionSid string, params *UpdateInsightsQuestionnairesQuestionParams) (*FlexV1InsightsQuestionnairesQuestion, error) { 336 path := "/v1/Insights/QualityManagement/Questions/{QuestionSid}" 337 path = strings.Replace(path, "{"+"QuestionSid"+"}", QuestionSid, -1) 338 339 data := url.Values{} 340 headers := make(map[string]interface{}) 341 342 if params != nil && params.AllowNa != nil { 343 data.Set("AllowNa", fmt.Sprint(*params.AllowNa)) 344 } 345 if params != nil && params.CategorySid != nil { 346 data.Set("CategorySid", *params.CategorySid) 347 } 348 if params != nil && params.Question != nil { 349 data.Set("Question", *params.Question) 350 } 351 if params != nil && params.Description != nil { 352 data.Set("Description", *params.Description) 353 } 354 if params != nil && params.AnswerSetId != nil { 355 data.Set("AnswerSetId", *params.AnswerSetId) 356 } 357 358 if params != nil && params.Authorization != nil { 359 headers["Authorization"] = *params.Authorization 360 } 361 resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) 362 if err != nil { 363 return nil, err 364 } 365 366 defer resp.Body.Close() 367 368 ps := &FlexV1InsightsQuestionnairesQuestion{} 369 if err := json.NewDecoder(resp.Body).Decode(ps); err != nil { 370 return nil, err 371 } 372 373 return ps, err 374 }