Class: GoogleDrive::Acl

Inherits:
Object
  • Object
show all
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

Util::DOCS_BASE_URL, Util::EXT_TO_CONTENT_TYPE

Instance Method Summary collapse

Methods included from Util

concat_url, encode_query, h, to_v3_url

Constructor Details

#initialize(session, acls_feed_url) ⇒ Acl

:nodoc:



21
22
23
24
25
26
27
# File 'lib/google_drive/acl.rb', line 21

def initialize(session, acls_feed_url) #:nodoc:
  @session = session
  @acls_feed_url = acls_feed_url
  header = {"GData-Version" => "3.0"}
  doc = @session.request(:get, @acls_feed_url, :header => header, :auth => :writely)
  @acls = doc.css("entry").map(){ |e| AclEntry.new(entry_to_params(e)) }
end

Instance Method Details

#delete(entry) ⇒ Object

Deletes an ACL entry.

e.g.

spreadsheet.acl.delete(spreadsheet.acl[1])


67
68
69
70
71
# File 'lib/google_drive/acl.rb', line 67

def delete(entry)
  header = {"GData-Version" => "3.0"}
  @session.request(:delete, entry.edit_url, :header => header, :auth => :writely)
  @acls.delete(entry)
end

#inspectObject



84
85
86
# File 'lib/google_drive/acl.rb', line 84

def inspect
  return "\#<%p %p>" % [self.class, @acls]
end

#push(entry) ⇒ 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.

NOTE: This sends email to the new people.

e.g.

# A specific user can read or write.
spreadsheet.acl.push(
    {:scope_type => "user", :scope => "[email protected]", :role => "reader"})
spreadsheet.acl.push(
    {:scope_type => "user", :scope => "[email protected]", :role => "writer"})
# Publish on the Web.
spreadsheet.acl.push(
    {:scope_type => "default", :role => "reader"})
# Anyone who knows the link can read.
spreadsheet.acl.push(
    {:scope_type => "default", :with_key => true, :role => "reader"})


49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/google_drive/acl.rb', line 49

def push(entry)

  entry = AclEntry.new(entry) if entry.is_a?(Hash)

  header = {"GData-Version" => "3.0", "Content-Type" => "application/atom+xml"}
  doc = @session.request(
      :post, @acls_feed_url, :data => entry.to_xml(), :header => header, :auth => :writely)

  entry.params = entry_to_params(doc.root)
  @acls.push(entry)
  return entry

end

#update_role(entry, role) ⇒ Object

:nodoc:



73
74
75
76
77
78
79
80
81
82
# File 'lib/google_drive/acl.rb', line 73

def update_role(entry, role) #:nodoc:

  header = {"GData-Version" => "3.0", "Content-Type" => "application/atom+xml"}
  doc = @session.request(
      :put, entry.edit_url, :data => entry.to_xml(), :header => header, :auth => :writely)

  entry.params = entry_to_params(doc.root)
  return entry

end