Class: Commands::QueryRevision

Inherits:
Command
  • Object
show all
Includes:
Mime
Defined in:
lib/gdsh/query_revision.rb

Overview

Queries all revisions of a file.

Direct Known Subclasses

GetFile

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Mime

#docx, #html, #jpeg, #ods, #odt, #pdf, #png, #pptx, #rtf, #svg, #txt, #xlsx

Methods included from DriveError

#drive_error_string

Methods included from CommandMixin

included

Constructor Details

#initialize(client, params) ⇒ QueryRevision

Returns a new instance of QueryRevision.



23
24
25
26
# File 'lib/gdsh/query_revision.rb', line 23

def initialize(client, params)
  super(client, params)
  @file_id = params[1]
end

Class Method Details

.command_nameObject



11
12
13
# File 'lib/gdsh/query_revision.rb', line 11

def self.command_name
  'query'
end

.functionObject



19
20
21
# File 'lib/gdsh/query_revision.rb', line 19

def self.function
  'Queries all revisions of a file.'
end

.parametersObject



15
16
17
# File 'lib/gdsh/query_revision.rb', line 15

def self.parameters
  '(<file_id>)'
end

Instance Method Details



61
62
63
# File 'lib/gdsh/query_revision.rb', line 61

def docx_link_label
  'Download docx: '.colorize(:magenta)
end

#executeObject



83
84
85
86
87
88
89
90
# File 'lib/gdsh/query_revision.rb', line 83

def execute
  return if revisions.nil?

  puts_banner
  revisions.each do |r|
    puts_revision_info(r)
  end
end

#modified_date_labelObject



49
50
51
# File 'lib/gdsh/query_revision.rb', line 49

def modified_date_label
  'Modified: '.colorize(:magenta)
end

#modifying_user_labelObject



53
54
55
# File 'lib/gdsh/query_revision.rb', line 53

def modifying_user_label
  'Modifying User: '.colorize(:magenta)
end

#modifying_usersObject



98
99
100
101
102
103
104
# File 'lib/gdsh/query_revision.rb', line 98

def modifying_users
  modifying_hash = {}
  revisions.each do |r|
    modifying_hash[r['id']] = r['lastModifyingUserName']
  end
  modifying_hash
end


57
58
59
# File 'lib/gdsh/query_revision.rb', line 57

def pdf_link_label
  'Download pdf: '.colorize(:magenta)
end

#puts_bannerObject



40
41
42
43
# File 'lib/gdsh/query_revision.rb', line 40

def puts_banner
  puts 'Revisions'.colorize(:magenta)
  puts '---------'.colorize(:magenta)
end


69
70
71
72
73
# File 'lib/gdsh/query_revision.rb', line 69

def puts_download_links(revision)
  puts pdf_link_label + "#{revision['exportLinks'][pdf]}"
  puts docx_link_label + "#{revision['exportLinks'][docx]}"
  puts txt_link_label + "#{revision['exportLinks'][txt]}"
end

#puts_revision_info(revision) ⇒ Object



75
76
77
78
79
80
81
# File 'lib/gdsh/query_revision.rb', line 75

def puts_revision_info(revision)
  puts revision_id_label + "#{revision['id']}"
  puts modified_date_label + "#{revision['modifiedDate']}"
  puts modifying_user_label + "#{revision['lastModifyingUserName']}"
  puts_download_links
  puts ''
end

#revision_id_labelObject



45
46
47
# File 'lib/gdsh/query_revision.rb', line 45

def revision_id_label
  'Revision id: '.colorize(:magenta)
end

#revisionsObject



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/gdsh/query_revision.rb', line 28

def revisions
  drive = @client.discovered_api('drive', 'v2')
  api_result = @client.execute(
    api_method: drive.revisions.list,
    parameters: { 'fileId' => @file_id })
  if api_result.status == 200
    api_result.data.items
  else
    puts drive_error_string
  end
end


92
93
94
95
96
# File 'lib/gdsh/query_revision.rb', line 92

def txt_link(revision)
  rev = revisions.select { |r| r['id'] == revision }
  # should only have one element if revision exists
  rev.first['exportLinks'][txt] unless rev.empty?
end


65
66
67
# File 'lib/gdsh/query_revision.rb', line 65

def txt_link_label
  'Download txt: '.colorize(:magenta)
end