Class: GoogleDrive::AclEntry

Inherits:
Object
  • Object
show all
Includes:
Util
Defined in:
lib/google_drive/acl_entry.rb

Overview

An entry of an ACL (access control list) of a spreadsheet.

Use GoogleDrive::Acl#[] to get GoogleDrive::AclEntry object.

This code is based on github.com/guyboertje/gdata-spreadsheet-ruby .

Constant Summary collapse

PARAM_NAMES =

:nodoc:

[:acl, :scope_type, :scope, :with_key, :role, :title, :edit_url, :etag]

Constants included from Util

Util::DOCS_BASE_URL, Util::EXT_TO_CONTENT_TYPE

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Util

concat_url, encode_query, h, to_v3_url

Constructor Details

#initialize(params) ⇒ AclEntry

params is a Hash object with keys :scope_type, :scope and :role. See scope_type and role for the document of the fields.



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/google_drive/acl_entry.rb', line 22

def initialize(params)
  @params = {:role => "reader"}
  for name, value in params
    if !name.is_a?(Symbol)
      raise(ArgumentError, "Key must be Symbol, but is %p" % name)
    elsif !PARAM_NAMES.include?(name)
      raise(ArgumentError, "Invalid key: %p" % name)
    end
    @params[name] = value
  end
end

Instance Attribute Details

#paramsObject

:nodoc:



34
35
36
# File 'lib/google_drive/acl_entry.rb', line 34

def params
  @params
end

Instance Method Details

#inspectObject



50
51
52
53
# File 'lib/google_drive/acl_entry.rb', line 50

def inspect
  return "\#<%p scope_type=%p, scope=%p, with_key=%p, role=%p>" %
      [self.class, @params[:scope_type], @params[:scope], @params[:with_key], @params[:role]]
end

#role=(role) ⇒ Object

Changes the role of the scope.

e.g.

spreadsheet.acl[1].role = "writer"


46
47
48
# File 'lib/google_drive/acl_entry.rb', line 46

def role=(role)
  @params[:acl].update_role(self, role)
end

#to_xmlObject

:nodoc:



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/google_drive/acl_entry.rb', line 55

def to_xml()  #:nodoc:
  
  etag_attr = self.etag ? "gd:etag='#{h(self.etag)}'" : ""
  value_attr = self.scope ? "value='#{h(self.scope)}'" : ""
  if self.with_key
    role_tag = <<-EOS
        <gAcl:withKey key='[ACL KEY]'>
          <gAcl:role value='#{h(self.role)}'/>
        </gAcl:withKey>
    EOS
  else
    role_tag = <<-EOS
      <gAcl:role value='#{h(self.role)}'/>
    EOS
  end
  
  return <<-EOS
    <entry
        xmlns='http://www.w3.org/2005/Atom'
        xmlns:gAcl='http://schemas.google.com/acl/2007'
        xmlns:gd='http://schemas.google.com/g/2005'
        #{etag_attr}>
      <category scheme='http://schemas.google.com/g/2005#kind'
          term='http://schemas.google.com/acl/2007#accessRule'/>
      #{role_tag}
      <gAcl:scope type='#{h(self.scope_type)}' #{value_attr}/>
    </entry>
  EOS
  
end