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

CreateSubAccount() public method

public CreateSubAccount ( String friendlyName ) : twilio.sugar.Model.Account
friendlyName String
return twilio.sugar.Model.Account
        public Account CreateSubAccount(String friendlyName)
        {
            _parameters.Clear();
            _parameters.Add("FriendlyName", friendlyName);

            _twilioResponse = _account.request("Accounts.json", "POST", _parameters);
            dynamic data = ParseResponseData(_twilioResponse);

            var twilioAccount = new Account {
                sid = data.sid,
                friendly_name = data.friendly_name,
                status = data.status,
                auth_token = data.auth_token,
                date_created = Convert.ToDateTime(data.date_created),
                date_updated = Convert.ToDateTime(data.date_updated),
                type = data.type,
                uri = data.uri
            };

            var subresourceUri = new SubresourceUri {
                available_phone_numbers = data.subresource_uris.available_phone_numbers,
                calls = data.subresource_uris.calls,
                conferences = data.subresource_uris.conferences,
                incoming_phone_numbers = data.subresource_uris.incoming_phone_numbers,
                notifications = data.subresource_uris.notifications,
                outgoing_caller_ids = data.subresource_uris.outgoing_caller_ids,
                recordings = data.subresource_uris.recordings,
                sandbox = data.subresource_uris.sandbox,
                sms_messages = data.subresource_uris.sms_messages,
                transcriptions = data.subresource_uris.transcriptions
            };

            twilioAccount.subresource_uris = subresourceUri;

            return twilioAccount;
        }

Usage Example

        public void CreateSubAccountReturnsNewAccountResource()
        {
            var account = new TwilioAccountMock();
            var phoneAutomation = new PhoneAutomation(account);
            var twilioAccount = phoneAutomation.CreateSubAccount("My new account test");

            Assert.IsNotNull(twilioAccount);
        }