Skip to content

Commit

Permalink
Add missing number functionality (#262)
Browse files Browse the repository at this point in the history
* Add number type enumeration.

* Add number type to searching for a number.

* Add support for messages callback value.

* Update changelog.
  • Loading branch information
Steve Crow authored Aug 16, 2019
1 parent 2955058 commit 4c6b175
Show file tree
Hide file tree
Showing 7 changed files with 146 additions and 4 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 14 additions & 2 deletions src/main/java/com/nexmo/client/numbers/SearchNumbersFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand All @@ -91,7 +101,6 @@ public SearchPattern getSearchPattern() {
}

/**
*
* @param searchPattern
*/
public void setSearchPattern(SearchPattern searchPattern) {
Expand All @@ -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());
}
}
}
63 changes: 63 additions & 0 deletions src/main/java/com/nexmo/client/numbers/Type.java
Original file line number Diff line number Diff line change
@@ -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<String, Type> 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;
}
}
14 changes: 13 additions & 1 deletion src/main/java/com/nexmo/client/numbers/UpdateNumberRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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
Expand Down
44 changes: 44 additions & 0 deletions src/test/java/com/nexmo/client/numbers/TypeTest.java
Original file line number Diff line number Diff line change
@@ -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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,21 +68,24 @@ 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);

assertEquals("POST", builder.getMethod());
assertEquals("https://rest.nexmo.com/number/update", builder.build().getURI().toString());

Map<String, String> 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"));
assertEquals("inbound", params.get("moSmppSysType"));
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
Expand Down

0 comments on commit 4c6b175

Please sign in to comment.