public async System.Threading.Tasks.Task ShouldGetWorkflowStatistics()
        {
            RestRequest savedRequest = null;

            var tcs = new TaskCompletionSource<WorkflowStatistics>();
            tcs.SetResult(new WorkflowStatistics());

            mockClient.Setup(trc => trc.Execute<WorkflowStatistics>(It.IsAny<RestRequest>()))
                .Callback<RestRequest>((request) => savedRequest = request)
                .Returns(tcs.Task);
            var client = mockClient.Object;
            var options = new StatisticsRequest();
            options.Minutes = 10;

            await client.GetWorkflowStatisticsAsync(WORKSPACE_SID, WORKFLOW_SID, options);

            mockClient.Verify(trc => trc.Execute<WorkflowStatistics>(It.IsAny<RestRequest>()), Times.Once);
            Assert.IsNotNull(savedRequest);
            Assert.AreEqual("Workspaces/{WorkspaceSid}/Workflows/{WorkflowSid}/Statistics", savedRequest.Resource);
            Assert.AreEqual("GET", savedRequest.Method);
            Assert.AreEqual(3, savedRequest.Parameters.Count);
            var workspaceSidParam = savedRequest.Parameters.Find(x => x.Name == "WorkspaceSid");
            Assert.IsNotNull(workspaceSidParam);
            Assert.AreEqual(WORKSPACE_SID, workspaceSidParam.Value);
            var workflowSidParam = savedRequest.Parameters.Find(x => x.Name == "WorkflowSid");
            Assert.IsNotNull(workflowSidParam);
            Assert.AreEqual(WORKFLOW_SID, workflowSidParam.Value);
            var minutesParam = savedRequest.Parameters.Find(x => x.Name == "Minutes");
            Assert.IsNotNull(minutesParam);
            Assert.AreEqual(10, minutesParam.Value);
        }
        public void ShouldGetWorkflowStatisticsAsynchronously()
        {
            RestRequest savedRequest = null;
            mockClient.Setup(trc => trc.ExecuteAsync<WorkflowStatistics>(It.IsAny<RestRequest>(), It.IsAny<Action<WorkflowStatistics>>()))
                .Callback<RestRequest, Action<WorkflowStatistics>>((request, action) => savedRequest = request);
            var client = mockClient.Object;
            manualResetEvent = new ManualResetEvent(false);
            var options = new StatisticsRequest();
            options.Minutes = 10;

            client.GetWorkflowStatistics(WORKSPACE_SID, WORKFLOW_SID, options, stats =>
                {
                    manualResetEvent.Set();
                });
            manualResetEvent.WaitOne(1);

            mockClient.Verify(trc => trc.ExecuteAsync<WorkflowStatistics>(It.IsAny<RestRequest>(), It.IsAny<Action<WorkflowStatistics>>()), Times.Once);
            Assert.IsNotNull(savedRequest);
            Assert.AreEqual("Workspaces/{WorkspaceSid}/Workflows/{WorkflowSid}/Statistics", savedRequest.Resource);
            Assert.AreEqual("GET", savedRequest.Method);
            Assert.AreEqual(3, savedRequest.Parameters.Count);
            var workspaceSidParam = savedRequest.Parameters.Find(x => x.Name == "WorkspaceSid");
            Assert.IsNotNull (workspaceSidParam);
            Assert.AreEqual (WORKSPACE_SID, workspaceSidParam.Value);
            var workflowSidParam = savedRequest.Parameters.Find(x => x.Name == "WorkflowSid");
            Assert.IsNotNull(workflowSidParam);
            Assert.AreEqual(WORKFLOW_SID, workflowSidParam.Value);
            var minutesParam = savedRequest.Parameters.Find(x => x.Name == "Minutes");
            Assert.IsNotNull(minutesParam);
            Assert.AreEqual(10, minutesParam.Value);
        }
        public void ShouldGetWorkerStatistics()
        {
            RestRequest savedRequest = null;
            mockClient.Setup(trc => trc.Execute<WorkerStatistics>(It.IsAny<RestRequest>()))
                .Callback<RestRequest>((request) => savedRequest = request)
                .Returns(new WorkerStatistics());
            var client = mockClient.Object;
            var options = new StatisticsRequest();
            options.Minutes = 10;

            client.GetWorkerStatistics(WORKSPACE_SID, WORKER_SID, options);

            mockClient.Verify(trc => trc.Execute<WorkerStatistics>(It.IsAny<RestRequest>()), Times.Once);
            Assert.IsNotNull(savedRequest);
            Assert.AreEqual("Workspaces/{WorkspaceSid}/Workers/{WorkerSid}/Statistics", savedRequest.Resource);
            Assert.AreEqual("GET", savedRequest.Method);
            Assert.AreEqual(3, savedRequest.Parameters.Count);
            var workspaceSidParam = savedRequest.Parameters.Find(x => x.Name == "WorkspaceSid");
            Assert.IsNotNull(workspaceSidParam);
            Assert.AreEqual(WORKSPACE_SID, workspaceSidParam.Value);
            var workerSidParam = savedRequest.Parameters.Find(x => x.Name == "WorkerSid");
            Assert.IsNotNull(workerSidParam);
            Assert.AreEqual(WORKER_SID, workerSidParam.Value);
            var minutesParam = savedRequest.Parameters.Find(x => x.Name == "Minutes");
            Assert.IsNotNull(minutesParam);
            Assert.AreEqual(10, minutesParam.Value);
        }
        /// <summary>
        /// Retrieve the details for a workspace statistics instance. Makes a GET request to a WorkspaceStatistics Instance resource.
        /// </summary>
        /// <param name="workspaceSid">The Sid of the workspace the activity belongs to</param>
        /// <param name="options">Time-interval options.</param>
        public virtual WorkspaceStatistics GetWorkspaceStatistics(string workspaceSid, StatisticsRequest options)
        {
            Require.Argument("WorkspaceSid", workspaceSid);

            var request = new RestRequest();
            request.Resource = "Workspaces/{WorkspaceSid}/Statistics";

            request.AddUrlSegment("WorkspaceSid", workspaceSid);

            AddStatisticsDateOptions(options, request);

            return Execute<WorkspaceStatistics>(request);
        }
        /// <summary>
        /// Retrieve the details for a workspace statistics instance. Makes a GET request to a WorkspaceStatistics Instance resource.
        /// </summary>
        /// <param name="workspaceSid">The Sid of the workspace the activity belongs to</param>
        /// <param name="options">Time-interval options.</param>
        /// <param name="callback">Method to call upon successful completion</param>
        public virtual void GetWorkspaceStatistics(string workspaceSid, StatisticsRequest options, Action<WorkspaceStatistics> callback)
        {
            Require.Argument("WorkspaceSid", workspaceSid);

            var request = new RestRequest();
            request.Resource = "Workspaces/{WorkspaceSid}/Statistics";

            request.AddUrlSegment("WorkspaceSid", workspaceSid);

            AddStatisticsDateOptions(options, request);

            ExecuteAsync<WorkspaceStatistics>(request, (response) => { callback(response); });
        }
