Skip to content

ringcentral/ringcentral-java

Repository files navigation

RingCentral SDK for Java

Build Status Coverage Status Reference Chat Twitter

RingCentral Developers is a cloud communications platform which can be accessed via more than 70 APIs. The platform's main capabilities include technologies that enable:

Additional resources

  • RingCentral API Reference - an interactive reference for the RingCentral API that allows developers to make API calls with no code.
  • Document - an interactive reference for the SDK code documentation.

Getting help and support

If you are having difficulty using this SDK, or working with the RingCentral API, please visit our developer community forums for help and to get quick answers to your questions. If you wish to contact the RingCentral Developer Support team directly, please submit a help ticket from our developer website.

Installation

This SDK is tested against JDK 11 so we recommend using the same. Earlier versions such as Java 8 should work as well, please report issues if you encounter any.

Gradle

repositories {
  mavenCentral()
}

dependencies {
  implementation 'com.ringcentral:ringcentral:[version]'
}

Don't forget to replace [version] with expected version. You can find the latest versions in Maven Central.

Maven

<dependency>
  <groupId>com.ringcentral</groupId>
  <artifactId>ringcentral</artifactId>
  <version>[version]</version>
</dependency>

Don't forget to replace [version] with expected version. You can find the latest versions in Maven Central.

Manually

Download jar here and save it into your java classpath.

Usage

Initialization & Authorization Using jwtToken

RestClient rc = new RestClient(clientId, clientSecret, server);
rc.authorize(jwtToken);

// do something with `rc`

rc.revoke();

Below are some pointers which help to understand the JWT authorization flow

For the server parameter, there are two static final string variables in RestClient:

public static final String PRODUCTION_SERVER = "https://platform.ringcentral.com";

What is a Client ID and Client Secret used for?

Each app you build must first be registered in the RingCentral Developer Console. Upon doing so, you will receive a Client ID and Client Secret that together uniquely identify your application on our platform. A public app could be used by many companies while a private app can only be used by your current company.

Token refresh

Since 1.0 version, the SDK by default does NOT do auto token refresh. This is because most of the time it's better to manage token lifecycle manually: rc.refresh().

For simple apps, token auto refresh could be beneficial. So we provide a sugar method: rc.autoRefresh(). This method will start a background timer to refresh token for you every 30 minutes. You can customize the refresh period, for example, change it to every 50 minutes: rc.autoRefresh(1000 * 60 * 50).

Code samples

You can find sample code for all the endpoints.

There is also lots of useful code for your reference in our test cases.

Logging

The logging is implemented according to Java Logging Overview

To enable printing log to the console:

RestClient.logger.setLevel(Level.FINE);

For more log output channels, please refer to Handlers .

Demo project.

Binary content downloading

Some sample code for binary content downloading may not work.

Because RingCentral is gradually migrating binary content to CDN such as media.ringcentral.com.

For example, to download the attachment of a fax:

// `message` is the fax message object
byte[] content = rc.get<byte[]>(message.attachments[0].uri).bytes();

The following does NOT work:

// `message` is the fax message object
byte[] content = rc.restapi().account().extension().messageStore(message.id).content(message.attachments[0].id).get();

Rule of thumb

But not all binary content has been migrated to CDN. If the resource to download provides you with a CDN uri, use that CDN uri. If there is no CDN uri provided, construct the uri as the sample code shows.

Subscriptions & notifications

WebSocket

Please refer to the RingCentral WebSocket SDK for Java project.

(Deprecated) PubNub

Please refer to the RingCentral PubNub SDK for Java project.

Release Notes

3.0.0

We have renamed all "glip" to "team-messaging/v1". For example:

rc.restapi().glip()...

becomes

rc.teamMessaging().v1()...