Class Pusher

All Implemented Interfaces:
AutoCloseable

public class Pusher extends PusherAbstract<Result> implements AutoCloseable
A library for interacting with the Pusher HTTP API.

See http://github.com/pusher/pusher-http-java for an overview

Essentially:

 // Init
 Pusher pusher = new Pusher(APP_ID, KEY, SECRET);
 // Publish
 Result triggerResult = pusher.trigger("my-channel", "my-eventname", myPojoForSerialisation);
 if (triggerResult.getStatus() != Status.SUCCESS) {
   if (triggerResult.getStatus().shouldRetry()) {
     // Temporary, let's schedule a retry
   }
   else {
     // Something is wrong with our request
   }
 }

 // Query
 Result channelListResult = pusher.get("/channels");
 if (channelListResult.getStatus() == Status.SUCCESS) {
   String channelListAsJson = channelListResult.getMessage();
   // etc
 }
 
See PusherAsync for the asynchronous implementation.
  • Constructor Details

    • Pusher

      public Pusher(String appId, String key, String secret)
      Construct an instance of the Pusher object through which you may interact with the Pusher API.

      The parameters to use are found on your dashboard at https://app.pusher.com and are specific per App.

      Parameters:
      appId - The ID of the App you will to interact with.
      key - The App Key, the same key you give to websocket clients to identify your app when they connect to Pusher.
      secret - The App Secret. Used to sign requests to the API, this should be treated as sensitive and not distributed.
    • Pusher

      public Pusher(String appId, String key, String secret, String encryptionMasterKeyBase64)
      Construct an instance of the Pusher object through which you may interact with the Pusher API.

      The parameters to use are found on your dashboard at https://app.pusher.com and are specific per App.

      Parameters:
      appId - The ID of the App you will to interact with.
      key - The App Key, the same key you give to websocket clients to identify your app when they connect to Pusher.
      secret - The App Secret. Used to sign requests to the API, this should be treated as sensitive and not distributed.
      encryptionMasterKeyBase64 - 32 byte key, base64 encoded. This key, along with the channel name, are used to derive per-channel encryption keys.
    • Pusher

      public Pusher(String url)
  • Method Details

    • setRequestTimeout

      public void setRequestTimeout(int requestTimeout)
      Default: 4000
      Parameters:
      requestTimeout - the request timeout in milliseconds
    • defaultHttpClientBuilder

      public static org.apache.http.impl.client.HttpClientBuilder defaultHttpClientBuilder()
      Returns an HttpClientBuilder with the settings used by default applied. You may apply further configuration (for example an HTTP proxy), override existing configuration (for example, the connection manager which handles connection pooling for reuse) and then call configureHttpClient(HttpClientBuilder) to have this configuration applied to all subsequent calls.
      Returns:
      an HttpClientBuilder with the default settings applied
      See Also:
    • configureHttpClient

      public void configureHttpClient(org.apache.http.impl.client.HttpClientBuilder builder)
      Configure the HttpClient instance which will be used for making calls to the Pusher API.

      This method allows almost complete control over all aspects of the HTTP client, including

      • proxy host
      • connection pooling and reuse strategies
      • automatic retry and backoff strategies
      It is strongly recommended that you take the value of defaultHttpClientBuilder() as a base, apply your custom config to that and then pass the builder in here, to ensure that sensible defaults for configuration areas you are not setting explicitly are retained.

      e.g.

       pusher.configureHttpClient(
           Pusher.defaultHttpClientBuilder()
                 .setProxy(new HttpHost("proxy.example.com"))
                 .disableAutomaticRetries()
       );
       
      Parameters:
      builder - an HttpClientBuilder with which to configure the internal HTTP client
      See Also:
    • doGet

      protected Result doGet(URI uri)
      Specified by:
      doGet in class PusherAbstract<Result>
    • doPost

      protected Result doPost(URI uri, String body)
      Specified by:
      doPost in class PusherAbstract<Result>
    • close

      public void close() throws Exception
      Specified by:
      close in interface AutoCloseable
      Throws:
      Exception