Class: GoogleDrive::Acl
- Inherits:
-
Object
- Object
- GoogleDrive::Acl
- Extended by:
- Forwardable
- Includes:
- Util
- Defined in:
- lib/google_drive/acl.rb
Overview
ACL (access control list) of a spreadsheet.
Use GoogleDrive::Spreadsheet#acl to get GoogleDrive::Acl object. See GoogleDrive::Spreadsheet#acl for usage example.
This code is based on github.com/guyboertje/gdata-spreadsheet-ruby .
Constant Summary
Constants included from Util
Instance Method Summary collapse
-
#delete(entry) ⇒ Object
Deletes an ACL entry.
-
#initialize(session, file) ⇒ Acl
constructor
:nodoc:.
- #inspect ⇒ Object
-
#push(params_or_entry, options = {}) ⇒ Object
Adds a new entry.
-
#update_role(entry) ⇒ Object
:nodoc:.
Methods included from Util
concat_url, construct_and_query, construct_query, convert_params, delegate_api_methods, encode_query, get_singleton_class, h, new_upload_io
Constructor Details
#initialize(session, file) ⇒ Acl
:nodoc:
21 22 23 24 25 26 27 28 |
# File 'lib/google_drive/acl.rb', line 21 def initialize(session, file) #:nodoc: @session = session @file = file api_result = @session.execute!( :api_method => @session.drive..list, :parameters => { "fileId" => @file.id }) @entries = api_result.data.items.map(){ |i| AclEntry.new(i, self) } end |
Instance Method Details
#delete(entry) ⇒ Object
Deletes an ACL entry.
e.g.
spreadsheet.acl.delete(spreadsheet.acl[1])
80 81 82 83 84 85 86 87 88 |
# File 'lib/google_drive/acl.rb', line 80 def delete(entry) @session.execute!( :api_method => @session.drive..delete, :parameters => { "fileId" => @file.id, "permissionId" => entry.id, }) @entries.delete(entry) end |
#inspect ⇒ Object
102 103 104 |
# File 'lib/google_drive/acl.rb', line 102 def inspect return "\#<%p %p>" % [self.class, @entries] end |
#push(params_or_entry, options = {}) ⇒ Object
Adds a new entry. entry
is either a GoogleDrive::AclEntry or a Hash with keys :scope_type, :scope and :role. See GoogleDrive::AclEntry#scope_type and GoogleDrive::AclEntry#role for the document of the fields.
Also you can pass the second hash argument options
, which specifies optional query parameters for the API. Possible keys of options
are,
-
:emailMessage – A custom message to include in notification emails
-
:sendNotificationEmails – Whether to send notification emails when sharing to users or groups.
NOTE: This sends email to the new people.
e.g.
# A specific user can read or write.
spreadsheet.acl.push(
{:type => "user", :value => "[email protected]", :role => "reader"})
spreadsheet.acl.push(
{:type => "user", :value => "[email protected]", :role => "writer"})
# Publish on the Web.
spreadsheet.acl.push(
{:type => "anyone", :role => "reader"})
# Anyone who knows the link can read.
spreadsheet.acl.push(
{:type => "anyone", :withLink => true, :role => "reader"})
# Set ACL without sending notification emails
spreadsheet.acl.push(
{:type => "user", :value => "[email protected]", :role => "reader"},
{:sendNotificationEmails => false})
See here for parameter detais: developers.google.com/drive/v2/reference/permissions/insert
64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/google_drive/acl.rb', line 64 def push(params_or_entry, = {}) entry = params_or_entry.is_a?(AclEntry) ? params_or_entry : AclEntry.new(params_or_entry) = @session.drive..insert.request_schema.new(entry.params) api_result = @session.execute!( :api_method => @session.drive..insert, :body_object => , :parameters => .merge({ "fileId" => @file.id })) new_entry = AclEntry.new(api_result.data, self) @entries.push(new_entry) return new_entry end |
#update_role(entry) ⇒ Object
:nodoc:
90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/google_drive/acl.rb', line 90 def update_role(entry) #:nodoc: api_result = @session.execute!( :api_method => @session.drive..update, :body_object => entry., :parameters => { "fileId" => @file.id, "permissionId" => entry.id, }) entry. = api_result.data return entry end |