Class: Rmega::Nodes::Node
Instance Attribute Summary collapse
Instance Method Summary
collapse
#children, #empty?, #files, #folders, #parent
Methods included from Loggable
included, #logger
Constructor Details
#initialize(session, data) ⇒ Node
Returns a new instance of Node.
16
17
18
19
|
# File 'lib/rmega/nodes/node.rb', line 16
def initialize(session, data)
@session = session
@data = data
end
|
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
12
13
14
|
# File 'lib/rmega/nodes/node.rb', line 12
def data
@data
end
|
#session ⇒ Object
Returns the value of attribute session.
12
13
14
|
# File 'lib/rmega/nodes/node.rb', line 12
def session
@session
end
|
Instance Method Details
#attributes ⇒ Object
68
69
70
71
72
73
|
# File 'lib/rmega/nodes/node.rb', line 68
def attributes
@attributes ||= begin
return nil unless can_decrypt_attributes?
Crypto.decrypt_attributes decrypted_file_key, (data['a'] || data['at'])
end
end
|
#can_decrypt_attributes? ⇒ Boolean
64
65
66
|
# File 'lib/rmega/nodes/node.rb', line 64
def can_decrypt_attributes?
!data['u'] or data['u'] == owner_key
end
|
#decrypted_file_key ⇒ Object
#file_key ⇒ Object
52
53
54
|
# File 'lib/rmega/nodes/node.rb', line 52
def file_key
data['k'].split(':').last
end
|
#handle ⇒ Object
36
37
38
|
# File 'lib/rmega/nodes/node.rb', line 36
def handle
data['h']
end
|
#name ⇒ Object
48
49
50
|
# File 'lib/rmega/nodes/node.rb', line 48
def name
return attributes['n'] if attributes
end
|
#owner_key ⇒ Object
44
45
46
|
# File 'lib/rmega/nodes/node.rb', line 44
def owner_key
data['k'].split(':').first
end
|
#parent_handle ⇒ Object
40
41
42
|
# File 'lib/rmega/nodes/node.rb', line 40
def parent_handle
data['p']
end
|
#public_handle ⇒ Object
32
33
34
|
# File 'lib/rmega/nodes/node.rb', line 32
def public_handle
@public_handle ||= request(a: 'l', n: handle)
end
|
#public_url ⇒ Object
21
22
23
24
25
26
|
# File 'lib/rmega/nodes/node.rb', line 21
def public_url
@public_url ||= begin
b64_dec_key = Utils.a32_to_base64 decrypted_file_key[0..7]
"https://mega.co.nz/#!#{public_handle}!#{b64_dec_key}"
end
end
|
#public_url=(url) ⇒ Object
28
29
30
|
# File 'lib/rmega/nodes/node.rb', line 28
def public_url=(url)
@public_url = url
end
|
#type ⇒ Object
75
76
77
|
# File 'lib/rmega/nodes/node.rb', line 75
def type
Factory.type(data['t'])
end
|