Follow the file release RSS feed...
This is a Public Domain Java library for interacting with the Pushbullet service. It supports both sending and receiving notifications. Thanks to shakethat at github for the insights from his library, which was made for an earlier set of Pushbullet APIs. Thanks to hakan42 at github for getting this library converted and set up for Maven.
The Pushbullet HTTP API identifies seven capabilities, of which jPushbullet2 supports five:
Pushbullet API | Supported in jPushbullet2 | Future Plans |
---|---|---|
/v2/pushes | Yes | |
/v2/devices | Yes | |
/v2/contacts | No | Will explore this later |
/v2/users/me | Yes | |
/v2/upload-request | Yes | |
/v2/oauth2 | No | None |
websocket | Yes |
View the jPushbullet2 javadoc API online, if you like.
This jPushbullet2 library uses a few other libraries, which you will need to add to your classpath/project:
- Google Gson (for converting json text)
- Apache HTTPComponents (for communication with Pushbullet)
- javax.websocket (Tyrus a reference implementation)
- SL4J (for logging)
- Logback (or another logging back end)
So for instance my lib folder has the following files:
- commons-codec-1.6.jar
- commons-logging-1.2.jar
- commons-lang-3.3.2.jar
- fluent-hc-4.3.4.jar
- gson-2.3.jar
- httpclient-4.3.5.jar
- httpclient-cache-4.3.4.jar
- httpcore-4.3.2.jar
- httpmime-4.3.5.jar
- javax.json-1.0.4.jar
- jcl-over-slf4j-1.7.7.jar
- logback-classic-1.1.2.jar
- logback-core-1.1.2.jar
- slf4j-api-1.7.7.jar
- tyrus-standalone-client-1.8.3.jar
Examples
The quickest way to understand the library is to see some examples. These examples and more are included in the source code.
To send a note:
public class SendNote {
public static void main(String[] args) throws PushbulletException{
PushbulletClient client = new PushbulletClient( "ABCD1034...your.key.here...ABCD" );
String result = client.sendNote(null, "My First Push", "Great library. All my devices can see this!");
System.out.println( "Result: " + result );
} // end main
} // end Note
To retrieve, on another thread, all pushes ever sent with this Pushbullet account:
public class GetPushesAsync {
public static void main(String[] args) throws PushbulletException, InterruptedException{
PushbulletClient client = new PushbulletClient( "ABCD1034...your.key.here...ABCD" );
Future fut = client.getPushesAsync(new Callback<List<Push>>() {
@Override
public void completed(List pushes, PushbulletException ex) {
System.out.println( "Number of pushes: " + pushes.size() );
System.out.println("Destination\ttype");
for( Push push : pushes ){
System.out.println(
push.getTarget_device_iden()+ "\t" +
push.getType() );
}
}
});
Thread.sleep(1000);
System.out.println("1 sec has passed. Done yet? " + fut.isDone() );
Thread.sleep(10000);
} // end main
} // end GetPushesAsync
To listen for new incoming pushes and other changes to your Pushbullet account:
public class StartStopWebservice {
public static void main(String[] args) throws PushbulletException, InterruptedException{
if( args.length < 1 ){
System.out.println("Arguments: API_KEY ");
} else {
PushbulletClient client = new PushbulletClient( args[0] );
client.addPushbulletListener(new PushbulletListener(){
@Override
public void pushReceived(PushbulletEvent pushEvent) {
System.out.println("pushReceived PushEvent received: " + pushEvent);
}
@Override
public void devicesChanged(PushbulletEvent pushEvent) {
System.out.println("devicesChanged PushEvent received: " + pushEvent);
}
});
System.out.println("Getting previous pushes to find most recent...");
client.getPushes();
System.out.println("Starting websocket...try sending a push now.");
client.startWebsocket();
// Wait 30 seconds
for( int i = 30; i >= 0; i-- ){
System.out.print(" " + i + " ");
Thread.sleep(1000);
}
System.out.println("Stopping websocket");
client.stopWebsocket();
}
} // end main
} // end StartStopWebservice
A Note About Public Domain
I have released this software into the Public Domain. That means you can do whatever you want with it. Really. You don't have to match it up with any other open source license — just use it. You can rename the files, move the Java packages, whatever you want. If your lawyers say you have to have a license, contact me, and I'll make a special release to you under whatever reasonable license you desire: MIT, BSD, GPL, whatever.
Changes
- v0.3 - Changed to SL4J logging. Switched to Github. Added Maven capability. Fixed "unchecked" warnings with generics. Made binary distro compatible back to Java 1.6.
- v0.2 - Adding paging capability. Changed Push sorting to be newest first in keeping with Pushbullet.com practice. Cleaned up some dependencies.
- v0.1 - Initial release
blog comments powered by Disqus