Skip to content

Commit

Permalink
Merge branch '3.8.0-release'
Browse files Browse the repository at this point in the history
  • Loading branch information
Steve Crow committed Sep 19, 2018
2 parents e50149f + fb9ed50 commit 6331e32
Show file tree
Hide file tree
Showing 51 changed files with 2,343 additions and 63 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[bumpversion]
commit = True
tag = True
current_version = 3.7.0
current_version = 3.8.0
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)(\-(?P<release>[a-z]+))?
serialize =
{major}.{minor}.{patch}
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ nexmo-sdk.jar
publishing
valid_application_key.pem
/.idea
*.iml
*.iml
out/
28 changes: 28 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,34 @@ 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/).

## [3.8.0] - 2018-09-19
### Added
- Added `com.nexmo.client.incoming.MessageEvent` to assist with the deserialization of the JSON payload used for incoming messages.
- Added `com.nexmo.client.incoming.CallEvent` to assist with the deserialization of the JSON payload used for call events.
- Added `com.nexmo.client.incoming.InputEvent` to assist with the deserialization of the JSON payload used for input events.
- Added `com.nexmo.client.incoming.RecordEvent` to assist with the deserialization of the JSON payload used for record events.
- Added secret management methods to `AccountClient` in the form of the following methods:
- `listSecrets` for listing all secrets.
- `getSecret` for getting information on a specific secret.
- `revokeSecret` for revoking a secret.
- `createSecret` for creating a new secret.

### Changed
- User Agent String now includes the Java version in addition to the client version.
- `enum` classes that are used to deserialize JSON have been updated to return an `UNKNOWN` value instead of throwing an `IllegalArgumentException` when the value cannot be deserialized. These `enum`s are:
- `RecordingFormat`
- `MachineDetection`
- `ModifyCallAction`
- `CallDirection`
- `CallStatus`
- `RoamingDetails.RoamingStatus`
- `AdvancedInsightResponse.PortedStatus`
- `AdvancedInsightResponse.Validity`
- `AdvancedInsightResponse.Reachability`

### Fixed
- Updated `StreamNcco`'s `streamUrl` to serialize into an array for use in the Voice API.

## [3.7.0] - 2018-08-10
### Added
- Added `RedactClient` and the ability to interact with the Nexmo Redact API.
Expand Down
46 changes: 44 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ repositories {
}
dependencies {
compile 'com.nexmo:client:3.7.0'
compile 'com.nexmo:client:3.8.0'
}
```

Expand All @@ -40,7 +40,7 @@ Add the following to the correct place in your project's POM file:
<dependency>
<groupId>com.nexmo</groupId>
<artifactId>client</artifactId>
<version>3.7.0</version>
<version>3.8.0</version>
</dependency>
```

Expand Down Expand Up @@ -272,6 +272,48 @@ NexmoClient client = new NexmoClient(auth);
client.getRedactClient().redactTransaction(VOICE_ID, RedactRequest.Product.VOICE);
```

### Create Secret

Create a secret associated to your account id:

```java
AuthMethod auth = new TokenAuthMethod(API_KEY, API_SECRET);
NexmoClient client = new NexmoClient(auth);
SecretResponse response = client.getAccountClient().createSecret(API_KEY, "Foo84RSecret");
```

### List Secrets

List the secret id (but not content) associated to your account id:

```java
AuthMethod auth = new TokenAuthMethod(API_KEY, API_SECRET);
NexmoClient client = new NexmoClient(auth);
ListSecretsResponse response = client.getAccountClient().listSecrets(API_KEY);

