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# Tested with# Installing via gradle# Copy compile 'br.com.gerencianet.gnsdk:gn-api-sdk-java:0.2.2'
Installing via maven# Copy <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:
Copy 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:
Copy ```java
try {
} catch ( GerencianetException e ) {
} catch ( Exception ex ) {
}
For development environment# Instantiate the module passing its Client_Id, Client_Secret and sandbox being equal to true
:
Copy 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:
Copy 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 :
Copy 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:
Copy 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 :
Copy mvn clean test jacoco:report
Running examples# To run some existing examples follow the steps outlined in our Github (gn-api-sdk-java-examples ).