Beispiel #1
0
        public void ShouldListCallsWithFilters()
        {
            IRestRequest savedRequest = null;

            mockClient.Setup(trc => trc.Execute <CallResult>(It.IsAny <IRestRequest>()))
            .Callback <IRestRequest>((request) => savedRequest = request)
            .Returns(new CallResult());
            var             client  = mockClient.Object;
            CallListRequest options = new CallListRequest();

            options.From      = FROM;
            options.StartTime = new DateTime();

            client.ListCalls(options);

            mockClient.Verify(trc => trc.Execute <CallResult>(It.IsAny <IRestRequest>()), Times.Once);
            Assert.IsNotNull(savedRequest);
            Assert.AreEqual("Accounts/{AccountSid}/Calls.json", savedRequest.Resource);
            Assert.AreEqual(Method.GET, savedRequest.Method);
            Assert.AreEqual(2, savedRequest.Parameters.Count);
            var fromParam = savedRequest.Parameters.Find(x => x.Name == "From");

            Assert.IsNotNull(fromParam);
            Assert.AreEqual(FROM, fromParam.Value);
            var startTimeParam = savedRequest.Parameters.Find(x => x.Name == "StartTime");

            Assert.IsNotNull(startTimeParam);
            Assert.AreEqual(options.StartTime.Value.ToString("yyyy-MM-dd"), startTimeParam.Value);
        }
Beispiel #2
0
        public String Update()
        {
            string ans = "";

            // Set our AccountSid and AuthToken
            string sid   = ConfigurationManager.AppSettings["TwilioAccountSid"];;
            string token = ConfigurationManager.AppSettings["TwilioAuthToken"];;

            // Instantiate a new Twilio Rest Client
            var client = new TwilioRestClient(sid, token);

            // Get Recent Calls
            CallListRequest filter = new CallListRequest();

            filter.Count               = 1000;
            filter.PageNumber          = 2;
            filter.StartTime           = DateTime.Now.AddDays(-2).Date;
            filter.StartTimeComparison = ComparisonType.GreaterThanOrEqualTo;
            var calls = client.ListCalls(filter);

            if (calls.RestException != null)
            {
                ans = string.Format("Error: {0}", calls.RestException.Message);
                return(ans);
            }

            foreach (Call call in calls.Calls)
            {
                if (OracleRS.ExecuteScalar("select count(*) from twilio_call_log where sid = '" + call.Sid + "'", "adv") == "0")
                {
                    string sql = "insert into TWILIO_CALL_LOG( SID, PARENTCALLSID, DATECREATED, DATEUPDATED, ACCOUNTSID, CALL_TO,CALL_FROM,PHONENUMBERSID,STATUS,STARTTIME,ENDTIME,DURATION,PRICE,DIRECTION,ANSWEREDBY,FORWARDEDFROM,CALLERNAME,RESTEXCEPTION,URI) values ( '{0}' , '{1}' , to_date('{2}', 'mm/dd/yyyy HH12:MI:SS PM'), to_date('{3}', 'mm/dd/yyyy HH12:MI:SS PM') , '{4}' , '{5}' , '{6}' , '{7}' , '{8}' , to_date('{9}', 'mm/dd/yyyy HH12:MI:SS PM') , to_date('{10}', 'mm/dd/yyyy HH12:MI:SS PM') , {11} , {12} , '{13}' , '{14}' , '{15}' , '{16}' , '{17}' , '{18}' )";
                    sql = string.Format(sql,
                                        call.Sid,
                                        call.ParentCallSid,
                                        call.DateCreated.ToString("MM/dd/yyyy hh:mm:ss tt"),
                                        call.DateUpdated.ToString("MM/dd/yyyy hh:mm:ss tt"),
                                        call.AccountSid,
                                        call.To,
                                        call.From,
                                        call.PhoneNumberSid,
                                        call.Status,
                                        call.StartTime.Value.ToString("MM/dd/yyyy hh:mm:ss tt"),
                                        call.EndTime.Value.ToString("MM/dd/yyyy hh:mm:ss tt"),
                                        call.Duration,
                                        call.Price ?? 0,
                                        call.Direction,
                                        call.AnsweredBy,
                                        call.ForwardedFrom,
                                        call.CallerName,
                                        call.RestException,
                                        call.Uri.ToString());
                    OracleRS.Execute(sql, "adv");
                    ans += call.Sid + ",";
                }
            }

            return(ans);
        }
