github.com/twilio/twilio-go@v1.20.1/rest/taskrouter/v1/workspaces_workflows_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 'FetchWorkflowCumulativeStatistics'
    26  type FetchWorkflowCumulativeStatisticsParams struct {
    27  	// Only include usage that occurred on or before this date, specified in GMT as an [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) date-time.
    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  	// A comma separated list of values that describes the thresholds, in seconds, to calculate statistics on. For each threshold specified, the number of Tasks canceled and reservations accepted above and below the specified thresholds in seconds are computed. For example, `5,30` would show splits of Tasks that were canceled or accepted before and after 5 seconds and before and after 30 seconds. This can be used to show short abandoned Tasks or Tasks that failed to meet an SLA. TaskRouter will calculate statistics on up to 10,000 Tasks for any given threshold.
    36  	SplitByWaitTime *string `json:"SplitByWaitTime,omitempty"`
    37  }
    38  
    39  func (params *FetchWorkflowCumulativeStatisticsParams) SetEndDate(EndDate time.Time) *FetchWorkflowCumulativeStatisticsParams {
    40  	params.EndDate = &EndDate
    41  	return params
    42  }
    43  func (params *FetchWorkflowCumulativeStatisticsParams) SetMinutes(Minutes int) *FetchWorkflowCumulativeStatisticsParams {
    44  	params.Minutes = &Minutes
    45  	return params
    46  }
    47  func (params *FetchWorkflowCumulativeStatisticsParams) SetStartDate(StartDate time.Time) *FetchWorkflowCumulativeStatisticsParams {
    48  	params.StartDate = &StartDate
    49  	return params
    50  }
    51  func (params *FetchWorkflowCumulativeStatisticsParams) SetTaskChannel(TaskChannel string) *FetchWorkflowCumulativeStatisticsParams {
    52  	params.TaskChannel = &TaskChannel
    53  	return params
    54  }
    55  func (params *FetchWorkflowCumulativeStatisticsParams) SetSplitByWaitTime(SplitByWaitTime string) *FetchWorkflowCumulativeStatisticsParams {
    56  	params.SplitByWaitTime = &SplitByWaitTime
    57  	return params
    58  }
    59  
    60  //
    61  func (c *ApiService) FetchWorkflowCumulativeStatistics(WorkspaceSid string, WorkflowSid string, params *FetchWorkflowCumulativeStatisticsParams) (*TaskrouterV1WorkflowCumulativeStatistics, error) {
    62  	path := "/v1/Workspaces/{WorkspaceSid}/Workflows/{WorkflowSid}/CumulativeStatistics"
    63  	path = strings.Replace(path, "{"+"WorkspaceSid"+"}", WorkspaceSid, -1)
    64  	path = strings.Replace(path, "{"+"WorkflowSid"+"}", WorkflowSid, -1)
    65  
    66  	data := url.Values{}
    67  	headers := make(map[string]interface{})
    68  
    69  	if params != nil && params.EndDate != nil {
    70  		data.Set("EndDate", fmt.Sprint((*params.EndDate).Format(time.RFC3339)))
    71  	}
    72  	if params != nil && params.Minutes != nil {
    73  		data.Set("Minutes", fmt.Sprint(*params.Minutes))
    74  	}
    75  	if params != nil && params.StartDate != nil {
    76  		data.Set("StartDate", fmt.Sprint((*params.StartDate).Format(time.RFC3339)))
    77  	}
    78  	if params != nil && params.TaskChannel != nil {
    79  		data.Set("TaskChannel", *params.TaskChannel)
    80  	}
    81  	if params != nil && params.SplitByWaitTime != nil {
    82  		data.Set("SplitByWaitTime", *params.SplitByWaitTime)
    83  	}
    84  
    85  	resp, err := c.requestHandler.Get(c.baseURL+path, data, headers)
    86  	if err != nil {
    87  		return nil, err
    88  	}
    89  
    90  	defer resp.Body.Close()
    91  
    92  	ps := &TaskrouterV1WorkflowCumulativeStatistics{}
    93  	if err := json.NewDecoder(resp.Body).Decode(ps); err != nil {
    94  		return nil, err
    95  	}
    96  
    97  	return ps, err
    98  }