App Context API for Ruby SDK
App Context provides easy-to-use, serverless storage for user and channel data you need to build innovative, reliable, scalable applications. Use App Context to store metadata about your application users and channels, and their membership associations, without the need to stand up your own databases.
PubNub also triggers events when object data is changed: set, updated, or removed from the database. Making a request to set the same data that already exists doesn't trigger an event. Clients can receive these events in real time and update their front-end application accordingly.
User
Manage UUID metadata: list, fetch, set, and remove. Include only the fields you need to reduce payload size.
Get metadata for all users
Get a paginated list of UUID metadata. Use filters and sorting to narrow results.
Method(s)
To Get All UUID Metadata you can use the following method(s) in the Ruby SDK:
1get_all_uuid_metadata(
2    sort: sort,
3    include: include,
4    filter: filter,
5    start: start,
6    end: end,
7    limit: limit,
8    http_sync: http_sync,
9    callback: callback
10)
| Parameter | Description | 
|---|---|
| sortType: Array Default: n/a | List of criteria (name of field) which should be used for sorting in ascending order. Available options are id,name, andupdated. Useascordescto specify sort direction. | 
| includeType: Object Default: { count: true } | Additional information which should be included in response. Available options: 
 | 
| filterType: String Default: n/a | Expression to filter out results basing on specified criteria. For more details on the supported grammar, check here | 
| startType: String Default: n/a | Random string returned from the server, indicating a specific position in a data set. Used for forward pagination, it fetches the next page, allowing you to continue from where you left off. | 
| endType: String Default: n/a | Random string returned from the server, indicating a specific position in a data set. Used for backward pagination, it fetches the previous page, enabling access to earlier data. Ignored if the startparameter is supplied. | 
| limitType: Integer Default: 100 | Number of objects to return in response. Default is 100, which is also the maximum value. | 
| http_syncType: Boolean Default: false | Method will be executed asynchronouslyand will return future, to get itsvalueyou can usevaluemethod. If set totrue, method will return array of envelopes (even if there's only oneenvelope). ForsyncmethodsEnvelopeobject will be returned. | 
| callbackType: Lambda accepting one parameter Default: n/a | Callbackthat will be called for each envelope. Forasyncmethods future will be returned, to retrievevalueEnvelopeobject you have to callvaluemethod (thread will be locked until thevalueis returned). | 
Sample code
Reference code
1require 'pubnub'
2
3def get_all_uuid_metadata(pubnub)
4  pubnub.get_all_uuid_metadata(
5    limit: 5,
6    include: { custom: true }
7  ) do |envelope|
8    if envelope.status[:error]
9      puts "Error fetching UUID metadata: #{envelope.status[:error]}"
10    else
11      envelope.result[:data][:metadata].each do |uuid_data|
12        puts "UUID: #{uuid_data[:id]}"
13        puts "Name: #{uuid_data[:name]}"
14        puts "Custom: #{uuid_data[:custom]}"
15        puts "Updated: #{uuid_data[:updated]}"
Response
1#<Pubnub::Envelope
2    @result = {
3        :data => {
4            :metadata => [
5                {
6                    :id => "mg",
7                    :name => "magnum",
8                    :externalId => nil,
9                    :profileUrl => nil,
10                    :email => nil,
11                    :custom => { "XXX" => "YYYY" },
12                    :updated => <Date>,
13                    :eTag => "Ad2eyIWXwJzBqAE"
14                }
15            ],
Get user metadata
Fetch metadata for a single UUID. Include the Custom object if you need custom fields.
Method(s)
To Get UUID Metadata you can use the following method(s) in the Ruby SDK:
1get_uuid_metadata(
2    uuid: uuid,
3    include: include,
4    http_sync: http_sync,
5    callback: callback
6)
| Parameter | Description | 
|---|---|
| uuidType: String Default: Client UUID | Identifier for which associated metadatashould be fetched. Default: configured PubNub clientuuid. | 
| includeType: Object Default: { custom: true } | Additional information which should be included in response. Available options: 
 | 
| http_syncType: Boolean Default: false | Method will be executed asynchronouslyand will return future, to get itsvalueyou can usevaluemethod. If set totrue, method will return array of envelopes (even if there's only oneenvelope). ForsyncmethodsEnvelopeobject will be returned. | 
| callbackType: Lambda accepting one parameter Default: n/a | Callbackthat will be called for each envelope. Forasyncmethods future will be returned, to retrievevalueEnvelopeobject you have to callvaluemethod (thread will be locked until thevalueis returned). | 
Sample code
1pubnub.get_uuid_metadata(include: { custom: true }) do |envelope|
2    puts envelope
3end
Response
1#<Pubnub::Envelope
2    @result = {
3        :data => {
4            :id => "mg",
5            :name => "magnum",
6            :externalId => nil,
7            :profileUrl => nil,
8            :email => nil,
9            :custom => { "XXX" => "YYYY" },
10            :updated => <Date>,
11            :eTag => "Ad2eyIWXwJzBqAE"
12        }
13    },
14    @status = {
15        :code => 200
Set user metadata
Create or update metadata for a UUID. Use the eTag (if available in the SDK) to avoid overwriting concurrent updates.
Unsupported partial updates of custom metadata
The value of the custom metadata parameter sent in this method always overwrites the value stored on PubNub servers. If you want to add new custom data to an existing one, you must:
- Get the existing metadata and store it locally.
- Append the new custom metadata to the existing one.
- Set the entire updated custom object.
Set metadata for a UUID in the database, optionally including the custom data object for each.
Method(s)
To Set UUID Metadata you can use the following method(s) in the Ruby SDK:
1set_uuid_metadata(
2    uuid: uuid,
3    metadata: metadata,
4    include: include,
5    http_sync: http_sync,
6    callback: callback
7)
| Parameter | Description | 
|---|---|
| uuidType: String Default: Client UUID | Identifier with which new metadatashould be associated. Default: configured PubNub clientuuid. | 
| metadata*Type: Object Default: n/a | Metadata information which should be associated with UUID. Available options:
 | 
| includeType: Object Default: { custom: true } | Additional information which should be included in response.  Available options: 
 | 
| http_syncType: Boolean Default: false | Method will be executed asynchronouslyand will return future, to get itsvalueyou can usevaluemethod. If set totrue, method will return array of envelopes (even if there's only oneenvelope). ForsyncmethodsEnvelopeobject will be returned. | 
| callbackType: Lambda accepting one parameter Default: n/a | Callbackthat will be called for each envelope. Forasyncmethods future will be returned, to retrievevalueEnvelopeobject you have to callvaluemethod (thread will be locked until thevalueis returned). | 
API limits
To learn about the maximum length of parameters used to set user metadata, refer to REST API docs.
Sample code
1pubnub.set_uuid_metadata(
2    uuid: 'mg',
3    metadata: { name: 'magnum', custom: { XXX: 'YYYY' } },
4    include: { custom: true }
5) do |envelope|
6    puts envelope
7end
Response
1#<Pubnub::Envelope
2    @result = {
3        :data => {
4            :id => "mg",
5            :name => "magnum",
6            :externalId => nil,
7            :profileUrl => nil,
8            :email => nil,
9            :custom => { "XXX" => "YYYY" },
10            :updated => <Date>,
11            :eTag => "Ad2eyIWXwJzBqAE"
12        }
13    },
14    @status = {
15        :code => 200
Remove user metadata
Delete metadata for the specified UUID.
Method(s)
To Remove UUID Metadata you can use the following method(s) in the Ruby SDK:
1remove_uuid_metadata(
2    uuid: uuid,
3    http_sync: http_sync,
4    callback: callback
5)
| Parameter | Description | 
|---|---|
| uuidType: String Default: Client UUID | Identifier for which associated metadatashould be removed. Default: configured PubNub clientuuid. | 
| http_syncType: Boolean Default: false | Method will be executed asynchronouslyand will return future, to get itsvalueyou can usevaluemethod. If set totrue, method will return array of envelopes (even if there's only oneenvelope). ForsyncmethodsEnvelopeobject will be returned. | 
| callbackType: Lambda accepting one parameter Default: n/a | Callbackthat will be called for each envelope. Forasyncmethods future will be returned, to retrievevalueEnvelopeobject you have to callvaluemethod (thread will be locked until thevalueis returned). | 
Sample code
1pubnub.remove_uuid_metadata(uuid: 'mg') do |envelope|
2    puts envelope
3end
Response
1#<Pubnub::Envelope
2    @status = {
3        :code => 200,
4        :operation => :remove_uuid_metadata,
5        :category => :ack,
6        :error => false,
7        # [...]
8    },
9    # [...]
10>
Channel
Manage channel metadata: list, fetch, set, and remove.
Get metadata for all channels
Get a paginated list of channel metadata. Use filters and sorting to narrow results.
Method(s)
To Get All Channel Metadata you can use the following method(s) in the Ruby SDK:
1get_all_channels_metadata(
2    sort: sort,
3    include: include,
4    filter: filter,
5    start: start,
6    end: end,
7    limit: limit,
8    http_sync: http_sync,
9    callback: callback
10)
| Parameter | Description | 
|---|---|
| sortType: Array Default: n/a | List of criteria (name of field) which should be used for sorting in ascending order. Available options are id,name, andupdated. Useascordescto specify sort direction. | 
| includeType: Object Default: { count: true } | Additional information which should be included in response.  Available options: 
 | 
| filterType: String Default: n/a | Expression to filter out results basing on specified criteria. For more details on the supported grammar, check here | 
| startType: String Default: n/a | Random string returned from the server, indicating a specific position in a data set. Used for forward pagination, it fetches the next page, allowing you to continue from where you left off. | 
| endType: String Default: n/a | Random string returned from the server, indicating a specific position in a data set. Used for backward pagination, it fetches the previous page, enabling access to earlier data. Ignored if the startparameter is supplied. | 
| limitType: Integer Default: 100 | Number of objects to return in response. Default is 100, which is also the maximum value. | 
| http_syncType: Boolean Default: false | Method will be executed asynchronouslyand will return future, to get itsvalueyou can usevaluemethod. If set totrue, method will return array of envelopes (even if there's only oneenvelope). ForsyncmethodsEnvelopeobject will be returned. | 
| callbackType: Lambda accepting one parameter Default: n/a | Callbackthat will be called for each envelope. Forasyncmethods future will be returned, to retrievevalueEnvelopeobject you have to callvaluemethod (thread will be locked until thevalueis returned). | 
Sample code
1pubnub.get_all_channels_metadata(
2    limit: 5,
3    include: { custom: true }
4) do |envelope|
5    puts envelope
6end
Response
1#<Pubnub::Envelope
2    @result = {
3        :data => {
4            :metadata => [
5                {
6                    :id => "rb_channel1",
7                    :name => "some_name",
8                    :description => nil,
9                    :custom => { "XXX" => "YYYY" },
10                    :updated => <Date>,
11                    :eTag => "AZTUtcvx6NDGLQ"
12                },
13                # {...}
14            ],
15            :totalCount => 2,
Get channel metadata
Fetch metadata for a single channel. Include the Custom object if you need custom fields.
Method(s)
To Get Channel Metadata you can use the following method(s) in the Ruby SDK:
1get_channel_metadata(
2    channel: channel,
3    include: include,
4    http_sync: http_sync,
5    callback: callback
6)
| Parameter | Description | 
|---|---|
| channel*Type: String Default: n/a | Name of channel for which associated metadatashould be fetched. | 
| includeType: Object Default: { custom: true } | Additional information which should be included in response. Available options: 
 | 
| http_syncType: Boolean Default: false | Method will be executed asynchronouslyand will return future, to get itsvalueyou can usevaluemethod. If set totrue, method will return array of envelopes (even if there's only oneenvelope). ForsyncmethodsEnvelopeobject will be returned. | 
| callbackType: Lambda accepting one parameter Default: n/a | Callbackthat will be called for each envelope. Forasyncmethods future will be returned, to retrievevalueEnvelopeobject you have to callvaluemethod (thread will be locked until thevalueis returned). | 
Sample code
1pubnub.get_channel_metadata(
2    channel: 'channel',
3    include: { custom: true }
4) do |envelope|
5    puts envelope
6end
Response
1#<Pubnub::Envelope
2    @result = {
3        :data => {
4            :id => "channel",
5            :name => "some_name",
6            :description => nil,
7            :custom => { "XXX" => "YYYY" },
8            :updated => <Date>,
9            :eTag => "AZTUtcvx6NDGLQ"
10        }
11    },
12    @status = {
13        :code => 200
14    }
15>
Set channel metadata
Create or update metadata for a channel. Use concurrency controls if available.
Unsupported partial updates of custom metadata
The value of the custom metadata parameter sent in this method always overwrites the value stored on PubNub servers. If you want to add new custom data to an existing one, you must:
- Get the existing metadata and store it locally.
- Append the new custom metadata to the existing one.
- Set the entire updated custom object.
Method(s)
To Set Channel Metadata you can use the following method(s) in the Ruby SDK:
1set_channel_metadata(
2    channel: channel,
3    metadata: metadata,
4    include: include,
5    http_sync: http_sync,
6    callback: callback
7)
| Parameter | Description | 
|---|---|
| channel*Type: String Default: n/a | Name of channel with which new metadatashould be associated. | 
| metadata*Type: Object Default: n/a | Metadata information which should be associated with channel. Available options:
 | 
| includeType: Object Default: { custom: true } | Additional information which should be included in response. Available options: 
 | 
| http_syncType: Boolean Default: false | Method will be executed asynchronouslyand will return future, to get itsvalueyou can usevaluemethod. If set totrue, method will return array of envelopes (even if there's only oneenvelope). ForsyncmethodsEnvelopeobject will be returned. | 
| callbackType: Lambda accepting one parameter Default: n/a | Callbackthat will be called for each envelope. Forasyncmethods future will be returned, to retrievevalueEnvelopeobject you have to callvaluemethod (thread will be locked until thevalueis returned). | 
API limits
To learn about the maximum length of parameters used to set channel metadata, refer to REST API docs.
Sample code
1pubnub.set_channel_metadata(
2    channel: 'channel',
3    metadata: { name: 'some_name', custom: { XXX: 'YYYY' } }
4) do |envelope|
5    puts envelope
6end
Response
1#<Pubnub::Envelope
2    @result = {
3        :data => {
4            :id => "channel",
5            :name => "some_name",
6            :description => nil,
7            :custom => { "XXX" => "YYYY" },
8            :updated => <Date>,
9            :eTag => "AZTUtcvx6NDGLQ"
10        }
11    },
12    @status = {
13        :code => 200
14    }
15>
Other examples
Iteratively update existing metadata
1require 'pubnub'
2require 'json'
3
4pubnub = Pubnub.new(
5  publish_key: 'demo',
6  subscribe_key: 'demo',
7  uuid: 'example'
8)
9
10channel = 'demo_example'
11help_string = <<-HELP
12  To exit type '/exit'
13  To show the current object type '/show'
14  To show this help type '/help'
15HELP
Remove channel metadata
Delete metadata for the specified channel.
Method(s)
To Remove Channel Metadata you can use the following method(s) in the Ruby SDK:
1remove_channel_metadata(
2    channel: channel,
3    http_sync: http_sync,
4    callback: callback
5)
| Parameter | Description | 
|---|---|
| channel*Type: String Default: n/a | Name of channel with which the metadatashould be removed. | 
| http_syncType: Boolean Default: false | Method will be executed asynchronouslyand will return future, to get itsvalueyou can usevaluemethod. If set totrue, method will return array of envelopes (even if there's only oneenvelope). ForsyncmethodsEnvelopeobject will be returned. | 
| callbackType: Lambda accepting one parameter Default: n/a | Callbackthat will be called for each envelope. Forasyncmethods future will be returned, to retrievevalueEnvelopeobject you have to callvaluemethod (thread will be locked until thevalueis returned). | 
Sample code
1pubnub.remove_channel_metadata(channel: 'channel') do |envelope|
2    puts envelope
3end
Response
1#<Pubnub::Envelope
2    @status = {
3        :code => 200,
4        :operation => :remove_channel_metadata,
5        :category => :ack,
6        :error => false,
7        # [...]
8    },
9    # [...]
10>
Channel memberships
Manage the channels a UUID belongs to: list, set, and remove.
Get channel memberships
List channel memberships for a UUID. This doesn't return subscriptions.
Method(s)
To Get Memberships you can use the following method(s) in the Ruby SDK:
1get_memberships(
2    uuid: uuid,
3    sort: sort,
4    include: include,
5    filter: filter,
6    start: start,
7    end: end,
8    limit: limit,
9    http_sync: http_sync,
10    callback: callback
11)
| Parameter | Description | 
|---|---|
| uuidType: String Default: Client UUID | Identifier for which memberships in channelsshould be fetched. Default: configured PubNub clientuuid. | 
| sortType: Array Default: n/a | List of criteria (name of field) which should be used for sorting in ascending order. Available options are id,name, andupdated. Useascordescto specify sort direction. | 
| includeType: Object Default: { count: true } | Additional information which should be included in response.  Available options: 
 | 
| filterType: String Default: n/a | Expression to filter out results basing on specified criteria. For more details on the supported grammar, check here | 
| startType: String Default: n/a | Random string returned from the server, indicating a specific position in a data set. Used for forward pagination, it fetches the next page, allowing you to continue from where you left off. | 
| endType: String Default: n/a | Random string returned from the server, indicating a specific position in a data set. Used for backward pagination, it fetches the previous page, enabling access to earlier data. Ignored if the startparameter is supplied. | 
| limitType: Integer Default: 100 | Number of objects to return in response. Default is 100, which is also the maximum value. | 
| http_syncType: Boolean Default: false | Method will be executed asynchronouslyand will return future, to get itsvalueyou can usevaluemethod. If set totrue, method will return array of envelopes (even if there's only oneenvelope). ForsyncmethodsEnvelopeobject will be returned. | 
| callbackType: Lambda accepting one parameter Default: n/a | Callbackthat will be called for each envelope. Forasyncmethods future will be returned, to retrievevalueEnvelopeobject you have to callvaluemethod (thread will be locked until thevalueis returned). | 
Sample code
1pubnub.get_memberships(
2    uuid: 'mg',
3    include: { count: true, custom: true, channel_metadata: true }
4) do |envelope|
5    puts envelope
6end
Response
1#<Pubnub::Envelope
2    @result = {
3        :data => {
4            :memberships => [
5                {
6                    :channel => {
7                        :id => "channel-identifier1",
8                        :name => "Channel1",
9                        :description => nil,
10                        # {...}
11                    },
12                    :custom => { "membership-custom" => "custom-data-1" },
13                    :updated => <Date>,
14                    :eTag => "AYbepevg39XeDA"
15                },
Set channel memberships
Replace or add memberships for a UUID. Provide channels (optionally with custom data).
Method(s)
To Set Memberships you can use the following method(s) in the Ruby SDK:
1set_memberships(
2    uuid: uuid,
3    channels: channels,
4    sort: sort,
5    include: include,
6    filter: filter,
7    start: start,
8    end: end,
9    limit: limit,
10    http_sync: http_sync,
11    callback: callback
12)
| Parameter | Description | 
|---|---|
| uuidType: String Default: Client UUID | Identifier for which memberships in channelsshould be set. Default: configured PubNub clientuuid. | 
| channels*Type: Array Default: n/a | List of channelsfor whichmetadataassociated with each of them in context ofUUIDshould be set. Each entry is a dictionary withchanneland optional fields:
 | 
| sortType: Array Default: n/a | List of criteria (name of field) which should be used for sorting in ascending order. Available options are id,name, andupdated. Useascordescto specify sort direction. | 
| includeType: Object Default: { count: true } | Additional information which should be included in response.  Available options: 
 | 
| filterType: String Default: n/a | Expression to filter out results basing on specified criteria. For more details on the supported grammar, check here | 
| startType: String Default: n/a | Random string returned from the server, indicating a specific position in a data set. Used for forward pagination, it fetches the next page, allowing you to continue from where you left off. | 
| endType: String Default: n/a | Random string returned from the server, indicating a specific position in a data set. Used for backward pagination, it fetches the previous page, enabling access to earlier data. Ignored if the startparameter is supplied. | 
| limitType: Integer Default: 100 | Number of objects to return in response. Default is 100, which is also the maximum value. | 
| http_syncType: Boolean Default: false | Method will be executed asynchronouslyand will return future, to get itsvalueyou can usevaluemethod. If set totrue, method will return array of envelopes (even if there's only oneenvelope). ForsyncmethodsEnvelopeobject will be returned. | 
| callbackType: Lambda accepting one parameter Default: n/a | Callbackthat will be called for each envelope. Forasyncmethods future will be returned, to retrievevalueEnvelopeobject you have to callvaluemethod (thread will be locked until thevalueis returned). | 
API limits
To learn about the maximum length of parameters used to set channel membership metadata, refer to REST API docs.
Sample code
1pubnub.set_memberships(
2    uuid: 'mg',
3    channels: [
4        { channel: 'channel-1' }
5    ],
6    include: { custom: true }
7) do |envelope|
8    puts envelope
9end
Response
1#<Pubnub::Envelope
2    @result = {
3        :data => {
4            :memberships => [
5                {
6                    :channel => {
7                        :id => "channel-1",
8                        # {...}
9                    },
10                    :custom => nil,
11                    :updated => <Date>,
12                    :eTag => "AY39mJKK//C0VA"
13                }
14            ],
15            :totalCount => 1,
Remove channel memberships
Remove memberships for a UUID. Provide the channels to remove.
Method(s)
To Remove Memberships you can use the following method(s) in the Ruby SDK:
1remove_memberships(
2    uuid: uuid,
3    channels: channels,
4    sort: sort,
5    include: include,
6    filter: filter,
7    start: start,
8    end: end,
9    limit: limit,
10    http_sync: http_sync,
11    callback: callback
12)
| Parameter | Description | 
|---|---|
| uuidType: String Default: Client UUID | Identifier for which memberships in channelsshould be removed. Default: configured PubNub clientuuid. | 
| channels*Type: Array Default: n/a | List of channelsfrom whichUUIDshould be removed asmember. | 
| sortType: Array Default: n/a | List of criteria (name of field) which should be used for sorting in ascending order. Available options are id,name, andupdated. Useascordescto specify sort direction. | 
| includeType: Object Default: { count: true } | Additional information which should be included in response.  Available options: 
 | 
| filterType: String Default: n/a | Expression to filter out results basing on specified criteria. For more details on the supported grammar, check here | 
| startType: String Default: n/a | Random string returned from the server, indicating a specific position in a data set. Used for forward pagination, it fetches the next page, allowing you to continue from where you left off. | 
| endType: String Default: n/a | Random string returned from the server, indicating a specific position in a data set. Used for backward pagination, it fetches the previous page, enabling access to earlier data. Ignored if the startparameter is supplied. | 
| limitType: Integer Default: 100 | Number of objects to return in response. Default is 100, which is also the maximum value. | 
| http_syncType: Boolean Default: false | Method will be executed asynchronouslyand will return future, to get itsvalueyou can usevaluemethod. If set totrue, method will return array of envelopes (even if there's only oneenvelope). ForsyncmethodsEnvelopeobject will be returned. | 
| callbackType: Lambda accepting one parameter Default: n/a | Callbackthat will be called for each envelope. Forasyncmethods future will be returned, to retrievevalueEnvelopeobject you have to callvaluemethod (thread will be locked until thevalueis returned). | 
Sample code
1pubnub.remove_memberships(
2    uuid: 'mg',
3    channels: [ 'channel-1' ],
4    include: { custom: true }
5) do |envelope|
6    puts envelope
7end
Response
1#<Pubnub::Envelope
2    @result = {
3        :data => {
4            :memberships => [
5                {
6                    :channel => {
7                        :id => "channel-2",
8                        # {...}
9                    },
10                    :custom => nil,
11                    :updated => <Date>,
12                    :eTag => "AY39mJKK//C0VA"
13                }
14            ],
15            :totalCount => 1,
Channel members
Manage the users in a channel: list, set, and remove.
Get channel members
List users in a channel. Include user metadata if needed.
Method(s)
To Get Channel Members you can use the following method(s) in the Ruby SDK:
1get_channel_members(
2    channel: channel,
3    sort: sort,
4    include: include,
5    filter: filter,
6    start: start,
7    end: end,
8    limit: limit,
9    http_sync: http_sync,
10    callback: callback
11)
| Parameter | Description | 
|---|---|
| channel*Type: String Default: n/a | Name of channel from which members should be fetched. | 
| sortType: Array Default: n/a | List of criteria (name of field) which should be used for sorting in ascending order. Available options are id,name, andupdated. Useascordescto specify sort direction. | 
| includeType: Object Default: { count: true } | Additional information which should be included in response.  Available options: 
 | 
| filterType: String Default: n/a | Expression to filter out results basing on specified criteria. For more details on the supported grammar, check here | 
| startType: String Default: n/a | Random string returned from the server, indicating a specific position in a data set. Used for forward pagination, it fetches the next page, allowing you to continue from where you left off. | 
| endType: String Default: n/a | Random string returned from the server, indicating a specific position in a data set. Used for backward pagination, it fetches the previous page, enabling access to earlier data. Ignored if the startparameter is supplied. | 
| limitType: Integer Default: 100 | Number of objects to return in response. Default is 100, which is also the maximum value. | 
| http_syncType: Boolean Default: false | Method will be executed asynchronouslyand will return future, to get itsvalueyou can usevaluemethod. If set totrue, method will return array of envelopes (even if there's only oneenvelope). ForsyncmethodsEnvelopeobject will be returned. | 
| callbackType: Lambda accepting one parameter Default: n/a | Callbackthat will be called for each envelope. Forasyncmethods future will be returned, to retrievevalueEnvelopeobject you have to callvaluemethod (thread will be locked until thevalueis returned). | 
Sample code
1pubnub.get_channel_members(
2    channel: 'channel-1',
3    include: { count: true, custom: true, uuid_metadata: true }
4) do |envelope|
5    puts envelope
6end
Response
1#<Pubnub::Envelope
2    @result = {
3        :data => {
4            :members => [
5                {
6                    :uuid => {
7                        :id => "uuid-identifier1",
8                        :name => "uuid1",
9                        :externalId => nil,
10                        :profileUrl => nil,
11                        :email => nil,
12                        :updated => <Date>,
13                        :eTag => "AYfwuq+u+4C01gE",
14                        # {...}
15                    },
Set channel members
Set users in a channel. Provide UUIDs (optionally with custom data).
Method(s)
To Set Channel Members you can use the following method(s) in the Ruby SDK:
1set_channel_members(
2    channel: channel,
3    uuids: uuids,
4    sort: sort,
5    include: include,
6    filter: filter,
7    start: start,
8    end: end,
9    limit: limit,
10    http_sync: http_sync,
11    callback: callback
12)
| Parameter | Description | 
|---|---|
| channel*Type: String Default: n/a | Name of channel for which members should be set. | 
| uuids*Type: Array Default: n/a | List of UUIDsfor whichmetadataassociated with each of them in context ofchannelshould be set. Each entry is a dictionary withUUIDand optional fields:
 | 
| sortType: Array Default: n/a | List of criteria (name of field) which should be used for sorting in ascending order. Available options are id,name, andupdated. Useascordescto specify sort direction. | 
| includeType: Object Default: { count: true } | Additional information which should be included in response.  Available options: 
 | 
| filterType: String Default: n/a | Expression to filter out results basing on specified criteria. For more details on the supported grammar, check here | 
| startType: String Default: n/a | Random string returned from the server, indicating a specific position in a data set. Used for forward pagination, it fetches the next page, allowing you to continue from where you left off. | 
| endType: String Default: n/a | Random string returned from the server, indicating a specific position in a data set. Used for backward pagination, it fetches the previous page, enabling access to earlier data. Ignored if the startparameter is supplied. | 
| limitType: Integer Default: 100 | Number of objects to return in response. Default is 100, which is also the maximum value. | 
| http_syncType: Boolean Default: false | Method will be executed asynchronouslyand will return future, to get itsvalueyou can usevaluemethod. If set totrue, method will return array of envelopes (even if there's only oneenvelope). ForsyncmethodsEnvelopeobject will be returned. | 
| callbackType: Lambda accepting one parameter Default: n/a | Callbackthat will be called for each envelope. Forasyncmethods future will be returned, to retrievevalueEnvelopeobject you have to callvaluemethod (thread will be locked until thevalueis returned). | 
API limits
To learn about the maximum length of parameters used to set channel members metadata, refer to REST API docs.
Sample code
1pubnub.set_channel_members(
2    channel: 'channel',
3    uuids: [
4        { uuid: 'uuid1' }
5    ],
6    include: { custom: true }
7) do |envelope|
8    puts envelope
9end
Response
1#<Pubnub::Envelope
2    @result = {
3        :data => {
4            :members=>[
5                {
6                    :uuid => {
7                        :id => "mg2",
8                        # {...}
9                    },
10                    :custom => nil,
11                    :updated=><Date>,
12                    :eTag => "AY39mJKK//C0VA"
13                }
14            ],
15            :totalCount => 1,
Remove channel members
Remove users from a channel. Provide the UUIDs to remove.
Method(s)
To Remove Channel Members you can use the following method(s) in the Ruby SDK:
1remove_channel_members(
2    channel: channel,
3    uuids: uuids,
4    sort: sort,
5    include: include,
6    filter: filter,
7    start: start,
8    end: end,
9    limit: limit,
10    http_sync: http_sync,
11    callback: callback
12)
| Parameter | Description | 
|---|---|
| channel*Type: String Default: n/a | Name of channel from which members should be removed. | 
| uuids*Type: Array Default: n/a | List of UUIDswhich should be removed fromchannel'slist. | 
| sortType: Array Default: n/a | List of criteria (name of field) which should be used for sorting in ascending order. Available options are id,name, andupdated. Useascordescto specify sort direction. | 
| includeType: Object Default: { count: true } | Additional information which should be included in response.  Available options: 
 | 
| filterType: String Default: n/a | Expression to filter out results basing on specified criteria. For more details on the supported grammar, check here | 
| startType: String Default: n/a | Random string returned from the server, indicating a specific position in a data set. Used for forward pagination, it fetches the next page, allowing you to continue from where you left off. | 
| endType: String Default: n/a | Random string returned from the server, indicating a specific position in a data set. Used for backward pagination, it fetches the previous page, enabling access to earlier data. Ignored if the startparameter is supplied. | 
| limitType: Integer Default: 100 | Number of objects to return in response. Default is 100, which is also the maximum value. | 
| http_syncType: Boolean Default: false | Method will be executed asynchronouslyand will return future, to get itsvalueyou can usevaluemethod. If set totrue, method will return array of envelopes (even if there's only oneenvelope). ForsyncmethodsEnvelopeobject will be returned. | 
| callbackType: Lambda accepting one parameter Default: n/a | Callbackthat will be called for each envelope. Forasyncmethods future will be returned, to retrievevalueEnvelopeobject you have to callvaluemethod (thread will be locked until thevalueis returned). | 
Sample code
1pubnub.remove_channel_members(
2    channel: 'channel',
3    uuids: [ 'mg1' ],
4    include: { custom: true }
5) do |envelope|
6    puts envelope
7end
Response
1#<Pubnub::Envelope
2    @result = {
3        :data => {
4            :members=>[
5                {
6                    :uuid => {
7                        :id => "uuid-identifier",
8                        # {...}
9                    },
10                    :custom => nil,
11                    :updated => <Date>,
12                    :eTag => "AY39mJKK//C0VA"
13                }
14            ],
15            :totalCount => 1,