Exemplo n.º 6
0
        /// <summary>
        /// Retrieve the details for a workspace statistics instance. Makes a GET request to a WorkspaceStatistics Instance resource.
        /// </summary>
        /// <param name="workspaceSid">The Sid of the workspace the activity belongs to</param>
        /// <param name="options">Time-interval options.</param>
        /// <param name="callback">Method to call upon successful completion</param>
        public virtual void GetWorkspaceStatistics(string workspaceSid, StatisticsRequest options, Action <WorkspaceStatistics> callback)
        {
            Require.Argument("WorkspaceSid", workspaceSid);

            var request = new RestRequest();

            request.Resource = "Workspaces/{WorkspaceSid}/Statistics";

            request.AddUrlSegment("WorkspaceSid", workspaceSid);

            AddStatisticsDateOptions(options, request);

            ExecuteAsync <WorkspaceStatistics>(request, (response) => { callback(response); });
        }
        /// <summary>
        /// Retrieve the details for a workflow statistics instance. Makes a GET request to a WorkflowStatistics Instance resource.
        /// </summary>
        /// <param name="workspaceSid">The Sid of the workspace the activity belongs to</param>
        /// <param name="workflowSid">The Sid of the workflow to retrieve</param>
        /// <param name="options">Time-interval options.</param>
        public virtual async Task<WorkflowStatistics> GetWorkflowStatisticsAsync(string workspaceSid, string workflowSid, StatisticsRequest options)
        {
            Require.Argument("WorkspaceSid", workspaceSid);
            Require.Argument("WorkflowSid", workflowSid);

            var request = new RestRequest();
            request.Resource = "Workspaces/{WorkspaceSid}/Workflows/{WorkflowSid}/Statistics";

            request.AddUrlSegment("WorkspaceSid", workspaceSid);
            request.AddUrlSegment("WorkflowSid", workflowSid);

            AddStatisticsDateOptions(options, request);

            return await Execute<WorkflowStatistics>(request);
        }
