Class: Commands::GetFile
Overview
Downloads Files/Revisions
Class Method Summary
collapse
Instance Method Summary
collapse
#docx_link_label, #modified_date_label, #modifying_user_label, #modifying_users, #pdf_link_label, #puts_banner, #puts_download_links, #puts_revision_info, #revision_id_label, #revisions, #txt_link, #txt_link_label
Methods included from Mime
#docx, #html, #jpeg, #ods, #odt, #pdf, #png, #pptx, #rtf, #svg, #txt, #xlsx
Methods included from DriveError
#drive_error_string
included
Constructor Details
#initialize(client, params) ⇒ GetFile
Returns a new instance of GetFile.
22
23
24
25
26
|
# File 'lib/gdsh/get_file.rb', line 22
def initialize(client, params)
super(client, params)
@revision = (params.length == 3) ? params[2] : nil
@file_id = @params[1]
end
|
Class Method Details
.command_name ⇒ Object
9
10
11
|
# File 'lib/gdsh/get_file.rb', line 9
def self.command_name
'get_txt'
end
|
.function ⇒ Object
17
18
19
20
|
# File 'lib/gdsh/get_file.rb', line 17
def self.function
'Downloads a specific revision of a file if <revision_number> is ' \
'specified; downloads all revisions otherwise.'
end
|
.parameters ⇒ Object
13
14
15
|
# File 'lib/gdsh/get_file.rb', line 13
def self.parameters
'(<file_id>[,<revision_number>])'
end
|
Instance Method Details
#download(url) ⇒ Object
32
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/gdsh/get_file.rb', line 32
def download(url)
return unless @client
puts_downloading_banner(url)
result = @client.execute(uri: url)
if result.status == 200
result.body
else
puts drive_error_string
end
end
|
#download_revision_as_txt(rev) ⇒ Object
44
45
46
|
# File 'lib/gdsh/get_file.rb', line 44
def download_revision_as_txt(rev)
download(txt_link(rev))
end
|
#execute ⇒ Object
57
58
59
60
61
62
63
|
# File 'lib/gdsh/get_file.rb', line 57
def execute
if @revision.nil?
revisions.each { |r| write_to_file(r['id']) }
else
write_to_file(@revision)
end
end
|
#generate_filename_from_revision(revision) ⇒ Object
53
54
55
|
# File 'lib/gdsh/get_file.rb', line 53
def generate_filename_from_revision(revision)
@file_id + '_rev_' + revision + '.txt'
end
|
#puts_downloading_banner(url) ⇒ Object
28
29
30
|
# File 'lib/gdsh/get_file.rb', line 28
def puts_downloading_banner(url)
puts 'Downloading '.colorize(:cyan) + "#{url} ...".colorize(:light_yellow)
end
|
#write_to_file(revision) ⇒ Object
48
49
50
51
|
# File 'lib/gdsh/get_file.rb', line 48
def write_to_file(revision)
filename = generate_filename_from_revision(revision)
File.write(filename, download_revision_as_txt(revision))
end
|