Class: Rmega::Storage
Instance Attribute Summary collapse
-
#session ⇒ Object
readonly
Returns the value of attribute session.
Instance Method Summary collapse
- #download(public_url, path) ⇒ Object
- #folders ⇒ Object
-
#initialize(session) ⇒ Storage
constructor
A new instance of Storage.
- #nodes ⇒ Object
- #quota ⇒ Object
- #root ⇒ Object
- #total_space ⇒ Object
- #trash ⇒ Object
- #used_space ⇒ Object
Methods included from Loggable
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
#session ⇒ Object (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 |
#folders ⇒ Object
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 |
#nodes ⇒ Object
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 |
#quota ⇒ Object
21 22 23 |
# File 'lib/rmega/storage.rb', line 21 def quota session.request(a: 'uq', strg: 1) end |
#root ⇒ Object
47 48 49 |
# File 'lib/rmega/storage.rb', line 47 def root @root ||= nodes.find { |n| n.type == :root } end |
#total_space ⇒ Object
17 18 19 |
# File 'lib/rmega/storage.rb', line 17 def total_space quota['mstrg'] end |
#trash ⇒ Object
43 44 45 |
# File 'lib/rmega/storage.rb', line 43 def trash @trash ||= nodes.find { |n| n.type == :trash } end |
#used_space ⇒ Object
13 14 15 |
# File 'lib/rmega/storage.rb', line 13 def used_space quota['cstrg'] end |