Class: Commands::Share
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from DriveError
#drive_error_string
#execute, included
Constructor Details
#initialize(client, params) ⇒ Share
Returns a new instance of Share.
11
12
13
14
15
16
17
18
|
# File 'lib/gdsh/share.rb', line 11
def initialize(client, params)
super(client, params)
@email_list = []
@file_id = @params[1]
@params.drop(2).each do |email|
@email_list << email
end
end
|
Instance Attribute Details
#email_list ⇒ Object
Returns the value of attribute email_list.
5
6
7
|
# File 'lib/gdsh/share.rb', line 5
def email_list
@email_list
end
|
Class Method Details
.parameters ⇒ Object
7
8
9
|
# File 'lib/gdsh/share.rb', line 7
def self.parameters
'(<file_id>[, <email_1>, <email_2>, ...])'
end
|
Instance Method Details
#puts_shared_notification(email, role) ⇒ Object
33
34
35
36
37
38
|
# File 'lib/gdsh/share.rb', line 33
def puts_shared_notification(email, role)
puts "Shared ".colorize(:cyan) + @file_id.colorize(:light_yellow) +
" with ".colorize(:cyan) + email.colorize(:light_yellow) +
" with ".colorize(:cyan) + role_with_colours(role) +
" permissions.".colorize(:cyan)
end
|
#role_with_colours(role) ⇒ Object
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/gdsh/share.rb', line 20
def role_with_colours(role)
case role
when 'reader'
'read-only'.colorize(:green)
when 'writer'
'read-write'.colorize(:blue)
when 'owner'
'owner'.colorize(:magenta)
else
'error'.colorize(:red)
end
end
|
#share_with_email(email, role) ⇒ Object
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/gdsh/share.rb', line 40
def share_with_email(email, role)
drive = @client.discovered_api('drive', 'v2')
new_permission = drive.permissions.insert.request_schema.new(
value: email,
type: 'user',
role: role)
result = @client.execute(
api_method: drive.permissions.insert,
body_object: new_permission,
parameters: { fileId: @file_id })
if result.status == 200
puts_shared_notification(email, role)
return result.data
else
puts drive_error_string
end
end
|
#share_with_email_list(role) ⇒ Object
58
59
60
61
62
63
|
# File 'lib/gdsh/share.rb', line 58
def share_with_email_list(role)
return if @email_list.empty?
@email_list.each do |email|
share_with_email(email, role)
end
end
|