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
Requires Mobile Push Notifications add-on
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:
1pubnub.add_channels_to_push(
2 push_token: push_token,
3 push_gateway: push_gateway,
4 channel: channel,
5 topic: topic,
6 environment: environment,
7 auth_key: auth_key,
8 http_sync: http_sync,
9 callback: callback
10)
| 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. |
topicType: String | APNs topic (bundle identifier). Required if push_gateway is apns2. |
environmentType: String | APNs environment. Required if push_gateway is apns2. Default: development. Accepted values: development, production. |
auth_keyType: String | Access Manager authorization key (if Access Manager is enabled). |
http_syncType: Boolean | If false, runs asynchronously and returns a Future. If true, returns an array of envelopes (even if one). Default: false. |
callbackType: 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
1require 'pubnub'
2
3def add_device_to_channel(pubnub)
4 # For FCM/GCM
5 pubnub.add_channels_to_push(
6 push_token: 'push_token',
7 push_gateway: 'gcm',
8 channel: 'channel1,channel2'
9 ) do |envelope|
10 if envelope.status[:error]
11 puts "FCM/GCM Error: #{envelope.status[:error]}"
12 else
13 puts "FCM/GCM Success: Device added to channels."
14 end
15 end
show all 47 linesResponse
1#<Pubnub::Envelope
2 @result = {
3 :code => 200,
4 :operation => :add_channels_to_push,
5 :data => [1, "Modified Channels"]
6 },
7 @status = {
8 :code => 200,
9 :category => :ack,
10 :error => false,
11 }
12>
List push notifications channels for a device
Requires Mobile Push Notifications add-on
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:
1pubnub.list_push_provisions(
2 push_token: push_token,
3 push_gateway: push_gateway,
4 topic: topic,
5 environment: environment,
6 auth_key: auth_key,
7 http_sync: http_sync,
8 callback: callback
9)
| Parameter | Description |
|---|---|
push_token *Type: String | Device token. |
push_gateway *Type: String | Backend to use. Accepted values: gcm, apns2. |
topicType: String | APNs topic (bundle identifier). Required if push_gateway is apns2. |
environmentType: String | APNs environment. Required if push_gateway is apns2. Default: development. Accepted values: development, production. |
auth_keyType: String | Access Manager authorization key (if Access Manager is enabled). |
http_syncType: Boolean | If false, runs asynchronously and returns a Future. If true, returns an array of envelopes. Default: false. |
callbackType: Lambda accepting one parameter | Callback for each returned envelope. For async calls, use Future#value. |
Sample code
List channels for device
1# for FCM/GCM
2pubnub.list_push_provisions(
3 push_token: 'push_token',
4 type: 'gcm'
5) do |envelope|
6 puts envelope
7end
8
9# for APNS2
10pubnub.list_push_provisions(
11 push_token: 'push_token',
12 type: 'apns2',
13 topic: 'myapptopic'
14 environment: 'development'
15) do |envelope|
show all 17 linesResponse
1#<Pubnub::Envelope
2 @result = {
3 :code => 200,
4 :operation => :list_push_provisions,
5 :data => ["channel1", "channel2"]
6 },
7 @status = {
8 :code => 200,
9 :category => :ack,
10 :error => false,
11 }
12>
Remove a device from push notifications channels
Requires Mobile Push Notifications add-on
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:
1pubnub.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. |
topicType: String | APNs topic (bundle identifier). Required if push_gateway is apns2. |
environmentType: String | APNs environment. Required if push_gateway is apns2. Default: development. Accepted values: development, production. |
auth_keyType: String | Access Manager authorization key (if Access Manager is enabled). |
http_syncType: Boolean | If false, runs asynchronously and returns a Future. If true, returns an array of envelopes. Default: false. |
callbackType: Lambda accepting one parameter | Callback for each returned envelope. For async calls, use Future#value. |
Sample code
Remove device from channel
1# for FCM/GCM
2pubnub.remove_channels_from_push(
3 push_token: 'push_token',
4 remove: 'channel1,channel2',
5 type: 'gcm'
6) do |envelope|
7 puts envelope
8end
9
10# for APNS2
11pubnub.remove_channels_from_push(
12 push_token: 'push_token',
13 remove: 'channel1,channel2',
14 type: 'apns2',
15 topic: 'myapptopic',
show all 19 linesResponse
1#<Pubnub::Envelope
2 @result = {
3 :code => 200,
4 :operation => :remove_channels_from_push,
5 :data => [1, "Modified Channels"]
6 },
7 @status = {
8 :code => 200,
9 :category => :ack,
10 :error => false,
11 }
12>
Remove a device from all push notifications channels
Requires Mobile Push Notifications add-on
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:
1pubnub.remove_device_from_push(
2 push_token: push_token,
3 push_gateway: push_gateway,
4 topic: topic,
5 environment: environment,
6 auth_key: auth_key,
7 http_sync: http_sync,
8 callback: callback
9)
| Parameter | Description |
|---|---|
push_token *Type: String | Device token. |
push_gateway *Type: String | Backend to use. Accepted values: gcm, apns2. |
topicType: String | APNs topic (bundle identifier). Required if push_gateway is apns2. |
environmentType: String | APNs environment. Required if push_gateway is apns2. Default: development. Accepted values: development, production. |
auth_keyType: String | Access Manager authorization key (if Access Manager is enabled). |
http_syncType: Boolean | If false, runs asynchronously and returns a Future. If true, returns an array of envelopes. Default: false. |
callbackType: Lambda accepting one parameter | Callback for each returned envelope. For async calls, use Future#value. |
Sample code
Remove all mobile push notifications
1# for FCM/GCM
2pubnub.remove_device_from_push(
3 push_token: 'push_token',
4 type: 'gcm'
5) do |envelope|
6 puts envelope
7end
8
9# for APNS2
10pubnub.remove_device_from_push(
11 push_token: 'push_token',
12 type: 'apns2',
13 topic: 'myapptopic'
14 environment: 'development'
15) do |envelope|
show all 17 linesResponse
1#<Pubnub::Envelope
2 @result = {
3 :code => 200,
4 :operation => :remove_device_from_push,
5 :data => [1, "Modified Channels"]
6 },
7 @status = {
8 :code => 200,
9 :category => :ack,
10 :error => false,
11 }
12>