Push Notifications - Admin
Push Admin object
This object is accessible through client.push.admin and provides:
Push::Admin Properties
The push admin object exposes the following public properties:
device_registrations
The returned DeviceRegistrations object provides functionality for registering, updating, listing and de-registering push devices.
channel_subscriptions
The returned PushChannelSubscriptions object provides functionality for subscribing, listing and unsubscribing individual devices or groups of identified devices to push notifications published on channels.
Methods
publish
Deferrable publish(Hash recipient, Hash data) -> yield
Publishes a push notification directly to a device or group of devices sharing a client identifier. See the push notification direct publishing documentation for more information.
Parameters
| Parameter | Description | Type |
|---|---|---|
| recipient | a Hash containing the push recipient details. See the push notification publish REST API documentation for details on the supported recipient fields | Object |
| data | a Hash containing the push notification data. See the push admin payload structure for details on the supported push payload fields | Object |
| &block | yielded upon success | Block |
Returns
A Deferrable object is returned from the method.
On success, the registered success blocks for the Deferrable and any block provided to the method are yielded to.
Failure to publish the push notification will trigger the errback callback of the Deferrable with an ErrorInfo object with the failure reason.
DeviceRegistrations object
This object is accessible through client.push.admin.device_registrations and provides an API to register new push notification devices, update existing devices, deregister old devices, and retrieve or list devices registered to an app.
Methods
get
Deferrable get(String deviceId) -> yields DeviceDetails
Deferrable get(DeviceDetails device) -> yields DeviceDetails
Obtain the DeviceDetails for a device registered for receiving push registrations matching the deviceId argument, or the id attribute of the provided DeviceDetails object. Requires push-admin permission or push-subscribe permission together with device authentication matching the requested deviceId.
Parameters
| Parameter | Description | Type |
|---|---|---|
| deviceId | the unique device ID String for the requested device | String |
| device | a DeviceDetails object containing at a minimum the deviceId of the requested device | Object |
| &block | yields a DeviceDetails object upon success | Block |
Returns
A Deferrable object is returned from the method.
On success, the registered success blocks for the Deferrable and any block provided to the method yield the device registered for push notifications as a DeviceDetails object.
Failure to retrieve the device will trigger the errback callbacks of the Deferrable with an ErrorInfo object with the failure reason.
list
Deferrable list(Hash params) -> yields PaginatedResult<DeviceDetails>
Retrieve all devices matching the params filter as a paginated list of DeviceDetails objects. Requires push-admin permission.
Parameters
| Parameter | Description | Type |
|---|---|---|
| params | an object containing the query parameters as key value pairs as specified below. | Object |
| &block | yields a PaginatedResult<DeviceDetails> object | Block |
params properties
| Parameter | Description | Type |
|---|---|---|
| :client_id | optional filter to restrict to devices associated with that client identifier. Cannot be used with a :device_id param | String |
| :device_id | optional filter to restrict to devices associated with that device identifier. Cannot be used with a :client_id param | String |
| :limit | maximum number of devices per page to retrieve, up to 1,000 default: 100 | Integer |
Returns
A Deferrable object is returned from the method.
On success, the registered success blocks for the Deferrable and any block provided to the method yield a PaginatedResult that encapsulates an array of DeviceDetails corresponding to the current page of results. PaginatedResult supports pagination using next() and first() methods.
Failure to retrieve the devices will trigger the errback callbacks of the Deferrable with an ErrorInfo object with the failure reason.
save
Deferrable save(DeviceDetails device) -> yields DeviceDetails
Register a new DeviceDetails object, or update an existing DeviceDetails object with the Ably service. Requires push-admin permission or push-subscribe permission together with device authentication matching the requested deviceId.
Parameters
| Parameter | Description | Type |
|---|---|---|
| device | a DeviceDetails object | Object |
| &block | yields the new DeviceDetails object upon success | Block |
Returns
A Deferrable object is returned from the method.
On success, the registered success blocks for the Deferrable and any block provided to the method yield the newly registered or updated device as a DeviceDetails object.
Failure to create or update the device will trigger the errback callbacks of the Deferrable with an ErrorInfo object with the failure reason.
remove
Deferrable remove(String deviceId)
Deferrable remove(DeviceDetails device) -> yield
Remove a device registered for receiving push registrations that matches the deviceId argument, or the id attribute of the provided DeviceDetails object. Requires push-admin permission or push-subscribe permission together with device authentication matching the requested deviceId.
Parameters
| Parameter | Description | Type |
|---|---|---|
| deviceId | the unique device ID String for the device | String |
| device | a DeviceDetails object containing at a minimum the deviceId of the device | Object |
| &block | yields upon success | Block |
Returns
A Deferrable object is returned from the method.
On success, the registered success blocks for the Deferrable and any block provided to the method are yielded to. Note that a request to delete a device that does not exist will result in a successful operation.
Failure to delete the device will trigger the errback callbacks of the Deferrable with an ErrorInfo object with the failure reason.
remove_where
Deferrable remove_where(Hash params) -> yield
Delete all devices matching the params filter. Requires push-admin permission.
Parameters
| Parameter | Description | Type |
|---|---|---|
| params | an object containing the filter parameters as key value pairs as specified below. | Object |
| &block | yields upon success | Block |
params properties
| Parameter | Description | Type |
|---|---|---|
| :client_id | optional filter to restrict to devices associated with that client identifier. Cannot be used with a :device_id param | String |
| :device_id | optional filter to restrict to devices associated with that device identifier. Cannot be used with a :client_id param | String |
Returns
A Deferrable object is returned from the method.
On success, the registered success blocks for the Deferrable and any block provided to the method are yielded to. Note that a request that does match any existing devices will result in a successful operation.
Failure to delete the device will trigger the errback callbacks of the Deferrable with an ErrorInfo object with the failure reason.
PushChannelSubscriptions object
This object is accessible through client.push.admin.channel_subscriptions and provides an API to subscribe a push notification device to a channel ensuring it receives any push notifications published in the future on that channel. Additionally, this object allows these subscriptions to be retrieved, listed, updated or removed.
Methods
list
Deferrable list(Hash params) -> yields PaginatedResult<PushChannelSubscription>
Retrieve all push channel subscriptions that match the provided params filter as a paginated list of PushChannelSubscription objects. Each PushChannelSubscription represents a device or set of devices sharing the same client identifier registered to a channel to receive push notifications.
Parameters
| Parameter | Description | Type |
|---|---|---|
| params | an object containing the query parameters as key value pairs as specified below. | Object |
| &block | yields a PaginatedResult<PushChannelSubscription> object | Block |
params properties
| Parameter | Description | Type |
|---|---|---|
| :channel | filter to restrict to subscriptions associated with that channel | String |
| :client_id | optional filter to restrict to devices associated with that client identifier. Cannot be used with a :device_id param | String |
| :device_id | optional filter to restrict to devices associated with that device identifier. Cannot be used with a :client_id param | String |
| :limit | maximum number of channel subscriptions per page to retrieve, up to 1,000 default: 100 | Integer |
Returns
A Deferrable object is returned from the method.
On success, the registered success blocks for the Deferrable and any block provided to the method yield a PaginatedResult that encapsulates an array of PushChannelSubscription corresponding to the current page of results. PaginatedResult supports pagination using next() and first() methods.
Failure to retrieve the channel subscriptions will trigger the errback callbacks of the Deferrable with an ErrorInfo object with the failure reason.
list_channels
Deferrable list_channels(Hash params) -> yields PaginatedResult<String>
Retrieve a list of channels that have at least one device subscribed to push notifications as a paginated list of channel name String objects. Requires push-admin permission.
Parameters
| Parameter | Description | Type |
|---|---|---|
| params | an object containing the query parameters as key value pairs as specified below. | Object |
| &block | yields a PaginatedResult<String> object | Block |
params properties
| Parameter | Description | Type |
|---|---|---|
| :limit | maximum number of channels per page to retrieve, up to 1,000 default: 100 | Integer |
Returns
A Deferrable object is returned from the method.
On success, the registered success blocks for the Deferrable and any block provided to the method yield a PaginatedResult that encapsulates an array of channel name String values corresponding to the current page of results. PaginatedResult supports pagination using next() and first() methods.
Failure to retrieve the channels will trigger the errback callbacks of the Deferrable with an ErrorInfo object with the failure reason.
save
save(PushChannelSubscription channel_subscription)
Subscribe a device or group of devices sharing a client identifier for push notifications published on a channel.
Parameters
| Parameter | Description | Type |
|---|---|---|
| channel_subscription | a PushChannelSubscription object | Object |
remove
remove(PushChannelSubscription channel_subscription)
Unsubscribe a device or group of devices sharing a client identifier from push notifications on a channel. Requires push-admin permission or, in the case of a subscription associated with a given deviceId, push-subscribe permission together with device authentication matching that deviceId.
Parameters
| Parameter | Description | Type |
|---|---|---|
| channel_subscription | a PushChannelSubscription object | Object |
remove_where
remove_where(Hash params)
Delete all push channel subscriptions matching the params filter. Requires push-admin permission.
Parameters
| Parameter | Description | Type |
|---|---|---|
| params | an object containing the filter parameters as key value pairs as specified below. | Object |
params properties
| Parameter | Description | Type |
|---|---|---|
| :channel | filter to restrict to subscriptions associated with that channel | String |
| :client_id | optional filter to restrict to devices associated with that client identifier. Cannot be used with :device_id param | String |
| :device_id | optional filter to restrict to devices associated with that device identifier. Cannot be used with :client_id param | String |
Related types
Ably::Models::DeviceDetails
A DeviceDetails is a type encapsulating attributes of a device registered for push notifications.
Attributes
| Property | Description | Type |
|---|---|---|
| id | unique identifier for the device generated by the device itself | String |
| client_id | optional trusted client identifier for the device | String |
| form_factor | form factor of the push device. Must be one of phone, tablet, desktop, tv, watch, car or embedded | String |
| metadata | optional metadata object for this device. The metadata for a device may only be set by clients with push-admin privileges | Hash |
| platform | platform of the push device. Must be one of ios or android | String |
| deviceSecret | Secret value for the device. | String |
| push.recipient | push recipient details for this device. See the REST API push publish documentation for more details | Hash |
| push.state | the current state of the push device being either Active, Failing or Failed | String |
| push.error_reason | when the device's state is failing or failed, this attribute contains the reason for the most recent failure | ErrorInfo |
Ably::Models::PushChannel
A PushChannel is a property of a RealtimeChannel or RestChannel. It provides push devices the ability to subscribe and unsubscribe to push notifications on channels.
Methods
subscribeDevice
Subscribe your device to the channel's push notifications.
subscribeClient
Subscribe all devices associated with your device's clientId to the channel's push notifications.
unsubscribeDevice
Unsubscribe your device from the channel's push notifications.
unsubscribeClient
Unsubscribe all devices associated with your device's clientId from the channel's push notifications.
listSubscriptions
Lists push subscriptions on a channel specified by its channel name (channel). These subscriptions can be either be a list of client (clientId) subscriptions, device (deviceId) subscriptions, or if concatFilters is set to true, a list of both. This method requires clients to have the Push Admin capability. For more information, see GET main.realtime.ably.net/push/channelSubscriptions Rest API.
Parameters
| Parameter | Description | Type |
|---|---|---|
| deviceId | a deviceId to filter by | String |
| clientId | a clientId to filter by | String |
| deviceClientId | a client ID associated with a device to filter by | String |
Ably::Models::PushChannelSubscription
An PushChannelSubscription is a type encapsulating the subscription of a device or group of devices sharing a client identifier to a channel in order to receive push notifications.
Attributes
| Property | Description | Type |
|---|---|---|
| channel | the channel that this push notification subscription is associated with | String |
| device_id | the device with this identifier is linked to this channel subscription. When present, client_id is never present | String |
| client_id | devices with this client identifier are included in this channel subscription. When present, device_id is never present | String |
PushChannelSubscription constructors
PushChannelSubscription.for_device
PushChannelSubscription.for_device(String channel, String device_id) -> PushChannelSubscription
A static factory method to create a PushChannelSubscription object for a channel and single device.
Parameters
| Parameter | Description | Type |
|---|---|---|
| channel | channel name linked to this push channel subscription | String |
| device_id | the device with this identifier will be linked with this push channel subscription | String |
Returns
A PushChannelSubscription object
PushChannelSubscription.for_client
PushChannelSubscription.for_client(String channel, String client_id) -> PushChannelSubscription
A static factory method to create a PushChannelSubscription object for a channel and group of devices sharing a client identifier.
Parameters
| Parameter | Description | Type |
|---|---|---|
| channel | channel name linked to this push channel subscription | String |
| client_id | devices with this client identifier are included in the new push channel subscription | String |
Returns
A PushChannelSubscription object
Ably::Models::PaginatedResult
A PaginatedResult is a type that represents a page of results for all message and presence history, stats and REST presence requests. The response from a Ably REST API paginated query is accompanied by metadata that indicates the relative queries available to the PaginatedResult object.
Attributes
| Property | Description | Type |
|---|---|---|
| items | contains the current page of results (for example an Array of Message or PresenceMessage objects for a channel history request) | Array <Message, Presence, Stats> |
Methods
first
PaginatedResult first
Returns a new PaginatedResult for the first page of results. When using the Realtime library, the first method returns a Deferrable and yields a PaginatedResult.
has_next?
Boolean has_next?
Returns true if there are more pages available by calling next and returns false if this page is the last page available.
last?
Boolean last?
Returns true if this page is the last page and returns false if there are more pages available by calling next available.
next
PaginatedResult next
Returns a new PaginatedResult loaded with the next page of results. If there are no further pages, then is returned. When using the Realtime library, the first method returns a Deferrable and yields a PaginatedResult.
Example
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# When using the REST sync library
first_page = channel.history
puts "Page 0 item 0: #{first_page.items[0].data}"
if first_page.has_next?
next_page = first_page.next
puts "Page 1 item 1: #{next_page.items[1].data}"
puts "Last page?: #{next_page.is_last?}"
end
# When using the Realtime EventMachine library
channel.history do |first_page|
puts "Page 0 item 0: #{first_page.items[0].data}"
if first_page.has_next?
first_page.next do |next_page|
puts "Page 1 item 1: #{next_page.items[1].data}"
puts "Last page?: #{next_page.is_last?}"
end
end
end