twilio.sugar.Model.PhoneAutomation.SMSMessageList C# (CSharp) Method

SMSMessageList() public method

public SMSMessageList ( String to = "", String from = "", System.DateTime dateSent = null ) : twilio.sugar.Model.SMS
to String
from String
dateSent System.DateTime
return twilio.sugar.Model.SMS
        public SMS SMSMessageList(String to = "", String from = "", DateTime? dateSent = null)
        {
            _parameters.Clear();
            if (!String.IsNullOrEmpty(to))
            {
                _parameters.Add("To", to);
            }
            if (!String.IsNullOrEmpty(from))
            {
                _parameters.Add("From", from);
            }
            if (dateSent.HasValue)
            {
                _parameters.Add("DateSent", dateSent.Value);
            }

            _twilioResponse = _account.request(String.Format("Accounts/{0}/SMS/Messages.json", _account.id), "GET", _parameters);
            dynamic data = ParseResponseData(_twilioResponse);

            var sms = new SMS
            {
                start = data.start,
                total = data.total,
                num_pages = data.num_pages,
                page = data.page,
                page_size = data.page_size,
                end = data.end,
                uri = data.uri,
                first_page_uri = data.first_page_uri,
                last_page_uri = data.last_page_uri,
                next_page_uri = data.next_page_uri,
                previous_page_uri = data.previous_page_uri
            };

            IList<SMSMessage> messages = new List<SMSMessage>();

            foreach (dynamic item in data.sms_messages)
            {
                messages.Add(new SMSMessage {
                    account_sid = item.account_sid,
                    api_version = item.api_version,
                    body = item.body,
                    date_created = !String.IsNullOrEmpty(item.date_created) ? Convert.ToDateTime(item.date_created) : null,
                    date_sent = !String.IsNullOrEmpty(item.date_sent) ? Convert.ToDateTime(item.date_sent) : null,
                    date_updated = !String.IsNullOrEmpty(item.date_updated) ? Convert.ToDateTime(item.date_updated) : null,
                    direction = item.direction,
                    from = item.from,
                    price = !String.IsNullOrEmpty(item.price) ? Convert.ToDecimal(item.price) : null, 
                    sid = item.sid, 
                    status = item.status, 
                    to = item.to, 
                    uri = item.uri
                });
            }

            sms.sms_messages = messages;

            return sms;
        }

Usage Example

        public void SMSListShouldReturnListOfSMSResources()
        {
            var account = new TwilioAccountMock();
            var phoneAutomation = new PhoneAutomation(account);
            var smsList = phoneAutomation.SMSMessageList();

            Assert.IsNotNull(smsList);
            Assert.IsNotNull(smsList.sms_messages);
        }