Mobile Push Notifications API for Ruby SDK
The Mobile Push Notifications feature connects native PubNub publishing to third-party push services. Supported services include Google Android FCM (Firebase Cloud Messaging) and Apple iOS APNs (Apple Push Notification service).
To learn more, read about Mobile Push Notifications.
Add a device to a push notifications channel
note
Enable Mobile Push Notifications for your key in the Admin Portal. See how to enable add-on features.
Enable mobile push notifications on a set of channels.
Method(s)
Use the following method(s) in the Ruby SDK:
pubnub.add_channels_to_push(
push_token: push_token,
push_gateway: push_gateway,
channel: channel,
topic: topic,
environment: environment,
auth_key: auth_key,
http_sync: http_sync,
callback: callback
)
Parameter | Description |
---|---|
push_token *Type: String | Device token. |
push_gateway *Type: String | Backend to use. Accepted values: gcm , apns2 . |
channel *Type: String | Comma-separated channels to add. |
topic Type: String | APNs topic (bundle identifier). Required if push_gateway is apns2 . |
environment Type: String | APNs environment. Required if push_gateway is apns2 . Default: development . Accepted values: development , production . |
auth_key Type: String | Access Manager authorization key (if Access Manager is enabled). |
http_sync Type: Boolean | If false , runs asynchronously and returns a Future . If true , returns an array of envelopes (even if one). Default: false . |
callback Type: Lambda accepting one parameter | Callback for each returned envelope . For async calls, use Future#value to get the result. |
Sample code
Add device to channel
Reference code
require 'pubnub'
def add_device_to_channel(pubnub)
# For FCM/GCM
pubnub.add_channels_to_push(
push_token: 'push_token',
push_gateway: 'gcm',
channel: 'channel1,channel2'
) do |envelope|
if envelope.status[:error]
puts "FCM/GCM Error: #{envelope.status[:error]}"
else
puts "FCM/GCM Success: Device added to channels."
end
end
show all 47 linesResponse
#<Pubnub::Envelope
@result = {
:code => 200,
:operation => :add_channels_to_push,
:data => [1, "Modified Channels"]
},
@status = {
:code => 200,
:category => :ack,
:error => false,
}
>
List push notifications channels for a device
note
Enable Mobile Push Notifications for your key in the Admin Portal. See how to enable add-on features.
List channels that have push notifications enabled for the specified device token.
Method(s)
Use the following method(s) in the Ruby SDK:
pubnub.list_push_provisions(
push_token: push_token,
push_gateway: push_gateway,
topic: topic,
environment: environment,
auth_key: auth_key,
http_sync: http_sync,
callback: callback
)
Parameter | Description |
---|---|
push_token *Type: String | Device token. |
push_gateway *Type: String | Backend to use. Accepted values: gcm , apns2 . |
topic Type: String | APNs topic (bundle identifier). Required if push_gateway is apns2 . |
environment Type: String | APNs environment. Required if push_gateway is apns2 . Default: development . Accepted values: development , production . |
auth_key Type: String | Access Manager authorization key (if Access Manager is enabled). |
http_sync Type: Boolean | If false , runs asynchronously and returns a Future . If true , returns an array of envelopes. Default: false . |
callback Type: Lambda accepting one parameter | Callback for each returned envelope . For async calls, use Future#value . |
Sample code
List channels for device
# for FCM/GCM
pubnub.list_push_provisions(
push_token: 'push_token',
type: 'gcm'
) do |envelope|
puts envelope
end
# for APNS2
pubnub.list_push_provisions(
push_token: 'push_token',
type: 'apns2',
topic: 'myapptopic'
environment: 'development'
) do |envelope|
show all 17 linesResponse
#<Pubnub::Envelope
@result = {
:code => 200,
:operation => :list_push_provisions,
:data => ["channel1", "channel2"]
},
@status = {
:code => 200,
:category => :ack,
:error => false,
}
>
Remove a device from push notifications channels
note
Enable Mobile Push Notifications for your key in the Admin Portal. See how to enable add-on features.
Disable mobile push notifications on a set of channels.
Method(s)
Use the following method(s) in the Ruby SDK:
pubnub.remove_channels_from_push(push_token: push_token, push_gateway: push_gateway, channel: channel, topic: topic, environment: environment, auth_key: auth_key, http_sync: http_sync, callback: callback)
Parameter | Description |
---|---|
push_token *Type: String | Device token. |
push_gateway *Type: String | Backend to use. Accepted values: gcm , apns2 . |
channel *Type: String | Comma-separated channels to remove. |
topic Type: String | APNs topic (bundle identifier). Required if push_gateway is apns2 . |
environment Type: String | APNs environment. Required if push_gateway is apns2 . Default: development . Accepted values: development , production . |
auth_key Type: String | Access Manager authorization key (if Access Manager is enabled). |
http_sync Type: Boolean | If false , runs asynchronously and returns a Future . If true , returns an array of envelopes. Default: false . |
callback Type: Lambda accepting one parameter | Callback for each returned envelope . For async calls, use Future#value . |
Sample code
Remove device from channel
# for FCM/GCM
pubnub.remove_channels_from_push(
push_token: 'push_token',
remove: 'channel1,channel2',
type: 'gcm'
) do |envelope|
puts envelope
end
# for APNS2
pubnub.remove_channels_from_push(
push_token: 'push_token',
remove: 'channel1,channel2',
type: 'apns2',
topic: 'myapptopic',
show all 19 linesResponse
#<Pubnub::Envelope
@result = {
:code => 200,
:operation => :remove_channels_from_push,
:data => [1, "Modified Channels"]
},
@status = {
:code => 200,
:category => :ack,
:error => false,
}
>
Remove a device from all push notifications channels
note
Enable Mobile Push Notifications for your key in the Admin Portal. See how to enable add-on features.
Disable mobile push notifications from all channels registered with the specified device token.
Method(s)
Use the following method(s) in the Ruby SDK:
pubnub.remove_device_from_push(
push_token: push_token,
push_gateway: push_gateway,
topic: topic,
environment: environment,
auth_key: auth_key,
http_sync: http_sync,
callback: callback
)
Parameter | Description |
---|---|
push_token *Type: String | Device token. |
push_gateway *Type: String | Backend to use. Accepted values: gcm , apns2 . |
topic Type: String | APNs topic (bundle identifier). Required if push_gateway is apns2 . |
environment Type: String | APNs environment. Required if push_gateway is apns2 . Default: development . Accepted values: development , production . |
auth_key Type: String | Access Manager authorization key (if Access Manager is enabled). |
http_sync Type: Boolean | If false , runs asynchronously and returns a Future . If true , returns an array of envelopes. Default: false . |
callback Type: Lambda accepting one parameter | Callback for each returned envelope . For async calls, use Future#value . |
Sample code
Remove all mobile push notifications
# for FCM/GCM
pubnub.remove_device_from_push(
push_token: 'push_token',
type: 'gcm'
) do |envelope|
puts envelope
end
# for APNS2
pubnub.remove_device_from_push(
push_token: 'push_token',
type: 'apns2',
topic: 'myapptopic'
environment: 'development'
) do |envelope|
show all 17 linesResponse
#<Pubnub::Envelope
@result = {
:code => 200,
:operation => :remove_device_from_push,
:data => [1, "Modified Channels"]
},
@status = {
:code => 200,
:category => :ack,
:error => false,
}
>