For AI agents: this page in Markdown: https://www.pubnub.com/docs/sdks/ruby/api-reference/misc.md. Documentation index: https://www.pubnub.com/llms-full.txt.
Utility Methods API for Ruby SDK
The methods on this page are utility methods that don't fit into other categories.
Time
This function will return a 17 digit precision Unix epoch.
Algorithm constructing the timetoken
1timetoken = (Unix epoch time in seconds) * 10000000
Convert back and forth between current time and a timetoken:
1now = Time.now
22012-11-02 14:27:11 -0700
3
4timetoken = now.to_f * 10000000
513518916319742640
6
7Time.at(timetoken / 10000000)
82012-11-02 14:27:11 -0700
Method(s)
To fetch Time you can use the following method(s) in Ruby SDK:
1time(
2 http_sync: http_sync,
3 callback: callback
4)
http_sync#- Default
false. Method will be executedasynchronouslyand will return future, to get it'svalueyou 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 eachenvelope.
Forasyncmethods future will be returned, to retrievevalueEnvelopeobject you have to callvaluemethod (thread will be locked until thevalueis returned).
Sample code
Get PubNub timetoken
1require 'pubnub'
2
3def get_pubnub_timetoken(pubnub)
4 pubnub.time do |envelope|
5 if envelope.status[:error]
6 puts "Error fetching timetoken: #{envelope.status[:error]}"
7 else
8 puts "PubNub Timetoken: #{envelope.result[:data][:timetoken]}"
9 end
10 end
11end
12
13def main
14 # Configuration for PubNub instance
15 pubnub = Pubnub.new(
show all 26 linesRest response from server
The time() function returns a string timetoken in the following format:
113769501243685161