Class: Agora::AgoraDynamicKey2::Service

Inherits:
Object
  • Object
show all
Defined in:
lib/agora/dynamic_key2/access_token.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type) ⇒ Service

Returns a new instance of Service.



9
10
11
12
# File 'lib/agora/dynamic_key2/access_token.rb', line 9

def initialize(type)
  @type = type
  @privileges = {}
end

Instance Attribute Details

#privilegesObject

Returns the value of attribute privileges.



7
8
9
# File 'lib/agora/dynamic_key2/access_token.rb', line 7

def privileges
  @privileges
end

#typeObject

Returns the value of attribute type.



7
8
9
# File 'lib/agora/dynamic_key2/access_token.rb', line 7

def type
  @type
end

Instance Method Details

#add_privilege(privilege, expire) ⇒ Object



14
15
16
# File 'lib/agora/dynamic_key2/access_token.rb', line 14

def add_privilege(privilege, expire)
  @privileges[privilege] = expire
end

#fetch_uid(uid) ⇒ Object



18
19
20
21
22
# File 'lib/agora/dynamic_key2/access_token.rb', line 18

def fetch_uid(uid)
  return '' if uid.eql?(0)

  uid.to_s
end

#packObject



24
25
26
# File 'lib/agora/dynamic_key2/access_token.rb', line 24

def pack
  Util.pack_uint16(@type) + Util.pack_map_uint32(@privileges)
end

#unpack(data) ⇒ Object



28
29
30
# File 'lib/agora/dynamic_key2/access_token.rb', line 28

def unpack(data)
  @privileges, data = Util.unpack_map_uint32(data)
end