@Test public void testCancelNumber() throws Exception { NumbersClient client = new NumbersClient(stubHttpWrapper(200, "{\n" + " \"error-code\":\"200\",\n" + " \"error-code-label\":\"success\"\n" + "}")); client.cancelNumber("AA", "447700900000"); }
/** * Search for available Nexmo Virtual Numbers. * * @throws IOException if an error occurs contacting the Nexmo API * @throws NexmoClientException if an error is returned by the server. */ public SearchNumbersResponse searchNumbers(String country) throws IOException, NexmoClientException { return this.searchNumbers(new SearchNumbersFilter(country)); }
/** * Link a given Nexmo Virtual Number to a Nexmo Application with the given ID. * * @param msisdn The Nexmo Virtual Number to be updated. * @param country The country for the given msisdn. * @param appId The ID for the Nexmo Application to be associated with the number. * @throws IOException if an error occurs contacting the Nexmo API * @throws NexmoClientException if an error is returned by the server. */ public void linkNumber(String msisdn, String country, String appId) throws IOException, NexmoClientException { UpdateNumberRequest request = new UpdateNumberRequest(msisdn, country); request.setVoiceCallbackType(UpdateNumberRequest.CallbackType.APP); request.setVoiceCallbackValue(appId); this.updateNumber(request); } }
@Test public void testBuyNumber() throws Exception { NumbersClient client = new NumbersClient(stubHttpWrapper(200, "{\n" + " \"error-code\":\"200\",\n" + " \"error-code-label\":\"success\"\n" + "}")); client.buyNumber("AA", "447700900000"); }
@Test public void testUpdateNumber() throws Exception { try { NumbersClient client = new NumbersClient(stubHttpWrapper(200, "{\n" + " \"error-code\":\"200\",\n" + " \"error-code-label\":\"success\"\n" + "}")); client.updateNumber(new UpdateNumberRequest( "447700900328", "UK" )); } catch (Exception e) { fail("Parsing a valid response should not raise an exception"); } }
@Test public void testSearchNumbers() throws Exception { NumbersClient client = new NumbersClient(stubHttpWrapper(200, "{\n" + " \"count\": 4,\n" + " \"numbers\": [\n" + " {\n" + " \"country\": \"GB\",\n" + " \"msisdn\": \"447700900000\",\n" + " \"cost\": \"0.50\",\n" + " \"type\": \"mobile\",\n" + " \"features\": [\n" + " \"VOICE\",\n" + " \"SMS\"\n" + " ]\n" + " }\n" + " ]\n" + "}")); SearchNumbersResponse response = client.searchNumbers("YY"); assertEquals(4, response.getCount()); }
@Test public void testListNumbers() throws Exception { NumbersClient client = new NumbersClient(stubHttpWrapper(200, "{\n" + " \"count\": 1,\n" + " \"numbers\": [\n" + " {\n" + " \"country\": \"GB\",\n" + " \"msisdn\": \"447700900000\",\n" + " \"moHttpUrl\": \"https://example.com/mo\",\n" + " \"type\": \"mobile-lvn\",\n" + " \"features\": [\n" + " \"VOICE\",\n" + " \"SMS\"\n" + " ],\n" + " \"voiceCallbackType\": \"app\",\n" + " \"voiceCallbackValue\": \"aaaaaaaa-bbbb-cccc-dddd-0123456789ab\"\n" + " }\n" + " ]\n" + "}")); ListNumbersResponse response = client.listNumbers(); assertEquals(1, response.getCount()); }
@Test public void testLinkNumber() throws Exception { try { NumbersClient client = new NumbersClient(stubHttpWrapper(200, "{\n" + " \"error-code\":\"200\",\n" + " \"error-code-label\":\"success\"\n" + "}")); client.linkNumber("447700900328", "UK", "my-app-id"); } catch (Exception e) { fail("Parsing a valid response should not raise an exception"); } } }
private NexmoClient(Builder builder) { this.httpWrapper = new HttpWrapper(builder.httpConfig, builder.authCollection); this.httpWrapper.setHttpClient(builder.httpClient); this.account = new AccountClient(this.httpWrapper); this.application = new ApplicationClient(this.httpWrapper); this.insight = new InsightClient(this.httpWrapper); this.numbers = new NumbersClient(this.httpWrapper); this.verify = new VerifyClient(this.httpWrapper); this.voice = new VoiceClient(this.httpWrapper); this.sms = new SmsClient(this.httpWrapper); this.sns = new SnsClient(this.httpWrapper); this.conversion = new ConversionClient(this.httpWrapper); this.redact = new RedactClient(this.httpWrapper); }
@Test public void testListNumberWithParams() throws Exception { NumbersClient client = new NumbersClient(stubHttpWrapper(200, "{\n" + " \"count\": 1,\n" + " \"numbers\": [\n" + " {\n" + " \"country\": \"GB\",\n" + " \"msisdn\": \"447700900000\",\n" + " \"moHttpUrl\": \"https://example.com/mo\",\n" + " \"type\": \"mobile-lvn\",\n" + " \"features\": [\n" + " \"VOICE\",\n" + " \"SMS\"\n" + " ],\n" + " \"voiceCallbackType\": \"app\",\n" + " \"voiceCallbackValue\": \"aaaaaaaa-bbbb-cccc-dddd-0123456789ab\"\n" + " }\n" + " ]\n" + "}")); ListNumbersFilter filter = new ListNumbersFilter(); filter.setIndex(10); filter.setSize(20); filter.setPattern("234"); filter.setSearchPattern(SearchPattern.ENDS_WITH); ListNumbersResponse response = client.listNumbers(filter); assertEquals(1, response.getCount()); }