class Vidyo::Token
Public Class Methods
new(key:, application_id:, user_name:, expires_in:)
click to toggle source
# File lib/vidyo/token.rb, line 12 def initialize(key:, application_id:, user_name:, expires_in:) @key = key @application_id = application_id @user_name = user_name @expires_in = expires_in end
Public Instance Methods
body()
click to toggle source
# File lib/vidyo/token.rb, line 40 def body to_bytes(request_type) + separator + to_bytes(jid) + separator + to_bytes(expires_at.to_s) + separator end
epoch_seconds()
click to toggle source
# File lib/vidyo/token.rb, line 19 def epoch_seconds # Converts 1970-01-01 to seconds since 0 AD. 62167219200 end
expires_at()
click to toggle source
# File lib/vidyo/token.rb, line 24 def expires_at epoch_seconds + Time.now.gmtime.to_i + @expires_in end
jid()
click to toggle source
# File lib/vidyo/token.rb, line 28 def jid "#{@user_name}@#{@application_id}" end
mac()
click to toggle source
# File lib/vidyo/token.rb, line 44 def mac sha384 = OpenSSL::HMAC.new(@key, OpenSSL::Digest.new('sha384')) sha384.update(body.pack("C*")) end
request_type()
click to toggle source
# File lib/vidyo/token.rb, line 36 def request_type "provision" end
separator()
click to toggle source
# File lib/vidyo/token.rb, line 32 def separator [0] end
serialize()
click to toggle source
# File lib/vidyo/token.rb, line 53 def serialize Base64.strict_encode64(unserialized) end
unserialized()
click to toggle source
# File lib/vidyo/token.rb, line 49 def unserialized (body + separator).pack("C*") + mac.hexdigest end