Channel Groups API for PubNub Ruby SDK

Channel groups allow PubNub developers to bundle thousands of channels into a group that can be identified by a name. These channel groups can then be subscribed to, receiving data from the many back-end channels the channel group contains.

Channel group operations

You can't publish to a channel group. You can only subscribe to it. To publish within the channel group, you need to publish to each channel individually.

Add Channels

Requires Stream Controller add-on

This method requires that the Stream Controller add-on is enabled for your key in the Admin Portal. Read the support page on enabling add-on features on your keys.

This function adds a channel to a channel group.

Method(s)

Adding Channels is accomplished by using the following method(s) in the Ruby SDK:

Maximum number of channels

200 channels can be added to the channel group per API call.

channel_registration(
action: :add,
channels: channels,
channel_groups: channel_groups,
http_sync: http_sync,
callback: callback
)
ParameterTypeRequiredDescription
actionSymbolYesAction that you want to preform, to add, it's :add.
channelsString, SymbolYesThe channels to add to channel groups.
channel_groupsString, SymbolYesThe channel_groups to add channels to.
http_syncBooleanOptionalDefault false. Method will be executed asynchronously and will return future, to get it's value you can use value method. If set to true, method will return array of envelopes (even if there's only one envelope).
For sync methods Envelope object will be returned.
callbackLambda accepting one parameterOptionalCallback that will be called for each envelope.
For async methods future will be returned, to retrieve value Envelope object you have to call value method (thread will be locked until the value is returned).

Basic Usage

Add Channels

# Async without callback
future = pubnub.channel_registration(action: :add, channel: 'my_channel', channel_group: :somegroup)

# Sync without callback
envelopes = pubnub.channel_registration(action: :add, channel: 'my_channel', channel_group: :somegroup, http_sync: true)

# Async with callback (callback can be specified also as :callback key)
future = pubnub.channel_registration(action: :add, channel: 'my_channel', channel_group: :somegroup) {
|envelope| puts envelope.status
}

Response

#<Pubnub::Envelope:0x007fd385096220
@status = {
:code => 200,
:category => :ack,
:error => false,
}
>

List Channels

Requires Stream Controller add-on

This method requires that the Stream Controller add-on is enabled for your key in the Admin Portal. Read the support page on enabling add-on features on your keys.

This function lists all the channels of the channel group.

Method(s)

Listing Channels is accomplished by using the following method(s) in the Ruby SDK:

channel_registration(
action: :get,
channel_group: group,
http_sync: http_sync,
callback: callback
)
ParameterTypeRequiredDescription
actionSymbolYesTo get all channels from a channel groups you need to specify action as :get.
channel_groupsString, SymbolYesChannel groups to fetch the channels of.
http_syncBooleanOptionalDefault false. Method will be executed asynchronously and will return future, to get it's value you can use value method. If set to true, method will return array of envelopes (even if there's only one envelope).
For sync methods Envelope object will be returned.
callbackLambda accepting one parameterOptionalCallback that will be called for each envelope.
For async methods future will be returned, to retrieve value Envelope object you have to call value method (thread will be locked until the value is returned).

Basic Usage

List Channels

pubnub.channel_registration(action: :get, group: 'family') do |envelope|
pp envelope
end

Response

#<Pubnub::Envelope:0x007fd385856cf8
@result = {
:data => {
"channels" => ["ben"],
"group" => "family"
}
}
@status = {
:code => 200
}
>

Remove Channels

Requires Stream Controller add-on

This method requires that the Stream Controller add-on is enabled for your key in the Admin Portal. Read the support page on enabling add-on features on your keys.

This function removes the channels from the channel group.

Method(s)

Removing Channels is accomplished by using the following method(s) in the Ruby SDK:

channel_registration(
action: :remove,
channels: channels,
channel_groups: group,
http_sync: http_sync,
callback: callback
)
ParameterTypeRequiredDescription
actionSymbolYesUse :remove to remove channels.
channelsString, SymbolYesSpecify channels name to remove from channel groups.
channel_groupsString, SymbolYesSpecify channel_groups name to remove channels from.
http_syncBooleanOptionalDefault false. Method will be executed asynchronously and will return future, to get it's value you can use value method. If set to true, method will return array of envelopes (even if there's only one envelope).
For sync methods Envelope object will be returned.
callbackLambda accepting one parameterOptionalCallback that will be called for each envelope.
For async methods future will be returned, to retrieve value Envelope object you have to call value method (thread will be locked until the value is returned).

Basic Usage

Remove channels

pubnub.channel_registration(action: :remove, channel: 'son', group: 'family') do |envelope|
pp envelope
end

Response

#<Pubnub::Envelope:0x007fd385096220
@status = {
:code => 200,
:category => :ack,
:error => false,
}
>

Delete Channel Group

Requires Stream Controller add-on

This method requires that the Stream Controller add-on is enabled for your key in the Admin Portal. Read the support page on enabling add-on features on your keys.

This function removes the channel group.

Method(s)

Deleting Channel Group is accomplished by using the following method(s) in the Ruby SDK:

channel_registration(
action: :remove,
channel_groups: channel_groups,
http_sync: http_sync,
callback: callback
)
ParameterTypeRequiredDescription
actionSymbolYesUse :remove to remove the channel groups.
channel_groupsString, SymbolYesSpecify channel groups name to remove.
http_syncBooleanOptionalDefault false. Method will be executed asynchronously and will return future, to get it's value you can use value method. If set to true, method will return array of envelopes (even if there's only one envelope).
For sync methods Envelope object will be returned.
callbackLambda accepting one parameterOptionalCallback that will be called for each envelope.
For async methods future will be returned, to retrieve value Envelope object you have to call value method (thread will be locked until the value is returned).

Basic Usage

Delete Channel Group

pubnub.channel_registration(action: :remove, channel_group: 'family') do |envelope|
pp envelope
end

Response

#<Pubnub::Envelope:0x007fd385096220
@status = {
:code => 200,
:category => :ack,
:error => false,
}
>
Last updated on