github.com/twilio/twilio-go@v1.20.1/rest/taskrouter/v1/workspaces_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 'FetchWorkspaceStatistics'
    26  type FetchWorkspaceStatisticsParams struct {
    27  	// 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.
    28  	Minutes *int `json:"Minutes,omitempty"`
    29  	// Only calculate statistics from this date and time and later, specified in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format.
    30  	StartDate *time.Time `json:"StartDate,omitempty"`
    31  	// Only calculate statistics from this date and time and earlier, specified in GMT as an [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) date-time.
    32  	EndDate *time.Time `json:"EndDate,omitempty"`
    33  	// Only calculate 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.
    36  	SplitByWaitTime *string `json:"SplitByWaitTime,omitempty"`
    37  }
    38  
    39  func (params *FetchWorkspaceStatisticsParams) SetMinutes(Minutes int) *FetchWorkspaceStatisticsParams {
    40  	params.Minutes = &Minutes
    41  	return params
    42  }
    43  func (params *FetchWorkspaceStatisticsParams) SetStartDate(StartDate time.Time) *FetchWorkspaceStatisticsParams {
    44  	params.StartDate = &StartDate
    45  	return params
    46  }
    47  func (params *FetchWorkspaceStatisticsParams) SetEndDate(EndDate time.Time) *FetchWorkspaceStatisticsParams {
    48  	params.EndDate = &EndDate
    49  	return params
    50  }
    51  func (params *FetchWorkspaceStatisticsParams) SetTaskChannel(TaskChannel string) *FetchWorkspaceStatisticsParams {
    52  	params.TaskChannel = &TaskChannel
    53  	return params
    54  }
    55  func (params *FetchWorkspaceStatisticsParams) SetSplitByWaitTime(SplitByWaitTime string) *FetchWorkspaceStatisticsParams {
    56  	params.SplitByWaitTime = &SplitByWaitTime
    57  	return params
    58  }
    59  
    60  //
    61  func (c *ApiService) FetchWorkspaceStatistics(WorkspaceSid string, params *FetchWorkspaceStatisticsParams) (*TaskrouterV1WorkspaceStatistics, error) {
    62  	path := "/v1/Workspaces/{WorkspaceSid}/Statistics"
    63  	path = strings.Replace(path, "{"+"WorkspaceSid"+"}", WorkspaceSid, -1)
    64  
    65  	data := url.Values{}
    66  	headers := make(map[string]interface{})
    67  
    68  	if params != nil && params.Minutes != nil {
    69  		data.Set("Minutes", fmt.Sprint(*params.Minutes))
    70  	}
    71  	if params != nil && params.StartDate != nil {
    72  		data.Set("StartDate", fmt.Sprint((*params.StartDate).Format(time.RFC3339)))
    73  	}
    74  	if params != nil && params.EndDate != nil {
    75  		data.Set("EndDate", fmt.Sprint((*params.EndDate).Format(time.RFC3339)))
    76  	}
    77  	if params != nil && params.TaskChannel != nil {
    78  		data.Set("TaskChannel", *params.TaskChannel)
    79  	}
    80  	if params != nil && params.SplitByWaitTime != nil {
    81  		data.Set("SplitByWaitTime", *params.SplitByWaitTime)
    82  	}
    83  
    84  	resp, err := c.requestHandler.Get(c.baseURL+path, data, headers)
    85  	if err != nil {
    86  		return nil, err
    87  	}
    88  
    89  	defer resp.Body.Close()
    90  
    91  	ps := &TaskrouterV1WorkspaceStatistics{}
    92  	if err := json.NewDecoder(resp.Body).Decode(ps); err != nil {
    93  		return nil, err
    94  	}
    95  
    96  	return ps, err
    97  }