Native Java SDK for Trolley
Add this dependency to your project's POM:
<dependency>
<groupId>com.trolley</groupId>
<artifactId>java-sdk</artifactId>
<version>2.1.1</version>
</dependency>The library's source is hosted at https://github.com/Trolley/java-sdk
The library can be found at: https://central.sonatype.com/artifact/com.trolley/java-sdk/
import com.trolley.java-sdk.*;
import com.trolley.Exceptions.*;
public class TrolleyExample {
public static void main(String[] args) {
Configuration config = new Configuration("<YOUR_ACCESS_KEY>","<YOUR_SECRET_KEY>");
// Provide your custom HttpClient
// Configuration config = new Configuration("<YOUR_ACCESS_KEY>","<YOUR_SECRET_KEY>", customHttpClient);
Gateway client = new Gateway(config);
try {
Recipient recipient = client.recipient.find("R-1a2B3c4D5e6F7g8H9i0J1k");
System.out.println(recipient.getId());
} catch (Exception e) {
e.printStackTrace();
}
}
}If you are running from source and want to provide custom base url for the SDK to use (e.g. using a mock server temporarily), you will have to do the following:
- Create a file named
.envin the SDK source's root - Add a parameter in the env file:
BASE_URL=https://localhost:3000- While creating the
Configurationobject, pass a third parameter"development"so the constructor can look for theBASE_URLin the.envfile:
Configuration config = new Configuration("ACCESS_KEY","SECRET_KEY", "development")
Gateway client = new Gateway(config);A sample .env file is provided in the project rood named .env.example.
Methods should all have Java Doc comments to help you understand their usage.
For more code samples, refer to our documentation on https://docs.trolley.com
Limited Javadocs are available too.