diff --git a/src/main/java/com/vonage/client/account/AccountClient.java b/src/main/java/com/vonage/client/account/AccountClient.java index e67ea0fe5..5cf9c4da6 100644 --- a/src/main/java/com/vonage/client/account/AccountClient.java +++ b/src/main/java/com/vonage/client/account/AccountClient.java @@ -33,7 +33,7 @@ public class AccountClient { final RestEndpoint balance; final RestEndpoint pricing; - final RestEndpoint fullPricing; + final RestEndpoint fullPricing; final RestEndpoint prefixPricing; final RestEndpoint topUp; final RestEndpoint settings; @@ -49,7 +49,6 @@ public class AccountClient { */ @SuppressWarnings("unchecked") public AccountClient(HttpWrapper wrapper) { - super(); apiKeyGetter = () -> wrapper.getAuthCollection().getAuth(ApiKeyHeaderAuthMethod.class).getApiKey(); class Endpoint extends DynamicEndpoint { @@ -85,20 +84,20 @@ class SecretsEndpoint extends Endpoint { class SecretRequestEndpoint extends Endpoint { SecretRequestEndpoint(HttpMethod method, R... type) { - super(req -> String.format(SECRETS_PATH, req.getApiKey()) + "/" + req.getSecretId(), + super(req -> String.format(SECRETS_PATH, req.apiKey) + "/" + req.secretId, method, true, false, type ); } } balance = new Endpoint<>(req -> "/get-balance"); - pricing = new Endpoint<>(req -> "/get-pricing/outbound/" + req.getServiceType()); - fullPricing = new Endpoint<>(req -> "/get-full-pricing/outbound/" + req.getServiceType()); - prefixPricing = new Endpoint<>(req -> "/get-prefix-pricing/outbound/" + req.getServiceType()); + pricing = new Endpoint<>(req -> "/get-pricing/outbound/" + req.serviceType); + fullPricing = new Endpoint<>(req -> "/get-full-pricing/outbound/" + req); + prefixPricing = new Endpoint<>(req -> "/get-prefix-pricing/outbound/" + req.serviceType); topUp = new Endpoint<>(req -> "/top-up", HttpMethod.POST); settings = new Endpoint<>(req -> "/settings", HttpMethod.POST); listSecrets = new SecretsEndpoint<>(Function.identity(), HttpMethod.GET); - createSecret = new SecretsEndpoint<>(CreateSecretRequest::getApiKey, HttpMethod.POST); + createSecret = new SecretsEndpoint<>(req -> req.apiKey, HttpMethod.POST); getSecret = new SecretRequestEndpoint<>(HttpMethod.GET); revokeSecret = new SecretRequestEndpoint<>(HttpMethod.DELETE); } @@ -115,14 +114,18 @@ public BalanceResponse getBalance() throws AccountResponseException { } /** + * Obtain pricing data on all supported countries for a specific service type. * * @param service The service type to retrieve pricing and network information for. * - * @return The + * @return The list of pricing information for all supported countries. + * + * @throws AccountResponseException If the pricing data could not be retrieved. + * + * @since v7.9.0 */ public List listPriceAllCountries(ServiceType service) { - Objects.requireNonNull(service, "Service type is required."); - return fullPricing.execute(new FullPricingRequest(service)).getCountries(); + return fullPricing.execute(Objects.requireNonNull(service, "Service type is required.")).countries; } /** @@ -132,8 +135,7 @@ public List listPriceAllCountries(ServiceType service) { * * @return PricingResponse object which contains the results from the API. * - * @throws VonageResponseParseException if the response from the API could not be parsed. - * @throws VonageClientException if there was a problem with the Vonage request or response objects. + * @throws AccountResponseException If there was an error making the request or retrieving the response. */ public PricingResponse getVoicePrice(String country) throws AccountResponseException { return pricing.execute(new PricingRequest(country, ServiceType.VOICE)); @@ -146,8 +148,7 @@ public PricingResponse getVoicePrice(String country) throws AccountResponseExcep * * @return PricingResponse object which contains the results from the API. * - * @throws VonageResponseParseException if the response from the API could not be parsed. - * @throws VonageClientException if there was a problem with the Vonage request or response objects. + * @throws AccountResponseException If there was an error making the request or retrieving the response. */ public PricingResponse getSmsPrice(String country) throws AccountResponseException { return pricing.execute(new PricingRequest(country, ServiceType.SMS)); @@ -161,8 +162,7 @@ public PricingResponse getSmsPrice(String country) throws AccountResponseExcepti * * @return PrefixPricingResponse object which contains the results from the API. * - * @throws VonageResponseParseException if the response from the API could not be parsed. - * @throws VonageClientException if there was a problem with the Vonage request or response objects. + * @throws AccountResponseException If there was an error making the request or retrieving the response. */ public PrefixPricingResponse getPrefixPrice(ServiceType type, String prefix) throws AccountResponseException { return prefixPricing.execute(new PrefixPricingRequest(type, prefix)); @@ -174,9 +174,7 @@ public PrefixPricingResponse getPrefixPrice(ServiceType type, String prefix) thr * * @param transaction The ID associated with your original auto-reload transaction * - * @throws VonageResponseParseException if the response from the API could not be parsed. - * @throws VonageClientException if there was a problem with the Vonage request or response object indicating - * that the request was unsuccessful. + * @throws AccountResponseException If there was an error making the request or retrieving the response. */ public void topUp(String transaction) throws AccountResponseException { topUp.execute(new TopUpRequest(transaction)); @@ -202,9 +200,7 @@ public ListSecretsResponse listSecrets() throws AccountResponseException { * * @return ListSecretsResponse object which contains the results from the API. * - * @throws VonageResponseParseException if a network error occurred contacting the Vonage Account API - * @throws VonageClientException if there was a problem with the Vonage request or response object indicating - * that the request was unsuccessful. + * @throws AccountResponseException If there was an error making the request or retrieving the response. */ public ListSecretsResponse listSecrets(String apiKey) throws AccountResponseException { if (apiKey == null || apiKey.trim().isEmpty()) { @@ -236,9 +232,7 @@ public SecretResponse getSecret(String secretId) throws AccountResponseException * * @return SecretResponse object which contains the results from the API. * - * @throws VonageResponseParseException if a network error occurred contacting the Vonage Account API - * @throws VonageClientException if there was a problem with the Vonage request or response object indicating - * that the request was unsuccessful. + * @throws AccountResponseException If there was an error making the request or retrieving the response. */ public SecretResponse getSecret(String apiKey, String secretId) throws AccountResponseException { return getSecret.execute(new SecretRequest(apiKey, secretId)); @@ -267,9 +261,7 @@ public SecretResponse createSecret(String secret) throws AccountResponseExceptio * * @return SecretResponse object which contains the created secret from the API. * - * @throws VonageResponseParseException if a network error occurred contacting the Vonage Account API - * @throws VonageClientException if there was a problem with the Vonage request or response object indicating - * that the request was unsuccessful. + * @throws AccountResponseException If there was an error making the request or retrieving the response. */ public SecretResponse createSecret(String apiKey, String secret) throws AccountResponseException { return createSecret.execute(new CreateSecretRequest(apiKey, secret)); @@ -294,49 +286,52 @@ public void revokeSecret(String secretId) throws AccountResponseException { * @param apiKey The API key that the secret is associated to. * @param secretId The id of the secret to revoke. * - * @throws VonageResponseParseException if a network error occurred contacting the Vonage Account API - * @throws VonageClientException if there was a problem with the Vonage request or response object indicating - * that the request was unsuccessful. + * @throws AccountResponseException If there was an error making the request or retrieving the response. */ public void revokeSecret(String apiKey, String secretId) throws AccountResponseException { revokeSecret.execute(new SecretRequest(apiKey, secretId)); } /** - * @param url The new incoming sms webhook url to associate to your account. + * Updates the account-level incoming SMS URL, as used by the SMS API. + * + * @param url The URL where Vonage will send a webhook when an incoming SMS is received when a + * number-specific URL is not configured. Set to an empty string to unset the value. * * @return A {@link SettingsResponse} containing the newly-updated account settings. * - * @throws VonageResponseParseException if a network error occurred contacting the Vonage Account API - * @throws VonageClientException if there was a problem with the Vonage request or response object indicating - * that the request was unsuccessful. + * @throws AccountResponseException If there was an error making the request or retrieving the response. */ public SettingsResponse updateSmsIncomingUrl(String url) throws AccountResponseException { return updateSettings(SettingsRequest.withIncomingSmsUrl(url)); } /** - * @param url The new delivery receipt webhook url to associate to your account. + * Updates the account-level delivery receipt URL (mainly used by the SMS API). + * + * @param url The URL where Vonage will send a webhook when an incoming SMS is received when a + * number-specific URL is not configured. Set to an empty string to unset the value. * * @return A {@link SettingsResponse} containing the newly-updated account settings. * - * @throws VonageResponseParseException if a network error occurred contacting the Vonage Account API - * @throws VonageClientException if there was a problem with the Vonage request or response object indicating - * that the request was unsuccessful. + * @throws AccountResponseException If there was an error making the request or retrieving the response. */ public SettingsResponse updateDeliveryReceiptUrl(String url) throws AccountResponseException { return updateSettings(SettingsRequest.withDeliveryReceiptUrl(url)); } /** + * Updates the account-level settings. + * * @param request The {@link SettingsRequest} containing the fields to update. * * @return A {@link SettingsResponse} containing the newly-updated account settings. * - * @throws VonageResponseParseException if a network error occurred contacting the Vonage Account API - * @throws VonageClientException if there was a problem with the Vonage request or response object indicating - * that the request was unsuccessful. + * @throws AccountResponseException If there was an error making the request or retrieving the response. + * + * @deprecated Use {@link #updateSmsIncomingUrl(String)} or {@link #updateDeliveryReceiptUrl(String)} instead. */ + @Deprecated public SettingsResponse updateSettings(SettingsRequest request) throws AccountResponseException { return settings.execute(Objects.requireNonNull(request, "Settings request cannot be null.")); } diff --git a/src/main/java/com/vonage/client/account/BalanceResponse.java b/src/main/java/com/vonage/client/account/BalanceResponse.java index 9d3c8bb93..d6e568064 100644 --- a/src/main/java/com/vonage/client/account/BalanceResponse.java +++ b/src/main/java/com/vonage/client/account/BalanceResponse.java @@ -19,22 +19,36 @@ import com.vonage.client.Jsonable; import com.vonage.client.JsonableBaseObject; +/** + * Response data for the {@link AccountClient#getBalance()} method. + */ public class BalanceResponse extends JsonableBaseObject { private double value; private boolean autoReload; protected BalanceResponse() {} + /** + * Account balance in EUR as a double. + * + * @return The balance in Euros. + */ @JsonProperty("value") public double getValue() { return value; } + /** + * Whether balance auto-reloading is enabled. + * + * @return {@code true} if auto-reloading is enabled, {@code false} otherwise. + */ @JsonProperty("autoReload") public boolean isAutoReload() { return autoReload; } + @Deprecated public static BalanceResponse fromJson(String json) { return Jsonable.fromJson(json); } diff --git a/src/main/java/com/vonage/client/account/Country.java b/src/main/java/com/vonage/client/account/Country.java index 629e6aa03..7ae2c209a 100644 --- a/src/main/java/com/vonage/client/account/Country.java +++ b/src/main/java/com/vonage/client/account/Country.java @@ -18,19 +18,37 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.vonage.client.JsonableBaseObject; +/** + * Groups the country details in {@link PricingResponse}. + */ public class Country extends JsonableBaseObject { private String code, displayName, name; + /** + * Two-letter country code. + * + * @return The country code as a string. + */ @JsonProperty("countryCode") public String getCode() { return code; } + /** + * Readable alternate country name. + * + * @return The country display name. + */ @JsonProperty("countryDisplayName") public String getDisplayName() { return displayName; } + /** + * Country name. + * + * @return The country name. + */ @JsonProperty("countryName") public String getName() { return name; diff --git a/src/main/java/com/vonage/client/account/CreateSecretRequest.java b/src/main/java/com/vonage/client/account/CreateSecretRequest.java index 631fe2fd8..7d72f2583 100644 --- a/src/main/java/com/vonage/client/account/CreateSecretRequest.java +++ b/src/main/java/com/vonage/client/account/CreateSecretRequest.java @@ -20,20 +20,11 @@ import com.vonage.client.JsonableBaseObject; class CreateSecretRequest extends JsonableBaseObject { - @JsonIgnore private final String apiKey; - private final String secret; + @JsonIgnore final String apiKey; + @JsonProperty("secret") private final String secret; - public CreateSecretRequest(String apiKey, String secret) { + CreateSecretRequest(String apiKey, String secret) { this.apiKey = apiKey; this.secret = secret; } - - public String getApiKey() { - return apiKey; - } - - @JsonProperty("secret") - public String getSecret() { - return secret; - } } diff --git a/src/main/java/com/vonage/client/account/FullPricingRequest.java b/src/main/java/com/vonage/client/account/FullPricingRequest.java deleted file mode 100644 index 93a19fb55..000000000 --- a/src/main/java/com/vonage/client/account/FullPricingRequest.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * 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.account; - -import java.util.Objects; - -class FullPricingRequest { - private final ServiceType serviceType; - - public FullPricingRequest(ServiceType serviceType) { - this.serviceType = Objects.requireNonNull(serviceType, "Service type cannot be null."); - } - - public ServiceType getServiceType() { - return serviceType; - } -} diff --git a/src/main/java/com/vonage/client/account/FullPricingResponse.java b/src/main/java/com/vonage/client/account/FullPricingResponse.java index 7914a60b6..f19293788 100644 --- a/src/main/java/com/vonage/client/account/FullPricingResponse.java +++ b/src/main/java/com/vonage/client/account/FullPricingResponse.java @@ -24,13 +24,7 @@ * * @since 7.9.0 */ - class FullPricingResponse extends JsonableBaseObject { - private Integer count; - private List countries; - - @JsonProperty("countries") - public List getCountries() { - return countries; - } + @JsonProperty("count") Integer count; + @JsonProperty("countries") List countries; } diff --git a/src/main/java/com/vonage/client/account/ListSecretsResponse.java b/src/main/java/com/vonage/client/account/ListSecretsResponse.java index b18001ae4..74e0632d4 100644 --- a/src/main/java/com/vonage/client/account/ListSecretsResponse.java +++ b/src/main/java/com/vonage/client/account/ListSecretsResponse.java @@ -28,7 +28,9 @@ public class ListSecretsResponse extends HalPageResponse { @JsonProperty("_embedded") private Embedded _embedded; - + @Deprecated + public ListSecretsResponse() {} + private static final class Embedded extends JsonableBaseObject { @JsonProperty("secrets") private List secrets; } diff --git a/src/main/java/com/vonage/client/account/Network.java b/src/main/java/com/vonage/client/account/Network.java index 184442be0..74492901f 100644 --- a/src/main/java/com/vonage/client/account/Network.java +++ b/src/main/java/com/vonage/client/account/Network.java @@ -19,48 +19,97 @@ import com.vonage.client.JsonableBaseObject; import java.math.BigDecimal; +/** + * Represents a network in {@link PricingResponse}. + */ public class Network extends JsonableBaseObject { private Type type; private BigDecimal price; private String currency, mcc, mnc, code, name; + @Deprecated + public Network() { + } + + /** + * Network type. + * + * @return The type of network as an enum. + */ @JsonProperty("type") public Type getType() { return type; } + /** + * Cost to send a message or make a call to this network + * + * @return The network price, or {@code null} if unknown. + */ @JsonProperty("price") public BigDecimal getPrice() { return price; } + /** + * Currency code for the network price. + * + * @return The currency code as a string, or {@code null} if unknown. + */ @JsonProperty("currency") public String getCurrency() { return currency; } + /** + * Mobile Country Code of the operator. + * + * @return The network operator's mobile country code as a string, or {@code null} if unknown. + */ @JsonProperty("mcc") public String getMcc() { return mcc; } + /** + * Mobile Network Code of the operator. + * + * @return The network operator's code as a string, or {@code null} if unknown. + */ @JsonProperty("mnc") public String getMnc() { return mnc; } + /** + * Mobile Country Code and Mobile Network Code combined to give a unique reference for the operator. + * + * @return The network code (MCC and MNC) as a string, or {@code null} if unknown. + */ @JsonProperty("networkCode") public String getCode() { return code; } + /** + * Company/organisational name of the operator. + * + * @return The network operator name, or {@code null} if unknown. + */ @JsonProperty("networkName") public String getName() { return name; } + /** + * Represents the type of network. + */ public enum Type { - MOBILE, LANDLINE, PAGER, LANDLINE_TOLLFREE, UNKNOWN; + MOBILE, + LANDLINE, + @Deprecated PAGER, + LANDLINE_TOLLFREE, + UNKNOWN; @Override @JsonValue @@ -68,6 +117,12 @@ public String toString() { return name().toLowerCase(); } + /** + * Converts a string representation of the network type to an enum. + * + * @param type The network type as a string. + * @return The network type as an enum, or {@link Type#UNKNOWN} if unknown. + */ @JsonCreator public static Type fromString(String type) { try { diff --git a/src/main/java/com/vonage/client/account/PrefixPricingRequest.java b/src/main/java/com/vonage/client/account/PrefixPricingRequest.java index f316ba610..5fe3795a5 100644 --- a/src/main/java/com/vonage/client/account/PrefixPricingRequest.java +++ b/src/main/java/com/vonage/client/account/PrefixPricingRequest.java @@ -21,22 +21,14 @@ import java.util.Objects; class PrefixPricingRequest implements QueryParamsRequest { - private final ServiceType serviceType; - private final String prefix; + final ServiceType serviceType; + final String prefix; public PrefixPricingRequest(ServiceType serviceType, String prefix) { this.serviceType = Objects.requireNonNull(serviceType, "Service type cannot be null."); this.prefix = prefix; } - public ServiceType getServiceType() { - return serviceType; - } - - public String getPrefix() { - return prefix; - } - @Override public Map makeParams() { Map params = new LinkedHashMap<>(2); diff --git a/src/main/java/com/vonage/client/account/PrefixPricingResponse.java b/src/main/java/com/vonage/client/account/PrefixPricingResponse.java index eb3ed8050..7aca05b57 100644 --- a/src/main/java/com/vonage/client/account/PrefixPricingResponse.java +++ b/src/main/java/com/vonage/client/account/PrefixPricingResponse.java @@ -20,6 +20,12 @@ import com.vonage.client.JsonableBaseObject; import java.util.List; +/** + * Wrapper for the response in {@link AccountClient#getPrefixPrice(ServiceType, String)}. + * + * @deprecated This will be removed in favour of returning the list of countries' pricing directly. + */ +@Deprecated public class PrefixPricingResponse extends JsonableBaseObject { private int count; private List countries; diff --git a/src/main/java/com/vonage/client/account/PricingRequest.java b/src/main/java/com/vonage/client/account/PricingRequest.java index 5c5684955..3fff47a03 100644 --- a/src/main/java/com/vonage/client/account/PricingRequest.java +++ b/src/main/java/com/vonage/client/account/PricingRequest.java @@ -20,22 +20,14 @@ import java.util.Map; class PricingRequest implements QueryParamsRequest { - private final String countryCode; - private final ServiceType serviceType; + final String countryCode; + final ServiceType serviceType; - public PricingRequest(String countryCode, ServiceType serviceType) { + PricingRequest(String countryCode, ServiceType serviceType) { this.countryCode = countryCode; this.serviceType = serviceType; } - public String getCountryCode() { - return countryCode; - } - - public String getServiceType() { - return serviceType.toString(); - } - @Override public Map makeParams() { Map params = new LinkedHashMap<>(2); diff --git a/src/main/java/com/vonage/client/account/PricingResponse.java b/src/main/java/com/vonage/client/account/PricingResponse.java index 8a302bb57..f210086fb 100644 --- a/src/main/java/com/vonage/client/account/PricingResponse.java +++ b/src/main/java/com/vonage/client/account/PricingResponse.java @@ -22,6 +22,9 @@ import java.math.BigDecimal; import java.util.List; +/** + * Pricing information for a specific country. + */ public class PricingResponse extends JsonableBaseObject { private String dialingPrefix; private BigDecimal defaultPrice; @@ -29,26 +32,55 @@ public class PricingResponse extends JsonableBaseObject { @JsonUnwrapped private Country country; private List networks; + @Deprecated + public PricingResponse() { + } + + /** + * Dialing prefix for the country. + * + * @return The dialing prefix as a string. + */ @JsonProperty("dialingPrefix") public String getDialingPrefix() { return dialingPrefix; } + /** + * Default price for the country. + * + * @return The default price. + */ @JsonProperty("defaultPrice") public BigDecimal getDefaultPrice() { return defaultPrice; } + /** + * Currency that your account is being billed in (EUR by default). + * + * @return The billing currency code as a string. + */ @JsonProperty("currency") public String getCurrency() { return currency; } + /** + * Details of the country this pricing information is for. + * + * @return The country. + */ @JsonProperty("country") public Country getCountry() { return country; } + /** + * List of supported networks in the country. + * + * @return The list of networks. + */ @JsonProperty("networks") public List getNetworks() { return networks; @@ -59,7 +91,9 @@ public List getNetworks() { * * @param json The JSON string to parse. * @return An instance of this class with the fields populated, if present. + * @deprecated This will be removed in the next major release. */ + @Deprecated public static PricingResponse fromJson(String json) { return Jsonable.fromJson(json); } diff --git a/src/main/java/com/vonage/client/account/SecretRequest.java b/src/main/java/com/vonage/client/account/SecretRequest.java index e12e951cd..e6e458cbd 100644 --- a/src/main/java/com/vonage/client/account/SecretRequest.java +++ b/src/main/java/com/vonage/client/account/SecretRequest.java @@ -16,22 +16,14 @@ package com.vonage.client.account; class SecretRequest { - private final String apiKey, secretId; + final String apiKey, secretId; public SecretRequest(String apiKey, String secretId) { if ((this.apiKey = apiKey) == null || apiKey.trim().isEmpty()) { throw new IllegalArgumentException("API key is required."); } if ((this.secretId = secretId) == null || secretId.trim().isEmpty()) { - throw new IllegalArgumentException("Secret id is required."); + throw new IllegalArgumentException("Secret ID is required."); } } - - public String getApiKey() { - return apiKey; - } - - public String getSecretId() { - return secretId; - } } diff --git a/src/main/java/com/vonage/client/account/SecretResponse.java b/src/main/java/com/vonage/client/account/SecretResponse.java index ed04f5821..50c79336d 100644 --- a/src/main/java/com/vonage/client/account/SecretResponse.java +++ b/src/main/java/com/vonage/client/account/SecretResponse.java @@ -27,11 +27,21 @@ public class SecretResponse extends JsonableBaseObject { private String id; private Instant created; + /** + * ID of the secret. + * + * @return The secret ID as a string. + */ @JsonProperty("id") public String getId() { return id; } + /** + * Time the secret was created. + * + * @return The creation time as an Instant, or {@code null} if unknown. + */ @JsonProperty("created_at") public Instant getCreated() { return created; diff --git a/src/main/java/com/vonage/client/account/ServiceType.java b/src/main/java/com/vonage/client/account/ServiceType.java index 4386b9b2a..13da8e07a 100644 --- a/src/main/java/com/vonage/client/account/ServiceType.java +++ b/src/main/java/com/vonage/client/account/ServiceType.java @@ -15,6 +15,9 @@ */ package com.vonage.client.account; +/** + * Represents the service type for pricing requests. + */ public enum ServiceType { SMS, VOICE, SMS_TRANSIT; diff --git a/src/main/java/com/vonage/client/account/SettingsRequest.java b/src/main/java/com/vonage/client/account/SettingsRequest.java index 0fc83fec6..36bea55a2 100644 --- a/src/main/java/com/vonage/client/account/SettingsRequest.java +++ b/src/main/java/com/vonage/client/account/SettingsRequest.java @@ -15,14 +15,23 @@ */ package com.vonage.client.account; +import com.fasterxml.jackson.annotation.JsonProperty; import com.vonage.client.QueryParamsRequest; import java.util.LinkedHashMap; import java.util.Map; +/** + * Request wrapper for updating account settings. + * + * @deprecated This will be made package-private in the next major release. + */ +@Deprecated public class SettingsRequest implements QueryParamsRequest { private final String incomingSmsUrl, deliveryReceiptUrl; /** + * Constructor. + * * @param incomingSmsUrl The URL where Vonage will send a webhook when an incoming SMS is received when a * number-specific URL is not configured. Set to an empty string to unset the value. * @param deliveryReceiptUrl The URL where Vonage will send a webhook when an incoming SMS is received when a @@ -38,7 +47,9 @@ public SettingsRequest(String incomingSmsUrl, String deliveryReceiptUrl) { * number-specific URL is not configured. Set to an empty string to unset the value. * * @return An SettingsRequest with only the incoming SMS URL set. + * @deprecated This will be removed in the next major release. */ + @Deprecated public static SettingsRequest withIncomingSmsUrl(String incomingSmsUrl) { return new SettingsRequest(incomingSmsUrl, null); } @@ -48,7 +59,9 @@ public static SettingsRequest withIncomingSmsUrl(String incomingSmsUrl) { * number-specific URL is not configured. Set to an empty string to unset the value. * * @return An SettingsRequest with only the delivery receipt URL set. + * @deprecated This will be removed in the next major release. */ + @Deprecated public static SettingsRequest withDeliveryReceiptUrl(String deliveryReceiptUrl) { return new SettingsRequest(null, deliveryReceiptUrl); } @@ -72,8 +85,12 @@ public String getDeliveryReceiptUrl() { @Override public Map makeParams() { Map params = new LinkedHashMap<>(4); - params.put("moCallBackUrl", incomingSmsUrl); - params.put("drCallBackUrl", deliveryReceiptUrl); + if (incomingSmsUrl != null) { + params.put("moCallBackUrl", incomingSmsUrl); + } + if (deliveryReceiptUrl != null) { + params.put("drCallBackUrl", deliveryReceiptUrl); + } return params; } } diff --git a/src/main/java/com/vonage/client/account/SettingsResponse.java b/src/main/java/com/vonage/client/account/SettingsResponse.java index a78a6fc92..4dfdc2710 100644 --- a/src/main/java/com/vonage/client/account/SettingsResponse.java +++ b/src/main/java/com/vonage/client/account/SettingsResponse.java @@ -19,13 +19,21 @@ import com.vonage.client.Jsonable; import com.vonage.client.JsonableBaseObject; +/** + * Details of the configured account settings. + */ public class SettingsResponse extends JsonableBaseObject { - private String incomingSmsUrl,deliveryReceiptUrl; + private String incomingSmsUrl, deliveryReceiptUrl; private Integer maxOutboundMessagesPerSecond, maxInboundMessagesPerSecond, maxApiCallsPerSecond; + @Deprecated + public SettingsResponse() {} + /** - * @return The URL where Vonage will send a webhook when an incoming SMS is received when a number-specific URL is - * not configured. + * URL where Vonage will send a webhook when an incoming SMS is received when a + * number-specific URL is not configured. + * + * @return The default URL for inbound SMS webhooks. */ @JsonProperty("mo-callback-url") public String getIncomingSmsUrl() { @@ -33,8 +41,10 @@ public String getIncomingSmsUrl() { } /** - * @return The URL where Vonage will send a webhook when a delivery receipt is received when a number-specific URL is - * not configured. + * URL where Vonage will send a webhook when a delivery receipt is received when a + * number-specific URL is not configured. + * + * @return The default URL for delivery receipt webhooks. */ @JsonProperty("dr-callback-url") public String getDeliveryReceiptUrl() { @@ -42,7 +52,9 @@ public String getDeliveryReceiptUrl() { } /** - * @return The maximum number of outbound messages per second. + * Maximum number of outbound messages per second for the account. + * + * @return The maximum number of messages that can be sent per second. */ @JsonProperty("max-outbound-request") public Integer getMaxOutboundMessagesPerSecond() { @@ -50,7 +62,9 @@ public Integer getMaxOutboundMessagesPerSecond() { } /** - * @return The maximum number of inbound messages per second. + * Maximum number of inbound messages per second for the account. + * + * @return The maximum number of messages that can be received per second. */ @JsonProperty("max-inbound-request") public Integer getMaxInboundMessagesPerSecond() { @@ -58,7 +72,9 @@ public Integer getMaxInboundMessagesPerSecond() { } /** - * @return The maximum number of API calls per second. + * Maximum number of API calls per second for the account. + * + * @return The maximum number of API calls that can be made per second. */ @JsonProperty("max-calls-per-second") public Integer getMaxApiCallsPerSecond() { diff --git a/src/main/java/com/vonage/client/account/TopUpRequest.java b/src/main/java/com/vonage/client/account/TopUpRequest.java index a296cc50e..e13c2614d 100644 --- a/src/main/java/com/vonage/client/account/TopUpRequest.java +++ b/src/main/java/com/vonage/client/account/TopUpRequest.java @@ -20,7 +20,7 @@ import java.util.Map; class TopUpRequest implements QueryParamsRequest { - private final String trx; + final String trx; public TopUpRequest(String trx) { if ((this.trx = trx) == null || trx.trim().isEmpty()) { @@ -28,10 +28,6 @@ public TopUpRequest(String trx) { } } - public String getTrx() { - return trx; - } - @Override public Map makeParams() { Map params = new LinkedHashMap<>(2); diff --git a/src/main/java/com/vonage/client/video/ConnectRequest.java b/src/main/java/com/vonage/client/video/ConnectRequest.java index b766de48d..7a7ac3b53 100644 --- a/src/main/java/com/vonage/client/video/ConnectRequest.java +++ b/src/main/java/com/vonage/client/video/ConnectRequest.java @@ -160,9 +160,9 @@ public Builder audioRate(Websocket.AudioRate audioRate) { } /** - * Builds the StartCaptionsRequest object. + * Builds the ConnectRequest object. * - * @return The StartCaptionsRequest object with this builder's settings. + * @return The ConnectRequest object with this builder's settings. */ @Override public ConnectRequest build() { diff --git a/src/test/java/com/vonage/client/account/AccountClientTest.java b/src/test/java/com/vonage/client/account/AccountClientTest.java index 5fd329c78..71a643228 100644 --- a/src/test/java/com/vonage/client/account/AccountClientTest.java +++ b/src/test/java/com/vonage/client/account/AccountClientTest.java @@ -618,7 +618,7 @@ protected TopUpRequest sampleRequest() { @Override protected Map sampleQueryParams() { - return Collections.singletonMap("trx", sampleRequest().getTrx()); + return Collections.singletonMap("trx", sampleRequest().trx); } } .runTests(); @@ -637,7 +637,7 @@ protected RestEndpoint endpoint() { @Override protected String expectedEndpointUri(PricingRequest request) { - return "/account/get-pricing/outbound/" + request.getServiceType(); + return "/account/get-pricing/outbound/sms"; } @Override @@ -647,13 +647,7 @@ protected PricingRequest sampleRequest() { @Override protected Map sampleQueryParams() { - PricingRequest request = sampleRequest(); - assertEquals("de", request.getCountryCode()); - assertEquals("sms", request.getServiceType()); - - Map params = new LinkedHashMap<>(); - params.put("country", request.getCountryCode()); - return params; + return Map.of("country", "de"); } } .runTests(); @@ -661,23 +655,21 @@ protected Map sampleQueryParams() { @Test public void testFullPricingEndpoint() throws Exception { - new AccountEndpointTestSpec() { + new AccountEndpointTestSpec() { @Override - protected RestEndpoint endpoint() { + protected RestEndpoint endpoint() { return client.fullPricing; } @Override - protected String expectedEndpointUri(FullPricingRequest request) { - return "/account/get-full-pricing/outbound/" + request.getServiceType(); + protected String expectedEndpointUri(ServiceType request) { + return "/account/get-full-pricing/outbound/sms-transit"; } @Override - protected FullPricingRequest sampleRequest() { - FullPricingRequest request = new FullPricingRequest(ServiceType.SMS_TRANSIT); - assertEquals("sms-transit", request.getServiceType().toString()); - return request; + protected ServiceType sampleRequest() { + return ServiceType.SMS_TRANSIT; } } .runTests(); @@ -694,7 +686,7 @@ protected RestEndpoint endpoint() { @Override protected String expectedEndpointUri(PrefixPricingRequest request) { - return "/account/get-prefix-pricing/outbound/" + request.getServiceType(); + return "/account/get-prefix-pricing/outbound/voice"; } @Override @@ -705,11 +697,8 @@ protected PrefixPricingRequest sampleRequest() { @Override protected Map sampleQueryParams() { PrefixPricingRequest request = sampleRequest(); - assertEquals("voice", request.getServiceType().toString()); - assertEquals("44", request.getPrefix()); - Map params = new LinkedHashMap<>(); - params.put("prefix", request.getPrefix()); + params.put("prefix", "44"); return params; } } @@ -752,15 +741,9 @@ protected SettingsRequest sampleRequest() { @Override protected Map sampleQueryParams() { - SettingsRequest request = sampleRequest(); - String smsUrl = request.getIncomingSmsUrl(); - String drUrl = request.getDeliveryReceiptUrl(); - assertEquals("https://example.com/inbound-sms", smsUrl); - assertEquals("https://example.com/delivery-receipt", drUrl); - Map params = new LinkedHashMap<>(); - params.put("moCallBackUrl", smsUrl); - params.put("drCallBackUrl", drUrl); + params.put("moCallBackUrl", "https://example.com/inbound-sms"); + params.put("drCallBackUrl", "https://example.com/delivery-receipt"); return params; } } diff --git a/src/test/java/com/vonage/client/account/AccountSecretsEndpointTestSpec.java b/src/test/java/com/vonage/client/account/AccountSecretsEndpointTestSpec.java index 2f0ef8c17..3a56b6b05 100644 --- a/src/test/java/com/vonage/client/account/AccountSecretsEndpointTestSpec.java +++ b/src/test/java/com/vonage/client/account/AccountSecretsEndpointTestSpec.java @@ -37,15 +37,15 @@ protected String expectedDefaultBaseUri() { protected String expectedEndpointUri(T request) { String uri = "/accounts/%s/secrets"; if (request instanceof SecretRequest) { - String apiKey = ((SecretRequest) request).getApiKey(); - String secretId = ((SecretRequest) request).getSecretId(); + String apiKey = ((SecretRequest) request).apiKey; + String secretId = ((SecretRequest) request).secretId; uri = String.format(uri, apiKey); if (secretId != null) { uri += "/" + secretId; } } else if (request instanceof CreateSecretRequest) { - uri = String.format(uri, ((CreateSecretRequest) request).getApiKey()); + uri = String.format(uri, ((CreateSecretRequest) request).apiKey); } else if (request instanceof String) { uri = String.format(uri, request);