Class: Rmega::Storage

Inherits:
Object
  • Object
show all
Includes:
Crypto, Loggable, NotInspectable
Defined in:
lib/rmega/storage.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Crypto::Rsa

#powm, #rsa_decrypt

Methods included from Crypto::AesCtr

#aes_ctr_cipher, #aes_ctr_decrypt, #aes_ctr_encrypt

Methods included from Crypto::AesEcb

#aes_ecb_cipher, #aes_ecb_decrypt, #aes_ecb_encrypt

Methods included from Crypto::AesCbc

#aes_cbc_cipher, #aes_cbc_decrypt, #aes_cbc_encrypt, #aes_cbc_mac

Methods included from Loggable

#logger

Methods included from NotInspectable

#inspect

Constructor Details

#initialize(session) ⇒ Storage

Returns a new instance of Storage.



11
12
13
# File 'lib/rmega/storage.rb', line 11

def initialize(session)
  @session = session
end

Instance Attribute Details

#sessionObject (readonly)

Returns the value of attribute session.



7
8
9
# File 'lib/rmega/storage.rb', line 7

def session
  @session
end

Instance Method Details

#nodesObject



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/rmega/storage.rb', line 43

def nodes
  return @nodes if @nodes

  results = session.request(a: 'f', c: 1)

  (results['ok'] || []).each do |hash|
    shared_keys[hash['h']] ||= aes_ecb_decrypt(master_key, Utils.base64urldecode(hash['k']))
  end

  (results['f'] || []).map do |node_data|
    node = Nodes::Factory.build(session, node_data)
    node.process_shared_key if node.shared_root?
    node
  end
end

#nodes=(list) ⇒ Object



39
40
41
# File 'lib/rmega/storage.rb', line 39

def nodes=(list)
  @nodes = list
end

#quotaObject



35
36
37
# File 'lib/rmega/storage.rb', line 35

def quota
  session.request(a: 'uq', strg: 1)
end

#rootObject



67
68
69
# File 'lib/rmega/storage.rb', line 67

def root
  @root ||= nodes.find { |n| n.type == :root }
end

#sharedObject



59
60
61
# File 'lib/rmega/storage.rb', line 59

def shared
  nodes.select { |node| node.shared_root? }
end

#statsObject



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/rmega/storage.rb', line 23

def stats
  stats_hash = {files: 0, size: 0}

  nodes.each do |n|
    next unless n.type == :file
    stats_hash[:files] += 1
    stats_hash[:size] += n.filesize
  end

  return stats_hash
end

#total_spaceObject



19
20
21
# File 'lib/rmega/storage.rb', line 19

def total_space
  quota['mstrg']
end

#trashObject



63
64
65
# File 'lib/rmega/storage.rb', line 63

def trash
  @trash ||= nodes.find { |n| n.type == :trash }
end

#used_spaceObject



15
16
17
# File 'lib/rmega/storage.rb', line 15

def used_space
  quota['cstrg']
end