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