Please Wait

Loading..

Ruby SDK 1.0.2

Create amazing realtime applications easily with Yalgaar Ruby SDK

Ruby SDK

1 Connect To Yalgaar

Requirement :

Supports Ruby 1.9.3 and above

Download package and install gem into your machine.

gem install yalgaar

Include Yalgaar module into your program.

require 'yalgaar'

To connect to a Yalgaar client,use following method, it must have valid Client Key.

yalgaarConnect(clientKey, isSecure, $connectionCallback)
yalgaarConnect(clientKey, isSecure, UUID, $connectionCallback)
yalgaarConnect(clientKey, isSecure, AESSecretKey, AESType, $connectionCallback)
yalgaarConnect(clientKey, isSecure, UUID, AESSecretKey, AESType, $connectionCallback)

Parameter:

  • clientKey
    • Description: Yalgaar provided authentic client key for project.
    • DataType: string
  • isSecure
    • Description: Secure connection with SSL [True / False].
    • DataType: boolean (value must be true or false)
  • UUID
    • Description: Any unique user name or user id. UUID is CASE SENSITIVE and only alpha numeric, hyphens,@,underscore allowed and maximum length must be 50.
    • DataType: string
  • AESSecretKey
    • Description: Secret key use for encrypt/decrypt message.
    • DataType: string
  • AESType
    • Description: Type of AES algorithm use for encrypt/decrypt message. Support 128,192,256 for AES_128, AES_192, AES_256 respectively.
    • DataType: Numbers
  • $connectionCallback
    • Description: Called when successfully connected to server.
    • DataType: lambda


2 Publish Message

To publish message, use following method

yalgaarPublish(channel, message)

Parameter:

  • channel
    • Description: Channel name on which message will be published. Only alpha numeric, hyphens, @, underscore allowed and maximum length must be 50.
    • Data Type: string
  • message
    • Description: Data to be send on given channel.
    • DataType: string


3 Subscribe Message

To subscribe message,use following method.

yalgaarSubcribe(channel/channels, $subscribeReturnMessageCallback, $presenceMessageCallback, $errorMsgCallback)

Parameter:

  • channel/channels
    • Description: Single channel name or multiple channels name on which message will be subscribed. For multiple channel names use array. Channel name is CASE SENSITIVE. Only alpha numeric, hyphens, @, underscore allowed and maximum length must be 50.
    • DataType: string (for multiple channels use array).
  • $subscribeReturnMessageCallback
    • Description: Callback function to consume received message.
    • DataType: lambda
  • $presenceMessageCallback
    • Description: Callback function to consume presence events such as join or leave.
    • DataType: lambda
  • $errorMsgCallback
    • Description: Callback is called on system error occurred during subscription.
    • DataType: lambda


4 Unsubscribe Message

To unsubscribe message,use following method.

yalgaarUnSubcribe(channel/channels)

Parameter:

  • channel/channels
    • Description: Single channel name or multiple channels name to be unsubscribe. Only alpha numeric, hyphens, @, underscore allowed and maximum length must be 50. For multiple channel names use array
    • DataType: string


5 Get User List

To get list of all users subscribed with specific channel name, use following method.

yalgaarGetUserList(channel, $userListCallback, $errorMsgCallback)

Parameter:

  • channel
    • Description: Valid channel name. Channel name is CASE SENSITIVE and only alpha numeric, hyphens, @, underscore allowed and maximum length must be 50.
    • DataType: string
  • $userListCallback
    • Description: Callback is called when successfully get user list.
    • DataType: lambda
  • $errorMsgCallback
    • Description: Callback is called when an error occurred.
    • DataType: lambda


6 Get Channel List

To get list of all channels subscribed by specified user, use following method.

yalgaarGetChannelList(UUID, $channelListCallback, $errorMsgCallback)

Parameter:

  • UUID:
    • Description: Valid user Id. user Id is CASE SENSITIVE and only alpha numeric, hyphens, @, underscore allowed and maximum length must be 50.
    • DataType: string
  • $channelListCallback
    • Description: Callback is called when successfully get channel list.
    • DataType: lambda
  • $errorMsgCallback
    • Description: Callback is called when an error occurred
    • DataType: lambda


7 Get Message History

To get the already published messages, use following method

yalgaarHistory(channel, messageCount, $historyMessageCallback, $errorMsgCallback)

Parameter:

  • channel
    • Description: Valid channel name. Channel name is CASE SENSITIVE and only alpha numeric, hyphens, @, underscore allowed and maximum length must be 50.
    • DataType: string
  • messageCount
    • Description: How many messages that you want to fetch. Maximum 100 messages allow at a time.
    • Data Type: Numbers
  • $historyMessageCallback
    • Description: Callback is called when successfully get message history list.
    • DataType: lambda
  • $errorMsgCallback
    • Description: Callback is called when an error occurred.
    • DataType: lambda


You can publish/subscribe message like so :

require 'yalgaar'
yalgaarClient = Yalgaar.new
yalgaarClient.yalgaarConnect("ClientKey",1,"UUID",$connectionCallback)
yalgaarClient.yalgaarSubcribe("YourChannel",$subscribeReturnMessageCallback,$presenceMessageCallback,$errorMsgCallback)
yalgaarClient.yalgaarPublish("YourChannel","This is Yalgaar Ruby SDK Example")

$connectionCallback = -> (arg0) { connectionCallback(arg0) } 
def connectionCallback(arg0)
	puts arg0
end
$subscribeReturnMessageCallback = -> (arg0) { subscribeReturnMessageCallback(arg0) } 	
def subscribeReturnMessageCallback(message)
	puts message
end
$errorMsgCallback = -> (arg0) { errorMsgCallback(arg0) } 
def errorMsgCallback(message)
	puts message
end
$presenceMessageCallback = -> (arg0) { presenceMessageCallback(arg0) } 
def presenceMessageCallback(message)
	puts message	
end