Exemplo n.º 8
0
 private void AddStatisticsDateOptions(StatisticsRequest options, RestRequest request)
 {
     if (options.Minutes.HasValue)
     {
         request.AddParameter("Minutes", options.Minutes.Value);
     }
     if (options.StartDate.HasValue)
     {
         request.AddParameter("StartDate", options.StartDate.Value.ToUniversalTime().ToString(STATISTICS_DATE_FORMAT));
     }
     if (options.EndDate.HasValue)
     {
         request.AddParameter("EndDate", options.EndDate.Value.ToUniversalTime().ToString(STATISTICS_DATE_FORMAT));
     }
 }
Exemplo n.º 9
0
 private void AddStatisticsDateOptions(StatisticsRequest options, RestRequest request)
 {
     if (options.Minutes.HasValue)
     {
         request.AddParameter("Minutes", options.Minutes.Value);
     }
     if (options.StartDate.HasValue)
     {
         request.AddParameter("StartDate", options.StartDate.Value.ToUniversalTime().ToString(STATISTICS_DATE_FORMAT));
     }
     if (options.EndDate.HasValue)
     {
         request.AddParameter("EndDate", options.EndDate.Value.ToUniversalTime().ToString(STATISTICS_DATE_FORMAT));
     }
 }
Exemplo n.º 10
0
    static void Main(string[] args)
    {
        // Find your Account Sid and Auth Token at twilio.com/user/account
        string AccountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
        string AuthToken = "your_auth_token";
        string WorkspaceSid = "WSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
        string TaskQueueSid = "WQXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
        var client = new TaskRouterClient(AccountSid, AuthToken);

        StatisticsRequest request = new StatisticsRequest();
        request.Minutes = 500;
        request.EndDate = DateTime.Now;

        TaskQueueStatistics stats = client.GetTaskQueueStatistics(WorkspaceSid, TaskQueueSid, request);
        Console.WriteLine(stats.Cumulative.ReservationsAccepted);
    }
Exemplo n.º 11
0
        /// <summary>
        /// Retrieve the details for a workspace statistics instance. Makes a GET request to a WorkspaceStatistics Instance resource.
        /// </summary>
        /// <param name="workspaceSid">The Sid of the workspace the activity belongs to</param>
        /// <param name="options">Time-interval options.</param>
        public virtual WorkspaceStatistics GetWorkspaceStatistics(string workspaceSid, StatisticsRequest options)
        {
            Require.Argument("WorkspaceSid", workspaceSid);

            var request = new RestRequest();

            request.Resource = "Workspaces/{WorkspaceSid}/Statistics";

            request.AddUrlSegment("WorkspaceSid", workspaceSid);

            AddStatisticsDateOptions(options, request);

            return(Execute <WorkspaceStatistics>(request));
        }
        /// <summary>
        /// Retrieve the details for a task queue statistics instance. Makes a GET request to a TaskQueueStatistics Instance resource.
        /// </summary>
        /// <param name="workspaceSid">The Sid of the workspace the activity belongs to</param>
        /// <param name="taskQueueSid">The Sid of the task queue to retrieve</param>
        /// <param name="options">Time-interval options</param>
        public virtual async Task <TaskQueueStatistics> GetTaskQueueStatisticsAsync(string workspaceSid, string taskQueueSid, StatisticsRequest options)
        {
            Require.Argument("WorkspaceSid", workspaceSid);
            Require.Argument("TaskQueueSid", taskQueueSid);

            var request = new RestRequest();

            request.Resource = "Workspaces/{WorkspaceSid}/TaskQueues/{TaskQueueSid}/Statistics";

            request.AddUrlSegment("WorkspaceSid", workspaceSid);
            request.AddUrlSegment("TaskQueueSid", taskQueueSid);

            AddStatisticsDateOptions(options, request);

            return(await Execute <TaskQueueStatistics>(request));
        }