From 4c6b175f165e993d263c1862e258712b38454ec3 Mon Sep 17 00:00:00 2001 From: Steve Crow Date: Fri, 16 Aug 2019 11:16:16 -0400 Subject: [PATCH] Add missing number functionality (#262) * Add number type enumeration. * Add number type to searching for a number. * Add support for messages callback value. * Update changelog. --- CHANGELOG.md | 6 ++ .../client/numbers/SearchNumbersFilter.java | 16 ++++- .../java/com/nexmo/client/numbers/Type.java | 63 +++++++++++++++++++ .../client/numbers/UpdateNumberRequest.java | 14 ++++- .../numbers/SearchNumbersEndpointTest.java | 2 + .../com/nexmo/client/numbers/TypeTest.java | 44 +++++++++++++ .../numbers/UpdateNumberEndpointTest.java | 5 +- 7 files changed, 146 insertions(+), 4 deletions(-) create mode 100644 src/main/java/com/nexmo/client/numbers/Type.java create mode 100644 src/test/java/com/nexmo/client/numbers/TypeTest.java diff --git a/CHANGELOG.md b/CHANGELOG.md index 6a0a624cc..62f0e9595 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## [Development] + +### Added +- Added support for setting an application id as a messages callback value in updating a number. +- Added support for specifying a number type when searching for a number to purchase. + ## [5.0.0] - 2019-08-01 ### Added diff --git a/src/main/java/com/nexmo/client/numbers/SearchNumbersFilter.java b/src/main/java/com/nexmo/client/numbers/SearchNumbersFilter.java index 9d77c5381..221b0fe20 100644 --- a/src/main/java/com/nexmo/client/numbers/SearchNumbersFilter.java +++ b/src/main/java/com/nexmo/client/numbers/SearchNumbersFilter.java @@ -35,6 +35,7 @@ public class SearchNumbersFilter { private String[] features; private Integer index; private Integer size; + private Type type; /** * Construct a request with the only required parameter, the country code. @@ -77,10 +78,19 @@ public Integer getSize() { return size; } + public void setType(Type type) { + this.type = type; + } + + public Type getType() { + return type; + } + /** * Set the maximum number of matching results to be returned. * - * @param size An Integer between 10 and 100 (inclusive) or null, to indicate that the default value should be used. + * @param size An Integer between 10 and 100 (inclusive) or null, to indicate that the default value should be + * used. */ public void setSize(Integer size) { this.size = size; @@ -91,7 +101,6 @@ public SearchPattern getSearchPattern() { } /** - * * @param searchPattern */ public void setSearchPattern(SearchPattern searchPattern) { @@ -115,5 +124,8 @@ public void addParams(RequestBuilder request) { if (searchPattern != null) { request.addParameter("search_pattern", Integer.toString(searchPattern.getValue())); } + if (type != null) { + request.addParameter("type", type.getType()); + } } } diff --git a/src/main/java/com/nexmo/client/numbers/Type.java b/src/main/java/com/nexmo/client/numbers/Type.java new file mode 100644 index 000000000..27d3b872d --- /dev/null +++ b/src/main/java/com/nexmo/client/numbers/Type.java @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2011-2019 Nexmo Inc + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package com.nexmo.client.numbers; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonValue; + +import java.util.HashMap; +import java.util.Map; + +/** + * Enumeration representing the type of number. + */ +public enum Type { + LANDLINE("landline"), + MOBILE_LVN("mobile-lvn"), + LANDLINE_TOLL_FREE("landline-toll-free"), + UNKNOWN("unknown"); + + private static final Map TYPE_INDEX = new HashMap<>(); + + static { + for (Type type : Type.values()) { + TYPE_INDEX.put(type.type, type); + } + } + + private String type; + + Type(String type) { + this.type = type; + } + + @JsonValue + public String getType() { + return type; + } + + @JsonCreator + public static Type fromString(String type) { + Type foundType = TYPE_INDEX.get(type); + return (foundType != null) ? foundType : UNKNOWN; + } +} diff --git a/src/main/java/com/nexmo/client/numbers/UpdateNumberRequest.java b/src/main/java/com/nexmo/client/numbers/UpdateNumberRequest.java index 97d25396c..e0bd70889 100644 --- a/src/main/java/com/nexmo/client/numbers/UpdateNumberRequest.java +++ b/src/main/java/com/nexmo/client/numbers/UpdateNumberRequest.java @@ -31,6 +31,7 @@ public class UpdateNumberRequest { private CallbackType voiceCallbackType; private String voiceCallbackValue; private String voiceStatusCallback; + private String messagesCallbackValue; public UpdateNumberRequest(String msisdn, String country) { this.country = country; @@ -85,6 +86,14 @@ public void setVoiceStatusCallback(String voiceStatusCallback) { this.voiceStatusCallback = voiceStatusCallback; } + public String getMessagesCallbackValue() { + return messagesCallbackValue; + } + + public void setMessagesCallbackValue(String messagesCallbackValue) { + this.messagesCallbackValue = messagesCallbackValue; + } + public void addParams(RequestBuilder request) { request.addParameter("country", this.country).addParameter("msisdn", msisdn); if (this.moHttpUrl != null) { @@ -102,7 +111,10 @@ public void addParams(RequestBuilder request) { if (this.voiceStatusCallback != null) { request.addParameter("voiceStatusCallback", voiceStatusCallback); } - + if (this.messagesCallbackValue != null) { + request.addParameter("messagesCallbackValue", messagesCallbackValue); + request.addParameter("messagesCallbackType", CallbackType.APP.paramValue()); + } } public enum CallbackType { diff --git a/src/test/java/com/nexmo/client/numbers/SearchNumbersEndpointTest.java b/src/test/java/com/nexmo/client/numbers/SearchNumbersEndpointTest.java index 175095df9..8587f7ced 100644 --- a/src/test/java/com/nexmo/client/numbers/SearchNumbersEndpointTest.java +++ b/src/test/java/com/nexmo/client/numbers/SearchNumbersEndpointTest.java @@ -59,6 +59,7 @@ public void makeRequest() throws Exception { filter.setPattern("234"); filter.setFeatures(new String[]{"SMS", "VOICE"}); filter.setSearchPattern(SearchPattern.STARTS_WITH); + filter.setType(Type.LANDLINE_TOLL_FREE); RequestBuilder request = endpoint.makeRequest(filter); assertEquals("GET", request.getMethod()); @@ -69,6 +70,7 @@ public void makeRequest() throws Exception { assertEquals("0", params.get("search_pattern")); assertEquals("10", params.get("index")); assertEquals("20", params.get("size")); + assertEquals("landline-toll-free", params.get("type")); } @Test diff --git a/src/test/java/com/nexmo/client/numbers/TypeTest.java b/src/test/java/com/nexmo/client/numbers/TypeTest.java new file mode 100644 index 000000000..542ac3674 --- /dev/null +++ b/src/test/java/com/nexmo/client/numbers/TypeTest.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2011-2019 Nexmo Inc + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package com.nexmo.client.numbers; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class TypeTest { + @Test + public void testFromString() { + assertEquals(Type.LANDLINE, Type.fromString("landline")); + assertEquals(Type.MOBILE_LVN, Type.fromString("mobile-lvn")); + assertEquals(Type.LANDLINE_TOLL_FREE, Type.fromString("landline-toll-free")); + assertEquals(Type.UNKNOWN, Type.fromString("test unknown")); + } + + @Test + public void testName() { + assertEquals("landline", Type.LANDLINE.getType()); + assertEquals("mobile-lvn", Type.MOBILE_LVN.getType()); + assertEquals("landline-toll-free", Type.LANDLINE_TOLL_FREE.getType()); + assertEquals("unknown", Type.UNKNOWN.getType()); + } +} diff --git a/src/test/java/com/nexmo/client/numbers/UpdateNumberEndpointTest.java b/src/test/java/com/nexmo/client/numbers/UpdateNumberEndpointTest.java index 4e8b10c5a..17169e5c9 100644 --- a/src/test/java/com/nexmo/client/numbers/UpdateNumberEndpointTest.java +++ b/src/test/java/com/nexmo/client/numbers/UpdateNumberEndpointTest.java @@ -68,6 +68,7 @@ public void testMakeRequestWithOptionalParams() throws Exception { request.setVoiceCallbackValue("1234-5678-9123-4567"); request.setVoiceCallbackType(UpdateNumberRequest.CallbackType.APP); request.setVoiceStatusCallback("https://api.example.com/callback"); + request.setMessagesCallbackValue("MESSAGES-APPLICATION-ID"); RequestBuilder builder = this.endpoint.makeRequest(request); @@ -75,7 +76,7 @@ public void testMakeRequestWithOptionalParams() throws Exception { assertEquals("https://rest.nexmo.com/number/update", builder.build().getURI().toString()); Map params = TestUtils.makeParameterMap(builder.getParameters()); - assertEquals(7, params.size()); + assertEquals(9, params.size()); assertEquals("447700900013", params.get("msisdn")); assertEquals("UK", params.get("country")); assertEquals("https://api.example.com/mo", params.get("moHttpUrl")); @@ -83,6 +84,8 @@ public void testMakeRequestWithOptionalParams() throws Exception { assertEquals("1234-5678-9123-4567", params.get("voiceCallbackValue")); assertEquals("app", params.get("voiceCallbackType")); assertEquals("https://api.example.com/callback", params.get("voiceStatusCallback")); + assertEquals("MESSAGES-APPLICATION-ID", params.get("messagesCallbackValue")); + assertEquals(UpdateNumberRequest.CallbackType.APP.paramValue(), params.get("messagesCallbackType")); } @Test