Exemple #1
0
        /// <summary>
        /// List workers on current workspace with filters
        /// </summary>
        /// <param name="workspaceSid">The Sid of the workspace the workers belong to</param>
        /// <param name="options">List filter options. If an property is set the list will be filtered by that value.</param>
        public virtual WorkerResult ListWorkers(string workspaceSid, WorkerListRequest options)
        {
            Require.Argument("WorkspaceSid", workspaceSid);

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

            request.AddUrlSegment("WorkspaceSid", workspaceSid);

            AddWorkerListOptions(options, request);

            return Execute<WorkerResult>(request);
        }
Exemple #2
0
        /// <summary>
        /// List workers on current workspace with filters
        /// </summary>
        /// <param name="workspaceSid">The Sid of the workspace the workers belong to</param>
        /// <param name="options">List filter options. If an property is set the list will be filtered by that value.</param>
        /// <param name="callback">Method to call upon successful completion</param>
        public virtual void ListWorkers(string workspaceSid, WorkerListRequest options, Action <WorkerResult> callback)
        {
            Require.Argument("WorkspaceSid", workspaceSid);

            var request = new RestRequest();

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

            request.AddUrlSegment("WorkspaceSid", workspaceSid);

            AddWorkerListOptions(options, request);

            ExecuteAsync <WorkerResult>(request, callback);
        }
Exemple #3
0
        /// <summary>
        /// List workers on current workspace with filters
        /// </summary>
        /// <param name="workspaceSid">The Sid of the workspace the workers belong to</param>
        /// <param name="options">List filter options. If an property is set the list will be filtered by that value.</param>
        public virtual WorkerResult ListWorkers(string workspaceSid, WorkerListRequest options)
        {
            Require.Argument("WorkspaceSid", workspaceSid);

            var request = new RestRequest();

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

            request.AddUrlSegment("WorkspaceSid", workspaceSid);

            AddWorkerListOptions(options, request);

            return(Execute <WorkerResult>(request));
        }
