Class: Commands::ListFiles
Overview
List all files accessible by the application.
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Command
#initialize
Methods included from DriveError
#drive_error_string
included
Class Method Details
.command_name ⇒ Object
8
9
10
|
# File 'lib/gdsh/list_files.rb', line 8
def self.command_name
'ls'
end
|
.function ⇒ Object
12
13
14
|
# File 'lib/gdsh/list_files.rb', line 12
def self.function
'List files accessible by this application.'
end
|
Instance Method Details
#created_at_label ⇒ Object
60
61
62
|
# File 'lib/gdsh/list_files.rb', line 60
def created_at_label
'created at: '.colorize(:light_magenta)
end
|
#execute ⇒ Object
71
72
73
74
75
76
|
# File 'lib/gdsh/list_files.rb', line 71
def execute
filelist.each do |f|
next if f['labels']['trashed']
puts_file_info(f)
end
end
|
#filelist ⇒ Object
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/gdsh/list_files.rb', line 28
def filelist
puts_banner
result = []
page_token = nil
loop do
api_result = retrieve_file_by_page_token(page_token)
if api_result.status == 200
files = api_result.data
result.concat(files.items)
page_token = files.next_page_token
else
drive_error_string
page_token = nil
end
break if page_token.to_s.empty?
end
result
end
|
#id_label ⇒ Object
56
57
58
|
# File 'lib/gdsh/list_files.rb', line 56
def id_label
'id: '.colorize(:light_magenta)
end
|
#puts_banner ⇒ Object
24
25
26
|
# File 'lib/gdsh/list_files.rb', line 24
def puts_banner
puts 'Retrieving list of files accessible...'.colorize(:green)
end
|
#puts_file_info(f) ⇒ Object
64
65
66
67
68
69
|
# File 'lib/gdsh/list_files.rb', line 64
def puts_file_info(f)
puts title_label + "#{f['title']}"
puts id_label + "#{f['id']}"
puts created_at_label + "#{f['createdDate']}"
puts ''
end
|
#retrieve_file_by_page_token(pagetoken) ⇒ Object
16
17
18
19
20
21
22
|
# File 'lib/gdsh/list_files.rb', line 16
def retrieve_file_by_page_token(pagetoken)
parameters = pagetoken.to_s.empty? ? {} : { pageToken: pagetoken }
drive = @client.discovered_api('drive', 'v2')
@client.execute(
api_method: drive.files.list,
parameters: parameters)
end
|
#title_label ⇒ Object
52
53
54
|
# File 'lib/gdsh/list_files.rb', line 52
def title_label
'Title: '.colorize(:light_magenta)
end
|