We’re very excited to announce that the first snapshot release of v2.0 of the Nexmo Java client library is now available. We're publishing this now because we would like to start capturing your feedback, but it’s important to note that this is a SNAPSHOT release. There are some significant code changes coming soon.
This release adds coverage for the Nexmo Voice API. Under the hood, we’ve added automated testing and are enforcing code quality with tools like Codecov and Codacy. Additionally, we’ve published this library to the Maven Central snapshot repo and now you can install this library with Gradle or Maven!
The library already works with most of the Verification API and some of the SMS API. As we continue to work on the Nexmo Java client we’ll be sure to add more functionality. In the coming weeks and months, you should expect more frequent releases and additional functionality.
It’s also great timing because Mark (@judy2k) and I are headed off to Jfokus where Nexmo is proud to be a sponsor. You can find us at the Nexmo booth chatting with attendees about the newest version of the library and capturing feedback.
We’d Love Your Feedback
While the current beta covers only a few of the Nexmo APIs, it does cover all of those concepts and we really want to know what you think about them. Please create an issue if you have any thoughts or questions.
Please play around with the snapshot and let us know what you think. You can contact us on Twitter or join our community slack
If you’re at Jfokus, please stop by our booth at stand #23. We’ll be giving out swag, Nexmo credit, and an Amazon Echo Dot for the best piece of feedback we receive about the new release.
Include nexmo-java in Your Project
To install the Java client library using Gradle, add the following to build.gradle
:
compile 'com.nexmo:client:2.0.0-SNAPSHOT'
Alternatively, clone the repo and build the JAR yourself:
Vonage API Account
To complete this tutorial, you will need a Vonage API account. If you don’t have one already, you can sign up today and start building with free credit. Once you have an account, you can find your API Key and API Secret at the top of the Vonage API Dashboard.
This tutorial also uses a virtual phone number. To purchase one, go to Numbers > Buy Numbers and search for one that meets your needs.
What Can I Do with the Nexmo Java Client Library?
Like many client libraries that are simple wrappers around an HTTP client, you can pass the client an array of values that match the API’s expected parameters.
Here’s how to initiate an outbound call, which then reads the user a message:
import java.nio.file.Paths;
import com.nexmo.client.auth.JWTAuthMethod;
import com.nexmo.client.voice.NexmoClient;
import com.nexmo.client.voice.Call;
JWTAuthMethod auth = new JWTAuthMethod(application_id, Paths.get("application_key.pem"));
NexmoClient client = new NexmoClient(auth);
Call call = new Call(to, from,
"https://nexmo-community.github.io/ncco-examples/first_call_talk.json");
CallEvent event = client.getVoiceClient().createCall(call);
After the call is answered, you can get more information about it -- including the amount it cost -- with:
CallRecord info = client.getVoiceClient().getCallDetails(event.getUuid());
System.out.println("This cost: " + info.getPrice() + " EUR");
You can modify an existing call in progress, for example by streaming an audio file to an active call:
StreamResponse startStreamResponse = client.getVoiceClient().startStream(event.getUuid(), "https://nexmo-community.github.io/ncco-examples/assets/voice_api_audio_streaming.mp3");
System.out.println("Success! " + startStreamResponse.getMessage());
For more examples, please check out the README
Jfokus
If you’re at Jfokus, swing by our booth and say hi! Mark (@judy2k) and I (@speaktochris) would be happy to chat. You might even get some swag :)