Collection<SecretResponse> secrets = response.getSecrets();
```

### Revoke Secret

Revoke a secret associated to your account id:

```java
AuthMethod auth = new TokenAuthMethod(API_KEY, API_SECRET);
NexmoClient client = new NexmoClient(auth);
client.getAccountClient().revokeSecret(API_KEY, SECRET_ID);
```

### Retrieve Secret

Get information about a specific secret associated to your account id:

```java
AuthMethod auth = new TokenAuthMethod(API_KEY, API_SECRET);
NexmoClient client = new NexmoClient(auth);
SecretResponse response = client.getAccountClient().getSecret(API_KEY, SECRET_ID);
```

### Custom HTTP Configuration

If you need to configure the Apache HttpClient used for making requests, you can
Expand Down
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ apply plugin: 'eclipse'

group = "com.nexmo"
archivesBaseName = "client"
version = "3.7.0"
version = "3.8.0"

sourceCompatibility = "1.7"
targetCompatibility = "1.7"
Expand All @@ -52,6 +52,7 @@ dependencies {
compileOnly 'javax.servlet:javax.servlet-api:3.1.0'
compile 'com.fasterxml.jackson.core:jackson-databind:2.9.5'
compile 'com.auth0:java-jwt:2.2.1'
compile 'io.openapitools.jackson.dataformat:jackson-dataformat-hal:1.0.4'

if (Jvm.current().javaVersion.isJava9Compatible()) {
// JAXB API was removed as a default module in JDK9+ this is needed for building/testing in this specific JDK.
Expand Down
15 changes: 11 additions & 4 deletions src/main/java/com/nexmo/client/HttpWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@
* Internal class that holds available authentication methods and a shared HttpClient.
*/
public class HttpWrapper {
private static final String CLIENT_NAME = "nexmo-java";
private static final String CLIENT_VERSION = "3.8.0";
private static final String JAVA_VERSION = System.getProperty("java.version");

private AuthCollection authCollection;
private HttpClient httpClient = null;

Expand Down Expand Up @@ -74,18 +78,21 @@ protected HttpClient createHttpClient() {
PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager();
connectionManager.setDefaultMaxPerRoute(200);
connectionManager.setMaxTotal(200);
connectionManager.setDefaultConnectionConfig(
ConnectionConfig.custom().setCharset(Charset.forName("UTF-8")).build());
connectionManager.setDefaultConnectionConfig(ConnectionConfig
.custom()
.setCharset(Charset.forName("UTF-8"))
.build());
connectionManager.setDefaultSocketConfig(SocketConfig.custom().setTcpNoDelay(true).build());

// Need to work out a good value for the following:
// threadSafeClientConnManager.setValidateAfterInactivity();

RequestConfig requestConfig = RequestConfig.custom().build();

return HttpClientBuilder.create()
return HttpClientBuilder
.create()
.setConnectionManager(connectionManager)
.setUserAgent("nexmo-java/3.7.0")
.setUserAgent(String.format("%s/%s java/%s", CLIENT_NAME, CLIENT_VERSION, JAVA_VERSION))
.setDefaultRequestConfig(requestConfig)
.build();
}
Expand Down
85 changes: 81 additions & 4 deletions src/main/java/com/nexmo/client/account/AccountClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,15 @@
import java.io.IOException;

/**
* A client for talking to the Nexmo Number Insight API. The standard way to obtain an instance of this class is to use
* {@link NexmoClient#getInsightClient()}.
* A client for talking to the Nexmo Account API. The standard way to obtain an instance of this class is to use
* {@link NexmoClient#getAccountClient()} ()}.
*/
public class AccountClient extends AbstractClient {
protected BalanceEndpoint balance;
protected PricingEndpoint pricing;
protected PrefixPricingEndpoint prefixPricing;
protected TopUpEndpoint topUp;
protected SecretManagementEndpoint secret;

/**
* Constructor.
Expand All @@ -50,6 +51,7 @@ public AccountClient(HttpWrapper httpWrapper) {
this.pricing = new PricingEndpoint(httpWrapper);
this.prefixPricing = new PrefixPricingEndpoint(httpWrapper);
this.topUp = new TopUpEndpoint(httpWrapper);
this.secret = new SecretManagementEndpoint(httpWrapper);
}

public BalanceResponse getBalance() throws IOException, NexmoClientException {
Expand All @@ -60,7 +62,9 @@ public BalanceResponse getBalance() throws IOException, NexmoClientException {
* Retrieve the voice pricing for a specified country.
*
* @param country The two-character country code for which you would like to retrieve pricing.
*
* @return PricingResponse object which contains the results from the API.
*
* @throws IOException if a network error occurred contacting the Nexmo Account API.
* @throws NexmoClientException if there was a problem with the Nexmo request or response objects.
*/
Expand All @@ -76,7 +80,9 @@ private PricingResponse getVoicePrice(PricingRequest pricingRequest) throws IOEx
* Retrieve the SMS pricing for a specified country.
*
* @param country The two-character country code for which you would like to retrieve pricing.
*
* @return PricingResponse object which contains the results from the API.
*
* @throws IOException if a network error occurred contacting the Nexmo Account API.
* @throws NexmoClientException if there was a problem with the Nexmo request or response objects.
*/
Expand All @@ -93,12 +99,13 @@ private PricingResponse getSmsPrice(PricingRequest pricingRequest) throws IOExce
*
* @param type The type of service to retrieve pricing for.
* @param prefix The prefix to retrieve the pricing for.
*
* @return PrefixPricingResponse object which contains the results from the API.
*
* @throws IOException if a network error occurred contacting the Nexmo Account API.
* @throws NexmoClientException if there was a problem with the Nexmo request or response objects.
*/
public PrefixPricingResponse getPrefixPrice(ServiceType type,
String prefix) throws IOException, NexmoClientException {
public PrefixPricingResponse getPrefixPrice(ServiceType type, String prefix) throws IOException, NexmoClientException {
return getPrefixPrice(new PrefixPricingRequest(type, prefix));
}

Expand All @@ -111,6 +118,7 @@ private PrefixPricingResponse getPrefixPrice(PrefixPricingRequest prefixPricingR
* reload-enabled payment.
*
* @param transaction The ID associated with your original auto-reload transaction
*
* @throws IOException if a network error occurred contacting the Nexmo Account API.
* @throws NexmoClientException if there was a problem with the Nexmo request or response object indicating that
* the request was unsuccessful.
Expand All @@ -122,4 +130,73 @@ public void topUp(String transaction) throws IOException, NexmoClientException {
private void topUp(TopUpRequest request) throws IOException, NexmoClientException {
this.topUp.topUp(request);
}

/**
* List the ID of each secret associated to the given API key.
*
* @param apiKey The API key to look up secrets for.
*
* @return ListSecretsResponse object which contains the results from the API.
*
* @throws IOException if a network error occurred contacting the Nexmo Account API
* @throws NexmoClientException if there was a problem wit hthe Nexmo request or response object indicating that the request was unsuccessful.
*/
public ListSecretsResponse listSecrets(String apiKey) throws IOException, NexmoClientException {
return this.secret.listSecrets(apiKey);
}

/**
* Get information for a specific secret id associated to a given API key.
*
* @param apiKey The API key that the secret is associated to.
* @param secretId The id of the secret to get information on.
*
* @return SecretResponse object which contains the results from the API.
*
* @throws IOException if a network error occurred contacting the Nexmo Account API
* @throws NexmoClientException if there was a problem wit hthe Nexmo request or response object indicating that the request was unsuccessful.
*/
public SecretResponse getSecret(String apiKey, String secretId) throws IOException, NexmoClientException {
return getSecret(new SecretRequest(apiKey, secretId));
}

private SecretResponse getSecret(SecretRequest secretRequest) throws IOException, NexmoClientException {
return this.secret.getSecret(secretRequest);
}

/**
* Create a secret to be used with a specific API key.
*
* @param apiKey The API key that the secret is to be used with.
* @param secret The contents of the secret.
*
* @return SecretResponse object which contains the created secret from the API.
*
* @throws IOException if a network error occurred contacting the Nexmo Account API
* @throws NexmoClientException if there was a problem wit hthe Nexmo request or response object indicating that the request was unsuccessful.
*/
public SecretResponse createSecret(String apiKey, String secret) throws IOException, NexmoClientException {
return createSecret(new CreateSecretRequest(apiKey, secret));
}

private SecretResponse createSecret(CreateSecretRequest createSecretRequest) throws IOException, NexmoClientException {
return this.secret.createSecret(createSecretRequest);
}

/**
* Revoke a secret associated with a specific API key.
*
* @param apiKey The API key that the secret is associated to.
* @param secretId The id of the secret to revoke.
*
* @throws IOException if a network error occurred contacting the Nexmo Account API
* @throws NexmoClientException if there was a problem wit hthe Nexmo request or response object indicating that the request was unsuccessful.
*/
public void revokeSecret(String apiKey, String secretId) throws IOException, NexmoClientException {
revokeSecret(new SecretRequest(apiKey, secretId));
}

private void revokeSecret(SecretRequest secretRequest) throws IOException, NexmoClientException {
this.secret.revokeSecret(secretRequest);
}
}
Loading

0 comments on commit 6331e32

Please sign in to comment.