Exemple #4
0
        private void AddWorkerListOptions(WorkerListRequest options, RestRequest request)
        {
            if (options.TaskQueueSid.HasValue())
            {
                request.AddParameter("TaskQueueSid", options.TaskQueueSid);
            }
            if (options.TaskQueueName.HasValue())
            {
                request.AddParameter("TaskQueueName", options.TaskQueueName);
            }
            if (options.ActivitySid.HasValue())
            {
                request.AddParameter("ActivitySid", options.ActivitySid);
            }
            if (options.ActivityName.HasValue())
            {
                request.AddParameter("ActivityName", options.ActivityName);
            }
            if (options.FriendlyName.HasValue())
            {
                request.AddParameter("FriendlyName", options.FriendlyName);
            }
            if (options.TargetWorkersExpression.HasValue())
            {
                request.AddParameter("TargetWorkersExpression", options.TargetWorkersExpression);
            }

            if (options.AfterSid.HasValue())
            {
                request.AddParameter("AfterSid", options.AfterSid);
            }
            if (options.BeforeSid.HasValue())
            {
                request.AddParameter("BeforeSid", options.BeforeSid);
            }
            if (options.Count.HasValue)
            {
                request.AddParameter("PageSize", options.Count.Value);
            }
        }
    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";
        var client = new TaskRouterClient(AccountSid, AuthToken);

        WorkerListRequest filters = new WorkerListRequest();
        filters.TaskQueueSid = "WQf855e98ad280d0a0a325628e24ca9627";
        WorkerResult workerResult = client.ListWorkers(WorkspaceSid, filters);
        foreach(Worker worker in workerResult.Workers) {
        Console.WriteLine(worker.FriendlyName);
        }

        filters = new WorkerListRequest();
        filters.TargetWorkersExpression = "type == 'leads'";
        workerResult = client.ListWorkers(WorkspaceSid, filters);
        foreach(Worker worker in workerResult.Workers) {
        Console.WriteLine(worker.FriendlyName);
        }
    }
        public void ShouldListWorkersUsingFiltersAsynchronously()
        {
            RestRequest savedRequest = null;
            mockClient.Setup(trc => trc.ExecuteAsync<WorkerResult>(It.IsAny<RestRequest>(), It.IsAny<Action<WorkerResult>>()))
                .Callback<RestRequest, Action<WorkerResult>>((request, action) => savedRequest = request);
            var client = mockClient.Object;
            manualResetEvent = new ManualResetEvent(false);
            var options = new WorkerListRequest();
            var friendlyName = Twilio.Api.Tests.Utilities.MakeRandomFriendlyName();
            options.FriendlyName = friendlyName;
            options.ActivityName = "activityName";
            options.ActivitySid = "WA123";
            options.AfterSid = "afterSid";
            options.BeforeSid = "beforeSid";
            options.Count = 10;
            options.TargetWorkersExpression = "expression";
            options.TaskQueueName = "taskQueueName";
            options.TaskQueueSid = "WQ123";

            client.ListWorkers(WORKSPACE_SID, options, workers => {
                manualResetEvent.Set();
            });

            manualResetEvent.WaitOne(1);

            mockClient.Verify(trc => trc.ExecuteAsync<WorkerResult>(It.IsAny<RestRequest>(), It.IsAny<Action<WorkerResult>>()), Times.Once);
            Assert.IsNotNull(savedRequest);
            Assert.AreEqual("Workspaces/{WorkspaceSid}/Workers", savedRequest.Resource);
            Assert.AreEqual("GET", savedRequest.Method);
            Assert.AreEqual(10, savedRequest.Parameters.Count);
            var workspaceSidParam = savedRequest.Parameters.Find(x => x.Name == "WorkspaceSid");
            Assert.IsNotNull(workspaceSidParam);
            Assert.AreEqual(WORKSPACE_SID, workspaceSidParam.Value);
            var friendlyNameParam = savedRequest.Parameters.Find(x => x.Name == "FriendlyName");
            Assert.IsNotNull(friendlyNameParam);
            Assert.AreEqual(friendlyName, friendlyNameParam.Value);
            var activityNameParam = savedRequest.Parameters.Find(x => x.Name == "ActivityName");
            Assert.IsNotNull(activityNameParam);
            Assert.AreEqual(options.ActivityName, activityNameParam.Value);
            var activitySidParam = savedRequest.Parameters.Find(x => x.Name == "ActivitySid");
            Assert.IsNotNull(activitySidParam);
            Assert.AreEqual(options.ActivitySid, activitySidParam.Value);
            var targetWorkersExpressionParam = savedRequest.Parameters.Find(x => x.Name == "TargetWorkersExpression");
            Assert.IsNotNull(targetWorkersExpressionParam);
            Assert.AreEqual(options.TargetWorkersExpression, targetWorkersExpressionParam.Value);
            var taskQueueNameParam = savedRequest.Parameters.Find(x => x.Name == "TaskQueueName");
            Assert.IsNotNull(taskQueueNameParam);
            Assert.AreEqual(options.TaskQueueName, taskQueueNameParam.Value);
            var taskQueueSidParam = savedRequest.Parameters.Find(x => x.Name == "TaskQueueSid");
            Assert.IsNotNull(taskQueueSidParam);
            Assert.AreEqual(options.TaskQueueSid, taskQueueSidParam.Value);
            var afterSidParam = savedRequest.Parameters.Find(x => x.Name == "AfterSid");
            Assert.IsNotNull(afterSidParam);
            Assert.AreEqual("afterSid", afterSidParam.Value);
            var beforeSidParam = savedRequest.Parameters.Find(x => x.Name == "BeforeSid");
            Assert.IsNotNull(beforeSidParam);
            Assert.AreEqual("beforeSid", beforeSidParam.Value);
            var countSidParam = savedRequest.Parameters.Find(x => x.Name == "PageSize");
            Assert.IsNotNull(countSidParam);
            Assert.AreEqual(10, countSidParam.Value);
        }
