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.



9
10
11
# File 'lib/rmega/storage.rb', line 9

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



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

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

#foldersObject



35
36
37
38
39
40
41
# File 'lib/rmega/storage.rb', line 35

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



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

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

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

#quotaObject



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

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

#rootObject



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

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

#total_spaceObject



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

def total_space
  quota['mstrg']
end

#trashObject



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

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

#used_spaceObject



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

def used_space
  quota['cstrg']
end