Utility Methods API for PubNub Ruby SDK

The methods on this page are utility methods that don't fit into other categories.

Time

Description

This function will return a 17 digit precision Unix epoch.

Algorithm constructing the timetoken
timetoken = (Unix epoch time in seconds) * 10000000

Convert back and forth between current time and a timetoken:

now = Time.now
2012-11-02 14:27:11 -0700

timetoken = now.to_f * 10000000
13518916319742640

Time.at(timetoken / 10000000)
2012-11-02 14:27:11 -0700

Method(s)

To fetch Time you can use the following method(s) in Ruby V4 SDK:

time(http_sync: http_sync, callback: callback)
ParameterTypeRequiredDescription
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

Get PubNub Timetoken

pubnub.time do |envelope|
puts envelope.timetoken
end

Rest Response from Server

The time() function returns a string timetoken in the following format:

13769501243685161
Last updated on