Beispiel #3
0
        /// <summary>
        /// Returns a paged list of phone calls made to and from the account.
        /// Sorted by DateUpdated with most-recent calls first.
        /// </summary>
        /// <param name="options">List filter options. If an property is set the list will be filtered by that value.</param>
        public CallResult GetCalls(CallListRequest options)
        {
            var request = new RestRequest();
            request.Resource = "Accounts/{AccountSid}/Calls";

            AddCallListOptions(options, request);

            return Execute<CallResult>(request);
        }
Beispiel #4
0
        /// <summary>
        /// Returns a paged list of phone calls made to and from the account.
        /// Sorted by DateUpdated with most-recent calls first.
        /// </summary>
        /// <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 void GetCalls(CallListRequest options, Action<CallResult> callback)
        {
            var request = new RestRequest();
            request.Resource = "Accounts/{AccountSid}/Calls";

            AddCallListOptions(options, request);

            ExecuteAsync<CallResult>(request, (response) => callback(response));
        }
Beispiel #5
0
        public IEnumerable <Call> GetCalls()
        {
            var client  = new TwilioRestClient(accountSid, authToken);
            var options = new CallListRequest();

            options.StartTimeComparison = ComparisonType.GreaterThanOrEqualTo;
            options.StartTime           = DateTime.UtcNow.AddHours(-1);
            var callResult = client.ListCalls(options);

            if (callResult?.Calls == null || callResult.Calls.Count == 0)
            {
                return(Enumerable.Empty <Call>());
            }

            return(callResult.Calls);
        }
Beispiel #6
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";
        var    twilio     = new TwilioRestClient(AccountSid, AuthToken);

        var request = new CallListRequest();

        var calls = twilio.ListCalls(request);

        foreach (var call in calls.Calls)
        {
            Console.WriteLine(call.Direction);
        }
    }
    static void Main(string[] args)
    {
        // Find your Account Sid and Auth Token at twilio.com/user/account
        string AccountSid = "{{ account_sid }}";
        string AuthToken  = "{{ auth_token }}";
        var    twilio     = new TwilioRestClient(AccountSid, AuthToken);

        var request = new CallListRequest();

        request.Status = "busy";
        request.To     = "+15558675309";
        var calls = twilio.ListCalls(request);

        foreach (var call in calls.Calls)
        {
            Console.WriteLine(call.StartTime);
        }
    }
Beispiel #8
0
    static void Main(string[] args)
    {
        // Find your Account Sid and Auth Token at twilio.com/user/account
        string AccountSid = "{{ account_sid }}";
        string AuthToken  = "{{ auth_token }}";
        var    twilio     = new TwilioRestClient(AccountSid, AuthToken);

        var request = new CallListRequest();

        request.Status = "completed";
        request.StartTimeComparison = ComparisonType.EqualTo;
        request.StartTime           = new DateTime(2009, 07, 06);
        var calls = twilio.ListCalls(request);

        foreach (var call in calls.Calls)
        {
            Console.WriteLine(call.Direction);
        }
    }
Beispiel #9
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";
        var    twilio     = new TwilioRestClient(AccountSid, AuthToken);

        var request = new CallListRequest();

        request.Status = "in-progress";
        request.StartTimeComparison = ComparisonType.GreaterThanOrEqualTo;
        request.StartTime           = new DateTime(2009, 07, 04);
        request.EndTimeComparison   = ComparisonType.LessThanOrEqualTo;
        request.EndTime             = new DateTime(2009, 07, 06);
        var calls = twilio.ListCalls(request);

        foreach (var call in calls.Calls)
        {
            Console.WriteLine(call.To);
        }
    }
Beispiel #10
0
        public ObservableCollection <Call> CallList(string login, string password)
        {
            string request = SERVER_DOMAIN + CALL_LIST + "login="******"&password="******"f")
                        {
                            tmp.IsReceived = "Nie odebrane";
                        }
                        else
                        {
                            tmp.IsReceived = "Odebrane";
                        }
                        if (callListRequest.records[i].end_date != null)
                        {
                            tmp.EndDate = callListRequest.records[i].end_date;
                        }
                        result.Add(tmp);
                    }
                    return(result);
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
            }
            return(new ObservableCollection <Call>());
        }
