ParticleClient is a java library which provides a client class for interacting with Particle API
See Maven Central
Add dependency to maven pom.xml:
<dependency>
<groupId>io.github.fermi-4</groupId>
<artifactId>particle-client</artifactId>
<version>1.0.3</version>
</dependency>
Create instance using:
ParticleClient client = ParticleClient.builder()
.withToken(token)
.build();
// or optionally provide user/pass for
// endpoints requiring it like the generate token endpoint
ParticleClient client = ParticleClient.builder()
.withUsername(username)
.withPassword(password)
.withToken(token)
.build();
List all device id (parse json using jackson):
// jackson mapper
ObjectMapper mapper = new ObjectMapper();
// get the response (see https://docs.particle.io/reference/cloud-apis/api/)
Response response = client.listDevices();
// parse and print out each id
JsonNode rootNode = mapper.readTree(response.body().string());
for (JsonNode deviceNode : rootNode) {
System.out.println(deviceNode.get("id"));
}
Open a device event stream:
client.openEventStream("temperature", new EventSourceListener() {
@Override
public void onEvent(EventSource eventSource, String id, String type, String data) {
System.out.println("Got temperature event: " + data);
}
});