github.com/twilio/twilio-go@v1.20.1/rest/flex/v1/insights_quality_management_categories.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 'CreateInsightsQuestionnairesCategory' 27 type CreateInsightsQuestionnairesCategoryParams struct { 28 // The Authorization HTTP request header 29 Authorization *string `json:"Authorization,omitempty"` 30 // The name of this category. 31 Name *string `json:"Name,omitempty"` 32 } 33 34 func (params *CreateInsightsQuestionnairesCategoryParams) SetAuthorization(Authorization string) *CreateInsightsQuestionnairesCategoryParams { 35 params.Authorization = &Authorization 36 return params 37 } 38 func (params *CreateInsightsQuestionnairesCategoryParams) SetName(Name string) *CreateInsightsQuestionnairesCategoryParams { 39 params.Name = &Name 40 return params 41 } 42 43 // To create a category for Questions 44 func (c *ApiService) CreateInsightsQuestionnairesCategory(params *CreateInsightsQuestionnairesCategoryParams) (*FlexV1InsightsQuestionnairesCategory, error) { 45 path := "/v1/Insights/QualityManagement/Categories" 46 47 data := url.Values{} 48 headers := make(map[string]interface{}) 49 50 if params != nil && params.Name != nil { 51 data.Set("Name", *params.Name) 52 } 53 54 if params != nil && params.Authorization != nil { 55 headers["Authorization"] = *params.Authorization 56 } 57 resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) 58 if err != nil { 59 return nil, err 60 } 61 62 defer resp.Body.Close() 63 64 ps := &FlexV1InsightsQuestionnairesCategory{} 65 if err := json.NewDecoder(resp.Body).Decode(ps); err != nil { 66 return nil, err 67 } 68 69 return ps, err 70 } 71 72 // Optional parameters for the method 'DeleteInsightsQuestionnairesCategory' 73 type DeleteInsightsQuestionnairesCategoryParams struct { 74 // The Authorization HTTP request header 75 Authorization *string `json:"Authorization,omitempty"` 76 } 77 78 func (params *DeleteInsightsQuestionnairesCategoryParams) SetAuthorization(Authorization string) *DeleteInsightsQuestionnairesCategoryParams { 79 params.Authorization = &Authorization 80 return params 81 } 82 83 // 84 func (c *ApiService) DeleteInsightsQuestionnairesCategory(CategorySid string, params *DeleteInsightsQuestionnairesCategoryParams) error { 85 path := "/v1/Insights/QualityManagement/Categories/{CategorySid}" 86 path = strings.Replace(path, "{"+"CategorySid"+"}", CategorySid, -1) 87 88 data := url.Values{} 89 headers := make(map[string]interface{}) 90 91 if params != nil && params.Authorization != nil { 92 headers["Authorization"] = *params.Authorization 93 } 94 resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) 95 if err != nil { 96 return err 97 } 98 99 defer resp.Body.Close() 100 101 return nil 102 } 103 104 // Optional parameters for the method 'ListInsightsQuestionnairesCategory' 105 type ListInsightsQuestionnairesCategoryParams struct { 106 // The Authorization HTTP request header 107 Authorization *string `json:"Authorization,omitempty"` 108 // How many resources to return in each list page. The default is 50, and the maximum is 1000. 109 PageSize *int `json:"PageSize,omitempty"` 110 // Max number of records to return. 111 Limit *int `json:"limit,omitempty"` 112 } 113 114 func (params *ListInsightsQuestionnairesCategoryParams) SetAuthorization(Authorization string) *ListInsightsQuestionnairesCategoryParams { 115 params.Authorization = &Authorization 116 return params 117 } 118 func (params *ListInsightsQuestionnairesCategoryParams) SetPageSize(PageSize int) *ListInsightsQuestionnairesCategoryParams { 119 params.PageSize = &PageSize 120 return params 121 } 122 func (params *ListInsightsQuestionnairesCategoryParams) SetLimit(Limit int) *ListInsightsQuestionnairesCategoryParams { 123 params.Limit = &Limit 124 return params 125 } 126 127 // Retrieve a single page of InsightsQuestionnairesCategory records from the API. Request is executed immediately. 128 func (c *ApiService) PageInsightsQuestionnairesCategory(params *ListInsightsQuestionnairesCategoryParams, pageToken, pageNumber string) (*ListInsightsQuestionnairesCategoryResponse, error) { 129 path := "/v1/Insights/QualityManagement/Categories" 130 131 data := url.Values{} 132 headers := make(map[string]interface{}) 133 134 if params != nil && params.PageSize != nil { 135 data.Set("PageSize", fmt.Sprint(*params.PageSize)) 136 } 137 138 if pageToken != "" { 139 data.Set("PageToken", pageToken) 140 } 141 if pageNumber != "" { 142 data.Set("Page", pageNumber) 143 } 144 145 resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) 146 if err != nil { 147 return nil, err 148 } 149 150 defer resp.Body.Close() 151 152 ps := &ListInsightsQuestionnairesCategoryResponse{} 153 if err := json.NewDecoder(resp.Body).Decode(ps); err != nil { 154 return nil, err 155 } 156 157 return ps, err 158 } 159 160 // Lists InsightsQuestionnairesCategory records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. 161 func (c *ApiService) ListInsightsQuestionnairesCategory(params *ListInsightsQuestionnairesCategoryParams) ([]FlexV1InsightsQuestionnairesCategory, error) { 162 response, errors := c.StreamInsightsQuestionnairesCategory(params) 163 164 records := make([]FlexV1InsightsQuestionnairesCategory, 0) 165 for record := range response { 166 records = append(records, record) 167 } 168 169 if err := <-errors; err != nil { 170 return nil, err 171 } 172 173 return records, nil 174 } 175 176 // Streams InsightsQuestionnairesCategory records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. 177 func (c *ApiService) StreamInsightsQuestionnairesCategory(params *ListInsightsQuestionnairesCategoryParams) (chan FlexV1InsightsQuestionnairesCategory, chan error) { 178 if params == nil { 179 params = &ListInsightsQuestionnairesCategoryParams{} 180 } 181 params.SetPageSize(client.ReadLimits(params.PageSize, params.Limit)) 182 183 recordChannel := make(chan FlexV1InsightsQuestionnairesCategory, 1) 184 errorChannel := make(chan error, 1) 185 186 response, err := c.PageInsightsQuestionnairesCategory(params, "", "") 187 if err != nil { 188 errorChannel <- err 189 close(recordChannel) 190 close(errorChannel) 191 } else { 192 go c.streamInsightsQuestionnairesCategory(response, params, recordChannel, errorChannel) 193 } 194 195 return recordChannel, errorChannel 196 } 197 198 func (c *ApiService) streamInsightsQuestionnairesCategory(response *ListInsightsQuestionnairesCategoryResponse, params *ListInsightsQuestionnairesCategoryParams, recordChannel chan FlexV1InsightsQuestionnairesCategory, errorChannel chan error) { 199 curRecord := 1 200 201 for response != nil { 202 responseRecords := response.Categories 203 for item := range responseRecords { 204 recordChannel <- responseRecords[item] 205 curRecord += 1 206 if params.Limit != nil && *params.Limit < curRecord { 207 close(recordChannel) 208 close(errorChannel) 209 return 210 } 211 } 212 213 record, err := client.GetNext(c.baseURL, response, c.getNextListInsightsQuestionnairesCategoryResponse) 214 if err != nil { 215 errorChannel <- err 216 break 217 } else if record == nil { 218 break 219 } 220 221 response = record.(*ListInsightsQuestionnairesCategoryResponse) 222 } 223 224 close(recordChannel) 225 close(errorChannel) 226 } 227 228 func (c *ApiService) getNextListInsightsQuestionnairesCategoryResponse(nextPageUrl string) (interface{}, error) { 229 if nextPageUrl == "" { 230 return nil, nil 231 } 232 resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) 233 if err != nil { 234 return nil, err 235 } 236 237 defer resp.Body.Close() 238 239 ps := &ListInsightsQuestionnairesCategoryResponse{} 240 if err := json.NewDecoder(resp.Body).Decode(ps); err != nil { 241 return nil, err 242 } 243 return ps, nil 244 } 245 246 // Optional parameters for the method 'UpdateInsightsQuestionnairesCategory' 247 type UpdateInsightsQuestionnairesCategoryParams struct { 248 // The Authorization HTTP request header 249 Authorization *string `json:"Authorization,omitempty"` 250 // The name of this category. 251 Name *string `json:"Name,omitempty"` 252 } 253 254 func (params *UpdateInsightsQuestionnairesCategoryParams) SetAuthorization(Authorization string) *UpdateInsightsQuestionnairesCategoryParams { 255 params.Authorization = &Authorization 256 return params 257 } 258 func (params *UpdateInsightsQuestionnairesCategoryParams) SetName(Name string) *UpdateInsightsQuestionnairesCategoryParams { 259 params.Name = &Name 260 return params 261 } 262 263 // To update the category for Questions 264 func (c *ApiService) UpdateInsightsQuestionnairesCategory(CategorySid string, params *UpdateInsightsQuestionnairesCategoryParams) (*FlexV1InsightsQuestionnairesCategory, error) { 265 path := "/v1/Insights/QualityManagement/Categories/{CategorySid}" 266 path = strings.Replace(path, "{"+"CategorySid"+"}", CategorySid, -1) 267 268 data := url.Values{} 269 headers := make(map[string]interface{}) 270 271 if params != nil && params.Name != nil { 272 data.Set("Name", *params.Name) 273 } 274 275 if params != nil && params.Authorization != nil { 276 headers["Authorization"] = *params.Authorization 277 } 278 resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) 279 if err != nil { 280 return nil, err 281 } 282 283 defer resp.Body.Close() 284 285 ps := &FlexV1InsightsQuestionnairesCategory{} 286 if err := json.NewDecoder(resp.Body).Decode(ps); err != nil { 287 return nil, err 288 } 289 290 return ps, err 291 }