github.com/twilio/twilio-go@v1.20.1/rest/taskrouter/v1/workspaces_workers_cumulative_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  	"fmt"
    20  	"net/url"
    21  	"strings"
    22  	"time"
    23  )
    24  
    25  // Optional parameters for the method 'FetchWorkersCumulativeStatistics'
    26  type FetchWorkersCumulativeStatisticsParams struct {
    27  	// Only calculate statistics from this date and time and earlier, specified in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format.
    28  	EndDate *time.Time `json:"EndDate,omitempty"`
    29  	// Only calculate statistics since this many minutes in the past. The default 15 minutes. This is helpful for displaying statistics for the last 15 minutes, 240 minutes (4 hours), and 480 minutes (8 hours) to see trends.
    30  	Minutes *int `json:"Minutes,omitempty"`
    31  	// Only calculate statistics from this date and time and later, specified in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format.
    32  	StartDate *time.Time `json:"StartDate,omitempty"`
    33  	// Only calculate cumulative statistics on this TaskChannel. Can be the TaskChannel's SID or its `unique_name`, such as `voice`, `sms`, or `default`.
    34  	TaskChannel *string `json:"TaskChannel,omitempty"`
    35  }
    36  
    37  func (params *FetchWorkersCumulativeStatisticsParams) SetEndDate(EndDate time.Time) *FetchWorkersCumulativeStatisticsParams {
    38  	params.EndDate = &EndDate
    39  	return params
    40  }
    41  func (params *FetchWorkersCumulativeStatisticsParams) SetMinutes(Minutes int) *FetchWorkersCumulativeStatisticsParams {
    42  	params.Minutes = &Minutes
    43  	return params
    44  }
    45  func (params *FetchWorkersCumulativeStatisticsParams) SetStartDate(StartDate time.Time) *FetchWorkersCumulativeStatisticsParams {
    46  	params.StartDate = &StartDate
    47  	return params
    48  }
    49  func (params *FetchWorkersCumulativeStatisticsParams) SetTaskChannel(TaskChannel string) *FetchWorkersCumulativeStatisticsParams {
    50  	params.TaskChannel = &TaskChannel
    51  	return params
    52  }
    53  
    54  //
    55  func (c *ApiService) FetchWorkersCumulativeStatistics(WorkspaceSid string, params *FetchWorkersCumulativeStatisticsParams) (*TaskrouterV1WorkersCumulativeStatistics, error) {
    56  	path := "/v1/Workspaces/{WorkspaceSid}/Workers/CumulativeStatistics"
    57  	path = strings.Replace(path, "{"+"WorkspaceSid"+"}", WorkspaceSid, -1)
    58  
    59  	data := url.Values{}
    60  	headers := make(map[string]interface{})
    61  
    62  	if params != nil && params.EndDate != nil {
    63  		data.Set("EndDate", fmt.Sprint((*params.EndDate).Format(time.RFC3339)))
    64  	}
    65  	if params != nil && params.Minutes != nil {
    66  		data.Set("Minutes", fmt.Sprint(*params.Minutes))
    67  	}
    68  	if params != nil && params.StartDate != nil {
    69  		data.Set("StartDate", fmt.Sprint((*params.StartDate).Format(time.RFC3339)))
    70  	}
    71  	if params != nil && params.TaskChannel != nil {
    72  		data.Set("TaskChannel", *params.TaskChannel)
    73  	}
    74  
    75  	resp, err := c.requestHandler.Get(c.baseURL+path, data, headers)
    76  	if err != nil {
    77  		return nil, err
    78  	}
    79  
    80  	defer resp.Body.Close()
    81  
    82  	ps := &TaskrouterV1WorkersCumulativeStatistics{}
    83  	if err := json.NewDecoder(resp.Body).Decode(ps); err != nil {
    84  		return nil, err
    85  	}
    86  
    87  	return ps, err
    88  }