Skip to content

Commit

Permalink
Merge branch '3.6.0-release'
Browse files Browse the repository at this point in the history
  • Loading branch information
Steve Crow committed Jul 6, 2018
2 parents fffb571 + c0e3424 commit ca331c1
Show file tree
Hide file tree
Showing 42 changed files with 1,724 additions and 73 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.5.0
current_version = 3.6.0
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)(\-(?P<release>[a-z]+))?
serialize =
{major}.{minor}.{patch}
Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ 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.6.0] - 2018-07-06
### Added
- Added `getSmsPrice` to `AccountClient` for getting SMS pricing for a country.
- Added `getVoicePrice` to `AccountClient` for getting voice pricing for a country.
- Added `getPrefixPrice` to `AccountClient` for getting SMS and voice pricing for a prefix.
- Added `topUp` to `AccountClient` for topping up your account which has auto-reload enabled.
- Added `getSms` to `SmsClient` for searching for a single message by id.
- Added `ConversionClient` and the ability to interact with the Nexmo Conversion API.

## [3.5.0] - 2018-05-29
### Changed
- Updated `VerifyClient` to use the JSON endpoints instead of XML.
Expand Down
71 changes: 68 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[![Maven Release](https://maven-badges.herokuapp.com/maven-central/com.nexmo/client/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.nexmo/client)
[![Build Status](https://travis-ci.org/Nexmo/nexmo-java.svg?branch=version-2)](https://travis-ci.org/Nexmo/nexmo-java)
[![codecov](https://codecov.io/gh/Nexmo/nexmo-java/branch/version-2/graph/badge.svg)](https://codecov.io/gh/Nexmo/nexmo-java)
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/9888a9f2ec0d4599a11762e5d946da17)](https://www.codacy.com/app/mark-smith/nexmo-java?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=Nexmo/nexmo-java&amp;utm_campaign=Badge_Grade)
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/0049e762c00b4ce999f45492795ba50a)](https://www.codacy.com/app/cr0wst/nexmo-java?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=Nexmo/nexmo-java&amp;utm_campaign=Badge_Grade)


You can use this Java client library to add [Nexmo's API](#api-coverage) to your application. To use this, you'll
Expand All @@ -28,7 +28,7 @@ repositories {
}
dependencies {
compile 'com.nexmo:client:3.5.0'
compile 'com.nexmo:client:3.6.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.5.0</version>
<version>3.6.0</version>
</dependency>
```

Expand Down Expand Up @@ -189,6 +189,71 @@ When the user enters the code they received, you can check it like this:
client.getVerifyClient().check(ongoingVerify.getRequestId(), CODE)
```

### Get a List of SMS Prices for a Country

Get a list of SMS prices for a country with:

```java
AuthMethod auth = new TokenAuthMethod(API_KEY, API_SECRET);
NexmoClient client = new NexmoClient(auth);
PricingResponse response = client.getAccountClient().getSmsPrice("GB");
System.out.println(response.getDefaultPrice());
```

### Get a List of Voice Prices for a Country

Get a list of voice prices for a country with:

```java
AuthMethod auth = new TokenAuthMethod(API_KEY, API_SECRET);
NexmoClient client = new NexmoClient(auth);
PricingResponse response = client.getAccountClient().getVoicePrice("US");
System.out.println(response.getDefaultPrice());
```

### Get a List of SMS Prices for a Prefix

Get a list of SMS prices for a country with:

```java
AuthMethod auth = new TokenAuthMethod(API_KEY, API_SECRET);
NexmoClient client = new NexmoClient(auth);
PrefixPricingResponse response = client.getAccountClient().getPrefixPrice(ServiceType.SMS, "1");
System.out.println(response.getCountries().get(0).getDefaultPrice());
```

### Get a List of Voice Prices for a Prefix

Get a list of voice prices for a country with:

```java
AuthMethod auth = new TokenAuthMethod(API_KEY, API_SECRET);
NexmoClient client = new NexmoClient(auth);
PrefixPricingResponse response = client.getAccountClient().getPrefixPrice(ServiceType.VOICE, "1");
System.out.println(response.getCountries().get(0).getDefaultPrice());
```

### Top-up Account

Top-up your account that has auto-reload enabled with:
```java
AuthMethod auth = new TokenAuthMethod(API_KEY, API_SECRET);
NexmoClient client = new NexmoClient(auth);
client.getAccountClient().topUp("TRANSACTION_NUMBER");
```

### Submit Conversion

Submit a request to the Conversion API when it has been enabled on your account with:
```java
AuthMethod auth = new TokenAuthMethod(API_KEY, API_SECRET);
NexmoClient client = new NexmoClient(auth);
this.client.submitConversion(ConversionRequest.Type.VOICE,
"MESSAGE-ID",
true,
new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse("2014-03-04 10:11:12"));
```

### Custom HTTP Configuration

If you need to configure the Apache HttpClient used for making requests, you can
Expand Down
18 changes: 15 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import org.gradle.internal.jvm.Jvm

buildscript {
repositories {
jcenter()
if (Jvm.current().javaVersion.toString() == "1.7") {
// Fall back to HTTP because the public Oracle and OpenJDK 1.7 versions don't support TLSv1.2
maven { url "http://jcenter.bintray.com/" }
} else {
jcenter()
}
}
dependencies {
classpath 'com.github.jengelman.gradle.plugins:shadow:1.2.4'
Expand All @@ -18,13 +25,18 @@ apply plugin: 'eclipse'

group = "com.nexmo"
archivesBaseName = "client"
version = "3.5.0"
version = "3.6.0"

sourceCompatibility = "1.7"
targetCompatibility = "1.7"

repositories {
mavenCentral()
if (Jvm.current().javaVersion.toString() == "1.7") {
// Fall back to HTTP because the public Oracle and OpenJDK 1.7 versions don't support TLSv1.2
maven { url "http://repo.maven.apache.org/maven2/" }
} else {
mavenCentral()
}
}

tasks.withType(JavaCompile) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/nexmo/client/HttpWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ protected HttpClient createHttpClient() {

return HttpClientBuilder.create()
.setConnectionManager(connectionManager)
.setUserAgent("nexmo-java/3.5.0")
.setUserAgent("nexmo-java/3.6.0")
.setDefaultRequestConfig(requestConfig)
.build();
}
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/com/nexmo/client/NexmoClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.nexmo.client.auth.AuthMethod;
import com.nexmo.client.auth.JWTAuthMethod;
import com.nexmo.client.auth.NexmoUnacceptableAuthException;
import com.nexmo.client.conversion.ConversionClient;
import com.nexmo.client.insight.InsightClient;
import com.nexmo.client.numbers.NumbersClient;
import com.nexmo.client.sms.SmsClient;
Expand All @@ -53,6 +54,7 @@ public class NexmoClient {
private final VoiceClient voice;
private final VerifyClient verify;
private final SnsClient sns;
private final ConversionClient conversion;

private HttpWrapper httpWrapper;

Expand All @@ -67,6 +69,7 @@ public NexmoClient(AuthMethod... authMethods) {
this.voice = new VoiceClient(this.httpWrapper);
this.sms = new SmsClient(this.httpWrapper);
this.sns = new SnsClient(this.httpWrapper);
this.conversion = new ConversionClient(this.httpWrapper);
}

/**
Expand Down Expand Up @@ -112,6 +115,10 @@ public VoiceClient getVoiceClient() {
return this.voice;
}

public ConversionClient getConversionClient() {
return this.conversion;
}

/**
* Generate a JWT for the application the client has been configured with.
*
Expand Down
78 changes: 77 additions & 1 deletion src/main/java/com/nexmo/client/account/AccountClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
*/
package com.nexmo.client.account;

import com.nexmo.client.AbstractClient;
import com.nexmo.client.HttpWrapper;
import com.nexmo.client.NexmoClient;
import com.nexmo.client.NexmoClientException;
Expand All @@ -31,19 +32,94 @@
* 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()}.
*/
public class AccountClient {
public class AccountClient extends AbstractClient {
protected BalanceEndpoint balance;
protected PricingEndpoint pricing;
protected PrefixPricingEndpoint prefixPricing;
protected TopUpEndpoint topUp;

/**
* Constructor.
*
* @param httpWrapper (required) shared HTTP wrapper object used for making REST calls.
*/
public AccountClient(HttpWrapper httpWrapper) {
super(httpWrapper);

this.balance = new BalanceEndpoint(httpWrapper);
this.pricing = new PricingEndpoint(httpWrapper);
this.prefixPricing = new PrefixPricingEndpoint(httpWrapper);
this.topUp = new TopUpEndpoint(httpWrapper);
}

public BalanceResponse getBalance() throws IOException, NexmoClientException {
return this.balance.execute();
}

/**
* 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.
*/
public PricingResponse getVoicePrice(String country) throws IOException, NexmoClientException {
return getVoicePrice(new PricingRequest(country));
}

private PricingResponse getVoicePrice(PricingRequest pricingRequest) throws IOException, NexmoClientException {
return this.pricing.getPrice(ServiceType.VOICE, pricingRequest);
}

/**
* 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.
*/
public PricingResponse getSmsPrice(String country) throws IOException, NexmoClientException {
return getSmsPrice(new PricingRequest(country));
}

private PricingResponse getSmsPrice(PricingRequest pricingRequest) throws IOException, NexmoClientException {
return this.pricing.getPrice(ServiceType.SMS, pricingRequest);
}

/**
* Retrieve the pricing for a specified prefix.
*
* @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 {
return getPrefixPrice(new PrefixPricingRequest(type, prefix));
}

private PrefixPricingResponse getPrefixPrice(PrefixPricingRequest prefixPricingRequest) throws IOException, NexmoClientException {
return this.prefixPricing.getPrice(prefixPricingRequest);
}

/**
* Top-up your account when you have enabled auto-reload in the dashboard. Amount added is based on your initial
* 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.
*/
public void topUp(String transaction) throws IOException, NexmoClientException {
topUp(new TopUpRequest(transaction));
}

private void topUp(TopUpRequest request) throws IOException, NexmoClientException {
this.topUp.topUp(request);
}
}
47 changes: 47 additions & 0 deletions src/main/java/com/nexmo/client/account/Country.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright (c) 2011-2018 Nexmo Inc
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.nexmo.client.account;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;

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

@JsonProperty("countryCode")
public String getCode() {
return code;
}

@JsonProperty("countryDisplayName")
public String getDisplayName() {
return displayName;
}

@JsonProperty("countryName")
public String getName() {
return name;
}
}
Loading

0 comments on commit ca331c1

Please sign in to comment.