Class: Rmega::Storage

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Loggable

#logger

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

#download(public_url, path) ⇒ Object


55
56
57
# File 'lib/rmega/storage.rb', line 55

def download(public_url, path)
  Nodes::Factory.build_from_url(session, public_url).download(path)
end

#foldersObject


39
40
41
42
43
44
45
# File 'lib/rmega/storage.rb', line 39

def folders
  list = nodes
  root_handle = list.find { |node| node.type == :root }.handle
  list.select do |node|
    node.shared_root? || (node.type == :folder && node.parent_handle == root_handle)
  end
end

#nodesObject


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

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

  store_shared_keys(results['ok'] || [])

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

#quotaObject


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

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

#rootObject


51
52
53
# File 'lib/rmega/storage.rb', line 51

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

#total_spaceObject


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

def total_space
  quota['mstrg']
end

#trashObject


47
48
49
# File 'lib/rmega/storage.rb', line 47

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