github.com/twilio/twilio-go@v1.20.1/rest/taskrouter/v1/workspaces_task_queues_real_time_statistics.go (about)

     1  /*
     2   * This code was generated by
     3   * ___ _ _ _ _ _    _ ____    ____ ____ _    ____ ____ _  _ ____ ____ ____ ___ __   __
     4   *  |  | | | | |    | |  | __ |  | |__| | __ | __ |___ |\ | |___ |__/ |__|  | |  | |__/
     5   *  |  |_|_| | |___ | |__|    |__| |  | |    |__] |___ | \| |___ |  \ |  |  | |__| |  \
     6   *
     7   * Twilio - Taskrouter
     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  	"net/url"
    20  	"strings"
    21  )
    22  
    23  // Optional parameters for the method 'CreateTaskQueueBulkRealTimeStatistics'
    24  type CreateTaskQueueBulkRealTimeStatisticsParams struct {
    25  	//
    26  	Body *map[string]interface{} `json:"body,omitempty"`
    27  }
    28  
    29  func (params *CreateTaskQueueBulkRealTimeStatisticsParams) SetBody(Body map[string]interface{}) *CreateTaskQueueBulkRealTimeStatisticsParams {
    30  	params.Body = &Body
    31  	return params
    32  }
    33  
    34  // Fetch a Task Queue Real Time Statistics in bulk for the array of TaskQueue SIDs, support upto 50 in a request.
    35  func (c *ApiService) CreateTaskQueueBulkRealTimeStatistics(WorkspaceSid string, params *CreateTaskQueueBulkRealTimeStatisticsParams) (*TaskrouterV1TaskQueueBulkRealTimeStatistics, error) {
    36  	path := "/v1/Workspaces/{WorkspaceSid}/TaskQueues/RealTimeStatistics"
    37  	path = strings.Replace(path, "{"+"WorkspaceSid"+"}", WorkspaceSid, -1)
    38  
    39  	data := url.Values{}
    40  	headers := map[string]interface{}{
    41  		"Content-Type": "application/json",
    42  	}
    43  
    44  	body := []byte{}
    45  	if params != nil && params.Body != nil {
    46  		b, err := json.Marshal(*params.Body)
    47  		if err != nil {
    48  			return nil, err
    49  		}
    50  		body = b
    51  	}
    52  
    53  	resp, err := c.requestHandler.Post(c.baseURL+path, data, headers, body...)
    54  	if err != nil {
    55  		return nil, err
    56  	}
    57  
    58  	defer resp.Body.Close()
    59  
    60  	ps := &TaskrouterV1TaskQueueBulkRealTimeStatistics{}
    61  	if err := json.NewDecoder(resp.Body).Decode(ps); err != nil {
    62  		return nil, err
    63  	}
    64  
    65  	return ps, err
    66  }
    67  
    68  // Optional parameters for the method 'FetchTaskQueueRealTimeStatistics'
    69  type FetchTaskQueueRealTimeStatisticsParams struct {
    70  	// The TaskChannel for which to fetch statistics. Can be the TaskChannel's SID or its `unique_name`, such as `voice`, `sms`, or `default`.
    71  	TaskChannel *string `json:"TaskChannel,omitempty"`
    72  }
    73  
    74  func (params *FetchTaskQueueRealTimeStatisticsParams) SetTaskChannel(TaskChannel string) *FetchTaskQueueRealTimeStatisticsParams {
    75  	params.TaskChannel = &TaskChannel
    76  	return params
    77  }
    78  
    79  //
    80  func (c *ApiService) FetchTaskQueueRealTimeStatistics(WorkspaceSid string, TaskQueueSid string, params *FetchTaskQueueRealTimeStatisticsParams) (*TaskrouterV1TaskQueueRealTimeStatistics, error) {
    81  	path := "/v1/Workspaces/{WorkspaceSid}/TaskQueues/{TaskQueueSid}/RealTimeStatistics"
    82  	path = strings.Replace(path, "{"+"WorkspaceSid"+"}", WorkspaceSid, -1)
    83  	path = strings.Replace(path, "{"+"TaskQueueSid"+"}", TaskQueueSid, -1)
    84  
    85  	data := url.Values{}
    86  	headers := make(map[string]interface{})
    87  
    88  	if params != nil && params.TaskChannel != nil {
    89  		data.Set("TaskChannel", *params.TaskChannel)
    90  	}
    91  
    92  	resp, err := c.requestHandler.Get(c.baseURL+path, data, headers)
    93  	if err != nil {
    94  		return nil, err
    95  	}
    96  
    97  	defer resp.Body.Close()
    98  
    99  	ps := &TaskrouterV1TaskQueueRealTimeStatistics{}
   100  	if err := json.NewDecoder(resp.Body).Decode(ps); err != nil {
   101  		return nil, err
   102  	}
   103  
   104  	return ps, err
   105  }