Java

Our API is RESTful and responds in JSON. Gerencianet uses OAuth to provide authorized access to the API. Our NodeJS SDK is already prepared to perform this authentication automatically.

Below, check out the procedures for installing the Gerencianet SDK in Java:


Pre requirements

  • Java >=7.0

Tested with

  • Java 7.0 e 8.0

Installing via gradle

compile 'br.com.gerencianet.gnsdk:gn-api-sdk-java:0.2.2'

Installing via maven

<dependency>
<groupId>br.com.gerencianet.gnsdk</groupId>
<artifactId>gn-api-sdk-java</artifactId>
<version>0.2.2</version>
</dependency>

Starting

Requer o módulo e os pacotes:

import br.com.gerencianet.gnsdk.Gerencianet;
import br.com.gerencianet.gnsdk.exceptions.GerencianetException;

Although the web services responses are in json format, the SDK will convert any server response to a JSONObject or Map <String, Object>. The code must be inside a try-catch and exceptions can be handled as follows:

```java
try {
/* code */
} catch(GerencianetException e) {
/* Gerencianet's api errors will come here */
} catch(Exception ex) {
/* Other errors will come here */
}

For development environment

Instantiate the module passing its Client_Id, Client_Secret and sandbox being equal to true:

JSONObject options = new JSONObject();
options.put("client_id", "client_id");
options.put("client_secret", "client_secret");
options.put("sandbox", true);
Gerencianet gn = new Gerencianet($options);

Ou então:

Map<String, Object> options = new HashMap<String, Object>();
options.put("client_id", "client_id");
options.put("client_secret", "client_secret");
options.put("sandbox", true);
Gerencianet gn = new Gerencianet($options);

For production environment

To change the environment to production, just set the third sandbox to false, and its production Client_Id and Client_Secret:

JSONObject options = new JSONObject();
options.put("client_id", "client_id");
options.put("client_secret", "client_secret");
options.put("sandbox", false);
Gerencianet gn = new Gerencianet($options);

Or else:

Map<String, Object> options = new HashMap<String, Object>();
options.put("client_id", "client_id");
options.put("client_secret", "client_secret");
options.put("sandbox", false);
Gerencianet gn = new Gerencianet($options);

Running tests

To run the test suite with coverage:

mvn clean test jacoco:report

Running examples

To run some existing examples follow the steps outlined in our Github (gn-api-sdk-java-examples).