Class: Vidyo::Token
- Inherits:
-
Object
- Object
- Vidyo::Token
- Defined in:
- lib/vidyo/token.rb
Instance Method Summary collapse
- #body ⇒ Object
- #epoch_seconds ⇒ Object
- #expires_at ⇒ Object
-
#initialize(key:, application_id:, user_name:, expires_in:) ⇒ Token
constructor
A new instance of Token.
- #jid ⇒ Object
- #mac ⇒ Object
- #request_type ⇒ Object
- #separator ⇒ Object
- #serialize ⇒ Object
- #unserialized ⇒ Object
Constructor Details
#initialize(key:, application_id:, user_name:, expires_in:) ⇒ Token
Returns a new instance of Token.
12 13 14 15 16 17 |
# 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 |
Instance Method Details
#body ⇒ Object
40 41 42 |
# 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 ⇒ Object
19 20 21 22 |
# File 'lib/vidyo/token.rb', line 19 def epoch_seconds # Converts 1970-01-01 to seconds since 0 AD. 62167219200 end |
#expires_at ⇒ Object
24 25 26 |
# File 'lib/vidyo/token.rb', line 24 def expires_at epoch_seconds + Time.now.gmtime.to_i + @expires_in end |
#jid ⇒ Object
28 29 30 |
# File 'lib/vidyo/token.rb', line 28 def jid "#{@user_name}@#{@application_id}" end |
#mac ⇒ Object
44 45 46 47 |
# 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 ⇒ Object
36 37 38 |
# File 'lib/vidyo/token.rb', line 36 def request_type "provision" end |
#separator ⇒ Object
32 33 34 |
# File 'lib/vidyo/token.rb', line 32 def separator [0] end |
#serialize ⇒ Object
53 54 55 |
# File 'lib/vidyo/token.rb', line 53 def serialize Base64.strict_encode64(unserialized) end |
#unserialized ⇒ Object
49 50 51 |
# File 'lib/vidyo/token.rb', line 49 def unserialized (body + separator).pack("C*") + mac.hexdigest end |