Class: CloudappExport::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/cloudapp_export/cli.rb

Instance Method Summary collapse

Instance Method Details

#allObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/cloudapp_export/cli.rb', line 14

def all
  authenticate!

  items = CloudappExport::ItemList.new(
    api,
    'limit' => options['limit'],
    'use_cache' => options['cache'],
    'cache_key' => "#{username}:#{options['limit']}",
  )
  say("Account contains #{set_color items.total_count, :bold} items")
  say("", nil, true)

  exporter = ::CloudappExport::Exporter.new(
    items,
    'dir' => options['dir'],
  )
  exporter.on_log do |message|
    print message
  end
  exporter.export_all
end

#statsObject



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/cloudapp_export/cli.rb', line 40

def stats
  authenticate!

  items = CloudappExport::ItemList.new(
    api,
  )
  say("Account contains #{set_color items.total_count, :bold} items")
  say("", nil, true)

  say("Dir         #{options['dir']}")
  say("", nil, true)

  # TODO: Just count files directly in local folder
  downloaded_items = items.data.select { |item| File.exist?("#{options['dir']}/#{item.filename}") }
  downloaded_items_size = downloaded_items.inject(0) { |sum, item| sum + File.size("#{options['dir']}/#{item.filename}") }

  say("Downloaded  #{downloaded_items.count}")
  say("            #{(downloaded_items_size.to_f / 1_000_000).round 2} mb")
end