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

included, #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



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

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

#nodesObject



25
26
27
28
# File 'lib/rmega/storage.rb', line 25

def nodes
  results = session.request(a: 'f', c: 1)['f']
  results.map { |node_data| Nodes::Factory.build(session, node_data) }
end

#quotaObject



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

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

#rootObject



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

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



30
31
32
# File 'lib/rmega/storage.rb', line 30

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