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

included, #logger

Methods included from NotInspectable

#inspect

Constructor Details

#initialize(session) ⇒ Storage

Returns a new instance of Storage.



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

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



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/rmega/storage.rb', line 46

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



42
43
44
# File 'lib/rmega/storage.rb', line 42

def nodes=(list)
  @nodes = list
end

#quotaObject



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

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

#rootObject



70
71
72
# File 'lib/rmega/storage.rb', line 70

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

#sharedObject



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

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

#statsObject



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/rmega/storage.rb', line 26

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



22
23
24
# File 'lib/rmega/storage.rb', line 22

def total_space
  quota['mstrg']
end

#trashObject



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

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

#used_spaceObject



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

def used_space
  quota['cstrg']
end