public void CreateIncomingNumberTest() { try { IncomingPhoneNumbersRequester requester = new IncomingPhoneNumbersRequester("AC907d7e328b3a5b402fa908857e047a243a8949b1", "2c78e8a8d1033b77902758e584ad5fc4a1c5ee02", "AC907d7e328b3a5b402fa908857e047a243a8949b1"); Type type = typeof(APIRequester); FieldInfo fieldInfo = type.GetField("freeClimbUrl", BindingFlags.NonPublic | BindingFlags.Instance); if (fieldInfo != null) { fieldInfo.SetValue(requester, "http://CreateIncomingTest:3000"); } WebRequest.RegisterPrefix("http://CreateIncomingTest:3000", new TestWebRequestCreate()); TestWebRequestCreate.MockHttpWebRequestWithGivenResponseCode(HttpStatusCode.OK, "{ \"phoneNumber\" : \"+13122290330\", \"alias\" : \"incoming number 1\", \"revision\" : 2, \"dateCreated\" : \"Fri, 11 Nov 2016 13:42:25 GMT\", \"dateUpdated\" : \"Wed, 01 Feb 2017 19:33:00 GMT\", \"phoneNumberId\" : \"PN3816047eda7b012ea2cf6d5e0697a2474363dcd6\", \"region\" : \"Illinois\", \"country\" : \"US\", \"voiceEnabled\" : true, \"smsEnabled\" : true, \"applicationId\" : \"APbd38defccbf9a1db844551aa8ae0531a876bc84b\", \"uri\" : \"/Accounts/AC907d7e328b3a5b402fa908857e047a243a8949b1/IncomingPhoneNumbers/PN3816047eda7b012ea2cf6d5e0697a2474363dcd6\", \"accountId\" : \"AC907d7e328b3a5b402fa908857e047a243a8949b1\"} "); IncomingPhoneNumberOptions options = new IncomingPhoneNumberOptions(); options.setAlias("incoming number 1"); options.setApplicationId("APbd38defccbf9a1db844551aa8ae0531a876bc84b"); IncomingPhoneNumber num = requester.create("+13122290330", options); Assert.IsNotNull(num); Assert.AreEqual(num.getAlias, "incoming number 1"); Assert.AreEqual(num.getPhoneNumber, "+13122290330"); Assert.IsNotNull(num.getPhoneNumberId); } catch (FreeClimbException pe) { Assert.Fail(pe.Message); } }
public void ShouldAddNewIncomingPhoneNumberAsynchronously() { manualResetEvent = new ManualResetEvent(false); var client = new TwilioRestClient(Credentials.TestAccountSid, Credentials.TestAuthToken); PhoneNumberOptions options = new PhoneNumberOptions(); options.PhoneNumber = "+15005550006"; options.VoiceUrl = "http://example.com/phone"; options.VoiceMethod = "GET"; options.VoiceFallbackUrl = "http://example.com/phone"; options.VoiceFallbackMethod = "GET"; options.SmsUrl = "http://example.com/sms"; options.SmsMethod = "GET"; options.SmsFallbackUrl = "http://example.com/sms"; options.SmsFallbackMethod = "GET"; IncomingPhoneNumber result = null; client.AddIncomingPhoneNumber(options, number => { result = number; manualResetEvent.Set(); }); manualResetEvent.WaitOne(); Assert.IsNotNull(result); Assert.IsNull(result.RestException); Assert.IsNotNull(result.Sid); }
public void GetIncomingNumberTest() { try { IncomingPhoneNumbersRequester requester = new IncomingPhoneNumbersRequester("AC907d7e328b3a5b402fa908857e047a243a8949b1", "2c78e8a8d1033b77902758e584ad5fc4a1c5ee02", "AC907d7e328b3a5b402fa908857e047a243a8949b1"); Type type = typeof(APIRequester); FieldInfo fieldInfo = type.GetField("freeClimbUrl", BindingFlags.NonPublic | BindingFlags.Instance); if (fieldInfo != null) { fieldInfo.SetValue(requester, "http://GetIncomingTest:3000"); } WebRequest.RegisterPrefix("http://GetIncomingTest:3000", new TestWebRequestCreate()); TestWebRequestCreate.MockHttpWebRequestWithGivenResponseCode(HttpStatusCode.OK, "{\"phoneNumber\" : \"+13126516046\", \"alias\" : \"312-651-6046\", \"revision\" : 2, \"dateCreated\" : \"Fri, 11 Nov 2016 13:42:22 GMT\", \"dateUpdated\" : \"Thu, 08 Dec 2016 20:41:18 GMT\", \"phoneNumberId\" : \"PN5fdc25a5db02d03aa1da1f85f18d6bfa6e45a701\", \"region\" : \"Illinois\", \"country\" : \"US\", \"voiceEnabled\" : true, \"smsEnabled\" : true, \"applicationId\" : \"APbd38defccbf9a1db844551aa8ae0531a876bc84b\", \"uri\" : \"/Accounts/AC907d7e328b3a5b402fa908857e047a243a8949b1/IncomingPhoneNumbers/PN5fdc25a5db02d03aa1da1f85f18d6bfa6e45a701\", \"accountId\" : \"AC907d7e328b3a5b402fa908857e047a243a8949b1\"}"); IncomingPhoneNumber num = requester.get("PN5fdc25a5db02d03aa1da1f85f18d6bfa6e45a701"); Assert.IsNotNull(num); Assert.AreEqual(num.getPhoneNumberId, "PN5fdc25a5db02d03aa1da1f85f18d6bfa6e45a701"); } catch (FreeClimbException pe) { Assert.Fail(pe.Message); } }
public void GetIncomingNumberListTest() { try { IncomingPhoneNumbersRequester requester = new IncomingPhoneNumbersRequester("AC907d7e328b3a5b402fa908857e047a243a8949b1", "2c78e8a8d1033b77902758e584ad5fc4a1c5ee02", "AC907d7e328b3a5b402fa908857e047a243a8949b1"); Type type = typeof(APIRequester); FieldInfo fieldInfo = type.GetField("freeClimbUrl", BindingFlags.NonPublic | BindingFlags.Instance); if (fieldInfo != null) { fieldInfo.SetValue(requester, "http://GetIncomingListTest:3000"); } WebRequest.RegisterPrefix("http://GetIncomingListTest:3000", new TestWebRequestCreate()); TestWebRequestCreate.MockHttpWebRequestWithGivenResponseCode(HttpStatusCode.OK, "{\"total\":3,\"start\":0,\"end\":1,\"page\":0,\"numPages\":2,\"pageSize\":2,\"nextPageUri\":\"/Accounts/ACabe7063197551fe51671f9ac3a9708e9dad51c4d/CallingNumbers&cursor=492dc883a811bd0204204ea9047122f93a2788a2\", \"incomingPhoneNumbers\" : [{\"phoneNumber\" : \"+13126516046\", \"alias\" : \"312-651-6046\", \"revision\" : 2, \"dateCreated\" : \"Fri, 11 Nov 2016 13:42:22 GMT\", \"dateUpdated\" : \"Thu, 08 Dec 2016 20:41:18 GMT\", \"phoneNumberId\" : \"PN5fdc25a5db02d03aa1da1f85f18d6bfa6e45a701\", \"region\" : \"Illinois\", \"country\" : \"US\", \"voiceEnabled\" : true, \"smsEnabled\" : true, \"applicationId\" : \"APbd38defccbf9a1db844551aa8ae0531a876bc84b\", \"uri\" : \"/Accounts/AC907d7e328b3a5b402fa908857e047a243a8949b1/IncomingPhoneNumbers/PN5fdc25a5db02d03aa1da1f85f18d6bfa6e45a701\", \"accountId\" : \"AC907d7e328b3a5b402fa908857e047a243a8949b1\"}, {\"phoneNumber\" : \"+13124881429\", \"alias\" : \"312-488-1429\", \"revision\" : 2, \"dateCreated\" : \"Fri, 11 Nov 2016 13:42:24 GMT\", \"dateUpdated\" : \"Sun, 15 Jan 2017 18:37:53 GMT\", \"phoneNumberId\" : \"PN5b881cc45548df1d015b7450fa9e3f1e301e1b97\", \"region\" : \"Illinois\", \"country\" : \"US\", \"voiceEnabled\" : true, \"smsEnabled\" : true, \"applicationId\" : \"APabfb2706f416285399ae6bdd96d07b3416f6d4ce\", \"uri\" : \"/Accounts/AC907d7e328b3a5b402fa908857e047a243a8949b1/IncomingPhoneNumbers/PN5b881cc45548df1d015b7450fa9e3f1e301e1b97\", \"accountId\" : \"AC907d7e328b3a5b402fa908857e047a243a8949b1\"}]}"); IncomingPhoneNumberList list = requester.get(); Assert.IsNotNull(list); Assert.AreEqual(list.getLocalSize, 2); Assert.AreEqual((list.export()).Count, 2); IncomingPhoneNumber num = list.get(0) as IncomingPhoneNumber; Assert.IsNotNull(num); Assert.AreEqual(num.getPhoneNumberId, "PN5fdc25a5db02d03aa1da1f85f18d6bfa6e45a701"); type = typeof(APIRequester); fieldInfo = type.GetField("freeClimbUrl", BindingFlags.NonPublic | BindingFlags.Instance); if (fieldInfo != null) { fieldInfo.SetValue(list, "http://GetIncomingListTest:3000"); } TestWebRequestCreate.MockHttpWebRequestWithGivenResponseCode(HttpStatusCode.OK, "{\"total\":3,\"start\":2,\"end\":2,\"page\":1,\"numPages\":2,\"pageSize\":2,\"nextPageUri\":null, \"incomingPhoneNumbers\" : [{\"phoneNumber\" : \"+13129975947\", \"alias\" : \"312-997-5947\", \"revision\" : 1, \"dateCreated\" : \"Fri, 11 Nov 2016 13:42:24 GMT\", \"dateUpdated\" : \"Thu, 26 Jan 2017 16:37:43 GMT\", \"phoneNumberId\" : \"PNeced5e8f2764adcc0cd0637bc52e6f45583458a6\", \"region\" : \"Illinois\", \"country\" : \"US\", \"voiceEnabled\" : true, \"smsEnabled\" : true, \"applicationId\" : null, \"uri\" : \"/Accounts/AC907d7e328b3a5b402fa908857e047a243a8949b1/IncomingPhoneNumbers/PNeced5e8f2764adcc0cd0637bc52e6f45583458a6\", \"accountId\" : \"AC907d7e328b3a5b402fa908857e047a243a8949b1\"}]}"); list.loadNextPage(); Assert.IsNotNull(list); Assert.AreEqual(list.getLocalSize, 3); Assert.AreEqual((list.export()).Count, 3); num = list.get(2) as IncomingPhoneNumber; Assert.IsNotNull(num); Assert.AreEqual(num.getPhoneNumberId, "PNeced5e8f2764adcc0cd0637bc52e6f45583458a6"); } catch (FreeClimbException pe) { Assert.Fail(pe.Message); } }
public void MakeIncomingNumberFromJsonTest() { string json = "{ \"phoneNumber\" : \"+13122290330\", \"alias\" : \"new incoming number 1\", \"revision\" : 2, \"dateCreated\" : \"Fri, 11 Nov 2016 13:42:25 GMT\", \"dateUpdated\" : \"Wed, 01 Feb 2017 19:33:00 GMT\", \"phoneNumberId\" : \"PN3816047eda7b012ea2cf6d5e0697a2474363dcd6\", \"region\" : \"Illinois\", \"country\" : \"US\", \"voiceEnabled\" : true, \"applicationId\" : \"APabfb2706f416285399ae6bdd96d07b3416f6d4ce\", \"uri\" : \"/Accounts/AC907d7e328b3a5b402fa908857e047a243a8949b1/IncomingPhoneNumbers/PN3816047eda7b012ea2cf6d5e0697a2474363dcd6\", \"accountId\" : \"AC907d7e328b3a5b402fa908857e047a243a8949b1\"} "; IncomingPhoneNumber num = IncomingPhoneNumber.fromJson(json); Assert.IsNotNull(num); Assert.AreEqual(num.getAlias, "new incoming number 1"); Assert.AreEqual(num.getAccountId, "AC907d7e328b3a5b402fa908857e047a243a8949b1"); Assert.AreEqual(num.getApplicationId, "APabfb2706f416285399ae6bdd96d07b3416f6d4ce"); Assert.AreEqual(num.getRegion, "Illinois"); Assert.AreEqual(num.getCountry, "US"); Assert.AreEqual(num.getVoiceEnabled, true); Assert.IsNotNull(num.getDateCreated); Assert.IsNotNull(num.getDateUpdated); Assert.AreEqual(num.getPhoneNumberId, "PN3816047eda7b012ea2cf6d5e0697a2474363dcd6"); Assert.AreEqual(num.getPhoneNumber, "+13122290330"); Assert.AreEqual(num.getRevision, 2); Assert.AreEqual(num.getUri, "/Accounts/AC907d7e328b3a5b402fa908857e047a243a8949b1/IncomingPhoneNumbers/PN3816047eda7b012ea2cf6d5e0697a2474363dcd6"); }
public void ShouldGetIncomingPhoneNumberAsynchronously() { manualResetEvent = new ManualResetEvent(false); var client = new TwilioRestClient(Credentials.AccountSid, Credentials.AuthToken); IncomingPhoneNumber result = null; client.GetIncomingPhoneNumber("", number => { result = number; manualResetEvent.Set(); }); manualResetEvent.WaitOne(); Assert.IsNotNull(result); Assert.IsNull(result.RestException); Assert.IsNotNull(result.Sid); Assert.Fail(); }
public void GetIncomingNumberListUsingFilterTest() { try { IncomingPhoneNumbersRequester requester = new IncomingPhoneNumbersRequester("AC907d7e328b3a5b402fa908857e047a243a8949b1", "2c78e8a8d1033b77902758e584ad5fc4a1c5ee02", "AC907d7e328b3a5b402fa908857e047a243a8949b1"); Type type = typeof(APIRequester); FieldInfo fieldInfo = type.GetField("freeClimbUrl", BindingFlags.NonPublic | BindingFlags.Instance); if (fieldInfo != null) { fieldInfo.SetValue(requester, "http://GetCallingListTest:3000"); } WebRequest.RegisterPrefix("http://GetCallingListTest:3000", new TestWebRequestCreate()); TestWebRequestCreate.MockHttpWebRequestWithGivenResponseCode(HttpStatusCode.OK, "{ \"total\" : 1, \"start\" : 0, \"end\" : 0, \"page\" : 0, \"numPages\" : 1, \"pageSize\" : 100, \"nextPageUri\" : null, \"incomingPhoneNumbers\" : [{\"phoneNumber\" : \"+13126516046\", \"alias\" : \"312-651-6046\", \"revision\" : 2, \"dateCreated\" : \"Fri, 11 Nov 2016 13:42:22 GMT\", \"dateUpdated\" : \"Thu, 08 Dec 2016 20:41:18 GMT\", \"phoneNumberId\" : \"PN5fdc25a5db02d03aa1da1f85f18d6bfa6e45a701\", \"region\" : \"Illinois\", \"country\" : \"US\", \"voiceEnabled\" : true, \"smsEnabled\" : true, \"applicationId\" : \"APbd38defccbf9a1db844551aa8ae0531a876bc84b\", \"uri\" : \"/Accounts/AC907d7e328b3a5b402fa908857e047a243a8949b1/IncomingPhoneNumbers/PN5fdc25a5db02d03aa1da1f85f18d6bfa6e45a701\", \"accountId\" : \"AC907d7e328b3a5b402fa908857e047a243a8949b1\"}]}"); IncomingPhoneNumbersSearchFilter filter = new IncomingPhoneNumbersSearchFilter(); filter.setPhoneNumber("^\\+1[0-9]{10}$"); filter.setAlias("312-651-6046"); IncomingPhoneNumberList list = requester.get(filter); Assert.IsNotNull(list); Assert.AreEqual(list.getLocalSize, 1); Assert.AreEqual((list.export()).Count, 1); IncomingPhoneNumber num = list.get(0) as IncomingPhoneNumber; Assert.IsNotNull(num); Assert.AreEqual(num.getPhoneNumber, "+13126516046"); Assert.AreEqual(num.getAlias, "312-651-6046"); } catch (FreeClimbException pe) { Assert.Fail(pe.Message); } }
private void CreateIncomingPhoneNumberParams(IncomingPhoneNumber phoneNumber, RestRequest request) { if (phoneNumber.FriendlyName.HasValue()) request.AddParameter("FriendlyName", phoneNumber.FriendlyName); if (phoneNumber.VoiceUrl.HasValue()) request.AddParameter("VoiceUrl", phoneNumber.VoiceUrl); if (phoneNumber.VoiceMethod.HasValue()) request.AddParameter("VoiceMethod", phoneNumber.VoiceMethod); if (phoneNumber.VoiceFallbackUrl.HasValue()) request.AddParameter("VoiceFallbackUrl", phoneNumber.VoiceFallbackUrl); if (phoneNumber.VoiceFallbackMethod.HasValue()) request.AddParameter("VoiceFallbackMethod", phoneNumber.VoiceFallbackMethod); if (phoneNumber.VoiceCallerIdLookup) request.AddParameter("VoiceCallerIdLookup", phoneNumber.VoiceCallerIdLookup); if (phoneNumber.SmsUrl.HasValue()) request.AddParameter("SmsUrl", phoneNumber.SmsUrl); if (phoneNumber.SmsMethod.HasValue()) request.AddParameter("SmsMethod", phoneNumber.SmsMethod); if (phoneNumber.SmsFallbackUrl.HasValue()) request.AddParameter("SmsFallbackUrl", phoneNumber.SmsFallbackUrl); if (phoneNumber.SmsFallbackMethod.HasValue()) request.AddParameter("SmsFallbackMethod", phoneNumber.SmsFallbackMethod); if (phoneNumber.HangupCallback.HasValue()) request.AddParameter("HangupCallback", phoneNumber.HangupCallback); if (phoneNumber.HangupCallbackMethod.HasValue()) request.AddParameter("HangupCallbackMethod", phoneNumber.HangupCallbackMethod); if (phoneNumber.HeartbeatUrl.HasValue()) request.AddParameter("HeartbeatUrl", phoneNumber.HeartbeatUrl); if (phoneNumber.HeartbeatMethod.HasValue()) request.AddParameter("HeartbeatMethod", phoneNumber.HeartbeatMethod); }
/// <summary> /// Update existing Incoming Phone number /// </summary> /// <param name="phoneNumber">Desired Incoming phone number to update</param> /// <returns></returns> public IncomingPhoneNumber UpdateIncomingPhoneNumber(IncomingPhoneNumber phoneNumber) { var request = new RestRequest(Method.POST); request.Resource = RequestUri.UpdateIncomingPhoneNumberUri; request.AddUrlSegment(RequestUriParams.IncomingPhoneNumberSid, phoneNumber.Sid); CreateIncomingPhoneNumberParams(phoneNumber, request); return Execute<IncomingPhoneNumber>(request); }
/// <summary> /// Update existing Incoming Phone number /// </summary> /// <param name="phoneNumber">Desired Incoming phone number to update</param> /// <returns></returns> public async Task<IncomingPhoneNumber> UpdateIncomingPhoneNumber(IncomingPhoneNumber phoneNumber) { var request = new RestRequest(System.Net.Http.HttpMethod.Post); request.Resource = RequestUri.UpdateIncomingPhoneNumberUri; request.AddUrlSegment(RequestUriParams.IncomingPhoneNumberSid, phoneNumber.Sid); CreateIncomingPhoneNumberParams(phoneNumber, request); return await Execute<IncomingPhoneNumber>(request); }