Exemple #7
0
        private void AddWorkerListOptions(WorkerListRequest options, RestRequest request)
        {
            if (options.TaskQueueSid.HasValue()) request.AddParameter("TaskQueueSid", options.TaskQueueSid);
            if (options.TaskQueueName.HasValue()) request.AddParameter("TaskQueueName", options.TaskQueueName);
            if (options.ActivitySid.HasValue()) request.AddParameter("ActivitySid", options.ActivitySid);
            if (options.ActivityName.HasValue()) request.AddParameter("ActivityName", options.ActivityName);
            if (options.FriendlyName.HasValue()) request.AddParameter("FriendlyName", options.FriendlyName);
            if (options.TargetWorkersExpression.HasValue()) request.AddParameter("TargetWorkersExpression", options.TargetWorkersExpression);

            if (options.AfterSid.HasValue()) request.AddParameter("AfterSid", options.AfterSid);
            if (options.BeforeSid.HasValue()) request.AddParameter("BeforeSid", options.BeforeSid);
            if (options.Count.HasValue) request.AddParameter("PageSize", options.Count.Value);
        }
        /// <summary>
        /// List workers on current workspace with filters
        /// </summary>
        /// <param name="workspaceSid">The Sid of the workspace the workers belong to</param>
        /// <param name="options">List filter options. If an property is set the list will be filtered by that value.</param>
        /// <param name="callback">Method to call upon successful completion</param>
        public virtual void ListWorkers(string workspaceSid, WorkerListRequest options, Action<WorkerResult> callback)
        {
            Require.Argument("WorkspaceSid", workspaceSid);

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

            request.AddUrlSegment("WorkspaceSid", workspaceSid);

            AddWorkerListOptions(options, request);

            ExecuteAsync<WorkerResult>(request, callback);
        }
        public async System.Threading.Tasks.Task ShouldListWorkersUsingFilters()
        {
            RestRequest savedRequest = null;

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

            mockClient.Setup(trc => trc.Execute<WorkerResult>(It.IsAny<RestRequest>()))
                .Callback<RestRequest>((request) => savedRequest = request)
                .Returns(tcs.Task);
            var client = mockClient.Object;
            var options = new WorkerListRequest();
            var friendlyName = Twilio.Api.Tests.Utilities.MakeRandomFriendlyName();
            options.FriendlyName = friendlyName;
            options.ActivityName = "activityName";
            options.ActivitySid = "WA123";
            options.AfterSid = "afterSid";
            options.BeforeSid = "beforeSid";
            options.Count = 10;
            options.TargetWorkersExpression = "expression";
            options.TaskQueueName = "taskQueueName";
            options.TaskQueueSid = "WQ123";

            await client.ListWorkersAsync(WORKSPACE_SID, options);

            mockClient.Verify(trc => trc.Execute<WorkerResult>(It.IsAny<RestRequest>()), Times.Once);
            Assert.IsNotNull(savedRequest);
            Assert.AreEqual("Workspaces/{WorkspaceSid}/Workers", savedRequest.Resource);
            Assert.AreEqual("GET", savedRequest.Method);
            Assert.AreEqual(10, savedRequest.Parameters.Count);
            var workspaceSidParam = savedRequest.Parameters.Find(x => x.Name == "WorkspaceSid");
            Assert.IsNotNull(workspaceSidParam);
            Assert.AreEqual(WORKSPACE_SID, workspaceSidParam.Value);
            var friendlyNameParam = savedRequest.Parameters.Find(x => x.Name == "FriendlyName");
            Assert.IsNotNull(friendlyNameParam);
            Assert.AreEqual(friendlyName, friendlyNameParam.Value);
            var activityNameParam = savedRequest.Parameters.Find(x => x.Name == "ActivityName");
            Assert.IsNotNull(activityNameParam);
            Assert.AreEqual(options.ActivityName, activityNameParam.Value);
            var activitySidParam = savedRequest.Parameters.Find(x => x.Name == "ActivitySid");
            Assert.IsNotNull(activitySidParam);
            Assert.AreEqual(options.ActivitySid, activitySidParam.Value);
            var targetWorkersExpressionParam = savedRequest.Parameters.Find(x => x.Name == "TargetWorkersExpression");
            Assert.IsNotNull(targetWorkersExpressionParam);
            Assert.AreEqual(options.TargetWorkersExpression, targetWorkersExpressionParam.Value);
            var taskQueueNameParam = savedRequest.Parameters.Find(x => x.Name == "TaskQueueName");
            Assert.IsNotNull(taskQueueNameParam);
            Assert.AreEqual(options.TaskQueueName, taskQueueNameParam.Value);
            var taskQueueSidParam = savedRequest.Parameters.Find(x => x.Name == "TaskQueueSid");
            Assert.IsNotNull(taskQueueSidParam);
            Assert.AreEqual(options.TaskQueueSid, taskQueueSidParam.Value);
            var afterSidParam = savedRequest.Parameters.Find(x => x.Name == "AfterSid");
            Assert.IsNotNull(afterSidParam);
            Assert.AreEqual("afterSid", afterSidParam.Value);
            var beforeSidParam = savedRequest.Parameters.Find(x => x.Name == "BeforeSid");
            Assert.IsNotNull(beforeSidParam);
            Assert.AreEqual("beforeSid", beforeSidParam.Value);
            var countSidParam = savedRequest.Parameters.Find(x => x.Name == "PageSize");
            Assert.IsNotNull(countSidParam);
            Assert.AreEqual(10, countSidParam.Value);
        }