Beispiel #11
0
        public void ShouldListCallsWithFilters()
        {
            var  client       = new TwilioRestClient(Credentials.AccountSid, Credentials.AuthToken);
            Call originalCall = client.InitiateOutboundCall("+13144586142", "+13215946383", "http://devin.webscript.io/twilioconf?conf=" + Utilities.MakeRandomFriendlyName());

            Assert.IsNotNull(originalCall.Sid);

            var callSid   = originalCall.Sid;
            var startTime = originalCall.StartTime;

            client.HangupCall(originalCall.Sid, HangupStyle.Completed);

            CallListRequest options = new CallListRequest();

            options.From      = "+13144586142";
            options.StartTime = startTime;

            CallResult calls = client.ListCalls(options);

            Assert.IsNotNull(calls);
            Assert.IsNull(calls.RestException);
            Assert.IsNotNull(calls.Calls);
            Assert.IsNotNull(calls.Calls.FirstOrDefault(c => c.Sid == callSid));
        }
Beispiel #12
0
        public void ShouldListCallsWithFilters()
        {
            IRestRequest savedRequest = null;
            mockClient.Setup(trc => trc.Execute<CallResult>(It.IsAny<IRestRequest>()))
                .Callback<IRestRequest>((request) => savedRequest = request)
                .Returns(new CallResult());
            var client = mockClient.Object;
            CallListRequest options = new CallListRequest();
            options.From = FROM;
            options.StartTime = new DateTime();

            client.ListCalls(options);

            mockClient.Verify(trc => trc.Execute<CallResult>(It.IsAny<IRestRequest>()), Times.Once);
            Assert.IsNotNull(savedRequest);
            Assert.AreEqual("Accounts/{AccountSid}/Calls.json", savedRequest.Resource);
            Assert.AreEqual(Method.GET, savedRequest.Method);
            Assert.AreEqual(2, savedRequest.Parameters.Count);
            var fromParam = savedRequest.Parameters.Find(x => x.Name == "From");
            Assert.IsNotNull(fromParam);
            Assert.AreEqual(FROM, fromParam.Value);
            var startTimeParam = savedRequest.Parameters.Find(x => x.Name == "StartTime");
            Assert.IsNotNull(startTimeParam);
            Assert.AreEqual(options.StartTime.Value.ToString("yyyy-MM-dd"), startTimeParam.Value);
        }
Beispiel #13
0
        public void ShouldListCallsWithFilters()
        {
            var client = new TwilioRestClient(Credentials.AccountSid, Credentials.AuthToken);
            Call originalCall = client.InitiateOutboundCall("+13144586142", "+13215946383", "http://devin.webscript.io/twilioconf?conf=" + Utilities.MakeRandomFriendlyName());
            
            Assert.IsNotNull(originalCall.Sid);

            var callSid = originalCall.Sid;
            var startTime = originalCall.StartTime;

            client.HangupCall(originalCall.Sid, HangupStyle.Completed);

            CallListRequest options = new CallListRequest();
            options.From = "+13144586142";
            options.StartTime = startTime;

            CallResult calls = client.ListCalls(options);

            Assert.IsNotNull(calls);
            Assert.IsNull(calls.RestException);
            Assert.IsNotNull(calls.Calls);
            Assert.IsNotNull(calls.Calls.FirstOrDefault(c=>c.Sid == callSid));
        }
Beispiel #14
0
        private void AddCallListOptions(CallListRequest options, RestRequest request)
        {
            if (options.From.HasValue()) request.AddParameter("From", options.From);
            if (options.To.HasValue()) request.AddParameter("To", options.To);
            if (options.Status.HasValue()) request.AddParameter("Status", options.Status);
            if (options.StartTime.HasValue) request.AddParameter("StartTime", options.StartTime.Value.ToString("yyyy-MM-dd"));
            if (options.EndTime.HasValue) request.AddParameter("EndTime", options.EndTime.Value.ToString("yyyy-MM-dd"));

            var startTimeParameterName = GetParameterNameWithEquality(options.StartTimeComparison, "StartTime");
            var endTimeParameterName = GetParameterNameWithEquality(options.EndTimeComparison, "EndTime");

            if (options.StartTime.HasValue) request.AddParameter(startTimeParameterName, options.StartTime.Value.ToString("yyyy-MM-dd"));
            if (options.EndTime.HasValue) request.AddParameter(endTimeParameterName, options.EndTime.Value.ToString("yyyy-MM-dd"));

            if (options.Count.HasValue) request.AddParameter("num", options.Count.Value);
            if (options.PageNumber.HasValue) request.AddParameter("page", options.PageNumber.Value);
        }