Channel Groups API for PubNub Ruby SDK

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

Learn more about our Channel Groups here.

Channel Group operations

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

Adding 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.

Description

This function adds a channel to a channel group.

Method(s)

Adding Channels is accomplished by using the following method(s) in the Ruby V4 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

Adding 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,
}
>

Listing 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.

Description

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 V4 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

Listing 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
}
>

Removing 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.

Description

This function removes the channels from the channel group.

Method(s)

Removing Channels is accomplished by using the following method(s) in the Ruby V4 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

Removing 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,
}
>

Deleting 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.

Description

This function removes the channel group.

Method(s)

Deleting Channel Group is accomplished by using the following method(s) in the Ruby V4 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

Deleting 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