Skip to content

Commit

Permalink
Minor internal tidy-up for consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
SMadani authored Aug 23, 2022
2 parents 88b3b73 + bcb7f7d commit 35a1236
Show file tree
Hide file tree
Showing 60 changed files with 69 additions and 218 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ dependencies {

testImplementation 'javax.servlet:javax.servlet-api:4.0.1'
testImplementation 'junit:junit:4.13.2'
testImplementation 'org.mockito:mockito-inline:4.6.1'
testImplementation 'org.mockito:mockito-inline:4.7.0'
testImplementation 'org.hamcrest:hamcrest-all:1.3'
testImplementation 'org.springframework:spring-test:5.3.22'
testImplementation 'org.springframework:spring-web:5.3.22'
Expand All @@ -48,7 +48,7 @@ test {
}

javadoc {
/* info for JavaDoc options http://docs.oracle.com/javase/6/docs/technotes/tools/windows/javadoc.html#overviewcomment */
/* info for JavaDoc options https://docs.oracle.com/javase/8/docs/technotes/tools/windows/javadoc.html#overviewcomment */
title "Vonage Java Server SDK"
// uncomment this to use a custom javadoc overview
//options.overview = file("src/main/javadoc/overview.html")
Expand Down
20 changes: 13 additions & 7 deletions src/main/java/com/vonage/client/account/AccountClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,18 @@

/**
* A client for talking to the Vonage Account API. The standard way to obtain an instance of this class is to use {@link
* VonageClient#getAccountClient()} ()}.
* VonageClient#getAccountClient()}.
*/
public class AccountClient {
final BalanceEndpoint balance;
final PricingEndpoint pricing;
final PrefixPricingEndpoint prefixPricing;
final TopUpEndpoint topUp;
final SecretManagementEndpoint secret;
final SettingsEndpoint settings;
final ListSecretsEndpoint listSecrets;
final GetSecretEndpoint getSecret;
final CreateSecretEndpoint createSecret;
final RevokeSecretEndpoint revokeSecret;

/**
* Constructor.
Expand All @@ -39,8 +42,11 @@ public AccountClient(HttpWrapper httpWrapper) {
pricing = new PricingEndpoint(httpWrapper);
prefixPricing = new PrefixPricingEndpoint(httpWrapper);
topUp = new TopUpEndpoint(httpWrapper);
secret = new SecretManagementEndpoint(httpWrapper);
settings = new SettingsEndpoint(httpWrapper);
listSecrets = new ListSecretsEndpoint(httpWrapper);
getSecret = new GetSecretEndpoint(httpWrapper);
createSecret = new CreateSecretEndpoint(httpWrapper);
revokeSecret = new RevokeSecretEndpoint(httpWrapper);
}

public BalanceResponse getBalance() throws VonageResponseParseException, VonageClientException {
Expand Down Expand Up @@ -116,7 +122,7 @@ public void topUp(String transaction) throws VonageResponseParseException, Vonag
* that the request was unsuccessful.
*/
public ListSecretsResponse listSecrets(String apiKey) throws VonageResponseParseException, VonageClientException {
return secret.listSecrets(apiKey);
return listSecrets.execute(apiKey);
}

/**
Expand All @@ -132,7 +138,7 @@ public ListSecretsResponse listSecrets(String apiKey) throws VonageResponseParse
* that the request was unsuccessful.
*/
public SecretResponse getSecret(String apiKey, String secretId) throws VonageResponseParseException, VonageClientException {
return secret.getSecret(new SecretRequest(apiKey, secretId));
return getSecret.execute(new SecretRequest(apiKey, secretId));
}

/**
Expand All @@ -148,7 +154,7 @@ public SecretResponse getSecret(String apiKey, String secretId) throws VonageRes
* that the request was unsuccessful.
*/
public SecretResponse createSecret(String apiKey, String secret) throws VonageResponseParseException, VonageClientException {
return this.secret.createSecret(new CreateSecretRequest(apiKey, secret));
return createSecret.execute(new CreateSecretRequest(apiKey, secret));
}

/**
Expand All @@ -162,7 +168,7 @@ public SecretResponse createSecret(String apiKey, String secret) throws VonageRe
* that the request was unsuccessful.
*/
public void revokeSecret(String apiKey, String secretId) throws VonageResponseParseException, VonageClientException {
secret.revokeSecret(new SecretRequest(apiKey, secretId));
revokeSecret.execute(new SecretRequest(apiKey, secretId));
}

/**
Expand Down
5 changes: 1 addition & 4 deletions src/main/java/com/vonage/client/account/BalanceEndpoint.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@
import java.io.UnsupportedEncodingException;

class BalanceEndpoint extends AbstractMethod<Void, BalanceResponse> {

private static final Class<?>[] ALLOWED_AUTH_METHODS = {TokenAuthMethod.class};

private static final String PATH = "/account/get-balance";

BalanceEndpoint(HttpWrapper httpWrapper) {
Expand All @@ -41,8 +39,7 @@ protected Class<?>[] getAcceptableAuthMethods() {
@Override
public RequestBuilder makeRequest(Void request) throws UnsupportedEncodingException {
String uri = httpWrapper.getHttpConfig().getRestBaseUri() + PATH;
return RequestBuilder.get(uri)
.setHeader("Accept", "application/json");
return RequestBuilder.get(uri).setHeader("Accept", "application/json");
}

public BalanceResponse execute() {
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/com/vonage/client/account/Country.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@

@JsonIgnoreProperties(ignoreUnknown = true)
public class Country {
private String code;
private String displayName;
private String name;
private String code, displayName, name;

@JsonProperty("countryCode")
public String getCode() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@

class CreateSecretEndpoint extends AbstractMethod<CreateSecretRequest, SecretResponse> {
private static final Class<?>[] ALLOWED_AUTH_METHODS = {SignatureAuthMethod.class, TokenAuthMethod.class};

private static final String PATH = "/accounts/%s/secrets";

CreateSecretEndpoint(HttpWrapper httpWrapper) {
Expand Down Expand Up @@ -65,7 +64,6 @@ public SecretResponse parseResponse(HttpResponse response) throws IOException {
if (response.getStatusLine().getStatusCode() != 201) {
throw new VonageBadRequestException(EntityUtils.toString(response.getEntity()));
}

return SecretResponse.fromJson(basicResponseHandler.handleResponse(response));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@
import com.vonage.client.VonageUnexpectedException;

public class CreateSecretRequest {
@JsonIgnore
private String apiKey;
private String secret;
@JsonIgnore private final String apiKey;
private final String secret;

public CreateSecretRequest(String apiKey, String secret) {
this.apiKey = apiKey;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

class FullPricingEndpoint extends AbstractMethod<FullPricingRequest, PricingResponse> {
private static final Class<?>[] ALLOWED_AUTH_METHODS = {TokenAuthMethod.class};

private static final String PATH = "/account/get-full-pricing/outbound/%s";

FullPricingEndpoint(HttpWrapper httpWrapper) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
import java.util.Objects;

public class FullPricingRequest {

private ServiceType serviceType;
private final ServiceType serviceType;

public FullPricingRequest(ServiceType serviceType) {
this.serviceType = Objects.requireNonNull(serviceType, "Service type cannot be null.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@

class GetSecretEndpoint extends AbstractMethod<SecretRequest, SecretResponse> {
private static final Class<?>[] ALLOWED_AUTH_METHODS = {SignatureAuthMethod.class, TokenAuthMethod.class};

private static final String PATH = "/accounts/%s/secrets/%s";

GetSecretEndpoint(HttpWrapper httpWrapper) {
Expand All @@ -43,14 +42,6 @@ protected Class<?>[] getAcceptableAuthMethods() {

@Override
public RequestBuilder makeRequest(SecretRequest secretRequest) throws UnsupportedEncodingException {
if (secretRequest.getApiKey() == null) {
throw new IllegalArgumentException("API key is required.");
}

if (secretRequest.getSecretId() == null) {
throw new IllegalArgumentException("Secret id is required.");
}

String uri = String.format(
httpWrapper.getHttpConfig().getApiBaseUri() + PATH,
secretRequest.getApiKey(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@

class ListSecretsEndpoint extends AbstractMethod<String, ListSecretsResponse> {
private static final Class<?>[] ALLOWED_AUTH_METHODS = {SignatureAuthMethod.class, TokenAuthMethod.class};

private static final String PATH = "/accounts/%s/secrets";

ListSecretsEndpoint(HttpWrapper httpWrapper) {
Expand All @@ -43,21 +42,18 @@ protected Class<?>[] getAcceptableAuthMethods() {

@Override
public RequestBuilder makeRequest(String apiKey) throws UnsupportedEncodingException {
if (apiKey == null) {
if (apiKey == null || apiKey.isEmpty()) {
throw new IllegalArgumentException("API key is required.");
}

String uri = String.format(httpWrapper.getHttpConfig().getApiBaseUri() + PATH, apiKey);
return RequestBuilder.get(uri)
.setHeader("Accept", "application/json");
return RequestBuilder.get(uri).setHeader("Accept", "application/json");
}

@Override
public ListSecretsResponse parseResponse(HttpResponse response) throws IOException {
if (response.getStatusLine().getStatusCode() != 200) {
throw new VonageBadRequestException(EntityUtils.toString(response.getEntity()));
}

return ListSecretsResponse.fromJson(basicResponseHandler.handleResponse(response));
}

Expand Down
6 changes: 1 addition & 5 deletions src/main/java/com/vonage/client/account/Network.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,7 @@
public class Network {
private Type type;
private BigDecimal price;
private String currency;
private String mcc;
private String mnc;
private String code;
private String name;
private String currency, mcc, mnc, code, name;

public Type getType() {
return type;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

class PrefixPricingEndpoint extends AbstractMethod<PrefixPricingRequest, PrefixPricingResponse> {
private static final Class<?>[] ALLOWED_AUTH_METHODS = {TokenAuthMethod.class};

private static final String PATH = "/account/get-prefix-pricing/outbound/%s";

PrefixPricingEndpoint(HttpWrapper httpWrapper) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
import java.util.Objects;

public class PrefixPricingRequest {
private ServiceType serviceType;
private String prefix;
private final ServiceType serviceType;
private final String prefix;

public PrefixPricingRequest(ServiceType serviceType, String prefix) {
this.serviceType = Objects.requireNonNull(serviceType, "Service type cannot be null.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

class PricingEndpoint extends AbstractMethod<PricingRequest, PricingResponse> {
private static final Class<?>[] ALLOWED_AUTH_METHODS = {TokenAuthMethod.class};

private static final String PATH = "/account/get-pricing/outbound/%s";

PricingEndpoint(HttpWrapper httpWrapper) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/vonage/client/account/PricingRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
package com.vonage.client.account;

public class PricingRequest {
private String countryCode;
private ServiceType serviceType;
private final String countryCode;
private final ServiceType serviceType;

public PricingRequest(String countryCode, ServiceType serviceType) {
this.countryCode = countryCode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@

class RevokeSecretEndpoint extends AbstractMethod<SecretRequest, Void> {
private static final Class<?>[] ALLOWED_AUTH_METHODS = {SignatureAuthMethod.class, TokenAuthMethod.class};

private static final String PATH = "/accounts/%s/secrets/%s";

RevokeSecretEndpoint(HttpWrapper httpWrapper) {
Expand All @@ -43,14 +42,6 @@ protected Class<?>[] getAcceptableAuthMethods() {

@Override
public RequestBuilder makeRequest(SecretRequest secretRequest) throws UnsupportedEncodingException {
if (secretRequest.getApiKey() == null) {
throw new IllegalArgumentException("API key is required.");
}

if (secretRequest.getSecretId() == null) {
throw new IllegalArgumentException("Secret id is required.");
}

String uri = String.format(
httpWrapper.getHttpConfig().getApiBaseUri() + PATH,
secretRequest.getApiKey(),
Expand Down

This file was deleted.

11 changes: 7 additions & 4 deletions src/main/java/com/vonage/client/account/SecretRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,15 @@
package com.vonage.client.account;

public class SecretRequest {
private String apiKey;
private String secretId;
private final String apiKey, secretId;

public SecretRequest(String apiKey, String secretId) {
this.apiKey = apiKey;
this.secretId = secretId;
if ((this.apiKey = apiKey) == null || apiKey.isEmpty()) {
throw new IllegalArgumentException("API key is required.");
}
if ((this.secretId = secretId) == null || secretId.isEmpty()) {
throw new IllegalArgumentException("Secret id is required.");
}
}

public String getApiKey() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@

class SettingsEndpoint extends AbstractMethod<SettingsRequest, SettingsResponse> {
private static final Class<?>[] ALLOWED_AUTH_METHODS = {TokenAuthMethod.class};

private static final String PATH = "/account/settings";

SettingsEndpoint(HttpWrapper httpWrapper) {
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/com/vonage/client/account/SettingsRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
package com.vonage.client.account;

public class SettingsRequest {
private String incomingSmsUrl;
private String deliveryReceiptUrl;
private final String incomingSmsUrl, deliveryReceiptUrl;

/**
* @param incomingSmsUrl The URL where Vonage will send a webhook when an incoming SMS is received when a
Expand Down
1 change: 0 additions & 1 deletion src/main/java/com/vonage/client/account/TopUpEndpoint.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@

class TopUpEndpoint extends AbstractMethod<TopUpRequest, Void> {
private static final Class<?>[] ALLOWED_AUTH_METHODS = {TokenAuthMethod.class};

private static final String PATH = "/account/top-up";

TopUpEndpoint(HttpWrapper httpWrapper) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/vonage/client/account/TopUpRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
package com.vonage.client.account;

public class TopUpRequest {
private String trx;
private final String trx;

public TopUpRequest(String trx) {
this.trx = trx;
Expand Down
Loading

0 comments on commit 35a1236

Please sign in to comment.