Skip to content

Commit

Permalink
WIP: More tidying up
Browse files Browse the repository at this point in the history
  • Loading branch information
SMadani committed Jul 31, 2024
1 parent 7afaf94 commit d5a5c54
Show file tree
Hide file tree
Showing 8 changed files with 263 additions and 67 deletions.
31 changes: 7 additions & 24 deletions src/main/java/com/vonage/client/numbers/AvailableNumber.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,60 +15,43 @@
*/
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
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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
57 changes: 57 additions & 0 deletions src/main/java/com/vonage/client/numbers/Feature.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
75 changes: 75 additions & 0 deletions src/main/java/com/vonage/client/numbers/JsonableNumber.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
29 changes: 17 additions & 12 deletions src/main/java/com/vonage/client/numbers/ListNumbersFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
}
Expand All @@ -88,4 +89,8 @@ public Map<String, String> makeParams() {
}
return params;
}

public static class Builder {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<OwnedNumber>}.
*/
@Deprecated
public class ListNumbersResponse extends JsonableBaseObject {
private int count;
private OwnedNumber[] numbers;
Expand Down
Loading

0 comments on commit d5a5c54

Please sign in to comment.