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.
Required keyset configuration
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)
sort#- 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. include#- Additional information which should be included in response. Available options:
count- include how many UUID has been associated with metadata.custom- include field with additional information from metadata which has been used duringUUIDmetadata set requests.type- include the type of the metadata.status- include the status of the metadata.
filter#- Expression to filter out results basing on specified criteria. For more details on the supported grammar, check the filtering reference
start#- 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.
end#- 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. limit#- Number of objects to return in response. Default is
100, which is also the maximum value. http_sync#- 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. callback#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
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]}"
show all 35 linesResponse
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 ],
show all 24 linesGet 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)
uuid#- Identifier for which associated
metadatashould be fetched. Default: configured PubNub clientuuid. include#- Additional information which should be included in response. Available options:
custom- include field with additional information from metadata which has been used duringUUIDmetadata set requests.type- include the type of the metadata.status- include the status of the metadata.
http_sync#- 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. callback#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
show all 17 linesSet 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)
uuid#- Identifier with which new
metadatashould be associated. Default: configured PubNub clientuuid. metadatarequired#- Metadata information which should be associated with
UUID. Available options:name- Name which should be stored inmetadataassociated with specifiedUUID.externalId- External identifier (database, auth service) associated with specifiedUUID.profileUrl- External URL with information for specifiedUUIDrepresentation.custom- Additional information which should be stored inmetadataassociated with specifiedUUID. App Context filtering language doesn’t support filtering by custom properties.email- Email address which should be stored inmetadataassociated with specifiedUUID.type- Type of the metadata associated with specifiedUUID.status- Status of the metadata associated with specifiedUUID.
include#- Additional information which should be included in response. Available options:
custom- include field with additional information from metadata which has been used duringUUIDmetadata set requests.
http_sync#- 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. callback#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
show all 17 linesRemove 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)
uuid#- Identifier for which associated
metadatashould be removed. Default: configured PubNub clientuuid. http_sync#- 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. callback#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)
sort#- 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. include#- Additional information which should be included in response. Available options:
count- include how many channels has been associated with metadata.custom- include field with additional information from metadata which has been used during channel metadata set requests.type- include the type of the metadata.status- include the status of the metadata.
filter#- Expression to filter out results basing on specified criteria. For more details on the supported grammar, check the filtering reference
start#- 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.
end#- 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. limit#- Number of objects to return in response. Default is
100, which is also the maximum value. http_sync#- 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. callback#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,
show all 23 linesGet 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)
channelrequired#- Name of channel for which associated
metadatashould be fetched. include#- Additional information which should be included in response. Available options:
custom- include field with additional information from metadata which has been used during channel metadata set requests.type- include the type of the metadata.status- include the status of the metadata.
http_sync#- 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. callback#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)
channelrequired#- Name of channel with which new
metadatashould be associated. metadatarequired#- Metadata information which should be associated with
channel. Available options:name- Name which should stored inmetadataassociated with specifiedchannel.information- Description which should be stored inmetadataassociated with specifiedchannel.custom- Additional information which should be stored inmetadataassociated with specifiedchannel. App Context filtering language doesn’t support filtering by custom properties.type- Type of the metadata associated with specifiedchannel.status- Status of the metadata associated with specifiedchannel.
include#- Additional information which should be included in response. Available options:
custom- include field with additional information from metadata which has been used duringUUIDmetadata set requests.
http_sync#- 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. callback#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
show all 89 linesRemove 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)
channelrequired#- Name of channel with which the
metadatashould be removed. http_sync#- 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. callback#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)
uuid#- Identifier for which memberships in
channelsshould be fetched. Default: configured PubNub clientuuid. sort#- 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. include#- Additional information which should be included in response. Available options:
count- include how many memberships UUID has.custom- include field with additional information from metadata which has been associated with UUID during membership add requests.channel_metadata- include channel's metadata into response (not only name).channel_custom- include channel's additional information which has been used during channel metadata set requests.status- include the status of the membership.type- include the type of the membership.channel_type- include the type of the channel.channel_status- include the status of the channel.
filter#- Expression to filter out results basing on specified criteria. For more details on the supported grammar, check the filtering reference
start#- 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.
end#- 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. limit#- Number of objects to return in response. Default is
100, which is also the maximum value. http_sync#- 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. callback#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 },
show all 26 linesSet 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)
uuid#- Identifier for which memberships in
channelsshould be set. Default: configured PubNub clientuuid. channelsrequired#- List of
channelsfor whichmetadataassociated with each of them in context ofUUIDshould be set. Each entry is a dictionary withchanneland optional fields:custom- A dictionary with simple objects:StringandInteger.type- Type of the metadata associated with specifiedmembership.status- Status of the metadata associated with specifiedmembership.
sort#- 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. include#- Additional information which should be included in response. Available options:
count- include how many memberships UUID has.custom- include field with additional information from metadata which has been associated with UUID during membership add requests.channel_metadata- include channel's metadata into response (not only name).channel_custom- include channel's additional information which has been used during channel metadata set requests.status- include the status of the membership.type- include the type of the membership.channel_type- include the type of the channel.channel_status- include the status of the channel.
filter#- Expression to filter out results basing on specified criteria. For more details on the supported grammar, check the filtering reference
start#- 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.
end#- 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. limit#- Number of objects to return in response. Default is
100, which is also the maximum value. http_sync#- 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. callback#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,
show all 23 linesRemove 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)
uuid#- Identifier for which memberships in
channelsshould be removed. Default: configured PubNub clientuuid. channelsrequired#- List of
channelsfrom whichUUIDshould be removed asmember. sort#- 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. include#- Additional information which should be included in response. Available options:
count- include how many memberships UUID has.custom- include field with additional information from metadata which has been associated with UUID during membership add requests.channel_metadata- include channel's metadata into response (not only name).channel_custom- include channel's additional information which has been used during channel metadata set requests..
filter#- Expression to filter out results basing on specified criteria. For more details on the supported grammar, check the filtering reference
start#- 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.
end#- 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. limit#- Number of objects to return in response. Default is
100, which is also the maximum value. http_sync#- 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. callback#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,
show all 23 linesChannel 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)
channelrequired#- Name of channel from which members should be fetched.
sort#- 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. include#- Additional information which should be included in response. Available options:
count- include how many members channel has.custom- include field with additional information frommetadatawhich has been associated withUUIDduringchannel member addrequests.uuid_metadata- includeUUID's metadatainto response (not only identifier).uuid_custom- includeUUID'sadditional information which has been used duringUUID metadata setrequests.status- include the status of the member.type- include the type of the member.uuid_status- include the status of the UUID.uuid_type- include the type of the UUID.
filter#- Expression to filter out results basing on specified criteria. For more details on the supported grammar, check the filtering reference
start#- 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.
end#- 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. limit#- Number of objects to return in response. Default is
100, which is also the maximum value. http_sync#- 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. callback#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 },
show all 30 linesSet 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)
channelrequired#- Name of channel for which members should be set.
uuidsrequired#- List of
UUIDsfor whichmetadataassociated with each of them in context ofchannelshould be set. Each entry is a dictionary withUUIDand optional fields:custom- A dictionary with simple objects:StringandInteger.type- Type of the metadata associated with specifiedUUID.status- Status of the metadata associated with specifiedUUID.
sort#- 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. include#- Additional information which should be included in response. Available options:
count- include how many members channel has.custom- include field with additional information frommetadatawhich has been associated withUUIDduringchannel member addrequests.uuid_metadata- includeUUID's metadatainto response (not only identifier).uuid_custom- includeUUID'sadditional information which has been used duringUUID metadata setrequests.status- include the status of the member.type- include the type of the member.uuid_status- include the status of the UUID.uuid_type- include the type of the UUID.
filter#- Expression to filter out results basing on specified criteria. For more details on the supported grammar, check the filtering reference
start#- 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.
end#- 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. limit#- Number of objects to return in response. Default is
100, which is also the maximum value. http_sync#- 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. callback#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,
show all 23 linesRemove 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)
channelrequired#- Name of channel from which members should be removed.
uuidsrequired#- List of
UUIDswhich should be removed fromchannel'slist. sort#- 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. include#- Additional information which should be included in response. Available options:
count- include how many members channel has.custom- include field with additional information frommetadatawhich has been associated withUUIDduringchannel member addrequests.uuid_metadata- includeUUID's metadatainto response (not only identifier).uuid_custom- includeUUID'sadditional information which has been used duringUUID metadata setrequests.
filter#- Expression to filter out results basing on specified criteria. For more details on the supported grammar, check the filtering reference
start#- 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.
end#- 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. limit#- Number of objects to return in response. Default is
100, which is also the maximum value. http_sync#- 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. callback#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,
show all 23 lines