From d5a5c54ea58f2261a4e24bafc0be2eef51435bc9 Mon Sep 17 00:00:00 2001 From: Sina Madani Date: Wed, 31 Jul 2024 17:45:05 +0100 Subject: [PATCH] WIP: More tidying up --- .../client/numbers/AvailableNumber.java | 31 ++--- .../numbers/BuyCancelNumberRequest.java | 6 + .../com/vonage/client/numbers/Feature.java | 57 +++++++++ .../vonage/client/numbers/JsonableNumber.java | 75 ++++++++++++ .../client/numbers/ListNumbersFilter.java | 29 +++-- .../client/numbers/ListNumbersResponse.java | 4 + .../vonage/client/numbers/OwnedNumber.java | 108 +++++++++++++----- .../client/numbers/UpdateNumberRequest.java | 20 +++- 8 files changed, 263 insertions(+), 67 deletions(-) create mode 100644 src/main/java/com/vonage/client/numbers/Feature.java create mode 100644 src/main/java/com/vonage/client/numbers/JsonableNumber.java diff --git a/src/main/java/com/vonage/client/numbers/AvailableNumber.java b/src/main/java/com/vonage/client/numbers/AvailableNumber.java index 91d17a5e7..e933e4cbe 100644 --- a/src/main/java/com/vonage/client/numbers/AvailableNumber.java +++ b/src/main/java/com/vonage/client/numbers/AvailableNumber.java @@ -15,20 +15,19 @@ */ package com.vonage.client.numbers; -import com.vonage.client.JsonableBaseObject; - -public class AvailableNumber extends JsonableBaseObject { - private String country, msisdn, cost, type; - private String[] features; +public class AvailableNumber extends JsonableNumber { + private Double cost; /** + * Constructor. + * * @deprecated This will be made package-private in a future release. */ @Deprecated public AvailableNumber() {} - public String getCountry() { - return country; + public String getCost() { + return cost != null ? cost.toString() : null; } @Deprecated @@ -36,39 +35,23 @@ public void setCountry(String country) { this.country = country; } - public String getMsisdn() { - return msisdn; - } - @Deprecated public void setMsisdn(String msisdn) { this.msisdn = msisdn; } - public String getCost() { - return cost; - } - @Deprecated public void setCost(String cost) { this.cost = cost; } - public String getType() { - return type; - } - @Deprecated public void setType(String type) { this.type = type; } - public String[] getFeatures() { - return features; - } - @Deprecated public void setFeatures(String[] features) { - this.features = features; + this.features = Feature.setFromString(features); } } diff --git a/src/main/java/com/vonage/client/numbers/BuyCancelNumberRequest.java b/src/main/java/com/vonage/client/numbers/BuyCancelNumberRequest.java index 2736fbcdd..5b11a913b 100644 --- a/src/main/java/com/vonage/client/numbers/BuyCancelNumberRequest.java +++ b/src/main/java/com/vonage/client/numbers/BuyCancelNumberRequest.java @@ -25,6 +25,12 @@ class BuyCancelNumberRequest extends BaseNumberRequest { this.targetApiKey = targetApiKey; } + /** + * The subaccount API key to perform this action on. + * + * @return The account API key for this request, or {@code null} if unspecified / the main account. + * @since 8.10.0 + */ public String getTargetApiKey() { return targetApiKey; } diff --git a/src/main/java/com/vonage/client/numbers/Feature.java b/src/main/java/com/vonage/client/numbers/Feature.java new file mode 100644 index 000000000..0c6397918 --- /dev/null +++ b/src/main/java/com/vonage/client/numbers/Feature.java @@ -0,0 +1,57 @@ +/* + * Copyright 2024 Vonage + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.vonage.client.numbers; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonValue; +import java.util.Arrays; + +/** + * Represents the capabilities of a phone number. + * + * @since 8.10.0 + */ +public enum Feature { + SMS, + MMS, + VOICE; + + @JsonValue + @Override + public String toString() { + return super.toString(); + } + + /** + * Converts the string representation of the feature to its enum value. + * + * @param feature The feature as a string. + * @return The enum value of the feature. + */ + @JsonCreator + public static Feature fromString(String feature) { + if (feature == null) return null; + return valueOf(feature); + } + + static Feature[] setFromString(String[] features) { + return features == null ? null : Arrays.stream(features).map(Feature::fromString).toArray(Feature[]::new); + } + + static String[] getToString(Feature[] features) { + return features == null ? null : Arrays.stream(features).map(Feature::toString).toArray(String[]::new); + } +} diff --git a/src/main/java/com/vonage/client/numbers/JsonableNumber.java b/src/main/java/com/vonage/client/numbers/JsonableNumber.java new file mode 100644 index 000000000..072fa58d9 --- /dev/null +++ b/src/main/java/com/vonage/client/numbers/JsonableNumber.java @@ -0,0 +1,75 @@ +/* + * Copyright 2024 Vonage + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.vonage.client.numbers; + +import com.vonage.client.JsonableBaseObject; + +/** + * Base class for shared fields of {@link OwnedNumber} and {@link AvailableNumber}. + * + * @since 8.10.0 + */ +class JsonableNumber extends JsonableBaseObject { + private String country, msisdn; + private Type type; + private Feature[] features; + + /** + * Two character country code in ISO 3166-1 alpha-2 format. + * + * @return The number's country code. + */ + public String getCountry() { + return country; + } + + /** + * Phone number in E.164 format. + * + * @return The MSISDN as a string. + */ + public String getMsisdn() { + return msisdn; + } + + public String getType() { + return type != null ? type.toString() : null; + } + + public String[] getFeatures() { + return Feature.getToString(features); + } + + @Deprecated + public void setCountry(String country) { + this.country = country; + } + + @Deprecated + public void setMsisdn(String msisdn) { + this.msisdn = msisdn; + } + + @Deprecated + public void setType(String type) { + this.type = Type.fromString(type); + } + + @Deprecated + public void setFeatures(String[] features) { + this.features = Feature.setFromString(features); + } +} diff --git a/src/main/java/com/vonage/client/numbers/ListNumbersFilter.java b/src/main/java/com/vonage/client/numbers/ListNumbersFilter.java index a48ddc949..2415bbbd8 100644 --- a/src/main/java/com/vonage/client/numbers/ListNumbersFilter.java +++ b/src/main/java/com/vonage/client/numbers/ListNumbersFilter.java @@ -23,6 +23,7 @@ public class ListNumbersFilter implements QueryParamsRequest { private Integer index, size; private String pattern; private SearchPattern searchPattern; + private Type type; public ListNumbersFilter() { this(null, null, null, null); @@ -43,30 +44,30 @@ public Integer getIndex() { return index; } - public void setIndex(Integer index) { - this.index = index; - } - public Integer getSize() { return size; } - public void setSize(Integer size) { - this.size = size; - } - public String getPattern() { return pattern; } - public void setPattern(String pattern) { - this.pattern = pattern; - } - public SearchPattern getSearchPattern() { return searchPattern; } + public void setIndex(Integer index) { + this.index = index; + } + + public void setSize(Integer size) { + this.size = size; + } + + public void setPattern(String pattern) { + this.pattern = pattern; + } + public void setSearchPattern(SearchPattern searchPattern) { this.searchPattern = searchPattern; } @@ -88,4 +89,8 @@ public Map makeParams() { } return params; } + + public static class Builder { + + } } diff --git a/src/main/java/com/vonage/client/numbers/ListNumbersResponse.java b/src/main/java/com/vonage/client/numbers/ListNumbersResponse.java index 317ac0caa..410bfcf41 100644 --- a/src/main/java/com/vonage/client/numbers/ListNumbersResponse.java +++ b/src/main/java/com/vonage/client/numbers/ListNumbersResponse.java @@ -21,7 +21,11 @@ /** * Response from a request to list the numbers currently being rented buy an account. + * + * @deprecated This will be made package-private in a future release and the return type of + * {@link NumbersClient#listNumbers(ListNumbersFilter)} will be replaced by {@code List}. */ +@Deprecated public class ListNumbersResponse extends JsonableBaseObject { private int count; private OwnedNumber[] numbers; diff --git a/src/main/java/com/vonage/client/numbers/OwnedNumber.java b/src/main/java/com/vonage/client/numbers/OwnedNumber.java index 3eb4286f0..b43f172ea 100644 --- a/src/main/java/com/vonage/client/numbers/OwnedNumber.java +++ b/src/main/java/com/vonage/client/numbers/OwnedNumber.java @@ -16,67 +16,117 @@ package com.vonage.client.numbers; import com.vonage.client.JsonableBaseObject; +import java.net.URI; public class OwnedNumber extends JsonableBaseObject { - private String country, msisdn, moHttpUrl, type, voiceCallbackType, voiceCallbackValue; - private String[] features; + private URI moHttpUrl; + private Type type; + private UpdateNumberRequest.CallbackType voiceCallbackType; + private String country, msisdn, voiceCallbackValue; + private Feature[] features; + + /** + * Constructor, not for public use. + * + * @deprecated This will be made private in a future release. + */ + @Deprecated + public OwnedNumber() { + } + /** + * Two character country code in ISO 3166-1 alpha-2 format. + * + * @return The number's country code. + */ public String getCountry() { return country; } - @Deprecated - public void setCountry(String country) { - this.country = country; - } - + /** + * Phone number in E.164 format. + * + * @return The MSISDN as a string. + */ public String getMsisdn() { return msisdn; } - @Deprecated - public void setMsisdn(String msisdn) { - this.msisdn = msisdn; + /** + * URL of the webhook endpoint that handles inbound messages. + * + * @return The inbound message webhook URL as a string, or {@code null} if unspecified. + */ + public String getMoHttpUrl() { + return moHttpUrl != null ? moHttpUrl.toString() : null; } - public String getMoHttpUrl() { - return moHttpUrl; + /** + * Type of number as a string. In a future release, this will be an enum. + * + * @return The type of number as a string. + */ + public String getType() { + return type != null ? type.toString() : null; } - @Deprecated - public void setMoHttpUrl(String moHttpUrl) { - this.moHttpUrl = moHttpUrl; + /** + * Capabilities of the number as an array of strings. In a future release, these will be enums. + * + * @return The number's capabilities as a string array. + */ + public String[] getFeatures() { + return Feature.getToString(features); } - public String getType() { - return type; + /** + * Voice webhook type. In a future release, this will be an enum. + * + * @return The voice webhook callback type as a string, or {@code null} if unknown. + */ + public String getVoiceCallbackType() { + return voiceCallbackType != null ? voiceCallbackType.toString() : null; + } + + /** + * SIP URI, telephone number or Application ID. + * + * @return The voice webhook value as a string, or {@code null} if unknown. + */ + public String getVoiceCallbackValue() { + return voiceCallbackValue; } @Deprecated - public void setType(String type) { - this.type = type; + public void setCountry(String country) { + this.country = country; } - public String[] getFeatures() { - return features; + @Deprecated + public void setMsisdn(String msisdn) { + this.msisdn = msisdn; } @Deprecated - public void setFeatures(String[] features) { - this.features = features; + public void setMoHttpUrl(String moHttpUrl) { + if (moHttpUrl != null) { + this.moHttpUrl = URI.create(moHttpUrl); + } } - public String getVoiceCallbackType() { - return voiceCallbackType; + @Deprecated + public void setType(String type) { + this.type = Type.fromString(type); } @Deprecated - public void setVoiceCallbackType(String voiceCallbackType) { - this.voiceCallbackType = voiceCallbackType; + public void setFeatures(String[] features) { + this.features = Feature.setFromString(features); } - public String getVoiceCallbackValue() { - return voiceCallbackValue; + @Deprecated + public void setVoiceCallbackType(String voiceCallbackType) { + this.voiceCallbackType = UpdateNumberRequest.CallbackType.fromString(voiceCallbackType); } @Deprecated diff --git a/src/main/java/com/vonage/client/numbers/UpdateNumberRequest.java b/src/main/java/com/vonage/client/numbers/UpdateNumberRequest.java index b356a2347..66513fe66 100644 --- a/src/main/java/com/vonage/client/numbers/UpdateNumberRequest.java +++ b/src/main/java/com/vonage/client/numbers/UpdateNumberRequest.java @@ -15,6 +15,7 @@ */ package com.vonage.client.numbers; +import com.fasterxml.jackson.annotation.JsonCreator; import java.net.URI; import java.util.*; @@ -64,7 +65,7 @@ public UUID getApplicationId() { * @return The inbound message webhook URL as a string, or {@code null} if unspecified. */ public String getMoHttpUrl() { - return moHttpUrl.toString(); + return moHttpUrl != null ? moHttpUrl.toString() : null; } /** @@ -101,7 +102,7 @@ public String getVoiceCallbackValue() { * @return The voice status callback URL as a string, or {@code null} if unspecified. */ public String getVoiceStatusCallback() { - return voiceStatusCallback.toString(); + return voiceStatusCallback != null ? voiceStatusCallback.toString() : null; } @Deprecated @@ -181,6 +182,7 @@ public enum CallbackType { @Deprecated APP; + /** * Serialized enum. * @@ -196,6 +198,20 @@ public String paramValue() { public String toString() { return name().toLowerCase(); } + + /** + * Creates the enum from its string representation. + * + * @param type The serialized callback type as a string. + * + * @return Enum representation of the callback type, or {@code null} if {@code type} is null. + * @since 8.10.0 + */ + @JsonCreator + public static CallbackType fromString(String type) { + if (type == null) return null; + return valueOf(type.toUpperCase()); + } } /**