public static AvailablePhoneNumber Parse(String phone)
        {
            Match match = PhonePattern.Match(phone);
            if (!match.Success)
                throw new FormatException("The phone number is not in a supported format and could not be parsed. Expected Format: (510) 564-7903 or +15105647903");

            String plusone = match.Groups[1].Value;
            String areacode = match.Groups[2].Value;
            String exchange = match.Groups[3].Value;
            String last = match.Groups[4].Value;

            if (String.IsNullOrWhiteSpace(plusone))
                plusone = "+1";

            String phonenumber = plusone + areacode + exchange + last;
            String friendly = String.Format("({0}) {1}-{2}", areacode, exchange, last);
            String web = String.Format("{0}-{1}-{2}", areacode, exchange, last);

            AvailablePhoneNumber result = new AvailablePhoneNumber();
            result.PhoneNumber = phonenumber;
            result.FriendlyName = friendly;
            result.WebDisplay = web;

            result.AreaCode = areacode;
            result.Exchange = exchange;
            result.LineNumber = last;

            return result;
        }
Esempio n. 2
0
        /// <summary>
        /// Attempts to purchase the specified phone number
        /// </summary>
        /// <param name="number"></param>
        /// <param name="handlerUri"></param>
        /// <returns></returns>
        public AssignedPhoneNumber PurchasePhoneNumber(AvailablePhoneNumber number, String handlerUri)
        {
            if (number == null)
                throw new ArgumentException("You must specify a phone number when purchasing a new number.");

            String url = String.Format("/{0}/Accounts/{1}/IncomingPhoneNumbers", API_VERSION, this.accountSid);

            Hashtable fields = new Hashtable();
            fields.Add("PhoneNumber", number.PhoneNumber);
            fields.Add("VoiceUrl", handlerUri.ToString());
            fields.Add("VoiceCallerIdLookup", "true");

            return ParseAssignedPhoneNumber(Execute(url, fields, POST));
        }
Esempio n. 3
0
 public void ReleasePhoneNumber(String phoneSid, AvailablePhoneNumber availablePhoneNumber)
 {
     String url = String.Format("/{0}/Accounts/{1}/IncomingPhoneNumbers/{2}", API_VERSION, this.accountSid, phoneSid);
     String result = Execute(url, null, "DELETE");
 }
Esempio n. 4
0
        private static List<AvailablePhoneNumber> ParseAvailablePhoneNumber(String text)
        {
            List<AvailablePhoneNumber> results = new List<AvailablePhoneNumber>();

            XmlDocument xml = GetXmlDocument(text);
            XmlNodeList list = xml.SelectNodes("//AvailablePhoneNumber");
            foreach (XmlNode node in list)
            {
                String name = node.SelectSingleNode("FriendlyName").InnerText;
                String number = node.SelectSingleNode("PhoneNumber").InnerText;

                AvailablePhoneNumber item = new AvailablePhoneNumber();
                item.FriendlyName = name;
                item.PhoneNumber = number;

                results.Add(item);
            }
            results.Sort((d, n) => d.PhoneNumber.CompareTo(n.PhoneNumber));

            return results;
        }