Class: Rmega::Nodes::Node
Instance Attribute Summary collapse
Instance Method Summary
collapse
#children, #empty?, #files, #folders, #parent
Methods included from Loggable
#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
99
100
101
102
103
|
# File 'lib/rmega/nodes/node.rb', line 99
def attributes
encrypted = data['a'] || data['at']
return if !encrypted or encrypted.empty?
Crypto.decrypt_attributes(decrypted_file_key, encrypted)
end
|
#decrypted_file_key ⇒ Object
#file_key ⇒ Object
59
60
61
|
# File 'lib/rmega/nodes/node.rb', line 59
def file_key
file_keys.values.first
end
|
#file_keys ⇒ Object
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/rmega/nodes/node.rb', line 48
def file_keys
return {} unless data['k']
pairs = data['k'].split('/')
pairs.inject({}) do |hash, pair|
h, k = pair.split(':')
hash[h] = k
hash
end
end
|
#handle ⇒ Object
36
37
38
|
# File 'lib/rmega/nodes/node.rb', line 36
def handle
data['h']
end
|
#name ⇒ Object
44
45
46
|
# File 'lib/rmega/nodes/node.rb', line 44
def name
attributes['n'] if attributes
end
|
#parent_handle ⇒ Object
40
41
42
|
# File 'lib/rmega/nodes/node.rb', line 40
def parent_handle
data['p']
end
|
#process_shared_key ⇒ Object
#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
|
#shared_root? ⇒ Boolean
63
64
65
|
# File 'lib/rmega/nodes/node.rb', line 63
def shared_root?
data['su'] && data['sk'] && data['k']
end
|
#type ⇒ Object
105
106
107
|
# File 'lib/rmega/nodes/node.rb', line 105
def type
Factory.type(data['t'])
end
|