Class PusherAbstract<T>
- Type Parameters:
T
- The return type of the IO calls. SeePusher
for the synchronous implementation,PusherAsync
for the asynchronous implementation.
- Direct Known Subclasses:
Pusher
,PusherAsync
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionPusherAbstract
(String url) PusherAbstract
(String appId, String key, String secret) Construct an instance of the Pusher object through which you may interact with the Pusher API.PusherAbstract
(String appId, String key, String secret, String encryptionMasterKeyBase64) Construct an instance of the Pusher object through which you may interact with the Pusher API. -
Method Summary
Modifier and TypeMethodDescriptionauthenticate
(String socketId, String channel) Generate authentication response to authorise a user on a private channelauthenticate
(String socketId, String channel, PresenceUser user) Generate authentication response to authorise a user on a presence channelprotected abstract T
protected abstract T
Make a generic HTTP call to the Pusher API.Make a generic HTTP call to the Pusher API.Make a generic HTTP call to the Pusher API.protected String
This method provides an override point if the default Gson based serialisation is absolutely unsuitable for your use case, even with customisation of the Gson instance doing the serialisation.void
setCluster
(String cluster) For Specifying an alternative cluster.protected void
setCryptoUtil
(CryptoUtil crypto) void
setDataMarshaller
(DataMarshaller marshaller) Set a custom marshaller used to serialize Objects passed totrigger(List, String, Object)
and friends.void
setEncrypted
(boolean encrypted) Set whether to use a secure connection to the API (SSL).void
setGsonSerialiser
(com.google.gson.Gson gson) Set the Gson instance used to marshal Objects passed totrigger(List, String, Object)
Set the marshaller used to serialize Objects passed totrigger(List, String, Object)
and friends.void
For testing or specifying an alternative cluster.If you wanted to send the HTTP API requests manually (e.g.If you wanted to send the HTTP API requests manually (e.g.Publish a message to a single channel.Publish a message to a single channel, excluding the specified socketId from receiving the message.Publish a batch of different events with a single API call.Publish identical messages to multiple channels.Publish identical messages to multiple channels, excluding the specified socketId from receiving the message.validateWebhookSignature
(String xPusherKeyHeader, String xPusherSignatureHeader, String body) Check the signature on a webhook received from Pusher
-
Field Details
-
BODY_SERIALISER
-
appId
-
key
-
secret
-
host
-
scheme
-
-
Constructor Details
-
PusherAbstract
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.
-
PusherAbstract
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.
-
PusherAbstract
-
-
Method Details
-
setCryptoUtil
-
setHost
For testing or specifying an alternative cluster. See alsosetCluster(String)
for the latter.Default: api.pusherapp.com
- Parameters:
host
- the API endpoint host
-
setCluster
For Specifying an alternative cluster.See also
setHost(String)
for targetting an arbitrary endpoint.- Parameters:
cluster
- the Pusher cluster to target
-
setEncrypted
Set whether to use a secure connection to the API (SSL).Authentication is secure even without this option, requests cannot be faked or replayed with access to their plain text, a secure connection is only required if the requests or responses contain sensitive information.
Default: false
- Parameters:
encrypted
- whether to use SSL to contact the API
-
setGsonSerialiser
Set the Gson instance used to marshal Objects passed totrigger(List, String, Object)
Set the marshaller used to serialize Objects passed totrigger(List, String, Object)
and friends. By default, the library marshals the objects provided to JSON using the Gson library (see https://code.google.com/p/google-gson/ for more details). By providing an instance here, you may exert control over the marshalling, for example choosing how Java property names are mapped on to the field names in the JSON representation, allowing you to match the expected scheme on the client side. We added thesetDataMarshaller(DataMarshaller)
method to allow specification of other marshalling libraries. This method was kept around to maintain backwards compatibility.- Parameters:
gson
- a GSON instance configured to your liking
-
setDataMarshaller
Set a custom marshaller used to serialize Objects passed totrigger(List, String, Object)
and friends.By default, the library marshals the objects provided to JSON using the Gson library (see https://code.google.com/p/google-gson/ for more details). By providing an instance here, you may exert control over the marshalling, for example choosing how Java property names are mapped on to the field names in the JSON representation, allowing you to match the expected scheme on the client side.
- Parameters:
marshaller
- a DataMarshaller instance configured to your liking
-
serialise
This method provides an override point if the default Gson based serialisation is absolutely unsuitable for your use case, even with customisation of the Gson instance doing the serialisation.For example, in the simplest case, you might already have your data pre-serialised and simply want to elide the default serialisation:
Pusher pusher = new Pusher(appId, key, secret) { protected String serialise(final Object data) { return (String)data; } }; pusher.trigger("my-channel", "my-event", "{\"my-data\":\"my-value\"}");
- Parameters:
data
- an unserialised event payload- Returns:
- a serialised event payload
-
trigger
Publish a message to a single channel.The message data should be a POJO, which will be serialised to JSON for submission. Use
setDataMarshaller(DataMarshaller)
to control the serialisationNote that if you do not wish to create classes specifically for the purpose of specifying the message payload, use Map<String, Object>. These maps will nest just fine.
- Parameters:
channel
- the channel name on which to trigger the eventeventName
- the name given to the eventdata
- an object which will be serialised to create the event body- Returns:
- a
Result
object encapsulating the success state and response to the request
-
trigger
Publish identical messages to multiple channels.- Parameters:
channels
- the channel names on which to trigger the eventeventName
- the name given to the eventdata
- an object which will be serialised to create the event body- Returns:
- a
Result
object encapsulating the success state and response to the request
-
trigger
Publish a message to a single channel, excluding the specified socketId from receiving the message.- Parameters:
channel
- the channel name on which to trigger the eventeventName
- the name given to the eventdata
- an object which will be serialised to create the event bodysocketId
- a socket id which should be excluded from receiving the event- Returns:
- a
Result
object encapsulating the success state and response to the request
-
trigger
Publish identical messages to multiple channels, excluding the specified socketId from receiving the message.- Parameters:
channels
- the channel names on which to trigger the eventeventName
- the name given to the eventdata
- an object which will be serialised to create the event bodysocketId
- a socket id which should be excluded from receiving the event- Returns:
- a
Result
object encapsulating the success state and response to the request
-
trigger
Publish a batch of different events with a single API call.The batch is limited to 10 events on our multi-tenant clusters.
- Parameters:
batch
- a list of events to publish- Returns:
- a
Result
object encapsulating the success state and response to the request
-
get
Make a generic HTTP call to the Pusher API.See: http://pusher.com/docs/rest_api
NOTE: the path specified here is relative to that of your app. For example, to access the channel list for your app, simply pass "/channels". Do not include the "/apps/[appId]" at the beginning of the path.
- Parameters:
path
- the path (e.g. /channels) to query- Returns:
- a
Result
object encapsulating the success state and response to the request
-
get
Make a generic HTTP call to the Pusher API.See: http://pusher.com/docs/rest_api
Parameters should be a map of query parameters for the HTTP call, and may be null if none are required.
NOTE: the path specified here is relative to that of your app. For example, to access the channel list for your app, simply pass "/channels". Do not include the "/apps/[appId]" at the beginning of the path.
- Parameters:
path
- the path (e.g. /channels) to queryparameters
- query parameters to submit with the request- Returns:
- a
Result
object encapsulating the success state and response to the request
-
doGet
-
post
Make a generic HTTP call to the Pusher API.The body should be a UTF-8 encoded String
See: http://pusher.com/docs/rest_api
NOTE: the path specified here is relative to that of your app. For example, to access the channel list for your app, simply pass "/channels". Do not include the "/apps/[appId]" at the beginning of the path.
- Parameters:
path
- the path (e.g. /channels) to submitbody
- the body to submit- Returns:
- a
Result
object encapsulating the success state and response to the request
-
doPost
-
signedUri
If you wanted to send the HTTP API requests manually (e.g. using a different HTTP client), this method will return a java.net.URI which includes all of the appropriate query parameters which sign the request.- Parameters:
method
- the HTTP method, e.g. GET, POSTpath
- the HTTP path, e.g. /channelsbody
- the HTTP request body, if there is one (otherwise pass null)- Returns:
- a URI object which includes the necessary query params for request authentication
-
signedUri
If you wanted to send the HTTP API requests manually (e.g. using a different HTTP client), this method will return a java.net.URI which includes all of the appropriate query parameters which sign the request.Note that any further query parameters you wish to be add must be specified here, as they form part of the signature.
- Parameters:
method
- the HTTP method, e.g. GET, POSTpath
- the HTTP path, e.g. /channelsbody
- the HTTP request body, if there is one (otherwise pass null)parameters
- HTTP query parameters to be included in the request- Returns:
- a URI object which includes the necessary query params for request authentication
-
authenticate
Generate authentication response to authorise a user on a private channelThe return value is the complete body which should be returned to a client requesting authorisation.
- Parameters:
socketId
- the socket id of the connection to authenticatechannel
- the name of the channel which the socket id should be authorised to join- Returns:
- an authentication string, suitable for return to the requesting client
-
authenticate
Generate authentication response to authorise a user on a presence channelThe return value is the complete body which should be returned to a client requesting authorisation.
- Parameters:
socketId
- the socket id of the connection to authenticatechannel
- the name of the channel which the socket id should be authorised to joinuser
- aPresenceUser
object which represents the channel data to be associated with the user- Returns:
- an authentication string, suitable for return to the requesting client
-
validateWebhookSignature
public Validity validateWebhookSignature(String xPusherKeyHeader, String xPusherSignatureHeader, String body) Check the signature on a webhook received from Pusher- Parameters:
xPusherKeyHeader
- the X-Pusher-Key header as received in the webhook requestxPusherSignatureHeader
- the X-Pusher-Signature header as received in the webhook requestbody
- the webhook body- Returns:
- enum representing the possible validities of the webhook request
-