Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added toll free number search

  • Loading branch information...
commit 0b6f078737b5bcd434d14cb67b489c456e90ec68 1 parent 33f4464
Billy Coover authored
24 twilio.sugar.tests/TwilioAccountTest.cs
View
@@ -112,11 +112,31 @@ public void CreateSubAccountReturnsNewAccountResource()
}
[TestMethod()]
- public void AvailablePhoneNumbersByAreaCodeShouldReturnAvailablePhoneNumbersList()
+ public void AvailableLocalPhoneNumbersByAreaCodeShouldReturnAvailablePhoneNumbersList()
{
TwilioAccount_Mock account = new TwilioAccount_Mock();
PhoneAutomation PhoneAutomation = new PhoneAutomation(account);
- IList<AvailablePhoneNumber> AvailablePhoneNumbers = PhoneAutomation.AvailablePhoneNumbers(1);
+ IList<AvailablePhoneNumber> AvailablePhoneNumbers = PhoneAutomation.AvailableLocalPhoneNumbers(1);
+
+ Assert.IsNotNull(AvailablePhoneNumbers);
+ }
+
+ [TestMethod()]
+ public void AvailableTollFreePhoneNumbersShouldReturnAvailablePhoneNumbersList()
+ {
+ TwilioAccount_Mock account = new TwilioAccount_Mock();
+ PhoneAutomation PhoneAutomation = new PhoneAutomation(account);
+ IList<AvailablePhoneNumber> AvailablePhoneNumbers = PhoneAutomation.AvailableTollFreePhoneNumbers();
+
+ Assert.IsNotNull(AvailablePhoneNumbers);
+ }
+
+ [TestMethod()]
+ public void AvailableTollFreePhoneNumbersByContainsShouldReturnAvailablePhoneNumbersList()
+ {
+ TwilioAccount_Mock account = new TwilioAccount_Mock();
+ PhoneAutomation PhoneAutomation = new PhoneAutomation(account);
+ IList<AvailablePhoneNumber> AvailablePhoneNumbers = PhoneAutomation.AvailableTollFreePhoneNumbers("55");
Assert.IsNotNull(AvailablePhoneNumbers);
}
3  twilio.sugar/Model/IPhoneAutomation.cs
View
@@ -5,7 +5,8 @@ namespace twilio.sugar.Model
public interface IPhoneAutomation
{
TwilioAccount CreateSubAccount(String friendlyName);
- IList<twilio.sugar.AvailablePhoneNumber> AvailablePhoneNumbers(int? areaCode = null, string contains = null, string inRegion = null, int? inPostalCode = null);
+ IList<twilio.sugar.AvailablePhoneNumber> AvailableLocalPhoneNumbers(int? areaCode = null, string contains = null, string inRegion = null, int? inPostalCode = null);
+ IList<twilio.sugar.AvailablePhoneNumber> AvailableTollFreePhoneNumbers(String contains = null);
SMSMessage GetSMSMessage(String sid);
SMS SMSMessageList(String to = null, String from = null, DateTime? dateSent = null);
PhoneNumber ProvisionPhoneNumber(String phoneNumber = null, Int32? areaCode = null, PhoneNumber model = null);
51 twilio.sugar/Model/PhoneAutomation.cs
View
@@ -9,7 +9,7 @@ public class PhoneAutomation : twilio.sugar.Model.IPhoneAutomation
{
const String ApiVersion = "2010-04-01";
const String IsoCountryCode = "US";
- const String AccountSid = "ACba8bc05eacf94afdae398e642c9cc32d";
+ const String AccountSid = "fake_sid";
const String AuthToken = "fake_test_token";
private ITwilioAccount account;
@@ -71,23 +71,19 @@ public TwilioAccount CreateSubAccount(String friendlyName)
return twilioAccount;
}
- public IList<AvailablePhoneNumber> AvailablePhoneNumbers(Int32? areaCode = null, String contains = null, String inRegion = null, Int32? inPostalCode = null)
+ public IList<AvailablePhoneNumber> AvailableLocalPhoneNumbers(Int32? areaCode = null, String contains = null, String inRegion = null, Int32? inPostalCode = null)
{
parameters.Clear();
- if (areaCode.HasValue)
- {
+ if (areaCode.HasValue) {
parameters.Add("AreaCode", areaCode);
}
- if (!String.IsNullOrEmpty(contains))
- {
+ if (!String.IsNullOrEmpty(contains)) {
parameters.Add("Contains", contains);
}
- if (!String.IsNullOrEmpty(inRegion))
- {
+ if (!String.IsNullOrEmpty(inRegion)) {
parameters.Add("InRegion", inRegion);
}
- if (inPostalCode.HasValue)
- {
+ if (inPostalCode.HasValue) {
parameters.Add("InPostalCode", inPostalCode);
}
@@ -96,10 +92,37 @@ public IList<AvailablePhoneNumber> AvailablePhoneNumbers(Int32? areaCode = null,
IList<AvailablePhoneNumber> phoneNumbers = new List<AvailablePhoneNumber>();
- foreach (dynamic item in data.available_phone_numbers)
- {
- phoneNumbers.Add(new AvailablePhoneNumber
- {
+ foreach (dynamic item in data.available_phone_numbers) {
+ phoneNumbers.Add(new AvailablePhoneNumber {
+ friendly_name = item.friendly_name,
+ iso_country = item.iso_country,
+ lata = item.lata,
+ latitude = !String.IsNullOrEmpty(item.latitude) ? Convert.ToDecimal(item.latitude) : null,
+ longitude = !String.IsNullOrEmpty(item.longitude) ? Convert.ToDecimal(item.longitude) : null,
+ phone_number = item.phone_number,
+ postal_code = item.postal_code,
+ rate_center = item.rate_center,
+ region = item.region
+ });
+ }
+
+ return phoneNumbers;
+ }
+
+ public IList<AvailablePhoneNumber> AvailableTollFreePhoneNumbers(String contains = null)
+ {
+ parameters.Clear();
+ if (!String.IsNullOrEmpty(contains)) {
+ parameters.Add("Contains", contains);
+ }
+
+ twilioResponse = account.request(String.Format("/{0}/Accounts/{1}/AvailablePhoneNumbers/{2}/TollFree.json", ApiVersion, AccountSid, IsoCountryCode), "GET", parameters);
+ dynamic data = ParseResponseData(twilioResponse);
+
+ IList<AvailablePhoneNumber> phoneNumbers = new List<AvailablePhoneNumber>();
+
+ foreach (dynamic item in data.available_phone_numbers) {
+ phoneNumbers.Add(new AvailablePhoneNumber {
friendly_name = item.friendly_name,
iso_country = item.iso_country,
lata = item.lata,
Please sign in to comment.
Something went wrong with that request. Please try again.